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
(Attribute attribute, double baseValue, Collection<AttributeModifier> modifiers, @Nullable Consumer<AttributeInstance> listener) AttributeInstance
(Attribute attribute, @Nullable Consumer<AttributeInstance> listener) -
Method Summary
Modifier and TypeMethodDescriptionaddModifier
(AttributeModifier modifier) Add a modifier to this instance.double
applyModifiers
(double baseValue) Gets the value of this instance, calculated assuming the givenbaseValue
.Gets the attribute associated to this instance.void
Clears all modifiers on this instance, excepting those whose ID is defined inLivingEntity.PROTECTED_MODIFIERS
.Deprecated.double
The base value of this instance without modifiersDeprecated.double
getValue()
Gets the value of this instance calculated with modifiers applied.@UnmodifiableView Collection
<AttributeModifier> Get the modifiers applied to this instance.removeModifier
(net.kyori.adventure.key.Key id) Remove a modifier from this instance.removeModifier
(AttributeModifier modifier) 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(Attribute attribute, @Nullable @Nullable Consumer<AttributeInstance> listener) -
AttributeInstance
public AttributeInstance(Attribute attribute, double baseValue, 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.
-