Package net.minecraft.world.item
Class ItemStack
java.lang.Object
net.minecraft.world.item.ItemStack
- All Implemented Interfaces:
DataComponentHolder,IDataComponentHolderExtension,IItemStackExtension,MutableDataComponentHolder
public final class ItemStack
extends Object
implements DataComponentHolder, MutableDataComponentHolder, IItemStackExtension
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec<ItemStack> (package private) final PatchedDataComponentMapprivate intprivate static final Componentstatic final ItemStackprivate EntityThe entity the item is attached to, like an Item Frame.private final ItemDeprecated.static final StreamCodec<RegistryFriendlyByteBuf, List<ItemStack>> private static final org.slf4j.Loggerstatic final com.mojang.serialization.Codec<ItemStack> static final StreamCodec<RegistryFriendlyByteBuf, List<ItemStack>> static final StreamCodec<RegistryFriendlyByteBuf, ItemStack> private intstatic final com.mojang.serialization.Codec<ItemStack> static final com.mojang.serialization.Codec<ItemStack> static final StreamCodec<RegistryFriendlyByteBuf, ItemStack> static final com.mojang.serialization.Codec<ItemStack> static final com.mojang.serialization.Codec<ItemStack> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateItemStack(Holder<Item> pItem, int pCount, DataComponentPatch p_330362_) privateItemStack(ItemLike pItem, int pCount, PatchedDataComponentMap pComponents) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddAttributeTooltips(Consumer<Component> pTooltipAdder, Player pPlayer) Deprecated.private voidaddModifierTooltip(Consumer<Component> pTooltipAdder, Player pPlayer, Holder<Attribute> pAttribute, AttributeModifier pModifier) <T extends TooltipProvider>
voidaddToTooltip(DataComponentType<T> pComponent, Item.TooltipContext pContext, Consumer<Component> pTooltipAdder, TooltipFlag pTooltipFlag) voidapplyComponents(DataComponentMap pComponents) Applies a set of component changes to this stack.voidapplyComponents(DataComponentPatch pComponents) Applies a set of component changes to this stack.voidapplyComponentsAndValidate(DataComponentPatch pComponents) booleancanBeHurtBy(DamageSource pDamageSource) booleanbooleanvoidconsume(int pAmount, LivingEntity pEntity) consumeAndReturn(int pAmount, LivingEntity pEntity) copy()copyWithCount(int pCount) voidenchant(Holder<Enchantment> pEnchantment, int pLevel) finishUsingItem(Level pLevel, LivingEntity pLivingEntity) Called when the item in use count reach 0, e.g. item food eaten.voidforEachModifier(EquipmentSlotGroup pSlotGroup, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) voidforEachModifier(EquipmentSlot pEquipmentSLot, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) intintintgetCount()intfloatgetDestroySpeed(BlockState pState) Deprecated.Neo: UsegetTagEnchantments()for NBT enchantments, orIItemStackExtension.getAllEnchantments(net.minecraft.core.HolderLookup.RegistryLookup<net.minecraft.world.item.enchantment.Enchantment>)for gameplay.getFrame()getItem()intintintGets all enchantments from NBT.getTags()getTooltipLines(Item.TooltipContext pTooltipContext, Player pPlayer, TooltipFlag pTooltipFlag) intgetUseDuration(LivingEntity pEntity) voidgrow(int pIncrement) booleanhasFoil()static inthashItemAndComponents(ItemStack pStack) static inthashStackList(List<ItemStack> pList) Deprecated.voidhurtAndBreak(int pDamage, ServerLevel pLevel, ServerPlayer pPlayer, Consumer<Item> pOnBreak) voidhurtAndBreak(int p_220158_, ServerLevel p_346256_, LivingEntity p_220160_, Consumer<Item> p_348596_) voidhurtAndBreak(int pAmount, LivingEntity pEntity, EquipmentSlot pSlot) hurtAndConvertOnBreak(int pAmount, ItemLike pItem, LivingEntity pEntity, EquipmentSlot pSlot) booleanhurtEnemy(LivingEntity pTarget, Player pAttacker) interactLivingEntity(Player pPlayer, LivingEntity pEntity, InteractionHand pUsedHand) voidinventoryTick(Level pLevel, Entity pEntity, int pInventorySlot, boolean pIsCurrentItem) Called each tick as long theItemStackin in player's inventory.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanisCorrectToolForDrops(BlockState pState) Check whether the given Block can be harvested using this ItemStack.booleanbooleanbooleanisEmpty()booleanbooleanbooleanisFramed()booleanisItemEnabled(FeatureFlagSet pEnabledFlags) static booleanisSameItem(ItemStack pStack, ItemStack pOther) static booleanisSameItemSameComponents(ItemStack pStack, ItemStack pOther) booleanstatic com.mojang.serialization.MapCodec<ItemStack> lenientOptionalFieldOf(String pFieldName) voidlimitSize(int pMaxSize) static booleanlistMatches(List<ItemStack> pList, List<ItemStack> pOther) Deprecated.static booleanCompares bothItemStacks, returnstrueif bothItemStacksare equal.voidmineBlock(Level pLevel, BlockState pState, BlockPos pPos, Player pPlayer) Called when a Block is destroyed using this ItemStackvoidonCraftedBy(Level pLevel, Player pPlayer, int pAmount) voidonCraftedBySystem(Level pLevel) voidonDestroyed(ItemEntity pItemEntity) Deprecated.Forge: Use invalid input: '{@linkplain net.neoforged.neoforge.common.extensions.IItemStackExtension#' onDestroyed(ItemEntity, net.minecraft.world.damagesource.DamageSource) damage source sensitive version}private InteractionResultonItemUse(UseOnContext p_41662_, Function<UseOnContext, InteractionResult> callback) onItemUseFirst(UseOnContext p_41662_) voidonUseTick(Level pLevel, LivingEntity pLivingEntity, int pCount) Called as the stack is being used by an entity.booleanoverrideOtherStackedOnMe(ItemStack pStack, Slot pSlot, ClickAction pAction, Player pPlayer, SlotAccess pAccess) booleanoverrideStackedOnOther(Slot pSlot, ClickAction pAction, Player pPlayer) parse(HolderLookup.Provider pLookupProvider, Tag pTag) static ItemStackparseOptional(HolderLookup.Provider pLookupProvider, CompoundTag pTag) voidpostHurtEnemy(LivingEntity pTarget, Player pAttacker) voidreleaseUsing(Level pLevel, LivingEntity pLivingEntity, int pTimeLeft) Called when the player releases the use item button.<T> Tremove(DataComponentType<? extends T> pComponent) Removes a data component.save(HolderLookup.Provider pLevelRegistryAccess) save(HolderLookup.Provider pLevelRegistryAccess, Tag pOutputTag) saveOptional(HolderLookup.Provider pLevelRegistryAccess) <T> Tset(DataComponentType<? super T> pComponent, T pValue) Sets a data component.voidsetCount(int pCount) voidsetDamageValue(int pDamage) voidsetEntityRepresentation(Entity pEntity) voidsetPopTime(int pPopTime) voidshrink(int pDecrement) split(int pAmount) Splits off a stack of the given amount of this stack and reduces this stack by the amount.toString()transmuteCopy(ItemLike pItem) transmuteCopy(ItemLike pItem, int pCount) private ItemStacktransmuteCopyIgnoreEmpty(ItemLike pItem, int pCount) <T> Tupdate(DataComponentType<T> pComponent, T pDefaultValue, UnaryOperator<T> pUpdater) Updates a data component if it exists.<T,U> T update(DataComponentType<T> pComponent, T pDefaultValue, U pUpdateValue, BiFunction<T, U, T> pUpdater) Updates a data component if it exists, using an additionalupdateContext.use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) Called when theItemStackis equipped and right-clicked.useOn(UseOnContext pContext) booleanstatic com.mojang.serialization.DataResult<Unit> validateComponents(DataComponentMap pComponents) private static com.mojang.serialization.DataResult<ItemStack> validateStrict(ItemStack p_340966_) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.minecraft.core.component.DataComponentHolder
get, getOrDefault, hasMethods inherited from interface net.neoforged.neoforge.common.extensions.IDataComponentHolderExtension
addToTooltip, get, getOrDefault, hasMethods inherited from interface net.neoforged.neoforge.common.extensions.IItemStackExtension
canDisableShield, canElytraFly, canEquip, canFitInsideContainerItems, canGrindstoneRepair, canPerformAction, canWalkOnPowderedSnow, doesSneakBypassUse, elytraFlightTick, getAllEnchantments, getAttributeModifiers, getBurnTime, getCapability, getCapability, getCraftingRemainingItem, getEnchantmentLevel, getEnchantmentValue, getEntityLifespan, getEquipmentSlot, getFoodProperties, getHighlightTip, getSweepHitBox, getXpRepairRatio, hasCraftingRemainingItem, isBookEnchantable, isEnderMask, isNotReplaceableByPickAction, isPiglinCurrency, isPrimaryItemFor, isRepairable, makesPiglinsNeutral, onAnimalArmorTick, onDestroyed, onDroppedByPlayer, onEntityItemUpdate, onEntitySwing, onEntitySwing, onStopUsing, shouldCauseBlockBreakReset, supportsEnchantment
-
Field Details
-
ITEM_NON_AIR_CODEC
-
CODEC
-
SINGLE_ITEM_CODEC
-
STRICT_CODEC
-
STRICT_SINGLE_ITEM_CODEC
-
OPTIONAL_CODEC
-
SIMPLE_ITEM_CODEC
-
OPTIONAL_STREAM_CODEC
-
STREAM_CODEC
-
OPTIONAL_LIST_STREAM_CODEC
-
LIST_STREAM_CODEC
-
LOGGER
private static final org.slf4j.Logger LOGGER -
EMPTY
-
DISABLED_ITEM_TOOLTIP
-
count
private int count -
popTime
private int popTime -
item
Deprecated. -
components
-
entityRepresentation
The entity the item is attached to, like an Item Frame.
-
-
Constructor Details
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
-
Method Details
-
validateStrict
-
validatedStreamCodec
public static StreamCodec<RegistryFriendlyByteBuf,ItemStack> validatedStreamCodec(StreamCodec<RegistryFriendlyByteBuf, ItemStack> pCodec) -
getTooltipImage
-
getComponents
- Specified by:
getComponentsin interfaceDataComponentHolder
-
getPrototype
-
getComponentsPatch
-
isComponentsPatchEmpty
public boolean isComponentsPatchEmpty() -
validateComponents
public static com.mojang.serialization.DataResult<Unit> validateComponents(DataComponentMap pComponents) -
parse
-
parseOptional
-
isEmpty
public boolean isEmpty() -
isItemEnabled
-
split
Splits off a stack of the given amount of this stack and reduces this stack by the amount. -
copyAndClear
-
getItem
-
getItemHolder
-
is
-
is
-
is
-
is
-
is
-
getTags
-
useOn
-
onItemUseFirst
- Specified by:
onItemUseFirstin interfaceIItemStackExtension
-
onItemUse
private InteractionResult onItemUse(UseOnContext p_41662_, Function<UseOnContext, InteractionResult> callback) -
getDestroySpeed
-
use
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) Called when theItemStackis equipped and right-clicked. Replaces theItemStackwith the return value. -
finishUsingItem
Called when the item in use count reach 0, e.g. item food eaten. Return the new ItemStack. Args : world, entity -
save
-
save
-
saveOptional
-
getMaxStackSize
public int getMaxStackSize() -
isStackable
public boolean isStackable() -
isDamageableItem
public boolean isDamageableItem() -
isDamaged
public boolean isDamaged() -
getDamageValue
public int getDamageValue() -
setDamageValue
public void setDamageValue(int pDamage) -
getMaxDamage
public int getMaxDamage() -
hurtAndBreak
public void hurtAndBreak(int pDamage, ServerLevel pLevel, @Nullable ServerPlayer pPlayer, Consumer<Item> pOnBreak) -
hurtAndBreak
public void hurtAndBreak(int p_220158_, ServerLevel p_346256_, @Nullable LivingEntity p_220160_, Consumer<Item> p_348596_) -
hurtAndBreak
-
hurtAndConvertOnBreak
public ItemStack hurtAndConvertOnBreak(int pAmount, ItemLike pItem, LivingEntity pEntity, EquipmentSlot pSlot) -
isBarVisible
public boolean isBarVisible() -
getBarWidth
public int getBarWidth() -
getBarColor
public int getBarColor() -
overrideStackedOnOther
-
overrideOtherStackedOnMe
public boolean overrideOtherStackedOnMe(ItemStack pStack, Slot pSlot, ClickAction pAction, Player pPlayer, SlotAccess pAccess) -
hurtEnemy
-
postHurtEnemy
-
mineBlock
Called when a Block is destroyed using this ItemStack -
isCorrectToolForDrops
Check whether the given Block can be harvested using this ItemStack. -
interactLivingEntity
public InteractionResult interactLivingEntity(Player pPlayer, LivingEntity pEntity, InteractionHand pUsedHand) -
copy
-
copyWithCount
-
transmuteCopy
-
transmuteCopy
-
transmuteCopyIgnoreEmpty
-
matches
Compares bothItemStacks, returnstrueif bothItemStacksare equal. -
listMatches
Deprecated. -
isSameItem
-
isSameItemSameComponents
-
lenientOptionalFieldOf
-
hashItemAndComponents
-
hashStackList
Deprecated. -
getDescriptionId
-
toString
-
inventoryTick
Called each tick as long theItemStackin in player's inventory. Used to progress the pickup animation and update maps. -
onCraftedBy
-
onCraftedBySystem
-
getUseDuration
-
getUseAnimation
-
releaseUsing
Called when the player releases the use item button. -
useOnRelease
public boolean useOnRelease() -
set
Description copied from interface:MutableDataComponentHolderSets a data component.- Specified by:
setin interfaceMutableDataComponentHolder
-
update
@Nullable public <T,U> T update(DataComponentType<T> pComponent, T pDefaultValue, U pUpdateValue, BiFunction<T, U, T> pUpdater) Description copied from interface:MutableDataComponentHolderUpdates a data component if it exists, using an additionalupdateContext.- Specified by:
updatein interfaceMutableDataComponentHolder
-
update
@Nullable public <T> T update(DataComponentType<T> pComponent, T pDefaultValue, UnaryOperator<T> pUpdater) Description copied from interface:MutableDataComponentHolderUpdates a data component if it exists.- Specified by:
updatein interfaceMutableDataComponentHolder
-
remove
Description copied from interface:MutableDataComponentHolderRemoves a data component.- Specified by:
removein interfaceMutableDataComponentHolder
-
applyComponentsAndValidate
-
applyComponents
Description copied from interface:MutableDataComponentHolderApplies a set of component changes to this stack.- Specified by:
applyComponentsin interfaceMutableDataComponentHolder
-
applyComponents
Description copied from interface:MutableDataComponentHolderApplies a set of component changes to this stack.- Specified by:
applyComponentsin interfaceMutableDataComponentHolder
-
getHoverName
-
addToTooltip
public <T extends TooltipProvider> void addToTooltip(DataComponentType<T> pComponent, Item.TooltipContext pContext, Consumer<Component> pTooltipAdder, TooltipFlag pTooltipFlag) - Specified by:
addToTooltipin interfaceIDataComponentHolderExtension
-
getTooltipLines
public List<Component> getTooltipLines(Item.TooltipContext pTooltipContext, @Nullable Player pPlayer, TooltipFlag pTooltipFlag) -
addAttributeTooltips
@Deprecated private void addAttributeTooltips(Consumer<Component> pTooltipAdder, @Nullable Player pPlayer) Deprecated.Neo: UseaddAttributeTooltips}invalid @link
{@link net.neoforged.neoforge.client.util.TooltipUtil# -
addModifierTooltip
-
hasFoil
public boolean hasFoil() -
getRarity
-
isEnchantable
public boolean isEnchantable() -
enchant
-
isEnchanted
public boolean isEnchanted() -
getTagEnchantments
Gets all enchantments from NBT. UseIItemStackExtension.getAllEnchantments(net.minecraft.core.HolderLookup.RegistryLookup<net.minecraft.world.item.enchantment.Enchantment>)for gameplay logic. -
getEnchantments
Deprecated.Neo: UsegetTagEnchantments()for NBT enchantments, orIItemStackExtension.getAllEnchantments(net.minecraft.core.HolderLookup.RegistryLookup<net.minecraft.world.item.enchantment.Enchantment>)for gameplay. -
isFramed
public boolean isFramed() -
setEntityRepresentation
-
getFrame
-
getEntityRepresentation
-
forEachModifier
public void forEachModifier(EquipmentSlotGroup pSlotGroup, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) -
forEachModifier
public void forEachModifier(EquipmentSlot pEquipmentSLot, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) -
getDisplayName
-
canPlaceOnBlockInAdventureMode
-
canBreakBlockInAdventureMode
-
getPopTime
public int getPopTime() -
setPopTime
public void setPopTime(int pPopTime) -
getCount
public int getCount() -
setCount
public void setCount(int pCount) -
limitSize
public void limitSize(int pMaxSize) -
grow
public void grow(int pIncrement) -
shrink
public void shrink(int pDecrement) -
consume
-
consumeAndReturn
-
onUseTick
Called as the stack is being used by an entity. -
onDestroyed
Deprecated.Forge: Use invalid input: '{@linkplain net.neoforged.neoforge.common.extensions.IItemStackExtension#' onDestroyed(ItemEntity, net.minecraft.world.damagesource.DamageSource) damage source sensitive version} -
getDrinkingSound
-
getEatingSound
-
getBreakingSound
-
canBeHurtBy
-
invalid @link
{@link net.neoforged.neoforge.client.util.TooltipUtil#