Package net.minecraftforge.event
Class ItemAttributeModifierEvent
java.lang.Object
net.minecraftforge.eventbus.api.Event
net.minecraftforge.event.ItemAttributeModifierEvent
public class ItemAttributeModifierEvent
extends net.minecraftforge.eventbus.api.Event
This event is fired when the attributes for an ItemStack are being calculated.
Attributes are calculated on the server when equipping and unequipping 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.
Note that this event is fired regardless of if the stack has NBT overriding attributes or not. If your attribute should be ignored when attributes are overridden, you can check for the presence of the
This event is fired on the
Note that this event is fired regardless of if the stack has NBT overriding attributes or not. If your attribute should be ignored when attributes are overridden, you can check for the presence of the
AttributeModifiers
tag.
This event is fired on the
MinecraftForge.EVENT_BUS
.-
Nested Class Summary
Nested classes/interfaces inherited from class net.minecraftforge.eventbus.api.Event
net.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result
-
Field Summary
Modifier and TypeFieldDescriptionprivate com.google.common.collect.Multimap<Attribute,
AttributeModifier> private final com.google.common.collect.Multimap<Attribute,
AttributeModifier> private final EquipmentSlotType
private final ItemStack
private com.google.common.collect.Multimap<Attribute,
AttributeModifier> -
Constructor Summary
ConstructorDescriptionItemAttributeModifierEvent
(ItemStack stack, EquipmentSlotType slotType, com.google.common.collect.Multimap<Attribute, AttributeModifier> modifiers) -
Method Summary
Modifier and TypeMethodDescriptionboolean
addModifier
(Attribute attribute, AttributeModifier modifier) Adds a new attribute modifier to the given stack.void
Removes all modifiers for all attributesGets the item stack instanceprivate com.google.common.collect.Multimap<Attribute,
AttributeModifier> Gets a modifiable map instance, creating it if the current map is currently unmodifiablecom.google.common.collect.Multimap<Attribute,
AttributeModifier> Returns an unmodifiable view of the attribute multimap.com.google.common.collect.Multimap<Attribute,
AttributeModifier> Returns the attribute map before any changes from other event listeners was made.Gets the slot containing this stackremoveAttribute
(Attribute attribute) Removes all modifiers for the given attributeboolean
removeModifier
(Attribute attribute, AttributeModifier modifier) Removes a single modifier for the given attributeMethods inherited from class net.minecraftforge.eventbus.api.Event
getListenerList, getParentListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult, setup
-
Field Details
-
stack
-
slotType
-
originalModifiers
-
unmodifiableModifiers
-
modifiableModifiers
@Nullable private com.google.common.collect.Multimap<Attribute,AttributeModifier> modifiableModifiers
-
-
Constructor Details
-
ItemAttributeModifierEvent
public ItemAttributeModifierEvent(ItemStack stack, EquipmentSlotType slotType, com.google.common.collect.Multimap<Attribute, AttributeModifier> modifiers)
-
-
Method Details
-
getModifiers
Returns an unmodifiable view of the attribute multimap. Use other methods from this event to modify the attributes map. Note that adding attributes based on existing attributes may lead to inconsistent results between the tooltip (client) and the actual attributes (server) if the listener order is different. UsinggetOriginalModifiers()
instead will give more consistent results. -
getOriginalModifiers
Returns the attribute map before any changes from other event listeners was made. -
getModifiableMap
Gets a modifiable map instance, creating it if the current map is currently unmodifiable -
addModifier
Adds a new attribute modifier to the given stack. Modifier must have a consistent UUID for consistency between equipping and unequipping items. Modifier name should clearly identify the mod that added the modifier.- Parameters:
attribute
- Attributemodifier
- Modifier instance.- Returns:
- True if the attribute was added, false if it was already present
-
removeModifier
Removes a single modifier for the given attribute- Parameters:
attribute
- Attributemodifier
- Modifier instance- Returns:
- True if an attribute was removed, false if no change
-
removeAttribute
Removes all modifiers for the given attribute- Parameters:
attribute
- Attribute- Returns:
- Collection of removed modifiers
-
clearModifiers
public void clearModifiers()Removes all modifiers for all attributes -
getSlotType
Gets the slot containing this stack -
getItemStack
Gets the item stack instance
-