Package net.minecraft.world.item
Class ItemStack
java.lang.Object
net.minecraft.world.item.ItemStack
- All Implemented Interfaces:
DataComponentGetter,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.private static final org.slf4j.Loggerstatic final com.mojang.serialization.MapCodec<ItemStack> static final com.mojang.serialization.Codec<ItemStack> static final StreamCodec<RegistryFriendlyByteBuf, List<ItemStack>> static final StreamCodec<RegistryFriendlyByteBuf, 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> private static final Component -
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, TooltipDisplay pTooltipDisplay, Player pPlayer) Deprecated.voidaddDetailsToTooltip(Item.TooltipContext pContext, TooltipDisplay pTooltipDisplay, Player pPlayer, TooltipFlag pTooltipFlag, Consumer<Component> pTooltipAdder) <T extends TooltipProvider>
voidaddToTooltip(DataComponentType<T> pComponent, Item.TooltipContext pContext, TooltipDisplay pTooltipDisplay, Consumer<Component> pTooltipAdder, TooltipFlag pTooltipFlag) private ItemStackapplyAfterUseComponentSideEffects(LivingEntity pEntity, ItemStack pStack) 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) private voidapplyDamage(int pDamage, ServerPlayer pPlayer, Consumer<Item> pOnBreak) private voidapplyDamage(int p_361754_, LivingEntity p_364853_, Consumer<Item> p_360895_) booleancanBeHurtBy(DamageSource pDamageSource) booleanbooleancanDestroyBlock(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer) booleanvoidconsume(int pAmount, LivingEntity pEntity) consumeAndReturn(int pAmount, LivingEntity pEntity) copy()<T> voidcopyFrom(DataComponentType<T> pComponentType, DataComponentGetter pComponentGetter) Copies a data component from a component getter.copyWithCount(int pCount) private static StreamCodec<RegistryFriendlyByteBuf, ItemStack> 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 pSlot, org.apache.commons.lang3.function.TriConsumer<Holder<Attribute>, AttributeModifier, ItemAttributeModifiers.Display> 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.booleanhasNonDefault(DataComponentType<?> pComponent) 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) voidhurtAndBreak(int pAmount, LivingEntity pEntity, InteractionHand pHand) hurtAndConvertOnBreak(int pAmount, ItemLike pItem, LivingEntity pEntity, EquipmentSlot pSlot) booleanhurtEnemy(LivingEntity pEnemy, LivingEntity pAttacker) voidhurtWithoutBreaking(int pDamage, Player pPlayer) interactLivingEntity(Player pPlayer, LivingEntity pEntity, InteractionHand pUsedHand) voidinventoryTick(Level pLevel, Entity pEntity, EquipmentSlot pSlot) booleanbooleanbooleanbooleanbooleanbooleanbooleanisBroken()booleanbooleanisCorrectToolForDrops(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) booleanbooleanisValidRepairItem(ItemStack pItem) static 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 ItemStackbooleanvoidonCraftedBy(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 pRemainingUseDuration) 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) voidpostHurtEnemy(LivingEntity pEnemy, LivingEntity pAttacker) private intprocessDurabilityChange(int pDamage, ServerLevel pLevel, ServerPlayer pPlayer) private intprocessDurabilityChange(int p_361290_, ServerLevel p_361409_, LivingEntity p_364940_) 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.<T> Tset(DataComponentType<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 pHand) useOn(UseOnContext pContext) booleanstatic com.mojang.serialization.DataResult<Unit> validateComponents(DataComponentMap pComponents) 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.DataComponentGetter
get, getOrDefault, getTyped, hasMethods inherited from interface net.minecraft.core.component.DataComponentHolder
get, getAllOfType, getOrDefault, hasMethods inherited from interface net.neoforged.neoforge.common.extensions.IDataComponentHolderExtension
addToTooltip, addToTooltipMethods inherited from interface net.neoforged.neoforge.common.extensions.IItemStackExtension
canEquip, canFitInsideContainerItems, canGrindstoneRepair, canPerformAction, canWalkOnPowderedSnow, doesSneakBypassUse, getAllEnchantments, getAttributeModifiers, getBurnTime, getCapability, getCapability, getCraftingRemainder, getEnchantmentLevel, getEntityLifespan, getEquipmentSlot, getHighlightTip, getSweepHitBox, getXpRepairRatio, isCombineRepairable, isGazeDisguise, isNotReplaceableByPickAction, isPiglinCurrency, isPrimaryItemFor, makesPiglinsNeutral, onAnimalArmorTick, onDestroyed, onDroppedByPlayer, onEntityItemUpdate, onEntitySwing, onStopUsing, shouldCauseBlockBreakReset, supportsEnchantment
-
Field Details
-
OP_NBT_WARNING
-
UNBREAKABLE_TOOLTIP
-
MAP_CODEC
-
CODEC
-
SINGLE_ITEM_CODEC
-
STRICT_CODEC
-
STRICT_SINGLE_ITEM_CODEC
-
OPTIONAL_CODEC
-
SIMPLE_ITEM_CODEC
-
OPTIONAL_STREAM_CODEC
-
OPTIONAL_UNTRUSTED_STREAM_CODEC
-
STREAM_CODEC
-
OPTIONAL_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
-
createOptionalStreamCodec
private static StreamCodec<RegistryFriendlyByteBuf,ItemStack> createOptionalStreamCodec(StreamCodec<RegistryFriendlyByteBuf, DataComponentPatch> pCodec) -
validatedStreamCodec
public static StreamCodec<RegistryFriendlyByteBuf,ItemStack> validatedStreamCodec(StreamCodec<RegistryFriendlyByteBuf, ItemStack> pCodec) -
getTooltipImage
-
getComponents
- Specified by:
getComponentsin interfaceDataComponentHolder
-
getPrototype
-
getComponentsPatch
-
immutableComponents
-
hasNonDefault
-
isComponentsPatchEmpty
public boolean isComponentsPatchEmpty() -
validateComponents
public static com.mojang.serialization.DataResult<Unit> validateComponents(DataComponentMap pComponents) -
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
-
finishUsingItem
Called when the item in use count reach 0, e.g. item food eaten. Return the new ItemStack. Args : world, entity -
applyAfterUseComponentSideEffects
-
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() -
isBroken
public boolean isBroken() -
nextDamageWillBreak
public boolean nextDamageWillBreak() -
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_) -
processDurabilityChange
private int processDurabilityChange(int pDamage, ServerLevel pLevel, @Nullable ServerPlayer pPlayer) -
processDurabilityChange
private int processDurabilityChange(int p_361290_, ServerLevel p_361409_, @Nullable LivingEntity p_364940_) -
applyDamage
-
applyDamage
-
hurtWithoutBreaking
-
hurtAndBreak
-
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. -
toString
-
inventoryTick
-
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
-
copyFrom
Description copied from interface:MutableDataComponentHolderCopies a data component from a component getter.- Specified by:
copyFromin 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
-
getCustomName
-
getItemName
-
getStyledHoverName
-
addToTooltip
public <T extends TooltipProvider> void addToTooltip(DataComponentType<T> pComponent, Item.TooltipContext pContext, TooltipDisplay pTooltipDisplay, Consumer<Component> pTooltipAdder, TooltipFlag pTooltipFlag) -
getTooltipLines
public List<Component> getTooltipLines(Item.TooltipContext pTooltipContext, @Nullable Player pPlayer, TooltipFlag pTooltipFlag) -
addDetailsToTooltip
public void addDetailsToTooltip(Item.TooltipContext pContext, TooltipDisplay pTooltipDisplay, @Nullable Player pPlayer, TooltipFlag pTooltipFlag, Consumer<Component> pTooltipAdder) -
addAttributeTooltips
@Deprecated private void addAttributeTooltips(Consumer<Component> pTooltipAdder, TooltipDisplay pTooltipDisplay, @Nullable Player pPlayer) Deprecated.Neo: UseaddAttributeTooltips}invalid @link
{@link net.neoforged.neoforge.common.util.AttributeUtil# -
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 pSlot, org.apache.commons.lang3.function.TriConsumer<Holder<Attribute>, AttributeModifier, ItemAttributeModifiers.Display> 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} -
canBeHurtBy
-
isValidRepairItem
-
canDestroyBlock
-
invalid @link
{@link net.neoforged.neoforge.common.util.AttributeUtil#