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 AttributeModifiers tag.
This event is fired on the MinecraftForge.EVENT_BUS.
  • Field Details

  • Constructor Details

  • Method Details

    • 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. Using getOriginalModifiers() 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 - Attribute
      modifier - 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 - Attribute
      modifier - Modifier instance
      Returns:
      True if an attribute was removed, false if no change
    • removeAttribute

      public 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