Interface IItemStack

All Superinterfaces:
CommandStringDisplayable, IIngredient, IIngredientWithAmount
All Known Subinterfaces:
ForgeItemStack
All Known Implementing Classes:
MCItemStack, MCItemStackMutable

@ZenRegister public interface IItemStack extends IIngredient, IIngredientWithAmount
  • Field Details

    • CRAFTTWEAKER_DATA_KEY

      static final String CRAFTTWEAKER_DATA_KEY
      See Also:
    • BASE_ATTACK_DAMAGE_UUID

      static final UUID BASE_ATTACK_DAMAGE_UUID
    • BASE_ATTACK_SPEED_UUID

      static final UUID BASE_ATTACK_SPEED_UUID
  • Method Details

    • empty

      static IItemStack empty()
    • of

      static IItemStack of(net.minecraft.world.item.ItemStack stack)
    • of

      static IItemStack of(net.minecraft.world.item.ItemStack stack, boolean mutable)
    • ofMutable

      static IItemStack ofMutable(net.minecraft.world.item.ItemStack stack)
    • copy

      IItemStack copy()
      Creates a copy
    • getRegistryName

      default net.minecraft.resources.ResourceLocation getRegistryName()
      Gets the registry name for the Item in this IItemStack
      Returns:
      registry name of the Item this IItemStack represents
    • getOwner

      default String getOwner()
      Gets owning mod for the Item in this IItemStack
      Returns:
      owning mod of the Item this IItemStack represents
    • isEmpty

      default boolean isEmpty()
      Returns if the ItemStack is empty
      Specified by:
      isEmpty in interface IIngredient
      Returns:
      true if empty, false if not
    • getMaxStackSize

      default int getMaxStackSize()
      Returns the max stack size of the Item in the ItemStack
      Returns:
      Max stack size of the Item.
    • setMaxStackSize

      default void setMaxStackSize(int newMaxStackSize)
      Sets the max stacksize of the Item.
      Parameters:
      newMaxStackSize - The new max stack size of the Item.
      DocParam:
      newMaxStackSize 16
    • getRarity

      default net.minecraft.world.item.Rarity getRarity()
      Returns the rarity of the Item in the ItemStack
      Returns:
      Rarity of the Item.
    • setRarity

      default void setRarity(net.minecraft.world.item.Rarity newRarity)
      Sets the rarity of the Item.
      Parameters:
      newRarity - The new rarity of the Item.
      DocParam:
      newRarity Rarity.UNCOMMON
    • withLore

      default IItemStack withLore(net.minecraft.network.chat.Component... lore)
      Sets the lore of the ItemStack
      Parameters:
      lore - the new Lore of the ItemStack.
      DocParam:
      lore new crafttweaker.api.text.TextComponent("I am the lore I speak for the trees");
    • getDisplayName

      default net.minecraft.network.chat.Component getDisplayName()
      Gets the display name of the ItemStack
      Returns:
      formatted display name of the ItemStack.
    • withDisplayName

      default IItemStack withDisplayName(net.minecraft.network.chat.Component name)
      Sets the display name of the ItemStack
      Parameters:
      name - New name of the stack.
      DocParam:
      name "totally not dirt"
    • getHoverName

      default net.minecraft.network.chat.Component getHoverName()
      Gets the hover name of the ItemStack.

      This will give the raw name without the formatting that 'displayName' applies.

      Returns:
      The hover name of the ItemStack.
    • resetHoverName

      default void resetHoverName()
      Clears any custom name set for this ItemStack
    • hasDisplayName

      default boolean hasDisplayName()
      Returns true if the ItemStack has a display name.
      Returns:
      true if a display name is present on the ItemStack.
    • hasFoil

      default boolean hasFoil()
      Returns true if this ItemStack has a foil effect. Foil is the glint / effect that is added to enchanted ItemStacks (and other items).
      Returns:
      true if this ItemStack has a foil effect.
    • isEnchantable

      default boolean isEnchantable()
      Can this ItemStack be enchanted?
      Returns:
      true if this ItemStack can be enchanted.
    • isEnchanted

      default boolean isEnchanted()
      Is this ItemStack enchanted?
      Returns:
      true if this ItemStack is enchanted.
    • getBaseRepairCost

      default int getBaseRepairCost()
      Gets the base repair cost of the ItemStack, or 0 if no repair is defined.
      Returns:
      ItemStack repair cost or 0 if no repair is set.
    • getAmount

      default int getAmount()
      Gets the amount of Items in the ItemStack
      Specified by:
      getAmount in interface IIngredientWithAmount
      Returns:
      ItemStack's amount
    • setAmount

      default IItemStack setAmount(int amount)
      Sets the amount of the ItemStack
      Parameters:
      amount - new amount
      DocParam:
      amount 3
    • grow

      default IItemStack grow(int amount)
      Grows this IItemStack's stack size by the given amount, or 1 if no amount is given.
      Parameters:
      amount - The amount to grow by.
      Returns:
      This IItemStack if mutable, a new one with the new amount otherwise.
      DocParam:
      amount 2
    • shrink

      default IItemStack shrink(int amount)
      Shrinks this IItemStack's stack size by the given amount, or 1 if no amount is given.
      Parameters:
      amount - The amount to shrink by.
      Returns:
      This IItemStack if mutable, a new one with the new amount otherwise.
      DocParam:
      amount 2
    • isStackable

      default boolean isStackable()
      Returns if the ItemStack can have an amount greater than 1 I.E Swords and tools are not stackable, sticks are.
      Returns:
      true if this ItemStack can contain more than one item.
    • withDamage

      default IItemStack withDamage(int damage)
      Sets the damage of the ItemStack
      Parameters:
      damage - the new damage value
      DocParam:
      damage 10
    • withAttributeModifier

      default IItemStack withAttributeModifier(net.minecraft.world.entity.ai.attributes.Attribute attribute, String uuid, String name, double value, net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation operation, net.minecraft.world.entity.EquipmentSlot[] slotTypes, boolean preserveDefaults)
      Adds an AttributeModifier to this IItemStack using a specific UUID. The UUID can be used to override an existing attribute on an ItemStack with this new modifier. You can use `/ct hand attributes` to get the UUID of the attributes on an ItemStack. Attributes added with this method will only appear on this specific IItemStack. By defaults, adding a modifier will remove the default Attribute Modifiers on the Item, like the Diamond Chestplate's Armor and Toughness values. When `preserveDefaults` is set to true (by default it is false.), the default Attribute Modifiers will be preserved when adding this modifier. This means that if you were adding the `forge:nametag_distance` attribute to an Item, it would keep its default attributes (like Armor and Toughness values).
      Parameters:
      uuid - The unique identifier of the modifier to replace.
      attribute - The Attribute of the modifier.
      name - The name of the modifier.
      value - The value of the modifier.
      operation - The operation of the modifier.
      slotTypes - What slots the modifier is valid for.
      preserveDefaults - Should the default Item Attribute Modifiers be preserved when adding this modifier.
      DocParam:
      attribute <attribute:minecraft:generic.attack_damage>, uuid "8c1b5535-9f79-448b-87ae-52d81480aaa3", name "Extra Power", value 10, operation AttributeOperation.ADDITION, slotTypes [<constant:minecraft:equipmentslot:chest>], preserveDefaults true
    • withAttributeModifier

      default IItemStack withAttributeModifier(net.minecraft.world.entity.ai.attributes.Attribute attribute, UUID uuid, String name, double value, net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation operation, net.minecraft.world.entity.EquipmentSlot[] slotTypes, boolean preserveDefaults)
      Adds an AttributeModifier to this IItemStack using a specific UUID. The UUID can be used to override an existing attribute on an ItemStack with this new modifier. You can use `/ct hand attributes` to get the UUID of the attributes on an ItemStack. Attributes added with this method will only appear on this specific IItemStack. By defaults, adding a modifier will remove the default Attribute Modifiers on the Item, like the Diamond Chestplate's Armor and Toughness values. When `preserveDefaults` is set to true (by default it is false.), the default Attribute Modifiers will be preserved when adding this modifier. This means that if you were adding the `forge:nametag_distance` attribute to an Item, it would keep its default attributes (like Armor and Toughness values).
      Parameters:
      uuid - The unique identifier of the modifier to replace.
      attribute - The Attribute of the modifier.
      name - The name of the modifier.
      value - The value of the modifier.
      operation - The operation of the modifier.
      slotTypes - What slots the modifier is valid for.
      preserveDefaults - Should the default Item Attribute Modifiers be preserved when adding this modifier.
      DocParam:
      attribute <attribute:minecraft:generic.attack_damage>, uuid "8c1b5535-9f79-448b-87ae-52d81480aaa3", name "Extra Power", value 10, operation AttributeOperation.ADDITION, slotTypes [<constant:minecraft:equipmentslot:chest>], preserveDefaults true
    • withAttributeModifier

      default IItemStack withAttributeModifier(net.minecraft.world.entity.ai.attributes.Attribute attribute, String name, double value, net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation operation, net.minecraft.world.entity.EquipmentSlot[] slotTypes, boolean preserveDefaults)
      Adds an AttributeModifier to this IItemStack. The UUID can be used to override an existing attribute on an ItemStack with this new modifier. You can use `/ct hand attributes` to get the UUID of the attributes on an ItemStack. Attributes added with this method will only appear on this specific IItemStack. By defaults, adding a modifier will remove the default Attribute Modifiers on the Item, like the Diamond Chestplate's Armor and Toughness values. When `preserveDefaults` is set to true (by default it is false.), the default Attribute Modifiers will be preserved when adding this modifier. This means that if you were adding the `forge:nametag_distance` attribute to an Item, it would keep its default attributes (like Armor and Toughness values).
      Parameters:
      attribute - The Attribute of the modifier.
      name - The name of the modifier.
      value - The value of the modifier.
      operation - The operation of the modifier.
      slotTypes - What slots the modifier is valid for.
      preserveDefaults - Should the default Item Attribute Modifiers be preserved when adding this modifier.
      DocParam:
      attribute <attribute:minecraft:generic.attack_damage>, name "Extra Power", value 10, operation AttributeOperation.ADDITION, slotTypes [<constant:minecraft:equipmentslot:chest>], preserveDefaults true
    • getAttributes

      default Map<net.minecraft.world.entity.ai.attributes.Attribute,List<net.minecraft.world.entity.ai.attributes.AttributeModifier>> getAttributes(net.minecraft.world.entity.EquipmentSlot slotType)
      Gets the Attributes and the AttributeModifiers on this IItemStack for the given EquipmentSlot
      Parameters:
      slotType - The slot to get the Attributes for.
      Returns:
      A Map of Attribute to a List of AttributeModifier for the given EquipmentSlot.
      DocParam:
      slotType <constant:minecraft:equipmentslot:chest>
    • isDamageableItem

      default boolean isDamageableItem()
      Returns if the ItemStack is damageable I.E Swords and tools are damageable, sticks are not.
      Returns:
      true if this ItemStack can take damage.
    • isDamaged

      default boolean isDamaged()
      Returns if the ItemStack is damaged I.E a Swords that is no at full durability is damaged.
      Returns:
      true if this ItemStack is damaged.
    • getMaxDamage

      default int getMaxDamage()
      Returns the max damage of the ItemStack This is the max durability of the ItemStack.
      Returns:
      The ItemStack's max durability.
    • setMaxDamage

      default void setMaxDamage(int newMaxDamage)
      Sets the max damage of the ItemStack. Setting the damage to `0` will make the item unbreakable.
      Parameters:
      newMaxDamage - The new max damage of the ItemStack
      DocParam:
      maxDamage 5
    • getDescriptionId

      default String getDescriptionId()
      Returns the unlocalized Name of the Item in the ItemStack
      Returns:
      the unlocalized name.
    • withTag

      default IItemStack withTag(MapData tag)
      Sets the tag for the ItemStack.
      Parameters:
      tag - The tag to set.
      Returns:
      This itemStack if it is mutable, a new one with the changed property otherwise
      DocParam:
      tag {Display: {lore: ["Hello"]}}
    • withoutTag

      default IItemStack withoutTag()
      Removes the tag from this ItemStack.
      Returns:
      This itemStack if it is mutable, a new one with the changed property otherwise
    • hasTag

      default boolean hasTag()
      Returns true if this ItemStack has a Tag
      Returns:
      true if tag is present.
    • getTag

      default IData getTag()
      Returns the NBT tag attached to this ItemStack.
      Returns:
      MapData of the ItemStack NBT Tag, null if it doesn't exist.
    • getOrCreateTag

      default IData getOrCreateTag()
      Returns the NBT tag attached to this ItemStack or makes a new tag.
      Returns:
      MapData of the ItemStack NBT Tag, empty tag if it doesn't exist.
    • matches

      default boolean matches(IItemStack stack, boolean ignoreDamage)
      Description copied from interface: IIngredient
      Does the given stack match the ingredient?
      Specified by:
      matches in interface IIngredient
      Parameters:
      stack - The stack to check
      ignoreDamage - Should damage be checked?
    • getCommandString

      default String getCommandString()
      Description copied from interface: IIngredient
      Returns the BEP to get this stack
      Specified by:
      getCommandString in interface CommandStringDisplayable
      Specified by:
      getCommandString in interface IIngredient
    • getUseDuration

      default int getUseDuration()
      Gets the use duration of the ItemStack
      Returns:
      use duration
    • useOnRelease

      default boolean useOnRelease()
      Returns true if this stack is considered a crossbow item
      Returns:
      true if stack is a crossbow
    • getFood

      default net.minecraft.world.food.FoodProperties getFood()
    • setFood

      default void setFood(net.minecraft.world.food.FoodProperties food)
    • isEdible

      default boolean isEdible()
    • getBurnTime

      default int getBurnTime()
    • isFireResistant

      default boolean isFireResistant()
      Checks if this IItemStack burns when thrown into fire / lava or damaged by fire.
      Returns:
      True if this IItemStack is immune to fire. False otherwise.
    • setFireResistant

      default void setFireResistant(boolean fireResistant)
      Sets if this IItemStack is immune to fire / lava. If true, the item will not burn when thrown into fire or lava.
      Parameters:
      fireResistant - Should the item be immune to fire.
      DocParam:
      immuneToFire true
    • percent

      default Percentaged<IItemStack> percent(double percentage)
    • asWeightedItemStack

      default Percentaged<IItemStack> asWeightedItemStack()
    • getDefinition

      default net.minecraft.world.item.Item getDefinition()
    • asItemLike

      default net.minecraft.world.level.ItemLike asItemLike()
    • asMutable

      IItemStack asMutable()
    • asImmutable

      IItemStack asImmutable()
    • isImmutable

      boolean isImmutable()
    • isMutable

      default boolean isMutable()
    • getDamage

      default int getDamage()
    • getEnchantments

      default Map<net.minecraft.world.item.enchantment.Enchantment,Integer> getEnchantments()
    • setEnchantments

      default IItemStack setEnchantments(Map<net.minecraft.world.item.enchantment.Enchantment,Integer> enchantments)
      Sets the enchantments on this IItemStack.
      Parameters:
      enchantments - The new enchantments
      Returns:
      This itemStack if it is mutable, a new one with the enchantments otherwise
    • getEnchantmentLevel

      default int getEnchantmentLevel(net.minecraft.world.item.enchantment.Enchantment enchantment)
      Gets the level of the given enchantment on the item. Returns 0 if the item doesn't have the given enchantment.
    • withEnchantment

      default IItemStack withEnchantment(net.minecraft.world.item.enchantment.Enchantment enchantment, int level)
      Enchants this IItemStack with the given Enchantment.
      Parameters:
      enchantment - The enchantment to add.
      level - The level of the enchantment
      Returns:
      This itemStack if it is mutable, a new one with the enchantment added otherwise
      DocParam:
      enchantment <enchantment:minecraft:riptide>, level 2
    • removeEnchantment

      default IItemStack removeEnchantment(net.minecraft.world.item.enchantment.Enchantment enchantment)
      Removes the given enchantment from this IItemStack.
      Parameters:
      enchantment - The enchantment to remove.
      Returns:
      This itemStack if it is mutable, a new one with the enchantment removed otherwise
      DocParam:
      enchantment <enchantment:minecraft:riptide>
    • getInternal

      net.minecraft.world.item.ItemStack getInternal()
      Gets the internal ItemStack for this IItemStack.
      Returns:
      internal ItemStack
    • asVanillaIngredient

      default net.minecraft.world.item.crafting.Ingredient asVanillaIngredient()
      Description copied from interface: IIngredient
      Create a Vanilla ingredient matching this one.
      Specified by:
      asVanillaIngredient in interface IIngredient
    • getImmutableInternal

      default net.minecraft.world.item.ItemStack getImmutableInternal()
    • asIIngredientWithAmount

      default IIngredientWithAmount asIIngredientWithAmount()
      Description copied from interface: IIngredient
      Used implicitly when a machine can accept more than one item but you only provide one.
      Specified by:
      asIIngredientWithAmount in interface IIngredient
    • getIngredient

      default IItemStack getIngredient()
      Description copied from interface: IIngredientWithAmount
      The backing ingredient
      Specified by:
      getIngredient in interface IIngredientWithAmount
    • asIData

      default IData asIData()
      Specified by:
      asIData in interface IIngredient
      Specified by:
      asIData in interface IIngredientWithAmount
    • modify

      IItemStack modify(Consumer<net.minecraft.world.item.ItemStack> stackModifier)