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.

ZenScript
Copy
import crafttweaker.api.item.MCItemStackMutable;

Interfacce Implementate

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

Caster

Methods

addGlobalAttributeModifier

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

ZenScript
Copy
// 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
attributeAttributeThe Attribute of the modifier.
namestringThe name of the modifier.
valuedoubleThe value of the modifier.
operationAttributeOperationThe operation of the modifier.
slotTypesMCEquipmentSlotType[]What slots the modifier is valid for.
addGlobalAttributeModifier

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

ZenScript
Copy
// 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
attributeAttributeThe Attribute of the modifier.
uuidstringThe unique identifier of the modifier to replace.
namestringThe name of the modifier.
valuedoubleThe value of the modifier.
operationAttributeOperationThe operation of the modifier.
slotTypesMCEquipmentSlotType[]What slots the modifier is valid for.
addShiftTooltip

Return Type: void

ZenScript
Copy
MCItemStackMutable.addShiftTooltip(content as MCTextComponent, showMessage as MCTextComponent) as void
ParameterTypeDescriptionOptionalDefaultValue
contenutoMCTextComponentNo Description Providedfalse
showMessageMCTextComponentNo Description Providedtrue
addTooltip

Return Type: void

ZenScript
Copy
MCItemStackMutable.addTooltip(content as MCTextComponent) as void
ParameterTypeDescription
contenutoMCTextComponentNo Description Provided
anyDamage

Return Type: MCIngredientConditioned<IIngredient>

ZenScript
Copy
// MCItemStackMutable.anyDamage() as MCIngredientConditioned<IIngredient>

<item:minecraft:dirt>.mutable().anyDamage();
asIIngredientWithAmount

Return Type: IIngredientWithAmount

ZenScript
Copy
// MCItemStackMutable.asIIngredientWithAmount() as IIngredientWithAmount

<item:minecraft:dirt>.mutable().asIIngredientWithAmount();
clearCustomName

Clears any custom name set for this ItemStack

Return Type: void

ZenScript
Copy
// MCItemStackMutable.clearCustomName() as void

<item:minecraft:dirt>.mutable().clearCustomName();
clearTooltip

Return Type: void

ZenScript
Copy
// MCItemStackMutable.clearTooltip() as void

<item:minecraft:dirt>.mutable().clearTooltip();
contains

Does the ingredient contain the given ingredient?

Return Type: boolean

ZenScript
Copy
// MCItemStackMutable.contains(ingredient as IIngredient) as boolean

<item:minecraft:dirt>.mutable().contains((<item:minecraft:iron_ingot> | <item:minecraft:gold_ingot>));
ParameterTypeDescription
ingredientIIngredientThe ingredient to check
getAttributes

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]

ZenScript
Copy
// MCItemStackMutable.getAttributes(slotType as MCEquipmentSlotType) as stdlib.List<AttributeModifier>[Attribute]

<item:minecraft:dirt>.mutable().getAttributes(<equipmentslottype:chest>);
ParameterTypeDescription
slotTypeMCEquipmentSlotTypeThe slot to get the Attributes for.
getDefinition

Return Type: MCItemDefinition

ZenScript
Copy
// MCItemStackMutable.getDefinition() as MCItemDefinition

<item:minecraft:dirt>.mutable().getDefinition();
getEnchantmentLevel

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

Return Type: int

ZenScript
Copy
MCItemStackMutable.getEnchantmentLevel(enchantment as MCEnchantment) as int
ParameterTypeDescription
enchantmentMCEnchantmentNo Description Provided
getEnchantments

Return Type: Integer[MCEnchantment]

ZenScript
Copy
// MCItemStackMutable.getEnchantments() as Integer[MCEnchantment]

<item:minecraft:dirt>.mutable().getEnchantments();
getMaxStackSize

Returns the max stack size of the Item in the ItemStack

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

ZenScript
Copy
// MCItemStackMutable.getMaxStackSize() as int

<item:minecraft:dirt>.mutable().getMaxStackSize();
getRarity

Returns the rarity of the Item in the ItemStack

Returns: Rarity of the Item.
Return Type: Rarity

ZenScript
Copy
// MCItemStackMutable.getRarity() as Rarity

<item:minecraft:dirt>.mutable().getRarity();
getRemainingItem

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

ZenScript
Copy
// MCItemStackMutable.getRemainingItem(stack as IItemStack) as IItemStack

<item:minecraft:dirt>.mutable().getRemainingItem(<item:minecraft:iron_ingot>);
ParameterTypeDescription
stackIItemStackThe stack to provide for this ingredient.
isFood

Return Type: boolean

ZenScript
Copy
// MCItemStackMutable.isFood() as boolean

<item:minecraft:dirt>.mutable().isFood();
isImmuneToFire

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

ZenScript
Copy
// MCItemStackMutable.isImmuneToFire() as boolean

<item:minecraft:dirt>.mutable().isImmuneToFire();
matches

Does the given stack match the ingredient?

Return Type: boolean

ZenScript
Copy
// MCItemStackMutable.matches(stack as IItemStack) as boolean

<item:minecraft:dirt>.mutable().matches(<item:minecraft:iron_ingot>);
ParameterTypeDescription
stackIItemStackThe stack to check
modifyShiftTooltip

Return Type: void

ZenScript
Copy
MCItemStackMutable.modifyShiftTooltip(shiftedFunction as ITooltipFunction, unshiftedFunction as ITooltipFunction) as void
ParameterTypeDescriptionOptionalDefaultValue
shiftedFunctionITooltipFunctionNo Description Providedfalse
unshiftedFunctionITooltipFunctionNo Description Providedtrue
modifyTooltip

Return Type: void

ZenScript
Copy
MCItemStackMutable.modifyTooltip(function as ITooltipFunction) as void
ParameterTypeDescription
functionITooltipFunctionNo Description Provided
only

Use this if you already have the condition from another ingredient

Return Type: MCIngredientConditioned<IIngredient>

ZenScript
Copy
MCItemStackMutable.only(condition as IIngredientCondition<IIngredient>) as MCIngredientConditioned<IIngredient>
ParameterTypeDescription
conditionIIngredientCondition<IIngredient>No Description Provided
onlyDamaged

Return Type: MCIngredientConditioned<IIngredient>

ZenScript
Copy
// MCItemStackMutable.onlyDamaged() as MCIngredientConditioned<IIngredient>

<item:minecraft:dirt>.mutable().onlyDamaged();
onlyIf

Return Type: MCIngredientConditioned<IIngredient>

ZenScript
Copy
MCItemStackMutable.onlyIf(uid as string, function as Predicate<IItemStack>) as MCIngredientConditioned<IIngredient>
ParameterTypeDescriptionOptionalDefaultValue
uidstringNo Description Providedfalse
functionPredicate<IItemStack>No Description Providedtrue
removeGlobalAttribute

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

ZenScript
Copy
// MCItemStackMutable.removeGlobalAttribute(attribute as Attribute, slotTypes as MCEquipmentSlotType[]) as void

<item:minecraft:dirt>.mutable().removeGlobalAttribute(<attribute:minecraft:generic.attack_damage>, [<equipmentslottype:chest>]);
ParameterTypeDescription
attributeAttributeThe attribute to remove.
slotTypesMCEquipmentSlotType[]The slot types to remove it from.
removeGlobalAttributeModifier

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

Return Type: void

ZenScript
Copy
// MCItemStackMutable.removeGlobalAttributeModifier(uuid as string, slotTypes as MCEquipmentSlotType[]) as void

<item:minecraft:dirt>.mutable().removeGlobalAttributeModifier("8c1b5535-9f79-448b-87ae-52d81480aaa3", [<equipmentslottype:chest>]);
ParameterTypeDescription
uuidstringThe unique id of the AttributeModifier to remove.
slotTypesMCEquipmentSlotType[]The slot types to remove it from.
removeTooltip

Return Type: void

ZenScript
Copy
MCItemStackMutable.removeTooltip(regex as string) as void
ParameterTypeDescription
regexstringNo Description Provided
setImmuneToFire

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

ZenScript
Copy
// MCItemStackMutable.setImmuneToFire(immuneToFire as boolean) as void

<item:minecraft:dirt>.mutable().setImmuneToFire(true);
ParameterTypeDescription
immuneToFirebooleanShould the item be immune to fire.
setMaxStackSize

Sets the max stacksize of the Item.

Return Type: void

ZenScript
Copy
// MCItemStackMutable.setMaxStackSize(newMaxStackSize as int) as void

<item:minecraft:dirt>.mutable().setMaxStackSize(16);
ParameterTypeDescription
newMaxStackSizeintThe new max stack size of the Item.
setRarity

Sets the rarity of the Item.

Return Type: void

ZenScript
Copy
// MCItemStackMutable.setRarity(newRarity as Rarity) as void

<item:minecraft:dirt>.mutable().setRarity(Rarity.UNCOMMON);
ParameterTypeDescription
newRarityRarityThe new rarity of the Item.
weight

Return Type: MCWeightedItemStack

ZenScript
Copy
MCItemStackMutable.weight(weight as double) as MCWeightedItemStack
ParameterTypeDescription
weightdoubleNo Description Provided

Operators

CONTAINS

Does the ingredient contain the given ingredient?

ZenScript
Copy
ingredient as IIngredient in myMCItemStackMutable
(<item:minecraft:iron_ingot> | <item:minecraft:gold_ingot>) in <item:minecraft:dirt>.mutable()
EQUALS
ZenScript
Copy
myMCItemStackMutable == o as Object
MOD
ZenScript
Copy
myMCItemStackMutable % percentage as int
OR
ZenScript
Copy
myMCItemStackMutable | other as IIngredient

Properties

NameTypeHa GetterHa SetterDescription
amountinttruefalseGets the amount of Items in the ItemStack
burnTimeinttruetrueNo Description Provided
damageablebooleantruefalseReturns if the ItemStack is damageable
I.E Swords and tools are damageable, sticks are not.
damagedbooleantruefalseReturns if the ItemStack is damaged
I.E a Swords that is no at full durability is damaged.
definitionMCItemDefinitiontruefalseNo Description Provided
displayNamestringtruefalseGets the display name of the ItemStack
emptybooleantruefalseReturns if the ItemStack is empty
enchantmentsInteger[MCEnchantment]truefalseNo Description Provided
foodMCFood?truetrueNo Description Provided
getOrCreateIDatatruefalseReturns the NBT tag attached to this ItemStack or makes a new tag.
getRepairCostinttruefalseGets the repair cost of the ItemStack, or 0 if no repair is defined.
hasDisplayNamebooleantruefalseReturns true if the ItemStack has a display name.
hasEffectbooleantruefalseReturns true if this ItemStack has an effect.
hasTagbooleantruefalseReturns true if this ItemStack has a Tag
immuneToFirevoidtruetrueSets if this IItemStack is immune to fire / lava.

If true, the item will not burn when thrown into fire or lava.
isCrossbowbooleantruefalseReturns true if this stack is considered a crossbow item
isEnchantablebooleantruefalseCan this ItemStack be enchanted?
isEnchantedbooleantruefalseIs this ItemStack enchanted?
maxDamageinttruetrueReturns the max damage of the ItemStack
This is the max durability of the ItemStack.
maxStackSizeinttruetrueReturns the max stack size of the Item in the ItemStack
ownerstringtruefalseGets owning mod for the Item in this IItemStack
rarityRaritytruetrueReturns the rarity of the Item in the ItemStack
registryNameMCResourceLocationtruefalseGets the registry name for the Item in this IItemStack
stackablebooleantruefalseReturns if the ItemStack can have an amount greater than 1
I.E Swords and tools are not stackable, sticks are.
tagIDatatruefalseReturns the NBT tag attached to this ItemStack.
toolTypesToolType[]truefalseNo Description Provided
translationKeystringtruefalseReturns the unlocalized Name of the Item in the ItemStack
useDurationinttruefalseGets the use duration of the ItemStack