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.
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:
events.register<crafttweaker.forge.api.event.item.ItemAttributeModifierEvent>(event => { println("ItemAttributeModifierEvent ran!");});
Members
Returns: True if the modifier was added. False otherwise.
// ItemAttributeModifierEvent.addModifier(attribute as Attribute, name as string, value as double, operation as AttributeOperation) as bool;event.addModifier(<attribute:minecraft:generic.attack_damage>, "Extra Power", 10, AttributeOperation.ADDITION);
Parameters:
name: string
Type: string
- The name of the modifier to add value: double
Type: double
- The value of the modifier.
Return Type:
bool
Returns: True if the modifier was added. False otherwise.
// ItemAttributeModifierEvent.addModifier(attribute as Attribute, uuid as string, name as string, value as double, operation as AttributeOperation) as bool;event.addModifier(<attribute:minecraft:generic.attack_damage>, "8c1b5535-9f79-448b-87ae-52d81480aaa3", "Extra Power", 10, AttributeOperation.ADDITION);
Parameters:
uuid: string
Type: string
- The UUID of the modifier. name: string
Type: string
- The name of the modifier. value: double
Type: double
- The value of the modifier.
Return Type:
bool
setCanceled(true)
// ItemAttributeModifierEvent.cancel();event.cancel();
// ItemAttributeModifierEvent.cancelable as boolevent.cancelable
Return Type:
bool
// ItemAttributeModifierEvent.cancelable() as bool;event.cancelable();
Return Type:
bool
// ItemAttributeModifierEvent.canceled as boolevent.canceled
Return Type:
bool
// ItemAttributeModifierEvent.canceled = (cancel as bool);event.canceled = myBool;
Parameters:
cancel: bool
Type: bool
// ItemAttributeModifierEvent.canceled() as bool;event.canceled();
Return Type:
bool
// ItemAttributeModifierEvent.canceled(cancel as bool);event.canceled(myBool);
Parameters:
cancel: bool
Type: bool
// ItemAttributeModifierEvent.clearModifiers();event.clearModifiers();
// ItemAttributeModifierEvent.hasResult as boolevent.hasResult
Return Type:
bool
// ItemAttributeModifierEvent.hasResult() as bool;event.hasResult();
Return Type:
bool
// ItemAttributeModifierEvent.itemStack as IItemStackevent.itemStack
Return Type:
IItemStack
event.modifiers
Return Type:
List<AttributeModifier>[Attribute]
event.originalModifiers
Return Type:
List<AttributeModifier>[Attribute]
Returns: A List of the AttributeModifiers for the removed Attribute.
event.removeAttribute(<attribute:minecraft:generic.attack_damage>);
Return Type:
List<AttributeModifier>
Returns: True if the modifier was remove. False otherwise.
event.removeModifier(<attribute:minecraft:generic.attack_damage>, "8c1b5535-9f79-448b-87ae-52d81480aaa3");
Parameters:
Return Type:
bool
Returns: True if the modifier was remove. False otherwise.
// ItemAttributeModifierEvent.removeModifier(attribute as Attribute, modifier as AttributeModifier) as bool;event.removeModifier(<attribute:minecraft:generic.attack_damage>, modifier);
Parameters:
Return Type:
bool
// ItemAttributeModifierEvent.result as EventResultevent.result
Return Type:
EventResult
event.result = myResult;
Parameters:
result: EventResult
Type: EventResult
event.result(myResult);
Parameters:
result: EventResult
Type: EventResult
allow
// ItemAttributeModifierEvent.setAllow();event.setAllow();
default
// ItemAttributeModifierEvent.setDefault();event.setDefault();
deny
// ItemAttributeModifierEvent.setDeny();event.setDeny();
If you only want to add / remove a modifier from a specific slot, you can use this to filter based on the slot.
// ItemAttributeModifierEvent.slotType as EquipmentSlotevent.slotType
Return Type:
EquipmentSlot