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, IItemStackExtension, MutableDataComponentHolder
-
Field Summary
Modifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec
<ItemStack> (package private) final PatchedDataComponentMap
private int
private static final Component
static final ItemStack
private Entity
private final Item
Deprecated.static final StreamCodec
<RegistryFriendlyByteBuf, List<ItemStack>> private static final org.slf4j.Logger
static final com.mojang.serialization.Codec
<ItemStack> static final StreamCodec
<RegistryFriendlyByteBuf, List<ItemStack>> static final StreamCodec
<RegistryFriendlyByteBuf, ItemStack> private int
static 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
ModifierConstructorDescriptionprivate
ItemStack
(Holder<Item> p_312081_, int p_41605_, DataComponentPatch p_330362_) private
ItemStack
(ItemLike p_330978_, int p_330639_, PatchedDataComponentMap p_330546_) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addAttributeTooltips
(Consumer<Component> p_330796_, Player p_330530_) private void
addModifierTooltip
(Consumer<Component> p_331062_, Player p_330317_, Holder<Attribute> p_330626_, AttributeModifier p_331252_) <T extends TooltipProvider>
voidaddToTooltip
(DataComponentType<T> p_331344_, Item.TooltipContext p_341231_, Consumer<Component> p_331885_, TooltipFlag p_331177_) void
applyComponents
(DataComponentMap p_330402_) Applies a set of component changes to this stack.void
applyComponents
(DataComponentPatch p_332097_) Applies a set of component changes to this stack.void
applyComponentsAndValidate
(DataComponentPatch p_341407_) boolean
canBeHurtBy
(DamageSource p_335431_) boolean
canBreakBlockInAdventureMode
(BlockInWorld p_331592_) boolean
canPlaceOnBlockInAdventureMode
(BlockInWorld p_331419_) void
consume
(int p_326311_, LivingEntity p_326200_) consumeAndReturn
(int p_347624_, LivingEntity p_347710_) copy()
copyWithCount
(int p_256354_) void
enchant
(Holder<Enchantment> p_344751_, int p_41665_) finishUsingItem
(Level p_41672_, LivingEntity p_41673_) void
forEachModifier
(EquipmentSlotGroup p_348610_, BiConsumer<Holder<Attribute>, AttributeModifier> p_348516_) void
forEachModifier
(EquipmentSlot p_332001_, BiConsumer<Holder<Attribute>, AttributeModifier> p_330882_) int
int
int
getCount()
int
float
getDestroySpeed
(BlockState p_41692_) Deprecated.getFrame()
getItem()
int
int
int
Gets all enchantments from NBT.getTags()
getTooltipLines
(Item.TooltipContext p_339637_, Player p_41652_, TooltipFlag p_41653_) int
getUseDuration
(LivingEntity p_345724_) void
grow
(int p_41770_) boolean
hasFoil()
static int
hashItemAndComponents
(ItemStack p_331961_) static int
hashStackList
(List<ItemStack> p_332135_) Deprecated.void
hurtAndBreak
(int p_220158_, ServerLevel p_346256_, ServerPlayer p_220160_, Consumer<Item> p_348596_) void
hurtAndBreak
(int p_220158_, ServerLevel p_346256_, LivingEntity p_220160_, Consumer<Item> p_348596_) void
hurtAndBreak
(int p_41623_, LivingEntity p_41624_, EquipmentSlot p_319898_) hurtAndConvertOnBreak
(int p_352405_, ItemLike p_352337_, LivingEntity p_352175_, EquipmentSlot p_352058_) boolean
hurtEnemy
(LivingEntity p_41641_, Player p_41642_) interactLivingEntity
(Player p_41648_, LivingEntity p_41649_, InteractionHand p_41650_) void
inventoryTick
(Level p_41667_, Entity p_41668_, int p_41669_, boolean p_41670_) boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
isCorrectToolForDrops
(BlockState p_41736_) boolean
boolean
boolean
isEmpty()
boolean
boolean
boolean
isFramed()
boolean
isItemEnabled
(FeatureFlagSet p_250869_) static boolean
isSameItem
(ItemStack p_287761_, ItemStack p_287676_) static boolean
isSameItemSameComponents
(ItemStack p_150943_, ItemStack p_150944_) boolean
static com.mojang.serialization.MapCodec
<ItemStack> lenientOptionalFieldOf
(String p_338501_) void
limitSize
(int p_335437_) static boolean
listMatches
(List<ItemStack> p_331725_, List<ItemStack> p_331113_) Deprecated.static boolean
void
mineBlock
(Level p_41687_, BlockState p_41688_, BlockPos p_41689_, Player p_41690_) void
onCraftedBy
(Level p_41679_, Player p_41680_, int p_41681_) void
onCraftedBySystem
(Level p_307669_) void
onDestroyed
(ItemEntity p_150925_) Deprecated.Forge: Use damage source sensitive versionprivate InteractionResult
onItemUse
(UseOnContext p_41662_, Function<UseOnContext, InteractionResult> callback) onItemUseFirst
(UseOnContext p_41662_) void
onUseTick
(Level p_41732_, LivingEntity p_41733_, int p_41734_) boolean
overrideOtherStackedOnMe
(ItemStack p_150933_, Slot p_150934_, ClickAction p_150935_, Player p_150936_, SlotAccess p_150937_) boolean
overrideStackedOnOther
(Slot p_150927_, ClickAction p_150928_, Player p_150929_) parse
(HolderLookup.Provider p_331096_, Tag p_330238_) static ItemStack
parseOptional
(HolderLookup.Provider p_330543_, CompoundTag p_330539_) void
postHurtEnemy
(LivingEntity p_346409_, Player p_345517_) void
releaseUsing
(Level p_41675_, LivingEntity p_41676_, int p_41677_) <T> T
remove
(DataComponentType<? extends T> p_332139_) Removes a data component.save
(HolderLookup.Provider p_332160_) save
(HolderLookup.Provider p_331900_, Tag p_330830_) saveOptional
(HolderLookup.Provider p_330895_) <T> T
set
(DataComponentType<? super T> p_331064_, T p_330775_) Sets a data component.void
setCount
(int p_41765_) void
setDamageValue
(int p_41722_) void
setEntityRepresentation
(Entity p_41637_) void
setPopTime
(int p_41755_) void
shrink
(int p_41775_) split
(int p_41621_) toString()
transmuteCopy
(ItemLike p_347550_) transmuteCopy
(ItemLike p_323864_, int p_323647_) private ItemStack
transmuteCopyIgnoreEmpty
(ItemLike p_323811_, int p_323856_) <T> T
update
(DataComponentType<T> p_330921_, T p_331257_, UnaryOperator<T> p_331701_) Updates a data component if it exists.<T,
U> T update
(DataComponentType<T> p_331083_, T p_331443_, U p_331049_, BiFunction<T, U, T> p_331846_) Updates a data component if it exists, using an additionalupdateContext
.use
(Level p_41683_, Player p_41684_, InteractionHand p_41685_) useOn
(UseOnContext p_41662_) boolean
static com.mojang.serialization.DataResult
<Unit> validateComponents
(DataComponentMap p_341201_) 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, wait
Methods inherited from interface net.minecraft.core.component.DataComponentHolder
get, getOrDefault, has
Methods inherited from interface net.neoforged.neoforge.common.extensions.IDataComponentHolderExtension
addToTooltip, get, getOrDefault, has
Methods inherited from interface net.neoforged.neoforge.common.extensions.IItemStackExtension
canDisableShield, canElytraFly, canEquip, 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, onStopUsing, shouldCauseBlockBreakReset
-
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
-
-
Constructor Details
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
ItemStack
-
-
Method Details
-
validateStrict
-
validatedStreamCodec
public static StreamCodec<RegistryFriendlyByteBuf,ItemStack> validatedStreamCodec(StreamCodec<RegistryFriendlyByteBuf, ItemStack> p_340962_) -
getTooltipImage
-
getComponents
- Specified by:
getComponents
in interfaceDataComponentHolder
-
getPrototype
-
getComponentsPatch
-
isComponentsPatchEmpty
public boolean isComponentsPatchEmpty() -
validateComponents
public static com.mojang.serialization.DataResult<Unit> validateComponents(DataComponentMap p_341201_) -
parse
-
parseOptional
-
isEmpty
public boolean isEmpty() -
isItemEnabled
-
split
-
copyAndClear
-
getItem
-
getItemHolder
-
is
-
is
-
is
-
is
-
is
-
getTags
-
useOn
-
onItemUseFirst
- Specified by:
onItemUseFirst
in interfaceIItemStackExtension
-
onItemUse
private InteractionResult onItemUse(UseOnContext p_41662_, Function<UseOnContext, InteractionResult> callback) -
getDestroySpeed
-
use
public InteractionResultHolder<ItemStack> use(Level p_41683_, Player p_41684_, InteractionHand p_41685_) -
finishUsingItem
-
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 p_41722_) -
getMaxDamage
public int getMaxDamage() -
hurtAndBreak
public void hurtAndBreak(int p_220158_, ServerLevel p_346256_, @Nullable ServerPlayer p_220160_, Consumer<Item> p_348596_) -
hurtAndBreak
public void hurtAndBreak(int p_220158_, ServerLevel p_346256_, @Nullable LivingEntity p_220160_, Consumer<Item> p_348596_) -
hurtAndBreak
-
hurtAndConvertOnBreak
public ItemStack hurtAndConvertOnBreak(int p_352405_, ItemLike p_352337_, LivingEntity p_352175_, EquipmentSlot p_352058_) -
isBarVisible
public boolean isBarVisible() -
getBarWidth
public int getBarWidth() -
getBarColor
public int getBarColor() -
overrideStackedOnOther
-
overrideOtherStackedOnMe
public boolean overrideOtherStackedOnMe(ItemStack p_150933_, Slot p_150934_, ClickAction p_150935_, Player p_150936_, SlotAccess p_150937_) -
hurtEnemy
-
postHurtEnemy
-
mineBlock
-
isCorrectToolForDrops
-
interactLivingEntity
public InteractionResult interactLivingEntity(Player p_41648_, LivingEntity p_41649_, InteractionHand p_41650_) -
copy
-
copyWithCount
-
transmuteCopy
-
transmuteCopy
-
transmuteCopyIgnoreEmpty
-
matches
-
listMatches
Deprecated. -
isSameItem
-
isSameItemSameComponents
-
lenientOptionalFieldOf
-
hashItemAndComponents
-
hashStackList
Deprecated. -
getDescriptionId
-
toString
-
inventoryTick
-
onCraftedBy
-
onCraftedBySystem
-
getUseDuration
-
getUseAnimation
-
releaseUsing
-
useOnRelease
public boolean useOnRelease() -
set
Description copied from interface:MutableDataComponentHolder
Sets a data component.- Specified by:
set
in interfaceMutableDataComponentHolder
-
update
@Nullable public <T,U> T update(DataComponentType<T> p_331083_, T p_331443_, U p_331049_, BiFunction<T, U, T> p_331846_) Description copied from interface:MutableDataComponentHolder
Updates a data component if it exists, using an additionalupdateContext
.- Specified by:
update
in interfaceMutableDataComponentHolder
-
update
@Nullable public <T> T update(DataComponentType<T> p_330921_, T p_331257_, UnaryOperator<T> p_331701_) Description copied from interface:MutableDataComponentHolder
Updates a data component if it exists.- Specified by:
update
in interfaceMutableDataComponentHolder
-
remove
Description copied from interface:MutableDataComponentHolder
Removes a data component.- Specified by:
remove
in interfaceMutableDataComponentHolder
-
applyComponentsAndValidate
-
applyComponents
Description copied from interface:MutableDataComponentHolder
Applies a set of component changes to this stack.- Specified by:
applyComponents
in interfaceMutableDataComponentHolder
-
applyComponents
Description copied from interface:MutableDataComponentHolder
Applies a set of component changes to this stack.- Specified by:
applyComponents
in interfaceMutableDataComponentHolder
-
getHoverName
-
addToTooltip
public <T extends TooltipProvider> void addToTooltip(DataComponentType<T> p_331344_, Item.TooltipContext p_341231_, Consumer<Component> p_331885_, TooltipFlag p_331177_) - Specified by:
addToTooltip
in interfaceIDataComponentHolderExtension
-
getTooltipLines
public List<Component> getTooltipLines(Item.TooltipContext p_339637_, @Nullable Player p_41652_, TooltipFlag p_41653_) -
addAttributeTooltips
-
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 p_348610_, BiConsumer<Holder<Attribute>, AttributeModifier> p_348516_) -
forEachModifier
public void forEachModifier(EquipmentSlot p_332001_, BiConsumer<Holder<Attribute>, AttributeModifier> p_330882_) -
getDisplayName
-
canPlaceOnBlockInAdventureMode
-
canBreakBlockInAdventureMode
-
getPopTime
public int getPopTime() -
setPopTime
public void setPopTime(int p_41755_) -
getCount
public int getCount() -
setCount
public void setCount(int p_41765_) -
limitSize
public void limitSize(int p_335437_) -
grow
public void grow(int p_41770_) -
shrink
public void shrink(int p_41775_) -
consume
-
consumeAndReturn
-
onUseTick
-
onDestroyed
Deprecated.Forge: Use damage source sensitive version -
getDrinkingSound
-
getEatingSound
-
getBreakingSound
-
canBeHurtBy
-
getTagEnchantments()
for NBT enchantments, orIItemStackExtension.getAllEnchantments(net.minecraft.core.HolderLookup.RegistryLookup<net.minecraft.world.item.enchantment.Enchantment>)
for gameplay.