Class AttributeInstance

java.lang.Object
net.minestom.server.entity.attribute.AttributeInstance

public final class AttributeInstance extends Object
Represents an instance of an attribute and its modifiers. This class is thread-safe (you do not need to acquire the entity to modify its attributes).
  • Field Details

  • Constructor Details

  • Method Details

    • attribute

      @NotNull public @NotNull Attribute attribute()
      Gets the attribute associated to this instance.
      Returns:
      the associated attribute
    • getBaseValue

      public double getBaseValue()
      The base value of this instance without modifiers
      Returns:
      the instance base value
      See Also:
    • setBaseValue

      public void setBaseValue(double baseValue)
      Sets the base value of this instance.
      Parameters:
      baseValue - the new base value
      See Also:
    • modifiers

      @NotNull public @NotNull @UnmodifiableView Collection<AttributeModifier> modifiers()
      Get the modifiers applied to this instance.
      Returns:
      an immutable collection of the modifiers applied to this attribute.
    • addModifier

      public AttributeModifier addModifier(@NotNull @NotNull AttributeModifier modifier)
      Add a modifier to this instance.
      Parameters:
      modifier - the modifier to add
      Returns:
      the old modifier, or null if none
    • removeModifier

      public AttributeModifier removeModifier(@NotNull @NotNull AttributeModifier modifier)
      Remove a modifier from this instance.
      Parameters:
      modifier - the modifier to remove
      Returns:
      the modifier that was removed, or null if none
    • clearModifiers

      public void clearModifiers()
      Clears all modifiers on this instance, excepting those whose ID is defined in LivingEntity.PROTECTED_MODIFIERS.
    • removeModifier

      public AttributeModifier removeModifier(@NotNull @NotNull NamespaceID id)
      Remove a modifier from this instance.
      Parameters:
      id - The namespace id of the modifier to remove
      Returns:
      the modifier that was removed, or null if none
    • getValue

      public double getValue()
      Gets the value of this instance calculated with modifiers applied.
      Returns:
      the attribute value
    • applyModifiers

      public double applyModifiers(double baseValue)
      Gets the value of this instance, calculated assuming the given baseValue.
      Parameters:
      baseValue - the value to be used as the base for this operation, rather than this instance's normal base value
      Returns:
      the attribute value
    • getModifiers

      @Deprecated @NotNull public @NotNull Collection<AttributeModifier> getModifiers()
      Deprecated.
    • getAttribute

      @Deprecated @NotNull public @NotNull Attribute getAttribute()
      Deprecated.