ItemAttributeModifierEvent

Importing the class

If you need to reference this type directly, like when casting an Array, or as a parameter, you will need to import it. Simply add the import at the top of the file.

script.zs
import crafttweaker.forge.api.event.item.ItemAttributeModifierEvent;

Description

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.

Extends

ItemAttributeModifierEvent extends Event.

Listening to the event

This event can be listened to like so:

script.zs
events.register<crafttweaker.forge.api.event.item.ItemAttributeModifierEvent>(event => {
println("ItemAttributeModifierEvent ran!");
});

Members

addModifier(attribute as Attribute, name as string, value as double, operation as Operation) as bool
Adds a new AttributeModifier to the ItemStack.

Returns: True if the modifier was added. False otherwise.

script.zs
// ItemAttributeModifierEvent.addModifier(attribute as Attribute, name as string, value as double, operation as Operation) as bool;
event.addModifier(<attribute:minecraft:generic.attack_damage>, "Extra Power", 10, AttributeOperation.ADDITION);

Parameters:

attribute Type: Attribute - The Attribute to add.
name Type: string - The name of the modifier to add
value Type: double - The value of the modifier.
operation Type: AttributeOperation - The operation of the modifier.

Return Type: bool

addModifier(attribute as Attribute, uuid as string, name as string, value as double, operation as Operation) as bool
Adds a new AttributeModifier to the ItemStack.

Returns: True if the modifier was added. False otherwise.

script.zs
// ItemAttributeModifierEvent.addModifier(attribute as Attribute, uuid as string, name as string, value as double, operation as Operation) as bool;
event.addModifier(<attribute:minecraft:generic.attack_damage>, "8c1b5535-9f79-448b-87ae-52d81480aaa3", "Extra Power", 10, AttributeOperation.ADDITION);

Parameters:

attribute Type: Attribute - The Attribute to add.
uuid Type: string - The UUID of the modifier.
name Type: string - The name of the modifier.
value Type: double - The value of the modifier.
operation Type: AttributeOperation - The operation of the modifier.

Return Type: bool

cancel()
Cancels the event. Same as setCanceled(true)
script.zs
// ItemAttributeModifierEvent.cancel();
event.cancel();
Getter
script.zs
// ItemAttributeModifierEvent.cancelable as bool
event.cancelable

Return Type: bool

cancelable() as bool
script.zs
// ItemAttributeModifierEvent.cancelable() as bool;
event.cancelable();

Return Type: bool

Getter
script.zs
// ItemAttributeModifierEvent.canceled as bool
event.canceled

Return Type: bool

Setter
script.zs
// ItemAttributeModifierEvent.canceled = (cancel as bool);
event.canceled = myBool;

Parameters:

cancel Type: bool
canceled() as bool
script.zs
// ItemAttributeModifierEvent.canceled() as bool;
event.canceled();

Return Type: bool

canceled(cancel as bool)
script.zs
// ItemAttributeModifierEvent.canceled(cancel as bool);
event.canceled(myBool);

Parameters:

cancel Type: bool
clearModifiers()
Clears all AttributeModifiers from the ItemStack.
script.zs
// ItemAttributeModifierEvent.clearModifiers();
event.clearModifiers();
Getter
script.zs
// ItemAttributeModifierEvent.hasResult as bool
event.hasResult

Return Type: bool

hasResult() as bool
script.zs
// ItemAttributeModifierEvent.hasResult() as bool;
event.hasResult();

Return Type: bool

Getter
Gets the ItemStack that this event is being ran for.
script.zs
// ItemAttributeModifierEvent.itemStack as IItemStack
event.itemStack

Return Type: IItemStack

Getter
Gets the modifiers on the ItemStack
script.zs
// ItemAttributeModifierEvent.modifiers as List<AttributeModifier>[Attribute]
event.modifiers

Return Type: List<AttributeModifier>[Attribute]

Getter
Gets the original modifiers on the ItemStack before being changed by any other event listener.
script.zs
// ItemAttributeModifierEvent.originalModifiers as List<AttributeModifier>[Attribute]
event.originalModifiers

Return Type: List<AttributeModifier>[Attribute]

removeAttribute(attribute as Attribute) as List<AttributeModifier>
Removes an Attribute from the ItemStack.

Returns: A List of the AttributeModifiers for the removed Attribute.

script.zs
// ItemAttributeModifierEvent.removeAttribute(attribute as Attribute) as List<AttributeModifier>;
event.removeAttribute(<attribute:minecraft:generic.attack_damage>);

Parameters:

attribute Type: Attribute - The Attribute to remove.

Return Type: List<AttributeModifier>

removeModifier(attribute as Attribute, uuid as string) as bool
Removes an AttributeModifier from the ItemStack based on the modifier's UUID.

Returns: True if the modifier was remove. False otherwise.

script.zs
// ItemAttributeModifierEvent.removeModifier(attribute as Attribute, uuid as string) as bool;
event.removeModifier(<attribute:minecraft:generic.attack_damage>, "8c1b5535-9f79-448b-87ae-52d81480aaa3");

Parameters:

attribute Type: Attribute - The Attribute to remove.
uuid Type: string - The UUID of the modifier.

Return Type: bool

removeModifier(attribute as Attribute, modifier as AttributeModifier) as bool
Removes an AttributeModifier from the ItemStack.

Returns: True if the modifier was remove. False otherwise.

script.zs
// ItemAttributeModifierEvent.removeModifier(attribute as Attribute, modifier as AttributeModifier) as bool;
event.removeModifier(<attribute:minecraft:generic.attack_damage>, modifier);

Parameters:

attribute Type: Attribute - The Attribute to remove.
modifier Type: AttributeModifier - The modifier to remove.

Return Type: bool

Getter
script.zs
// ItemAttributeModifierEvent.result as Result
event.result

Return Type: EventResult

Setter
script.zs
// ItemAttributeModifierEvent.result = (result as Result);
event.result = myResult;

Parameters:

result Type: EventResult
result() as Result
script.zs
// ItemAttributeModifierEvent.result() as Result;
event.result();

Return Type: EventResult

result(result as Result)
script.zs
// ItemAttributeModifierEvent.result(result as Result);
event.result(myResult);

Parameters:

result Type: EventResult
setAllow()
sets the event's result to allow
script.zs
// ItemAttributeModifierEvent.setAllow();
event.setAllow();
setDefault()
sets the event's result to default
script.zs
// ItemAttributeModifierEvent.setDefault();
event.setDefault();
setDeny()
sets the event's result to deny
script.zs
// ItemAttributeModifierEvent.setDeny();
event.setDeny();
Getter
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.
script.zs
// ItemAttributeModifierEvent.slotType as EquipmentSlot
event.slotType

Return Type: EquipmentSlot