Class ItemAttributeModifierEvent.ItemAttributeModifiersBuilder

java.lang.Object
net.neoforged.neoforge.event.ItemAttributeModifierEvent.ItemAttributeModifiersBuilder
Enclosing class:
ItemAttributeModifierEvent

private static class ItemAttributeModifierEvent.ItemAttributeModifiersBuilder extends Object
Advanced version of ItemAttributeModifiers.Builder which supports removal and better sanity-checking.

The original builder only supports additions and does not guarantee that no duplicate modifiers exist for a given id.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final record 
    Internal key class.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private List<net.minecraft.world.item.component.ItemAttributeModifiers.Entry>
     
    private Map<ItemAttributeModifierEvent.ItemAttributeModifiersBuilder.Key,net.minecraft.world.item.component.ItemAttributeModifiers.Entry>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ItemAttributeModifiersBuilder(net.minecraft.world.item.component.ItemAttributeModifiers defaultModifiers)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) boolean
    addModifier(net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute> attribute, net.minecraft.world.entity.ai.attributes.AttributeModifier modifier, net.minecraft.world.entity.EquipmentSlotGroup slot)
    Attempts to add a new modifier, refusing if one is already present with the same id.
    net.minecraft.world.item.component.ItemAttributeModifiers
     
    (package private) void
     
    (package private) List<net.minecraft.world.item.component.ItemAttributeModifiers.Entry>
    Returns an unmodifiable view of the underlying entry list.
    (package private) boolean
    removeIf(Predicate<net.minecraft.world.item.component.ItemAttributeModifiers.Entry> condition)
    Removes modifiers based on a condition.
    (package private) boolean
    removeModifier(net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute> attribute, net.minecraft.resources.ResourceLocation id)
    Removes a modifier for the target attribute with the given id.
    (package private) net.minecraft.world.item.component.ItemAttributeModifiers.Entry
    replaceModifier(net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute> attribute, net.minecraft.world.entity.ai.attributes.AttributeModifier modifier, net.minecraft.world.entity.EquipmentSlotGroup slot)
    Adds a modifier to the list, replacing any existing modifiers with the same id.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ItemAttributeModifiersBuilder

      ItemAttributeModifiersBuilder(net.minecraft.world.item.component.ItemAttributeModifiers defaultModifiers)
  • Method Details

    • getEntryView

      List<net.minecraft.world.item.component.ItemAttributeModifiers.Entry> getEntryView()
      Returns an unmodifiable view of the underlying entry list.
      Returns:
      an unmodifiable view of the underlying entry list
    • addModifier

      boolean addModifier(net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute> attribute, net.minecraft.world.entity.ai.attributes.AttributeModifier modifier, net.minecraft.world.entity.EquipmentSlotGroup slot)
      Attempts to add a new modifier, refusing if one is already present with the same id.
      Returns:
      true if the modifier was added
    • removeModifier

      boolean removeModifier(net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute> attribute, net.minecraft.resources.ResourceLocation id)
      Removes a modifier for the target attribute with the given id.
      Returns:
      true if a modifier was removed
    • replaceModifier

      @Nullable net.minecraft.world.item.component.ItemAttributeModifiers.Entry replaceModifier(net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute> attribute, net.minecraft.world.entity.ai.attributes.AttributeModifier modifier, net.minecraft.world.entity.EquipmentSlotGroup slot)
      Adds a modifier to the list, replacing any existing modifiers with the same id.
      Returns:
      the previous modifier, or null if there was no previous modifier with the same id
    • removeIf

      boolean removeIf(Predicate<net.minecraft.world.item.component.ItemAttributeModifiers.Entry> condition)
      Removes modifiers based on a condition.
      Returns:
      true if any modifiers were removed
    • clear

      void clear()
    • build

      public net.minecraft.world.item.component.ItemAttributeModifiers build()