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 item stack are queried (for any reason) through IItemStackExtension.getAttributeModifiers().
This event is fired regardless of if the stack has DataComponents.ATTRIBUTE_MODIFIERS or not. If your attribute should be ignored when attributes are overridden, you can check for the presence of the component.

This event may be fired on both the logical server and logical client.

  • Field Details

  • Constructor Details

  • Method Details

    • getItemStack

      public ItemStack getItemStack()
      Returns the item stack whose attribute modifiers are being computed.
      Returns:
      the item stack whose attribute modifiers are being computed
    • getDefaultModifiers

      public ItemAttributeModifiers getDefaultModifiers()
      Returns the default attribute modifiers before changes made by the event.
      Returns:
      the default attribute modifiers before changes made by the event
    • getModifiers

      public List<ItemAttributeModifiers.Entry> getModifiers()
      Returns an unmodifiable view of the attribute modifier entries. Do not use the returned value to create an ItemAttributeModifiers since the underlying list is not immutable.

      If you need an ItemAttributeModifiers, you may need to call build()

    • addModifier

      public boolean addModifier(Holder<Attribute> attribute, AttributeModifier modifier, EquipmentSlotGroup slot)
      Adds a new attribute modifier to the given stack. Two modifiers with the same id may not exist for the same attribute, and this method will fail if one exists.
      Parameters:
      attribute - The attribute the modifier is for
      modifier - The new attribute modifier
      slot - The equipment slots for which the modifier should apply
      Returns:
      True if the modifier was added, false if it was already present
    • removeModifier

      public boolean removeModifier(Holder<Attribute> attribute, ResourceLocation id)
      Removes an attribute modifier for the target attribute by id
      Returns:
      True if an attribute modifier was removed, false otherwise
    • replaceModifier

      public void replaceModifier(Holder<Attribute> attribute, AttributeModifier modifier, EquipmentSlotGroup slot)
      Adds a new attribute modifier to the given stack, optionally replacing any existing modifiers with the same id.
      Parameters:
      attribute - The attribute the modifier is for
      modifier - The new attribute modifier
      slot - The equipment slots for which the modifier should apply
    • removeIf

      public boolean removeIf(Predicate<ItemAttributeModifiers.Entry> condition)
      Removes modifiers based on a condition.
      Returns:
      true if any modifiers were removed
    • removeAllModifiersFor

      public boolean removeAllModifiersFor(Holder<Attribute> attribute)
      Removes all modifiers for the given attribute.
      Returns:
      true if any modifiers were removed
    • clearModifiers

      public void clearModifiers()
      Removes all modifiers for all attributes.
    • build

      public ItemAttributeModifiers build()
      Builds a new ItemAttributeModifiers with the results of this event, returning the default modifiers if no changes were made.
    • getBuilder

      Returns the builder used for adjusting the attribute modifiers, creating it if it does not already exist.