Class ItemObject
java.lang.Object
com.saicone.rtag.item.ItemObject
Class to invoke ItemStack methods across versions.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidApply data component into ItemStack.
On versions before 1.20.5 this method load CompoundTag into item.static ItemStackasBukkitCopy(Object item) Convert Minecraft ItemStack into Bukkit ItemStack.
Take in count this method creates a new ItemStack instance.static ItemStackasCraftMirror(Object item) Convert Minecraft ItemStack into Bukkit ItemStack.
Take in count this method creates a new CraftItemStack instance.static ObjectConvert Bukkit ItemStack into Minecraft ItemStack.
Take in count this method copy the original ItemStackstatic ObjectCopy the provided Minecraft ItemStack.static Object[]getComponentPath(int srcPos, int destPos, Object... src) Deprecated.static Object[]getComponentPath(Object... path) Deprecated.To get component paths useItemData.getComponentPath(Object...)instead.static ItemStackgetCraftStack(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.static ObjectgetCustomDataTag(Object item) Get current CompoundTag from custom data component.
On versions before 1.20.5 this method return item tag.static ObjectGet defined Minecraft ItemStack inside CraftItemStack or create new one.static ObjectDeprecated.To get item tag-like data usegetCustomDataTag(Object)instead.static Object[]getTagPath(int srcPos, int destPos, Object... src) Deprecated.To get tag paths useItemData.getTagPath(int, int, Object...)instead.static Object[]getTagPath(Object... path) Deprecated.To get tag paths useItemData.getTagPath(Object...)instead.static ObjectgetUncheckedHandle(ItemStack item) Get defined Minecraft ItemStack inside CraftItemStack.static booleanhasCustomData(Object item) Check if the provided Minecraft ItemStack has custom data.
On versions older than 1.20.5 this check item tag.static booleanisCraftItem(Object object) Check if the provided object is instance of CraftItemStack.static booleanCheck if the provided Minecraft ItemStack is empty.
On versions before 1.11 this method only check item count.static booleanisMinecraftItem(Object object) Check if the provided object is instance of Minecraft ItemStack.static voidDeprecated.Since Minecraft 1.20.5, the safe-way to load data into item is applying a data component patch.static voidloadHandle(ItemStack item, Object handle) Load Minecraft ItemStack handle into Bukkit ItemStack.static ItemStacknewCraftItem(ItemStack item) Create CraftItemStack from ItemStack object.static ObjectCreate ItemStack from CompoundTag.static ObjectSave current Item tag into new CompoundTag.static voidsetCustomDataTag(Object item, Object tag) Overwrite current custom data component.
On versions before 1.20.5 this method replace item tag.static voidReplace defined Minecraft ItemStack inside CraftItemStack or load changes into Bukkit ItemStack.static voidDeprecated.To set item tag-like data usesetCustomDataTag(Object, Object)instead.
-
Field Details
-
CODEC
ItemStack codec.
-
-
Method Details
-
newItem
-
newCraftItem
-
isMinecraftItem
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
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
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
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
-
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
-
apply
-
copy
-
getComponentPath
@ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static Object[] getComponentPath(Object... path) throws IndexOutOfBoundsException Deprecated.To get component paths useItemData.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 useItemData.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 useItemData.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 useItemData.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
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
-
getUncheckedHandle
-
getCustomDataTag
-
getTag
Deprecated.To get item tag-like data usegetCustomDataTag(Object)instead.Get current CompoundTag.- Parameters:
item- ItemStack instance.- Returns:
- The CompoundTag inside provided item.
- See Also:
-
setHandle
-
setCustomDataTag
-
setTag
@ScheduledForRemoval(inVersion="1.6.0") @Deprecated public static void setTag(Object item, Object tag) Deprecated.To set item tag-like data usesetCustomDataTag(Object, Object)instead.Overwrite current CompoundTag.- Parameters:
item- ItemStack instance.tag- CompoundTag to put into item.- See Also:
-
asBukkitCopy
-
asCraftMirror
-
asNMSCopy
-
ItemData.getComponentPath(int, int, Object...)instead.