Class AttributeInstance
java.lang.Object
net.minestom.server.entity.attribute.AttributeInstance
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAttributeInstance
(@NotNull Attribute attribute, double baseValue, @NotNull Collection<AttributeModifier> modifiers, @Nullable Consumer<AttributeInstance> listener) AttributeInstance
(@NotNull Attribute attribute, @Nullable Consumer<AttributeInstance> listener) -
Method Summary
Modifier and TypeMethodDescriptionaddModifier
(@NotNull AttributeModifier modifier) Add a modifier to this instance.double
applyModifiers
(double baseValue) Gets the value of this instance, calculated assuming the givenbaseValue
.@NotNull Attribute
Gets the attribute associated to this instance.void
Clears all modifiers on this instance, excepting those whose ID is defined inLivingEntity.PROTECTED_MODIFIERS
.@NotNull Attribute
Deprecated.double
The base value of this instance without modifiers@NotNull Collection
<AttributeModifier> Deprecated.double
getValue()
Gets the value of this instance calculated with modifiers applied.@NotNull @UnmodifiableView Collection
<AttributeModifier> Get the modifiers applied to this instance.removeModifier
(@NotNull AttributeModifier modifier) Remove a modifier from this instance.removeModifier
(@NotNull NamespaceID id) Remove a modifier from this instance.void
setBaseValue
(double baseValue) Sets the base value of this instance.
-
Field Details
-
NETWORK_TYPE
-
-
Constructor Details
-
AttributeInstance
public AttributeInstance(@NotNull @NotNull Attribute attribute, @Nullable @Nullable Consumer<AttributeInstance> listener) -
AttributeInstance
public AttributeInstance(@NotNull @NotNull Attribute attribute, double baseValue, @NotNull @NotNull Collection<AttributeModifier> modifiers, @Nullable @Nullable Consumer<AttributeInstance> listener)
-
-
Method Details
-
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
Get the modifiers applied to this instance.- Returns:
- an immutable collection of the modifiers applied to this attribute.
-
addModifier
Add a modifier to this instance.- Parameters:
modifier
- the modifier to add- Returns:
- the old modifier, or null if none
-
removeModifier
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 inLivingEntity.PROTECTED_MODIFIERS
. -
removeModifier
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 givenbaseValue
.- 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. -
getAttribute
Deprecated.
-