ItemAttributeModifierEvent

Link to itemattributemodifierevent

This event is fired when the attributes for an ItemStack are being calculated. Attributes are calculated on the server when equipping and un-equipping an item to add and remove attributes respectively, both must be consistent. Attributes are calculated on the client when rendering an item's tooltip to show relevant attributes.

The event is not cancelable.

The event does not have a result.

Импорт класса

Link to импорт-класса

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.event.ItemAttributeModifierEvent;

ItemAttributeModifierEvent extends Event. That means all methods available in Event are also available in ItemAttributeModifierEvent

Name: addModifier

Adds a new AttributeModifier to the ItemStack.

Returns: True if the modifier was added. False otherwise.
Return Type: boolean

ZenScript
Copy
// ItemAttributeModifierEvent.addModifier(attribute as Attribute, name as string, value as double, operation as AttributeOperation) as boolean

myItemAttributeModifierEvent.addModifier(<attribute:minecraft:generic.attack_damage>, "Extra Power", 10, AttributeOperation.ADDITION);
ПараметрТипОписание
Параметр
attribute
Тип
Attribute
Описание
The Attribute to add.
Параметр
name
Тип
string
Описание
The name of the modifier to add
Параметр
value
Тип
double
Описание
The value of the modifier.
Параметр
operation
Тип
AttributeOperation
Описание
The operation of the modifier.

Name: addModifier

Adds a new AttributeModifier to the ItemStack.

Returns: True if the modifier was added. False otherwise.
Return Type: boolean

ZenScript
Copy
// ItemAttributeModifierEvent.addModifier(attribute as Attribute, uuid as string, name as string, value as double, operation as AttributeOperation) as boolean

myItemAttributeModifierEvent.addModifier(<attribute:minecraft:generic.attack_damage>, "8c1b5535-9f79-448b-87ae-52d81480aaa3", "Extra Power", 10, AttributeOperation.ADDITION);
ПараметрТипОписание
Параметр
attribute
Тип
Attribute
Описание
The Attribute to add.
Параметр
uuid
Тип
string
Описание
The UUID of the modifier.
Параметр
name
Тип
string
Описание
The name of the modifier.
Параметр
value
Тип
double
Описание
The value of the modifier.
Параметр
operation
Тип
AttributeOperation
Описание
The operation of the modifier.

Name: clearModifiers

Clears all AttributeModifiers from the ItemStack.

Return Type: void

ZenScript
Copy
// ItemAttributeModifierEvent.clearModifiers() as void

myItemAttributeModifierEvent.clearModifiers();

Name: getItemStack

Gets the ItemStack that this event is being ran for.

Returns: The ItemStack this event is being ran for.
Return Type: IItemStack

ZenScript
Copy
// ItemAttributeModifierEvent.getItemStack() as IItemStack

myItemAttributeModifierEvent.getItemStack();

Name: getModifiers

Gets the modifiers on the ItemStack

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

ZenScript
Copy
// ItemAttributeModifierEvent.getModifiers() as stdlib.List<AttributeModifier>[Attribute]

myItemAttributeModifierEvent.getModifiers();

Link to getOriginalModifiers

Name: getOriginalModifiers

Gets the original modifiers on the ItemStack before being changed by any other event listener.

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

ZenScript
Copy
// ItemAttributeModifierEvent.getOriginalModifiers() as stdlib.List<AttributeModifier>[Attribute]

myItemAttributeModifierEvent.getOriginalModifiers();

Name: getSlotType

Gets the EquipmentSlotType that this event is being ran for.

If you only want to add / remove a modifier from a specific slot, you can use this to filter based on the slot.

Returns: The EquipmentSlotType of this event.
Return Type: EquipmentSlot

ZenScript
Copy
// ItemAttributeModifierEvent.getSlotType() as EquipmentSlot

myItemAttributeModifierEvent.getSlotType();

Name: removeAttribute

Removes an Attribute from the ItemStack.

Returns: A List of the AttributeModifiers for the removed Attribute.
Return Type: stdlib.List<AttributeModifier>

ZenScript
Copy
// ItemAttributeModifierEvent.removeAttribute(attribute as Attribute) as stdlib.List<AttributeModifier>

myItemAttributeModifierEvent.removeAttribute(<attribute:minecraft:generic.attack_damage>);
ПараметрТипОписание
Параметр
attribute
Тип
Attribute
Описание
The Attribute to remove.

Name: removeModifier

Removes an AttributeModifier from the ItemStack.

Returns: True if the modifier was remove. False otherwise.
Return Type: boolean

ZenScript
Copy
// ItemAttributeModifierEvent.removeModifier(attribute as Attribute, modifier as AttributeModifier) as boolean

myItemAttributeModifierEvent.removeModifier(<attribute:minecraft:generic.attack_damage>, modifier);
ПараметрТипОписание
Параметр
attribute
Тип
Attribute
Описание
The Attribute to remove.
Параметр
modifier
Тип
AttributeModifier
Описание
The modifier to remove.

Name: removeModifier

Removes an AttributeModifier from the ItemStack based on the modifier's UUID.

Returns: True if the modifier was remove. False otherwise.
Return Type: boolean

ZenScript
Copy
// ItemAttributeModifierEvent.removeModifier(attribute as Attribute, uuid as string) as boolean

myItemAttributeModifierEvent.removeModifier(<attribute:minecraft:generic.attack_damage>, "8c1b5535-9f79-448b-87ae-52d81480aaa3");
ПараметрТипОписание
Параметр
attribute
Тип
Attribute
Описание
The Attribute to remove.
Параметр
uuid
Тип
string
Описание
The UUID of the modifier.

Свойства

Link to свойства

НазваниеТипИмеет GetterИмеет SetterОписание
Название
itemstack
Тип
IItemStack
Имеет Getter
true
Имеет Setter
false
Описание
Gets the ItemStack that this event is being ran for.
Название
modifiers
Тип
stdlib.List<AttributeModifier>[Attribute]
Имеет Getter
true
Имеет Setter
false
Описание
Gets the modifiers on the ItemStack
Название
originalModifiers
Тип
stdlib.List<AttributeModifier>[Attribute]
Имеет Getter
true
Имеет Setter
false
Описание
Gets the original modifiers on the ItemStack before being changed by any other event listener.
Название
slotType
Тип
EquipmentSlot
Имеет Getter
true
Имеет Setter
false
Описание
Gets the EquipmentSlotType that this event is being ran for.

If you only want to add / remove a modifier from a specific slot, you can use this to filter based on the slot.