T - The type of the attribute value.public class Attribute<T extends java.lang.Number>
extends java.lang.Object
AttributeModifiers.
It typically doesn't adjust the raw base value (unless explicitly requested) and instead adjusts the value by registered modifications. This is e.g. useful when a property might only be changed for a certain period of time or we need to know the original value of a property.
An example use-case are player stats that might be affected throughout the game (e.g. via certain skills, upgrades or level-ups).
| Constructor and Description |
|---|
Attribute(T initialValue)
Instantiates a new attribute.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addModifier(AttributeModifier<T> modifier)
Adds the specified modifier to this attribute.
|
protected T |
applyModifiers(T baseValue) |
T |
get()
Gets the current value of this attribute, respecting all the registered
AttributeModifiers. |
T |
getBase()
Gets the raw base value of this attribute without applying any modifications.
|
java.util.List<AttributeModifier<T>> |
getModifiers()
Gets all modifiers added to this instance.
|
boolean |
isModifierApplied(AttributeModifier<T> modifier)
Determines whether the specified modifier instance is added to this attribute instance.
|
void |
modifyBaseValue(AttributeModifier<T> modifier)
Adjusts the base value of this attribute once with the specified modifier.
|
void |
removeModifier(AttributeModifier<T> modifier)
Removes the specified modifier from this attribute.
|
void |
setBaseValue(T baseValue)
Sets the base value of this attribute.
|
public Attribute(T initialValue)
initialValue - the initial valuepublic void addModifier(AttributeModifier<T> modifier)
modifier - The modifier to be added to this instance.public void removeModifier(AttributeModifier<T> modifier)
modifier - The modifier to be removed from this instance.public T get()
AttributeModifiers.public T getBase()
public java.util.List<AttributeModifier<T>> getModifiers()
public boolean isModifierApplied(AttributeModifier<T> modifier)
modifier - The modifier to check for.public void modifyBaseValue(AttributeModifier<T> modifier)
modifier - The modifier used to adjust this attribute's base value.getBase(),
setBaseValue(Number)public void setBaseValue(T baseValue)
baseValue - The base value to be set.