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> tag, int count, DataComponentPatch components) privateItemStack(ItemLike item, int count, PatchedDataComponentMap components) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddAttributeTooltips(Consumer<Component> tooltipAdder, TooltipDisplay tooltipDisplay, Player player) Deprecated.voidaddDetailsToTooltip(Item.TooltipContext context, TooltipDisplay tooltipDisplay, Player playef, TooltipFlag tooltipFlag, Consumer<Component> tooltipAdder) private voidaddModifierTooltip(Consumer<Component> tooltipAdder, Player player, Holder<Attribute> attribute, AttributeModifier modifier) <T extends TooltipProvider>
voidaddToTooltip(DataComponentType<T> component, Item.TooltipContext context, TooltipDisplay tooltipDisplay, Consumer<Component> tooltipAdder, TooltipFlag tooltipFlag) private ItemStackapplyAfterUseComponentSideEffects(LivingEntity entity, ItemStack stack) voidapplyComponents(DataComponentMap components) Applies a set of component changes to this stack.voidapplyComponents(DataComponentPatch components) Applies a set of component changes to this stack.voidapplyComponentsAndValidate(DataComponentPatch components) private voidapplyDamage(int damage, ServerPlayer player, Consumer<Item> onBreak) private voidapplyDamage(int p_361754_, LivingEntity p_364853_, Consumer<Item> p_360895_) booleancanBeHurtBy(DamageSource damageSource) booleanbooleancanDestroyBlock(BlockState state, Level level, BlockPos pos, Player player) booleanvoidconsume(int amount, LivingEntity entity) consumeAndReturn(int amount, LivingEntity entity) copy()<T> voidcopyFrom(DataComponentType<T> componentType, DataComponentGetter componentGetter) copyWithCount(int count) private static StreamCodec<RegistryFriendlyByteBuf, ItemStack> voidenchant(Holder<Enchantment> enchantment, int level) finishUsingItem(Level level, LivingEntity livingEntity) Called when the item in use count reach 0, e.g. item food eaten.voidforEachModifier(EquipmentSlotGroup slotGroup, BiConsumer<Holder<Attribute>, AttributeModifier> action) voidforEachModifier(EquipmentSlot equipmentSLot, BiConsumer<Holder<Attribute>, AttributeModifier> action) intintintgetCount()intfloatgetDestroySpeed(BlockState state) 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 tooltipContext, Player player, TooltipFlag tooltipFlag) intgetUseDuration(LivingEntity entity) voidgrow(int increment) booleanhasFoil()static inthashItemAndComponents(ItemStack stack) static inthashStackList(List<ItemStack> list) Deprecated.booleanhasNonDefault(DataComponentType<?> component) voidhurtAndBreak(int damage, ServerLevel level, ServerPlayer player, Consumer<Item> onBreak) voidhurtAndBreak(int p_220158_, ServerLevel p_346256_, LivingEntity p_220160_, Consumer<Item> p_348596_) voidhurtAndBreak(int amount, LivingEntity entity, EquipmentSlot slot) hurtAndConvertOnBreak(int amount, ItemLike item, LivingEntity entity, EquipmentSlot slot) booleanhurtEnemy(LivingEntity enemy, LivingEntity attacker) voidhurtWithoutBreaking(int damage, Player player) interactLivingEntity(Player player, LivingEntity entity, InteractionHand usedHand) voidinventoryTick(Level level, Entity entity, EquipmentSlot slot) booleanbooleanbooleanbooleanbooleanbooleanbooleanisBroken()booleanbooleanisCorrectToolForDrops(BlockState state) Check whether the given Block can be harvested using this ItemStack.booleanbooleanbooleanisEmpty()booleanbooleanbooleanisFramed()booleanisItemEnabled(FeatureFlagSet enabledFlags) static booleanisSameItem(ItemStack stack, ItemStack other) static booleanisSameItemSameComponents(ItemStack stack, ItemStack other) booleanbooleanisValidRepairItem(ItemStack item) static com.mojang.serialization.MapCodec<ItemStack> lenientOptionalFieldOf(String fieldName) voidlimitSize(int maxSize) static booleanlistMatches(List<ItemStack> list, List<ItemStack> other) Deprecated.static booleanCompares bothItemStacks, returnstrueif bothItemStacksare equal.voidmineBlock(Level level, BlockState state, BlockPos pos, Player player) Called when a Block is destroyed using this ItemStackbooleanvoidonCraftedBy(Player player, int amount) voidonCraftedBySystem(Level level) voidonDestroyed(ItemEntity itemEntity) 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 level, LivingEntity livingEntity, int remainingUseDuration) Called as the stack is being used by an entity.booleanoverrideOtherStackedOnMe(ItemStack stack, Slot slot, ClickAction action, Player player, SlotAccess access) booleanoverrideStackedOnOther(Slot slot, ClickAction action, Player player) parse(HolderLookup.Provider lookupProvider, Tag tag) voidpostHurtEnemy(LivingEntity enemy, LivingEntity attacker) private intprocessDurabilityChange(int damage, ServerLevel level, ServerPlayer player) private intprocessDurabilityChange(int p_361290_, ServerLevel p_361409_, LivingEntity p_364940_) voidreleaseUsing(Level level, LivingEntity livingEntity, int timeLeft) Called when the player releases the use item button.<T> Tremove(DataComponentType<? extends T> component) Removes a data component.save(HolderLookup.Provider levelRegistryAccess) save(HolderLookup.Provider levelRegistryAccess, Tag outputTag) <T> Tset(DataComponentType<T> component, T value) Sets a data component.voidsetCount(int count) voidsetDamageValue(int damage) voidsetEntityRepresentation(Entity entity) voidsetPopTime(int popTime) voidshrink(int decrement) split(int amount) Splits off a stack of the given amount of this stack and reduces this stack by the amount.toString()transmuteCopy(ItemLike item) transmuteCopy(ItemLike item, int count) private ItemStacktransmuteCopyIgnoreEmpty(ItemLike item, int count) <T> Tupdate(DataComponentType<T> component, T defaultValue, UnaryOperator<T> updater) Updates a data component if it exists.<T,U> T update(DataComponentType<T> component, T defaultValue, U updateValue, BiFunction<T, U, T> updater) Updates a data component if it exists, using an additionalupdateContext.use(Level level, Player player, InteractionHand hand) useOn(UseOnContext context) booleanstatic com.mojang.serialization.DataResult<Unit> validateComponents(DataComponentMap components) static com.mojang.serialization.DataResult<ItemStack> validateStrict(ItemStack stack) 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, 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> codec) -
validatedStreamCodec
public static StreamCodec<RegistryFriendlyByteBuf,ItemStack> validatedStreamCodec(StreamCodec<RegistryFriendlyByteBuf, ItemStack> codec) -
getTooltipImage
-
getComponents
- Specified by:
getComponentsin interfaceDataComponentHolder
-
getPrototype
-
getComponentsPatch
-
immutableComponents
-
hasNonDefault
-
isComponentsPatchEmpty
public boolean isComponentsPatchEmpty() -
validateComponents
public static com.mojang.serialization.DataResult<Unit> validateComponents(DataComponentMap components) -
parse
-
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
-
save
-
save
-
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 damage) -
getMaxDamage
public int getMaxDamage() -
isBroken
public boolean isBroken() -
nextDamageWillBreak
public boolean nextDamageWillBreak() -
hurtAndBreak
public void hurtAndBreak(int damage, ServerLevel level, @Nullable ServerPlayer player, Consumer<Item> onBreak) -
hurtAndBreak
public void hurtAndBreak(int p_220158_, ServerLevel p_346256_, @Nullable LivingEntity p_220160_, Consumer<Item> p_348596_) -
processDurabilityChange
-
processDurabilityChange
private int processDurabilityChange(int p_361290_, ServerLevel p_361409_, @Nullable LivingEntity p_364940_) -
applyDamage
-
applyDamage
-
hurtWithoutBreaking
-
hurtAndBreak
-
hurtAndConvertOnBreak
public ItemStack hurtAndConvertOnBreak(int amount, ItemLike item, LivingEntity entity, EquipmentSlot slot) -
isBarVisible
public boolean isBarVisible() -
getBarWidth
public int getBarWidth() -
getBarColor
public int getBarColor() -
overrideStackedOnOther
-
overrideOtherStackedOnMe
public boolean overrideOtherStackedOnMe(ItemStack stack, Slot slot, ClickAction action, Player player, SlotAccess access) -
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 player, LivingEntity entity, InteractionHand usedHand) -
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
-
update
@Nullable public <T,U> T update(DataComponentType<T> component, T defaultValue, U updateValue, BiFunction<T, U, T> updater) 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> component, T defaultValue, UnaryOperator<T> updater) 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> component, Item.TooltipContext context, TooltipDisplay tooltipDisplay, Consumer<Component> tooltipAdder, TooltipFlag tooltipFlag) -
getTooltipLines
public List<Component> getTooltipLines(Item.TooltipContext tooltipContext, @Nullable Player player, TooltipFlag tooltipFlag) -
addDetailsToTooltip
public void addDetailsToTooltip(Item.TooltipContext context, TooltipDisplay tooltipDisplay, @Nullable Player playef, TooltipFlag tooltipFlag, Consumer<Component> tooltipAdder) -
addAttributeTooltips
@Deprecated private void addAttributeTooltips(Consumer<Component> tooltipAdder, TooltipDisplay tooltipDisplay, @Nullable Player player) Deprecated.Neo: UseaddAttributeTooltips}invalid @link
{@link net.neoforged.neoforge.common.util.AttributeUtil# -
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 slotGroup, BiConsumer<Holder<Attribute>, AttributeModifier> action) -
forEachModifier
public void forEachModifier(EquipmentSlot equipmentSLot, BiConsumer<Holder<Attribute>, AttributeModifier> action) -
getDisplayName
-
canPlaceOnBlockInAdventureMode
-
canBreakBlockInAdventureMode
-
getPopTime
public int getPopTime() -
setPopTime
public void setPopTime(int popTime) -
getCount
public int getCount() -
setCount
public void setCount(int count) -
limitSize
public void limitSize(int maxSize) -
grow
public void grow(int increment) -
shrink
public void shrink(int decrement) -
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#