Class ItemObject

java.lang.Object
com.saicone.rtag.item.ItemObject

public class ItemObject extends Object
Class to invoke ItemStack methods across versions.
  • Field Details

  • Method Details

    • newItem

      public static Object newItem(Object compound)
      Create ItemStack from CompoundTag.
      Parameters:
      compound - CompoundTag that represent the item.
      Returns:
      A new ItemStack.
    • newCraftItem

      public static ItemStack newCraftItem(ItemStack item)
      Create CraftItemStack from ItemStack object.
      Parameters:
      item - The item to use as constructor parameter.
      Returns:
      A new CraftItemStack.
    • isMinecraftItem

      public static boolean isMinecraftItem(Object object)
      Check if the provided object is instance of Minecraft ItemStack.
      Parameters:
      object - the object to check.
      Returns:
      true if the object is an instance of Minecraft ItemStack.
    • isCraftItem

      public static boolean isCraftItem(Object object)
      Check if the provided object is instance of CraftItemStack.
      Parameters:
      object - the object to check.
      Returns:
      true if the object is an instance of CraftItemStack.
    • isEmpty

      public static boolean isEmpty(Object item)
      Check if the provided Minecraft ItemStack is empty.
      On versions before 1.11 this method only check item count.
      Parameters:
      item - the item to check.
      Returns:
      true if item is empty, false otherwise.
    • hasCustomData

      public static boolean hasCustomData(Object item)
      Check if the provided Minecraft ItemStack has custom data.
      On versions older than 1.20.5 this check item tag.
      Parameters:
      item - the item to check.
      Returns:
      true if the item has custom data.
    • save

      public static Object save(Object item)
      Save current Item tag into new CompoundTag.
      Parameters:
      item - ItemStack instance.
      Returns:
      a compound tag that represent the item.
    • load

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static void load(Object item, Object compound)
      Deprecated.
      Since Minecraft 1.20.5, the safe-way to load data into item is applying a data component patch.
      Load CompoundTag into ItemStack.
      Parameters:
      item - ItemStack instance.
      compound - The CompoundTag to load.
      See Also:
    • loadHandle

      public static void loadHandle(ItemStack item, Object handle)
      Load Minecraft ItemStack handle into Bukkit ItemStack.
      Parameters:
      item - Bukkit ItemStack.
      handle - Minecraft ItemStack.
    • apply

      public static void apply(Object item, Object component)
      Apply data component into ItemStack.
      On versions before 1.20.5 this method load CompoundTag into item.
      Parameters:
      item - ItemStack instance.
      component - The data component to apply into.
    • copy

      public static Object copy(Object item)
      Copy the provided Minecraft ItemStack.
      Parameters:
      item - ItemStack to copy.
      Returns:
      A copy from Minecraft ItemStack.
    • getComponentPath

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static Object[] getComponentPath(Object... path) throws IndexOutOfBoundsException
      Deprecated.
      To get component paths use ItemData.getComponentPath(Object...) instead.
      Convert old tag path into new component path.
      This method skips first key of tag path, it assumes the given path has "tag" at first element
      Returns:
      a new component path representation of tag path.
      Throws:
      IndexOutOfBoundsException - if starting position of source or destination path is out of range.
      See Also:
    • getComponentPath

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static Object[] getComponentPath(int srcPos, int destPos, Object... src) throws IndexOutOfBoundsException
      Deprecated.
      To get component paths use ItemData.getComponentPath(int, int, Object...) instead.
      Convert old tag path into new component path.
      Every component path start with "components" key, if you want to skip that use a destPos of 1.
      Parameters:
      srcPos - starting position in the source path.
      destPos - starting position in the extracted destination data.
      src - the source path array.
      Returns:
      a new component path representation of tag path.
      Throws:
      IndexOutOfBoundsException - if starting position of source or destination path is out of range.
      See Also:
    • getTagPath

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static Object[] getTagPath(Object... path) throws IndexOutOfBoundsException
      Deprecated.
      To get tag paths use ItemData.getTagPath(Object...) instead.
      Convert new component path into old tag path.
      This method skips first key of component path, it assumes the given path has "components" at first element
      Returns:
      an old tag path representation of component path.
      Throws:
      IndexOutOfBoundsException - if starting position of source or destination path is out of range.
      See Also:
    • getTagPath

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static Object[] getTagPath(int srcPos, int destPos, Object... src) throws IndexOutOfBoundsException
      Deprecated.
      To get tag paths use ItemData.getTagPath(int, int, Object...) instead.
      Convert new component path into old tag path.
      Most tag paths start with "tag" key, if you want to skip that use a destPos of 1.
      Parameters:
      srcPos - starting position in the source path.
      destPos - starting position in the extracted destination data.
      src - the source path array.
      Returns:
      an old tag path representation of component path.
      Throws:
      IndexOutOfBoundsException - if starting position of source or destination path is out of range.
      See Also:
    • getCraftStack

      public static ItemStack getCraftStack(ItemStack item)
      Get delegated CraftItemStack from ItemStack object or the object itself if it's already a craft item.
      On non-paper platforms with versions before 1.21 this method will return the provided item if is CraftItemStack instance.
      Parameters:
      item - the Bukkit ItemStack to extract delegated craft item.
      Returns:
      a CraftItemStack instance.
    • getHandle

      public static Object getHandle(ItemStack item)
      Get defined Minecraft ItemStack inside CraftItemStack or create new one.
      Parameters:
      item - Bukkit ItemStack.
      Returns:
      Minecraft ItemStack.
    • getUncheckedHandle

      public static Object getUncheckedHandle(ItemStack item)
      Get defined Minecraft ItemStack inside CraftItemStack.
      Parameters:
      item - A CraftItemStack.
      Returns:
      Minecraft ItemStack or null.
    • getCustomDataTag

      public static Object getCustomDataTag(Object item)
      Get current CompoundTag from custom data component.
      On versions before 1.20.5 this method return item tag.
      Parameters:
      item - ItemStack instance.
      Returns:
      The custom data component inside provided item.
    • getTag

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static Object getTag(Object item)
      Deprecated.
      To get item tag-like data use getCustomDataTag(Object) instead.
      Get current CompoundTag.
      Parameters:
      item - ItemStack instance.
      Returns:
      The CompoundTag inside provided item.
      See Also:
    • setHandle

      public static void setHandle(ItemStack item, Object handle)
      Replace defined Minecraft ItemStack inside CraftItemStack or load changes into Bukkit ItemStack.
      Parameters:
      item - Bukkit ItemStack.
      handle - Minecraft ItemStack.
    • setCustomDataTag

      public static void setCustomDataTag(Object item, Object tag)
      Overwrite current custom data component.
      On versions before 1.20.5 this method replace item tag.
      Parameters:
      item - ItemStack instance.
      tag - CompoundTag to put into custom data component.
    • setTag

      @ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static void setTag(Object item, Object tag)
      Deprecated.
      To set item tag-like data use setCustomDataTag(Object, Object) instead.
      Overwrite current CompoundTag.
      Parameters:
      item - ItemStack instance.
      tag - CompoundTag to put into item.
      See Also:
    • asBukkitCopy

      public static ItemStack asBukkitCopy(Object item)
      Convert Minecraft ItemStack into Bukkit ItemStack.
      Take in count this method creates a new ItemStack instance.
      Parameters:
      item - Minecraft ItemStack.
      Returns:
      Bukkit ItemStack.
    • asCraftMirror

      public static ItemStack asCraftMirror(Object item)
      Convert Minecraft ItemStack into Bukkit ItemStack.
      Take in count this method creates a new CraftItemStack instance.
      Parameters:
      item - Minecraft ItemStack.
      Returns:
      Bukkit ItemStack.
    • asNMSCopy

      public static Object asNMSCopy(ItemStack item)
      Convert Bukkit ItemStack into Minecraft ItemStack.
      Take in count this method copy the original ItemStack
      Parameters:
      item - Bukkit ItemStack.
      Returns:
      Minecraft ItemStack.