Class ItemStack
- All Implemented Interfaces:
- DataComponentHolder,- DataComponentView,- PersistentDataViewHolder,- Cloneable,- HoverEventSource<HoverEvent.ShowItem>,- Translatable,- ConfigurationSerializable,- Translatable
 IMPORTANT: An ItemStack is only designed to contain items. Do not
 use this class to encapsulate Materials for which Material.isItem()
 returns false.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedDefaults stack size to 1, with no extra data.An item stack with no extra data.Deprecated.Deprecated, for removal: This API element is subject to removal in a future version.this method uses an ambiguous data byte objectCreates a new item stack derived from the specified stack
- 
Method SummaryModifier and TypeMethodDescriptionadd()Adds 1 to this itemstack.add(int qty) Adds quantity to this itemstack.voidaddEnchantment(@NotNull Enchantment enchant, int level) Adds the specifiedEnchantmentto this item stack.voidaddEnchantments(@NotNull Map<Enchantment, Integer> enchantments) Adds the specified enchantments to this item stack.voidaddItemFlags(@NotNull ItemFlag... itemFlags) Set itemflags which should be ignored when rendering a ItemStack in the Client.voidaddUnsafeEnchantment(@NotNull Enchantment enchant, int level) Adds the specifiedEnchantmentto this item stack.voidaddUnsafeEnchantments(@NotNull Map<Enchantment, Integer> enchantments) Adds the specified enchantments to this item stack in an unsafe manner.Creates a hover event with value derived from this object.asOne()Clones the itemstack and returns it a single quantity.asQuantity(int qty) Clones the itemstack and returns it as the specified quantitybooleanChecks if this itemstack can repair another.clone()computeTooltipLines(TooltipContext tooltipContext, Player player) Computes the tooltip lines for this stack.booleancontainsEnchantment(@NotNull Enchantment enchant) Checks if this ItemStack contains the givenEnchantmentvoidcopyDataFrom(@NotNull ItemStack source, @NotNull Predicate<@NotNull DataComponentType> filter) Copies component values and component removals from the provided ItemStack.damage(int amount, LivingEntity livingEntity) Damages this itemstack by the specified amount.deserialize(@NotNull Map<String, Object> args) Required method for configuration serializationdeserializeBytes(byte @NotNull [] bytes) Deserializes this itemstack from raw NBT bytes.deserializeItemsFromBytes(byte @NotNull [] bytes) Deserializes this itemstack from raw NBT bytes.Get the formatted display name of theItemStack.<M extends ItemMeta>
 booleanEdits theItemMetaof this stack if the meta is of the specified type.booleanEdits theItemMetaof this stack.booleanEdits thePersistentDataContainerof this stack.Gets the effective name of this item stack shown to player in inventory.empty()Returns an empty item stack, consists of an air material and a stack size of 0.enchantWithLevels(int levels, boolean allowTreasure, Random random) Randomly enchants a copy of thisItemStackusing the given experience levels.enchantWithLevels(int levels, RegistryKeySet<@NotNull Enchantment> keySet, Random random) Randomly enchants a copy of thisItemStackusing the given experience levels.Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks.booleanintGets the amount of items in this stackgetData()Deprecated, for removal: This API element is subject to removal in a future version.cast toBlockDataMetaand useBlockDataMeta.getBlockData(Material)<T> TgetData(@NotNull DataComponentType.Valued<T> type) Gets the value for the data component type on this stack.<T> TgetDataOrDefault(@NotNull DataComponentType.Valued<? extends T> type, T fallback) Gets the value for the data component type on this stack with a fallback value.Gets all the data component types set on this stack.shortDeprecated.intgetEnchantmentLevel(@NotNull Enchantment enchant) Gets the level of the specified enchantment on this item stackGets a map containing all enchantments and their levels on this item.Deprecated.ItemStackimplementsTranslatable; use that andComponent.translatable(net.kyori.adventure.translation.Translatable)instead.Get current set itemFlags.Get a copy of this ItemStack'sItemMeta.getLore()Deprecated.in favor oflore()intDeprecated, for removal: This API element is subject to removal in a future version.usegetMaxItemUseDuration(org.bukkit.entity.LivingEntity); crossbows, later possibly more items require an entity parameterintgetMaxItemUseDuration(LivingEntity entity) intGet the maximum stack size for this item.Returns a custom tag container view capable of viewing tags on the object.Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.getType()Gets the type of this itembooleanhasData(@NotNull DataComponentType type) Checks if the data component type is set on the itemstack.inthashCode()booleanhasItemFlag(@NotNull ItemFlag flag) Check if the specified flag is present on this item.booleanChecks to see if any meta data has been defined.booleanChecks if the data component type is overridden from the default for the item type.booleanisEmpty()Returns whether this item stack is empty and contains no item.booleanisRepairableBy(@NotNull ItemStack repairMaterial) Checks if an itemstack can repair this itemstack.booleanThis method is the same as equals, but does not consider stack size (amount).lore()If the item has lore, returns it, else it will return nullvoidSets the lore for this item.booleanmatchesWithoutData(@NotNull ItemStack item, Set<@NotNull DataComponentType> excludeTypes) Checks if this itemstack matches another given itemstack excluding the provided components.booleanmatchesWithoutData(@NotNull ItemStack item, Set<@NotNull DataComponentType> excludeTypes, boolean ignoreCount) Checks if this itemstack matches another given itemstack excluding the provided components.Creates an itemstack with the specified item type and a count of 1.Creates an itemstack with the specified item type and count.intremoveEnchantment(@NotNull Enchantment enchant) Removes the specifiedEnchantmentif it exists on this ItemStackvoidRemoves all enchantments on this ItemStack.voidremoveItemFlags(@NotNull ItemFlag... itemFlags) Remove specific set of itemFlags.voidResets the value of this component to be the default value for the item type fromMaterial.getDefaultData(io.papermc.paper.datacomponent.DataComponentType.Valued).Creates a Map representation of this class.byte @NotNull []Serializes this itemstack to raw bytes in NBT.static byte @NotNull []Serializes a collection of items to raw bytes in NBT.static byte @NotNull []serializeItemsAsBytes(@Nullable ItemStack @NotNull [] items) Serializes a collection of items to raw bytes in NBT.voidsetAmount(int amount) Sets the amount of items in this stackvoidMarks this non-valued data component type as present in this itemstack.<T> voidsetData(@NotNull DataComponentType.Valued<T> type, DataComponentBuilder<T> valueBuilder) Sets the value of the data component type for this itemstack.<T> voidsetData(@NotNull DataComponentType.Valued<T> type, T value) Sets the value of the data component type for this itemstack.voidsetData(@Nullable MaterialData data) Deprecated, for removal: This API element is subject to removal in a future version.voidsetDurability(short durability) Deprecated.durability is now part of ItemMeta.booleansetItemMeta(@Nullable ItemMeta itemMeta) Set the ItemMeta of this ItemStack.voidDeprecated.in favour oflore(java.util.List)voidDeprecated.Setting the material type of ItemStacks is no longer supported.subtract()Subtracts 1 to this itemstack.subtract(int qty) Subtracts quantity to this itemstack.toString()Gets the translation key.voidMarks this data component as removed for this itemstack.Creates a new ItemStack with the specified Material type, where the item count and item meta is preserved.Methods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface net.kyori.adventure.text.event.HoverEventSourceasHoverEvent
- 
Constructor Details- 
ItemStackprotected ItemStack()
- 
ItemStackDefaults stack size to 1, with no extra data.IMPORTANT: An ItemStack is only designed to contain items. Do not use this class to encapsulate Materials for which Material.isItem()returns false.- Parameters:
- type- item material
- See Also:
- API Note:
- use of(Material)
 
- 
ItemStackAn item stack with no extra data.IMPORTANT: An ItemStack is only designed to contain items. Do not use this class to encapsulate Materials for which Material.isItem()returns false.- Parameters:
- type- item material
- amount- stack size
- See Also:
- API Note:
- Use of(Material, int)
 
- 
ItemStack@Deprecated(since="1.20.5") public ItemStack(@NotNull @NotNull Material type, int amount, short damage) Deprecated.An item stack with the specified damage / durability- Parameters:
- type- item material
- amount- stack size
- damage- durability / damage
 
- 
ItemStack@Deprecated(since="1.4.5", forRemoval=true) public ItemStack(@NotNull @NotNull Material type, int amount, short damage, @Nullable @Nullable Byte data) Deprecated, for removal: This API element is subject to removal in a future version.this method uses an ambiguous data byte object- Parameters:
- type- the type
- amount- the amount in the stack
- damage- the damage value of the item
- data- the data value or null
 
- 
ItemStack@Obsolete(since="1.21") public ItemStack(@NotNull @NotNull ItemStack stack) throws IllegalArgumentException Creates a new item stack derived from the specified stack- Parameters:
- stack- the stack to copy
- Throws:
- IllegalArgumentException- if the specified stack is null or returns an item meta not created by the item factory
- See Also:
- API Note:
- Use clone()
 
 
- 
- 
Method Details- 
of@Contract(value="_ -> new", pure=true) @NotNull public static @NotNull ItemStack of(@NotNull @NotNull Material type) Creates an itemstack with the specified item type and a count of 1.- Parameters:
- type- the item type to use
- Returns:
- a new itemstack
- Throws:
- IllegalArgumentException- if the Material provided is not an item (- Material.isItem())
 
- 
of@Contract(value="_, _ -> new", pure=true) @NotNull public static @NotNull ItemStack of(@NotNull @NotNull Material type, int amount) Creates an itemstack with the specified item type and count.- Parameters:
- type- the item type to use
- amount- the count of items in the stack
- Returns:
- a new itemstack
- Throws:
- IllegalArgumentException- if the Material provided is not an item (- Material.isItem())
- IllegalArgumentException- if the amount is less than 1
 
- 
getPersistentDataContainerDescription copied from interface:PersistentDataViewHolderReturns a custom tag container view capable of viewing tags on the object.Note that the tags stored on this container are all stored under their own custom namespace therefore modifying default tags using this PersistentDataViewHolderis impossible.- Specified by:
- getPersistentDataContainerin interface- PersistentDataViewHolder
- Returns:
- the persistent data container view
- See Also:
 
- 
editPersistentDataContainerpublic boolean editPersistentDataContainer(@NotNull @NotNull Consumer<PersistentDataContainer> consumer) Edits thePersistentDataContainerof this stack. ThePersistentDataContainerinstance is only valid inside the consumer.- Parameters:
- consumer- the persistent data container consumer
- Returns:
- trueif the edit was successful,- falseotherwise. Failure to edit the persistent data container may be caused by empty or invalid itemstacks.
 
- 
getTypeGets the type of this item- Returns:
- Type of the items in this stack
 
- 
setTypeDeprecated.Setting the material type of ItemStacks is no longer supported.This method is deprecated due to potential illegal behavior that may occur during the context of which this ItemStack is being used, allowing for certain item validation to be bypassed. It is recommended to instead create a new ItemStack object with the desired Material type, and if possible, set it in the appropriate context. Using this method in ItemStacks passed in events will result in undefined behavior. Sets the type of this itemNote that in doing so you will reset the MaterialData for this stack. IMPORTANT: An ItemStack is only designed to contain items. Do not use this class to encapsulate Materials for which Material.isItem()returns false.- Parameters:
- type- New type to set the items in this stack to
- See Also:
 
- 
withType@NotNull @Contract(value="_ -> new", pure=true) public @NotNull ItemStack withType(@NotNull @NotNull Material type) Creates a new ItemStack with the specified Material type, where the item count and item meta is preserved.- Parameters:
- type- The Material type of the new ItemStack.
- Returns:
- A new ItemStack instance with the specified Material type.
 
- 
getAmountpublic int getAmount()Gets the amount of items in this stack- Returns:
- Amount of items in this stack
 
- 
setAmountpublic void setAmount(int amount) Sets the amount of items in this stack- Parameters:
- amount- New amount of items in this stack
 
- 
getDataDeprecated, for removal: This API element is subject to removal in a future version.cast toBlockDataMetaand useBlockDataMeta.getBlockData(Material)Gets the MaterialData for this stack of items- Returns:
- MaterialData for this item
 
- 
setData@Deprecated(forRemoval=true, since="1.13") public void setData(@Nullable @Nullable MaterialData data) Deprecated, for removal: This API element is subject to removal in a future version.Sets the MaterialData for this stack of items- Parameters:
- data- New MaterialData for this item
 
- 
setDurabilityDeprecated.durability is now part of ItemMeta. To avoid confusion and misuse,getItemMeta(),setItemMeta(ItemMeta)andDamageable.setDamage(int)should be used instead. This is because any call to this method will be overwritten by subsequent setting of ItemMeta which was created before this call.Sets the durability of this item- Parameters:
- durability- Durability of this item
 
- 
getDurabilityDeprecated.Gets the durability of this item- Returns:
- Durability of this item
 
- 
getMaxStackSizepublic int getMaxStackSize()Get the maximum stack size for this item. If this item has a max stack size component (ItemMeta.hasMaxStackSize()), the value of that component will be returned. Otherwise, this item's Material'sdefault maximum stack sizewill be returned instead.- Returns:
- The maximum you can stack this item to.
 
- 
toString
- 
equals
- 
isSimilarThis method is the same as equals, but does not consider stack size (amount).- Parameters:
- stack- the item stack to compare to
- Returns:
- true if the two stacks are equal, ignoring the amount
 
- 
clone
- 
hashCodepublic int hashCode()
- 
containsEnchantmentChecks if this ItemStack contains the givenEnchantment- Parameters:
- enchant- Enchantment to test
- Returns:
- True if this has the given enchantment
 
- 
getEnchantmentLevelGets the level of the specified enchantment on this item stack- Parameters:
- enchant- Enchantment to check
- Returns:
- Level of the enchantment, or 0
 
- 
getEnchantmentsGets a map containing all enchantments and their levels on this item.- Returns:
- Map of enchantments.
 
- 
addEnchantmentsAdds the specified enchantments to this item stack.This method is the same as calling addEnchantment(org.bukkit.enchantments.Enchantment, int)for each element of the map.- Parameters:
- enchantments- Enchantments to add
- Throws:
- IllegalArgumentException- if the specified enchantments is null
- IllegalArgumentException- if any specific enchantment or level is null. Warning: Some enchantments may be added before this exception is thrown.
 
- 
addEnchantmentAdds the specifiedEnchantmentto this item stack.If this item stack already contained the given enchantment (at any level), it will be replaced. - Parameters:
- enchant- Enchantment to add
- level- Level of the enchantment
- Throws:
- IllegalArgumentException- if enchantment null, or enchantment is not applicable
 
- 
addUnsafeEnchantmentsAdds the specified enchantments to this item stack in an unsafe manner.This method is the same as calling addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int)for each element of the map.- Parameters:
- enchantments- Enchantments to add
 
- 
addUnsafeEnchantmentAdds the specifiedEnchantmentto this item stack.If this item stack already contained the given enchantment (at any level), it will be replaced. This method is unsafe and will ignore level restrictions or item type. Use at your own discretion. - Parameters:
- enchant- Enchantment to add
- level- Level of the enchantment
 
- 
removeEnchantmentRemoves the specifiedEnchantmentif it exists on this ItemStack- Parameters:
- enchant- Enchantment to remove
- Returns:
- Previous level, or 0
 
- 
removeEnchantmentspublic void removeEnchantments()Removes all enchantments on this ItemStack.
- 
serializeDescription copied from interface:ConfigurationSerializableCreates a Map representation of this class.This class must provide a method to restore this class, as defined in the ConfigurationSerializableinterface javadocs. nb: It is not intended for this method to be called directly, this will be called by theConfigurationSerializationclass.- Specified by:
- serializein interface- ConfigurationSerializable
- Returns:
- Map containing the current state of this class
 
- 
deserializeRequired method for configuration serialization- Parameters:
- args- map to deserialize
- Returns:
- deserialized item stack
- See Also:
 
- 
editMetaEdits theItemMetaof this stack.The Consumermust only interact with this stack'sItemMetathrough the providedItemMetainstance. Calling this method or any other meta-related method of theItemStackclass (such asgetItemMeta(),addItemFlags(ItemFlag...),lore(), etc.) from inside the consumer is disallowed and will produce undefined results or exceptions.- Parameters:
- consumer- the meta consumer
- Returns:
- trueif the edit was successful,- falseotherwise
 
- 
editMetapublic <M extends ItemMeta> boolean editMeta(@NotNull @NotNull Class<M> metaClass, @NotNull Consumer<@NotNull ? super M> consumer) Edits theItemMetaof this stack if the meta is of the specified type.The Consumermust only interact with this stack'sItemMetathrough the providedItemMetainstance. Calling this method or any other meta-related method of theItemStackclass (such asgetItemMeta(),addItemFlags(ItemFlag...),lore(), etc.) from inside the consumer is disallowed and will produce undefined results or exceptions.- Type Parameters:
- M- the meta type
- Parameters:
- metaClass- the type of meta to edit
- consumer- the meta consumer
- Returns:
- trueif the edit was successful,- falseotherwise
 
- 
getItemMetaGet a copy of this ItemStack'sItemMeta.- Returns:
- a copy of the current ItemStack's ItemData
 
- 
hasItemMetapublic boolean hasItemMeta()Checks to see if any meta data has been defined.- Returns:
- Returns true if some meta data has been set for this item
 
- 
setItemMetaSet the ItemMeta of this ItemStack.- Parameters:
- itemMeta- new ItemMeta, or null to indicate meta data be cleared.
- Returns:
- True if successfully applied ItemMeta, see ItemFactory.isApplicable(ItemMeta, ItemStack)
- Throws:
- IllegalArgumentException- if the item meta was not created by the- ItemFactory
 
- 
getTranslationKeyDeprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:TranslatableGet the translation key, suitable for use in a translation component.- Specified by:
- getTranslationKeyin interface- Translatable
- Returns:
- the translation key
 
- 
enchantWithLevels@NotNull public @NotNull ItemStack enchantWithLevels(int levels, boolean allowTreasure, @NotNull Random random) Randomly enchants a copy of thisItemStackusing the given experience levels.If this ItemStack is already enchanted, the existing enchants will be removed before enchanting. Enchantment tables use levels in the range [1, 30].- Parameters:
- levels- levels to use for enchanting
- allowTreasure- whether to allow enchantments where- Enchantment.isTreasure()returns true
- random-- Randominstance to use for enchanting
- Returns:
- enchanted copy of the provided ItemStack
- Throws:
- IllegalArgumentException- on bad arguments
 
- 
enchantWithLevels@NotNull public @NotNull ItemStack enchantWithLevels(int levels, @NotNull RegistryKeySet<@NotNull Enchantment> keySet, @NotNull Random random) Randomly enchants a copy of thisItemStackusing the given experience levels.If the provided ItemStack is already enchanted, the existing enchants will be removed before enchanting. Enchantment tables use levels in the range [1, 30].- Parameters:
- levels- levels to use for enchanting
- keySet- registry key set defining the set of possible enchantments, e.g.- EnchantmentTagKeys.IN_ENCHANTING_TABLE.
- random-- Randominstance to use for enchanting
- Returns:
- enchanted copy of the provided ItemStack
- Throws:
- IllegalArgumentException- on bad arguments
 
- 
asHoverEvent@NotNull public HoverEvent<HoverEvent.ShowItem> asHoverEvent(@NotNull UnaryOperator<HoverEvent.ShowItem> op) Creates a hover event with value derived from this object.The event value will be passed through the provided callback to allow transforming the original value of the event. - Specified by:
- asHoverEventin interface- HoverEventSource<HoverEvent.ShowItem>
- Parameters:
- op- transformation on value
- Returns:
- a hover event
- Throws:
- IllegalArgumentException- if the- getAmount()is not between 1 and 99
 
- 
displayNameGet the formatted display name of theItemStack.- Returns:
- display name of the ItemStack
- API Note:
- this component include a item hover event. When used in chat, make sure to follow the ItemStack rules regarding amount, type, and other properties.
 
- 
effectiveNameGets the effective name of this item stack shown to player in inventory. It takes into account the display name (with italics) from the item meta, the potion effect, translatable name, rarity etc.- Returns:
- the effective name of this item stack
 
- 
ensureServerConversionsMinecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks. Use this method to ensure any desired data conversions are processed. The input itemstack will not be the same as the returned itemstack.- Returns:
- A potentially Data Converted ItemStack
 
- 
deserializeBytesDeserializes this itemstack from raw NBT bytes. NBT is safer for data migrations as it will use the built in data converter instead of bukkits dangerous serialization system. This expects that the DataVersion was stored on the root of the Compound, as saved from theserializeAsBytes()API returned.- Parameters:
- bytes- bytes representing an item in NBT
- Returns:
- ItemStack migrated to this version of Minecraft if needed.
 
- 
serializeAsBytesSerializes this itemstack to raw bytes in NBT. NBT is safer for data migrations as it will use the built in data converter instead of bukkits dangerous serialization system.- Returns:
- bytes representing this item in NBT.
 
- 
serializeItemsAsBytesSerializes a collection of items to raw bytes in NBT. Serializes null items asempty().If you need a string representation to put into a file, you can for example use Base64encoding.- Parameters:
- items- items to serialize
- Returns:
- bytes representing the items in NBT
- See Also:
 
- 
serializeItemsAsBytespublic static byte @NotNull [] serializeItemsAsBytes(@Nullable @Nullable ItemStack @NotNull [] items) Serializes a collection of items to raw bytes in NBT. Serializes null items asempty().If you need a string representation to put into a file, you can for example use Base64encoding.- Parameters:
- items- items to serialize
- Returns:
- bytes representing the items in NBT
- See Also:
 
- 
deserializeItemsFromBytes@NotNull public static @NotNull ItemStack @NotNull [] deserializeItemsFromBytes(byte @NotNull [] bytes) Deserializes this itemstack from raw NBT bytes.If you need a string representation to put into a file, you can for example use Base64encoding.- Parameters:
- bytes- bytes representing an item in NBT
- Returns:
- ItemStack array migrated to this version of Minecraft if needed
- See Also:
 
- 
getI18NDisplayNameDeprecated.ItemStackimplementsTranslatable; use that andComponent.translatable(net.kyori.adventure.translation.Translatable)instead.Gets the Display name as seen in the Client. Currently the server only supports the English language. To override this, You must replace the language file embedded in the server jar.- Returns:
- Display name of Item
 
- 
getMaxItemUseDurationDeprecated, for removal: This API element is subject to removal in a future version.usegetMaxItemUseDuration(org.bukkit.entity.LivingEntity); crossbows, later possibly more items require an entity parameter
- 
getMaxItemUseDuration
- 
asOneClones the itemstack and returns it a single quantity.- Returns:
- The new itemstack with 1 quantity
 
- 
asQuantityClones the itemstack and returns it as the specified quantity- Parameters:
- qty- The quantity of the cloned item
- Returns:
- The new itemstack with specified quantity
 
- 
addAdds 1 to this itemstack. Will not go over the items max stack size.- Returns:
- The same item (not a clone)
 
- 
addAdds quantity to this itemstack. Will not go over the items max stack size.- Parameters:
- qty- The amount to add
- Returns:
- The same item (not a clone)
 
- 
subtractSubtracts 1 to this itemstack. Going to 0 or less will invalidate the item.- Returns:
- The same item (not a clone)
 
- 
subtractSubtracts quantity to this itemstack. Going to 0 or less will invalidate the item.- Parameters:
- qty- The amount to add
- Returns:
- The same item (not a clone)
 
- 
getLoreDeprecated.in favor oflore()If the item has lore, returns it, else it will return null- Returns:
- The lore, or null
 
- 
loreIf the item has lore, returns it, else it will return null- Returns:
- The lore, or null
 
- 
setLoreDeprecated.in favour oflore(java.util.List)Sets the lore for this item. Removes lore when given null.- Parameters:
- lore- the lore that will be set
 
- 
loreSets the lore for this item. Removes lore when given null.- Parameters:
- lore- the lore that will be set
 
- 
addItemFlagsSet itemflags which should be ignored when rendering a ItemStack in the Client. This Method does silently ignore double set itemFlags.- Parameters:
- itemFlags- The hideflags which shouldn't be rendered
 
- 
removeItemFlagsRemove specific set of itemFlags. This tells the Client it should render it again. This Method does silently ignore double removed itemFlags.- Parameters:
- itemFlags- Hideflags which should be removed
 
- 
getItemFlagsGet current set itemFlags. The collection returned is unmodifiable.- Returns:
- A set of all itemFlags set
 
- 
hasItemFlagCheck if the specified flag is present on this item.- Parameters:
- flag- the flag to check
- Returns:
- if it is present
 
- 
translationKeyGets the translation key.This is not the same as getting the translation key for the material of this itemstack. - Specified by:
- translationKeyin interface- Translatable
- Returns:
- the translation key
 
- 
getRarityDeprecated, for removal: This API element is subject to removal in a future version.Gets the item rarity of the itemstack. The rarity can change based on enchantments.- Returns:
- the itemstack rarity
 
- 
isRepairableByChecks if an itemstack can repair this itemstack. Returns false ifthisorrepairMaterial's type is not an item (Material.isItem()).- Parameters:
- repairMaterial- the repair material
- Returns:
- true if it is repairable by, false if not
 
- 
canRepairChecks if this itemstack can repair another. Returns false ifthisortoBeRepaired's type is not an item (Material.isItem()).- Parameters:
- toBeRepaired- the itemstack to be repaired
- Returns:
- true if it can repair, false if not
 
- 
damageDamages this itemstack by the specified amount. This runs all logic associated with damaging an itemstack like events and stat changes.- Parameters:
- amount- the amount of damage to do
- livingEntity- the entity related to the damage
- Returns:
- the damaged itemstack or an empty one if it broke. May return the same instance of ItemStack
- See Also:
 
- 
emptyReturns an empty item stack, consists of an air material and a stack size of 0. Any item stack with a material of air or a stack size of 0 is seen as being empty byisEmpty().
- 
isEmptypublic boolean isEmpty()Returns whether this item stack is empty and contains no item. This means it is either air or the stack has a size of 0.
- 
computeTooltipLinespublic @NotNull @Unmodifiable List<Component> computeTooltipLines(@NotNull TooltipContext tooltipContext, @Nullable Player player) Computes the tooltip lines for this stack.Disclaimer: Tooltip contents are not guaranteed to be consistent across different Minecraft versions. - Parameters:
- tooltipContext- the tooltip context
- player- a player for player-specific tooltip lines
- Returns:
- an immutable list of components (can be empty)
 
- 
getData@Contract(pure=true) @Experimental @Nullable public <T> T getData(@NotNull DataComponentType.Valued<T> type) Gets the value for the data component type on this stack.- Specified by:
- getDatain interface- DataComponentView
- Type Parameters:
- T- the value type
- Parameters:
- type- the data component type
- Returns:
- the value for the data component type, or nullif not set or marked as removed
- See Also:
 
- 
getDataOrDefault@Contract(value="_, !null -> !null", pure=true) @Experimental @Nullable public <T> T getDataOrDefault(@NotNull DataComponentType.Valued<? extends T> type, @Nullable T fallback) Gets the value for the data component type on this stack with a fallback value.- Specified by:
- getDataOrDefaultin interface- DataComponentView
- Type Parameters:
- T- the value type
- Parameters:
- type- the data component type
- fallback- the fallback value if the value isn't present
- Returns:
- the value for the data component type or the fallback value
 
- 
hasDataChecks if the data component type is set on the itemstack.- Specified by:
- hasDatain interface- DataComponentView
- Parameters:
- type- the data component type
- Returns:
- trueif set,- falseotherwise
 
- 
getDataTypes@Contract("-> new") @Experimental public @Unmodifiable Set<@NotNull DataComponentType> getDataTypes()Gets all the data component types set on this stack.- Returns:
- an immutable set of data component types
 
- 
setData@Experimental public <T> void setData(@NotNull DataComponentType.Valued<T> type, @NotNull DataComponentBuilder<T> valueBuilder) Sets the value of the data component type for this itemstack. To reset the value to the default for theitem type, useresetData(io.papermc.paper.datacomponent.DataComponentType). To mark the data component type as removed, useunsetData(io.papermc.paper.datacomponent.DataComponentType).- Specified by:
- setDatain interface- DataComponentHolder
- Type Parameters:
- T- value type
- Parameters:
- type- the data component type
- valueBuilder- value builder
 
- 
setDataSets the value of the data component type for this itemstack. To reset the value to the default for theitem type, useresetData(io.papermc.paper.datacomponent.DataComponentType). To mark the data component type as removed, useunsetData(io.papermc.paper.datacomponent.DataComponentType).- Specified by:
- setDatain interface- DataComponentHolder
- Type Parameters:
- T- value type
- Parameters:
- type- the data component type
- value- value to set
 
- 
setDataMarks this non-valued data component type as present in this itemstack.- Specified by:
- setDatain interface- DataComponentHolder
- Parameters:
- type- the data component type
 
- 
unsetDataMarks this data component as removed for this itemstack.- Parameters:
- type- the data component type
 
- 
resetDataResets the value of this component to be the default value for the item type fromMaterial.getDefaultData(io.papermc.paper.datacomponent.DataComponentType.Valued).- Parameters:
- type- the data component type
 
- 
copyDataFrom@Experimental public void copyDataFrom(@NotNull @NotNull ItemStack source, @NotNull @NotNull Predicate<@NotNull DataComponentType> filter) Copies component values and component removals from the provided ItemStack.Example: Set<DataComponentType> types = Set.of( DataComponentTypes.CONSUMABLE, DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, DataComponentTypes.RARITY ); ItemStack source = ItemStack.of(Material.ENCHANTED_GOLDEN_APPLE); ItemStack target = ItemStack.of(Material.GOLDEN_CARROT); target.copyDataFrom(source, types::contains);- Parameters:
- source- the item stack to copy from
- filter- predicate for which components to copy
 
- 
isDataOverriddenChecks if the data component type is overridden from the default for the item type.- Parameters:
- type- the data component type
- Returns:
- trueif the data type is overridden
 
- 
matchesWithoutData@Experimental public boolean matchesWithoutData(@NotNull @NotNull ItemStack item, @NotNull Set<@NotNull DataComponentType> excludeTypes) Checks if this itemstack matches another given itemstack excluding the provided components. This is useful if you are wanting to ignore certain properties of itemstacks, such as durability.- Parameters:
- item- the item to compare
- excludeTypes- the data component types to ignore
- Returns:
- trueif the provided item is equal, ignoring the provided components
 
- 
matchesWithoutData@Experimental public boolean matchesWithoutData(@NotNull @NotNull ItemStack item, @NotNull Set<@NotNull DataComponentType> excludeTypes, boolean ignoreCount) Checks if this itemstack matches another given itemstack excluding the provided components. This is useful if you are wanting to ignore certain properties of itemstacks, such as durability.- Parameters:
- item- the item to compare
- excludeTypes- the data component types to ignore
- ignoreCount- ignore the count of the item
- Returns:
- trueif the provided item is equal, ignoring the provided components
 
 
- 
setDurability(short)