Home Migration Guide Getting Started With Scripts Commands Examples
BracketHandlers

MCItemStackMutable

An MCItemStackMutable object is the same as any other IItemStack. The only difference is that changes made to it will not create a new ItemStack, but instead modify the stack given.

This is useful for example when you are dealing with Event Handlers and need to shrink the stack the player is using without assigning a new stack.

Importing the class

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

script.zs
import crafttweaker.api.item.MCItemStackMutable;

Implemented Interfaces

MCItemStackMutable implements the following interfaces. That means all methods defined in these interfaces are also available in MCItemStackMutable

Static Properties

NameTypeHas GetterHas SetterDescription
Name
CRAFTTWEAKER_DATA_KEY
Type
string
Has Getter
true
Has Setter
false
Description
No Description Provided

Casters

Result typeIs Implicit
Result type
IData
Is Implicit
true
Result type
IIngredientWithAmount
Is Implicit
true
Result type
MapData
Is Implicit
true
Result type
MCItemDefinition
Is Implicit
true
Result type
MCWeightedItemStack
Is Implicit
true

Methods

Adds an AttributeModifier to this IIngredient.

Attributes added with this method appear on all ItemStacks that match this IIngredient, regardless of how or when the ItemStack was made, if you want to have the attribute on a single specific ItemStack (such as a specific Diamond Sword made in a recipe), then you should use IItemStack#withAttributeModifier

Return Type: void

script.zs
// MCItemStackMutable.addGlobalAttributeModifier(attribute as Attribute, name as string, value as double, operation as AttributeOperation, slotTypes as MCEquipmentSlotType[]) as void
<item:minecraft:dirt>.mutable().addGlobalAttributeModifier(<attribute:minecraft:generic.attack_damage>, "Extra Power", 10, AttributeOperation.ADDITION, [<equipmentslottype:chest>]);
ParameterTypeDescription
Parameter
attribute
Type
Attribute
Description
The Attribute of the modifier.
Parameter
name
Type
string
Description
The name of the modifier.
Parameter
value
Type
double
Description
The value of the modifier.
Parameter
operation
Type
AttributeOperation
Description
The operation of the modifier.
Parameter
slotTypes
Type
MCEquipmentSlotType[]
Description
What slots the modifier is valid for.

Adds an AttributeModifier to this IIngredient 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 appear on all ItemStacks that match this IIngredient, regardless of how or when the ItemStack was made, if you want to have the attribute on a single specific ItemStack (such as a specific Diamond Sword made in a recipe), then you should use IItemStack#withAttributeModifier

Return Type: void

script.zs
// MCItemStackMutable.addGlobalAttributeModifier(attribute as Attribute, uuid as string, name as string, value as double, operation as AttributeOperation, slotTypes as MCEquipmentSlotType[]) as void
<item:minecraft:dirt>.mutable().addGlobalAttributeModifier(<attribute:minecraft:generic.attack_damage>, "8c1b5535-9f79-448b-87ae-52d81480aaa3", "Extra Power", 10, AttributeOperation.ADDITION, [<equipmentslottype:chest>]);
ParameterTypeDescription
Parameter
attribute
Type
Attribute
Description
The Attribute of the modifier.
Parameter
uuid
Type
string
Description
The unique identifier of the modifier to replace.
Parameter
name
Type
string
Description
The name of the modifier.
Parameter
value
Type
double
Description
The value of the modifier.
Parameter
operation
Type
AttributeOperation
Description
The operation of the modifier.
Parameter
slotTypes
Type
MCEquipmentSlotType[]
Description
What slots the modifier is valid for.

Return Type: void

script.zs
MCItemStackMutable.addShiftTooltip(content as MCTextComponent, showMessage as MCTextComponent) as void
ParameterTypeDescriptionOptionalDefaultValue
Parameter
content
Type
MCTextComponent
Description
No Description Provided
Optional
false
DefaultValue
Parameter
showMessage
Type
MCTextComponent
Description
No Description Provided
Optional
true
DefaultValue

Return Type: void

script.zs
MCItemStackMutable.addTooltip(content as MCTextComponent) as void
ParameterTypeDescription
Parameter
content
Type
MCTextComponent
Description
No Description Provided

Return Type: MCIngredientConditioned<IIngredient>

script.zs
// MCItemStackMutable.anyDamage() as MCIngredientConditioned<IIngredient>
<item:minecraft:dirt>.mutable().anyDamage();

Return Type: IIngredientWithAmount

script.zs
// MCItemStackMutable.asIIngredientWithAmount() as IIngredientWithAmount
<item:minecraft:dirt>.mutable().asIIngredientWithAmount();

Clears any custom name set for this ItemStack

Return Type: void

script.zs
// MCItemStackMutable.clearCustomName() as void
<item:minecraft:dirt>.mutable().clearCustomName();

Return Type: void

script.zs
// MCItemStackMutable.clearTooltip() as void
<item:minecraft:dirt>.mutable().clearTooltip();

Does the ingredient contain the given ingredient?

Return Type: boolean

script.zs
// MCItemStackMutable.contains(ingredient as IIngredient) as boolean
<item:minecraft:dirt>.mutable().contains((<item:minecraft:iron_ingot> | <item:minecraft:gold_ingot>));
ParameterTypeDescription
Parameter
ingredient
Type
IIngredient
Description
The ingredient to check

Gets the Attributes and the AttributeModifiers on this IItemStack for the given EquipmentSlotType

Returns: A Map of Attribute to a List of AttributeModifier for the given EquipmentSlotType.
Return Type: stdlib.List<AttributeModifier>[Attribute]

script.zs
// MCItemStackMutable.getAttributes(slotType as MCEquipmentSlotType) as stdlib.List<AttributeModifier>[Attribute]
<item:minecraft:dirt>.mutable().getAttributes(<equipmentslottype:chest>);
ParameterTypeDescription
Parameter
slotType
Type
MCEquipmentSlotType
Description
The slot to get the Attributes for.

Return Type: MCItemDefinition

script.zs
// MCItemStackMutable.getDefinition() as MCItemDefinition
<item:minecraft:dirt>.mutable().getDefinition();

Gets the level of the given enchantment on the item. Returns 0 if the item doesn’t have the given enchantment.

Return Type: int

script.zs
MCItemStackMutable.getEnchantmentLevel(enchantment as MCEnchantment) as int
ParameterTypeDescription
Parameter
enchantment
Type
MCEnchantment
Description
No Description Provided

Return Type: int?[MCEnchantment]

script.zs
// MCItemStackMutable.getEnchantments() as int?[MCEnchantment]
<item:minecraft:dirt>.mutable().getEnchantments();

Returns the max stack size of the Item in the ItemStack

Returns: Max stack size of the Item.
Return Type: int

script.zs
// MCItemStackMutable.getMaxStackSize() as int
<item:minecraft:dirt>.mutable().getMaxStackSize();

Returns the rarity of the Item in the ItemStack

Returns: Rarity of the Item.
Return Type: Rarity

script.zs
// MCItemStackMutable.getRarity() as Rarity
<item:minecraft:dirt>.mutable().getRarity();

When this ingredient stack is crafted, what will remain in the grid? Does not check if the stack matches though! Used e.g. in Crafting Table recipes.

Return Type: IItemStack

script.zs
// MCItemStackMutable.getRemainingItem(stack as IItemStack) as IItemStack
<item:minecraft:dirt>.mutable().getRemainingItem(<item:minecraft:iron_ingot>);
ParameterTypeDescription
Parameter
stack
Type
IItemStack
Description
The stack to provide for this ingredient.

Return Type: boolean

script.zs
// MCItemStackMutable.isFood() as boolean
<item:minecraft:dirt>.mutable().isFood();

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.
Return Type: boolean

script.zs
// MCItemStackMutable.isImmuneToFire() as boolean
<item:minecraft:dirt>.mutable().isImmuneToFire();

Does the given stack match the ingredient?

Return Type: boolean

script.zs
// MCItemStackMutable.matches(stack as IItemStack) as boolean
<item:minecraft:dirt>.mutable().matches(<item:minecraft:iron_ingot>);
ParameterTypeDescription
Parameter
stack
Type
IItemStack
Description
The stack to check

Return Type: void

script.zs
MCItemStackMutable.modifyShiftTooltip(shiftedFunction as ITooltipFunction, unshiftedFunction as ITooltipFunction) as void
ParameterTypeDescriptionOptionalDefaultValue
Parameter
shiftedFunction
Type
ITooltipFunction
Description
No Description Provided
Optional
false
DefaultValue
Parameter
unshiftedFunction
Type
ITooltipFunction
Description
No Description Provided
Optional
true
DefaultValue

Return Type: void

script.zs
MCItemStackMutable.modifyTooltip(function as ITooltipFunction) as void
ParameterTypeDescription
Parameter
function
Type
ITooltipFunction
Description
No Description Provided

Use this if you already have the condition from another ingredient

Return Type: MCIngredientConditioned<IIngredient>

script.zs
MCItemStackMutable.only(condition as IIngredientCondition<IIngredient>) as MCIngredientConditioned<IIngredient>
ParameterTypeDescription
Parameter
condition
Type
IIngredientCondition<IIngredient>
Description
No Description Provided

Return Type: MCIngredientConditioned<IIngredient>

script.zs
// MCItemStackMutable.onlyDamaged() as MCIngredientConditioned<IIngredient>
<item:minecraft:dirt>.mutable().onlyDamaged();

Return Type: MCIngredientConditioned<IIngredient>

script.zs
MCItemStackMutable.onlyDamagedAtLeast(minDamage as int) as MCIngredientConditioned<IIngredient>
ParameterTypeDescription
Parameter
minDamage
Type
int
Description
No Description Provided

Return Type: MCIngredientConditioned<IIngredient>

script.zs
MCItemStackMutable.onlyDamagedAtMost(maxDamage as int) as MCIngredientConditioned<IIngredient>
ParameterTypeDescription
Parameter
maxDamage
Type
int
Description
No Description Provided

Return Type: MCIngredientConditioned<IIngredient>

script.zs
MCItemStackMutable.onlyIf(uid as string, function as Predicate<IItemStack>) as MCIngredientConditioned<IIngredient>
ParameterTypeDescriptionOptionalDefaultValue
Parameter
uid
Type
string
Description
No Description Provided
Optional
false
DefaultValue
Parameter
function
Type
Predicate<IItemStack>
Description
No Description Provided
Optional
true
DefaultValue

Removes all AttributeModifiers that use the given Attribute from this IIngredient.

Attributes removed with this method are removed from ItemStacks that match this IIngredient, regardless of how or when the ItemStack was made, if you want to remove the attribute on a single specific ItemStack (such as a specific Diamond Sword made in a recipe), then you should use IItemStack#withoutAttribute.

This method can only remove default Attributes from an ItemStack, it is still possible that an ItemStack can override it.

Return Type: void

script.zs
// MCItemStackMutable.removeGlobalAttribute(attribute as Attribute, slotTypes as MCEquipmentSlotType[]) as void
<item:minecraft:dirt>.mutable().removeGlobalAttribute(<attribute:minecraft:generic.attack_damage>, [<equipmentslottype:chest>]);
ParameterTypeDescription
Parameter
attribute
Type
Attribute
Description
The attribute to remove.
Parameter
slotTypes
Type
MCEquipmentSlotType[]
Description
The slot types to remove it from.

Removes all AttributeModifiers who’s ID is the same as the given uuid from this IIngredient.

Return Type: void

script.zs
// MCItemStackMutable.removeGlobalAttributeModifier(uuid as string, slotTypes as MCEquipmentSlotType[]) as void
<item:minecraft:dirt>.mutable().removeGlobalAttributeModifier("8c1b5535-9f79-448b-87ae-52d81480aaa3", [<equipmentslottype:chest>]);
ParameterTypeDescription
Parameter
uuid
Type
string
Description
The unique id of the AttributeModifier to remove.
Parameter
slotTypes
Type
MCEquipmentSlotType[]
Description
The slot types to remove it from.

Return Type: void

script.zs
MCItemStackMutable.removeTooltip(regex as string) as void
ParameterTypeDescription
Parameter
regex
Type
string
Description
No Description Provided

Sets if this IItemStack is immune to fire / lava.

If true, the item will not burn when thrown into fire or lava.

Return Type: void

script.zs
// MCItemStackMutable.setImmuneToFire(immuneToFire as boolean) as void
<item:minecraft:dirt>.mutable().setImmuneToFire(true);
ParameterTypeDescription
Parameter
immuneToFire
Type
boolean
Description
Should the item be immune to fire.

Sets the max stacksize of the Item.

Return Type: void

script.zs
// MCItemStackMutable.setMaxStackSize(newMaxStackSize as int) as void
<item:minecraft:dirt>.mutable().setMaxStackSize(16);
ParameterTypeDescription
Parameter
newMaxStackSize
Type
int
Description
The new max stack size of the Item.

Sets the rarity of the Item.

Return Type: void

script.zs
// MCItemStackMutable.setRarity(newRarity as Rarity) as void
<item:minecraft:dirt>.mutable().setRarity(Rarity.UNCOMMON);
ParameterTypeDescription
Parameter
newRarity
Type
Rarity
Description
The new rarity of the Item.

Return Type: MCWeightedItemStack

script.zs
MCItemStackMutable.weight(weight as double) as MCWeightedItemStack
ParameterTypeDescription
Parameter
weight
Type
double
Description
No Description Provided

Operators

Does the ingredient contain the given ingredient?

script.zs
ingredient as IIngredient in myMCItemStackMutable
(<item:minecraft:iron_ingot> | <item:minecraft:gold_ingot>) in <item:minecraft:dirt>.mutable()
script.zs
myMCItemStackMutable == o as Object
script.zs
myMCItemStackMutable % percentage as int
script.zs
myMCItemStackMutable | other as IIngredient

Properties

NameTypeHas GetterHas SetterDescription
Name
amount
Type
int
Has Getter
true
Has Setter
false
Description
Gets the amount of Items in the ItemStack
Name
burnTime
Type
int
Has Getter
true
Has Setter
true
Description
No Description Provided
Name
damageable
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns if the ItemStack is damageable
I.E Swords and tools are damageable, sticks are not.
Name
damaged
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns if the ItemStack is damaged
I.E a Swords that is no at full durability is damaged.
Name
definition
Type
MCItemDefinition
Has Getter
true
Has Setter
false
Description
No Description Provided
Name
displayName
Type
string
Has Getter
true
Has Setter
false
Description
Gets the display name of the ItemStack
Name
empty
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns if the ItemStack is empty
Name
enchantments
Type
int?[MCEnchantment]
Has Getter
true
Has Setter
false
Description
No Description Provided
Name
food
Type
MCFood?
Has Getter
true
Has Setter
true
Description
No Description Provided
Name
getOrCreate
Type
IData
Has Getter
true
Has Setter
false
Description
Returns the NBT tag attached to this ItemStack or makes a new tag.
Name
getRepairCost
Type
int
Has Getter
true
Has Setter
false
Description
Gets the repair cost of the ItemStack, or 0 if no repair is defined.
Name
hasDisplayName
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns true if the ItemStack has a display name.
Name
hasEffect
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns true if this ItemStack has an effect.
Name
hasTag
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns true if this ItemStack has a Tag
Name
immuneToFire
Type
void
Has Getter
true
Has Setter
true
Description
Sets if this IItemStack is immune to fire / lava.

If true, the item will not burn when thrown into fire or lava.
Name
isCrossbow
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns true if this stack is considered a crossbow item
Name
isEnchantable
Type
boolean
Has Getter
true
Has Setter
false
Description
Can this ItemStack be enchanted?
Name
isEnchanted
Type
boolean
Has Getter
true
Has Setter
false
Description
Is this ItemStack enchanted?
Name
maxDamage
Type
int
Has Getter
true
Has Setter
true
Description
Returns the max damage of the ItemStack
This is the max durability of the ItemStack.
Name
maxStackSize
Type
int
Has Getter
true
Has Setter
true
Description
Returns the max stack size of the Item in the ItemStack
Name
owner
Type
string
Has Getter
true
Has Setter
false
Description
Gets owning mod for the Item in this IItemStack
Name
rarity
Type
Rarity
Has Getter
true
Has Setter
true
Description
Returns the rarity of the Item in the ItemStack
Name
registryName
Type
MCResourceLocation
Has Getter
true
Has Setter
false
Description
Gets the registry name for the Item in this IItemStack
Name
stackable
Type
boolean
Has Getter
true
Has Setter
false
Description
Returns if the ItemStack can have an amount greater than 1
I.E Swords and tools are not stackable, sticks are.
Name
tag
Type
IData
Has Getter
true
Has Setter
false
Description
Returns the NBT tag attached to this ItemStack.
Name
toolTypes
Type
ToolType[]
Has Getter
true
Has Setter
false
Description
No Description Provided
Name
translationKey
Type
string
Has Getter
true
Has Setter
false
Description
Returns the unlocalized Name of the Item in the ItemStack
Name
useDuration
Type
int
Has Getter
true
Has Setter
false
Description
Gets the use duration of the ItemStack