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.EventThis 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 theAttributeModifierstag.
This event is fired on theMinecraftForge.EVENT_BUS.
-
-
Field Summary
Fields Modifier and Type Field Description private com.google.common.collect.Multimap<Attribute,AttributeModifier>modifiableModifiersprivate com.google.common.collect.Multimap<Attribute,AttributeModifier>originalModifiersprivate EquipmentSlotTypeslotTypeprivate ItemStackstackprivate com.google.common.collect.Multimap<Attribute,AttributeModifier>unmodifiableModifiers
-
Constructor Summary
Constructors Constructor Description ItemAttributeModifierEvent(ItemStack stack, EquipmentSlotType slotType, com.google.common.collect.Multimap<Attribute,AttributeModifier> modifiers)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddModifier(Attribute attribute, AttributeModifier modifier)Adds a new attribute modifier to the given stack.voidclearModifiers()Removes all modifiers for all attributesItemStackgetItemStack()Gets the item stack instanceprivate com.google.common.collect.Multimap<Attribute,AttributeModifier>getModifiableMap()Gets a modifiable map instance, creating it if the current map is currently unmodifiablecom.google.common.collect.Multimap<Attribute,AttributeModifier>getModifiers()Returns an unmodifiable view of the attribute multimap.com.google.common.collect.Multimap<Attribute,AttributeModifier>getOriginalModifiers()Returns the attribute map before any changes from other event listeners was made.EquipmentSlotTypegetSlotType()Gets the slot containing this stackjava.util.Collection<AttributeModifier>removeAttribute(Attribute attribute)Removes all modifiers for the given attributebooleanremoveModifier(Attribute attribute, AttributeModifier modifier)Removes a single modifier for the given attribute
-
-
-
Field Detail
-
stack
private final ItemStack stack
-
slotType
private final EquipmentSlotType slotType
-
originalModifiers
private final com.google.common.collect.Multimap<Attribute,AttributeModifier> originalModifiers
-
unmodifiableModifiers
private com.google.common.collect.Multimap<Attribute,AttributeModifier> unmodifiableModifiers
-
modifiableModifiers
@Nullable private com.google.common.collect.Multimap<Attribute,AttributeModifier> modifiableModifiers
-
-
Constructor Detail
-
ItemAttributeModifierEvent
public ItemAttributeModifierEvent(ItemStack stack, EquipmentSlotType slotType, com.google.common.collect.Multimap<Attribute,AttributeModifier> modifiers)
-
-
Method Detail
-
getModifiers
public com.google.common.collect.Multimap<Attribute,AttributeModifier> 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<Attribute,AttributeModifier> getOriginalModifiers()
Returns the attribute map before any changes from other event listeners was made.
-
getModifiableMap
private com.google.common.collect.Multimap<Attribute,AttributeModifier> getModifiableMap()
Gets a modifiable map instance, creating it if the current map is currently unmodifiable
-
addModifier
public boolean addModifier(Attribute attribute, AttributeModifier modifier)
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
public boolean removeModifier(Attribute attribute, AttributeModifier modifier)
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
public java.util.Collection<AttributeModifier> removeAttribute(Attribute attribute)
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
public EquipmentSlotType getSlotType()
Gets the slot containing this stack
-
getItemStack
public ItemStack getItemStack()
Gets the item stack instance
-
-