Package net.neoforged.neoforge.event
Class ItemAttributeModifierEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.ItemAttributeModifierEvent
public class ItemAttributeModifierEvent
extends net.neoforged.bus.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
NeoForge.EVENT_BUS
.-
Field Summary
Modifier and TypeFieldDescriptionprivate @Nullable com.google.common.collect.Multimap
<Holder<Attribute>, AttributeModifier> private final com.google.common.collect.Multimap
<Holder<Attribute>, AttributeModifier> private final EquipmentSlot
private final ItemStack
private com.google.common.collect.Multimap
<Holder<Attribute>, AttributeModifier> -
Constructor Summary
ConstructorDescriptionItemAttributeModifierEvent
(ItemStack stack, EquipmentSlot slotType, com.google.common.collect.Multimap<Holder<Attribute>, AttributeModifier> modifiers) -
Method Summary
Modifier and TypeMethodDescriptionboolean
addModifier
(Holder<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
<Holder<Attribute>, AttributeModifier> Gets a modifiable map instance, creating it if the current map is currently unmodifiablecom.google.common.collect.Multimap
<Holder<Attribute>, AttributeModifier> Returns an unmodifiable view of the attribute multimap.com.google.common.collect.Multimap
<Holder<Attribute>, AttributeModifier> Returns the attribute map before any changes from other event listeners was made.Gets the slot containing this stackremoveAttribute
(Holder<Attribute> attribute) Removes all modifiers for the given attributeboolean
removeModifier
(Holder<Attribute> attribute, AttributeModifier modifier) Removes a single modifier for the given attribute
-
Field Details
-
stack
-
slotType
-
originalModifiers
private final com.google.common.collect.Multimap<Holder<Attribute>,AttributeModifier> originalModifiers -
unmodifiableModifiers
private com.google.common.collect.Multimap<Holder<Attribute>,AttributeModifier> unmodifiableModifiers -
modifiableModifiers
@Nullable private @Nullable com.google.common.collect.Multimap<Holder<Attribute>,AttributeModifier> modifiableModifiers
-
-
Constructor Details
-
ItemAttributeModifierEvent
public ItemAttributeModifierEvent(ItemStack stack, EquipmentSlot slotType, com.google.common.collect.Multimap<Holder<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
public com.google.common.collect.Multimap<Holder<Attribute>,AttributeModifier> 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
-