Skip to content

Class endstone::AttributeInstance

ClassList > endstone > AttributeInstance

Represents a mutable instance of an attribute and its associated modifiers and values.

  • #include <endstone/attribute/attribute_instance.h>

Public Functions

Type Name
virtual void addModifier (const AttributeModifier & modifier) = 0
Add a modifier to this instance.
virtual void addTransientModifier (const AttributeModifier & modifier) = 0
Add a transient modifier to this instance.
virtual float getBaseValue () const = 0
Base value of this instance before modifiers are applied.
virtual float getMaxValue () const = 0
The maximum value this instance is allowed to take.
virtual float getMinValue () const = 0
The minimum value this instance is allowed to take.
virtual std::optional< AttributeModifier > getModifier (AttributeModifierId id) const = 0
Gets the modifier with the corresponding id.
virtual std::vector< AttributeModifier > getModifiers () const = 0
Get all modifiers present on this instance.
virtual AttributeId getType () const = 0
The attribute type pertaining to this instance.
virtual float getValue () const = 0
Get the value of this instance after all associated modifiers have been applied.
virtual void removeModifier (const AttributeModifier & modifier) = 0
Remove a modifier from this instance.
virtual void removeModifier (AttributeModifierId id) = 0
Remove a modifier with the corresponding id from this instance.
virtual void setBaseValue (float value) = 0
Set the base value of this instance.
virtual void setMaxValue (float value) = 0
Set the maximum value this instance is allowed to take.
virtual void setMinValue (float value) = 0
Set the minimum value this instance is allowed to take.
virtual ~AttributeInstance () = default

Public Functions Documentation

function addModifier

Add a modifier to this instance.

virtual void endstone::AttributeInstance::addModifier (
    const  AttributeModifier & modifier
) = 0

Parameters:

  • modifier to add

function addTransientModifier

Add a transient modifier to this instance.

virtual void endstone::AttributeInstance::addTransientModifier (
    const  AttributeModifier & modifier
) = 0

Transient modifiers are not persisted (saved with the NBT data).

Parameters:

  • modifier to add

function getBaseValue

Base value of this instance before modifiers are applied.

virtual float endstone::AttributeInstance::getBaseValue () const = 0

Returns:

base value


function getMaxValue

The maximum value this instance is allowed to take.

virtual float endstone::AttributeInstance::getMaxValue () const = 0

Note:

Bedrock-specific. The value of this instance is clamped to the range [min, max].

Returns:

maximum value


function getMinValue

The minimum value this instance is allowed to take.

virtual float endstone::AttributeInstance::getMinValue () const = 0

Note:

Bedrock-specific. The value of this instance is clamped to the range [min, max].

Returns:

minimum value


function getModifier

Gets the modifier with the corresponding id.

virtual std::optional< AttributeModifier > endstone::AttributeInstance::getModifier (
    AttributeModifierId id
) const = 0

Parameters:

  • id the id of the modifier

Returns:

the modifier, or std::nullopt if no modifier with the given id is present


function getModifiers

Get all modifiers present on this instance.

virtual std::vector< AttributeModifier > endstone::AttributeInstance::getModifiers () const = 0

Returns:

a copied collection of all modifiers


function getType

The attribute type pertaining to this instance.

virtual AttributeId endstone::AttributeInstance::getType () const = 0

Returns:

the attribute type


function getValue

Get the value of this instance after all associated modifiers have been applied.

virtual float endstone::AttributeInstance::getValue () const = 0

Returns:

the total attribute value


function removeModifier [½]

Remove a modifier from this instance.

virtual void endstone::AttributeInstance::removeModifier (
    const  AttributeModifier & modifier
) = 0

Parameters:

  • modifier to remove

function removeModifier [2/2]

Remove a modifier with the corresponding id from this instance.

virtual void endstone::AttributeInstance::removeModifier (
    AttributeModifierId id
) = 0

Parameters:

  • id the id of the modifier to remove

function setBaseValue

Set the base value of this instance.

virtual void endstone::AttributeInstance::setBaseValue (
    float value
) = 0

Parameters:

  • value new base value

function setMaxValue

Set the maximum value this instance is allowed to take.

virtual void endstone::AttributeInstance::setMaxValue (
    float value
) = 0

For example, raising the maximum of an entity's minecraft:health attribute increases its maximum health.

Note:

Bedrock-specific. The value is re-clamped to the new range on the next recalculation.

Parameters:

  • value new maximum value

function setMinValue

Set the minimum value this instance is allowed to take.

virtual void endstone::AttributeInstance::setMinValue (
    float value
) = 0

Note:

Bedrock-specific. The value is re-clamped to the new range on the next recalculation.

Parameters:

  • value new minimum value

function ~AttributeInstance

virtual endstone::AttributeInstance::~AttributeInstance () = default


The documentation for this class was generated from the following file include/endstone/attribute/attribute_instance.h