API reference / @jsprismarine/protocol / Attribute
Class: Attribute
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:50
One entity attribute with its bounds, default, current value, and wire codecs.
Constructors
Constructor
new Attribute(
data):Attribute
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:80
Class used to store Attribute data.
Parameters
data
The attribute data.
def
number
The default value of the attribute.
max
number
The maximum value of the attribute.
min
number
The minimum value of the attribute.
modifiers?
readonly AttributeModifier[] = []
The modifiers the value includes, none by default.
name
string
The name of the attribute.
value?
number
The current value of the attribute.
Returns
Attribute
Methods
clone()
clone():
Attribute
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:256
Copy of this attribute, at its current value and with its modifiers.
Returns
Attribute
The copy.
getDefault()
getDefault():
number
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:218
Returns
number
getMax()
getMax():
number
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:214
Returns
number
getMin()
getMin():
number
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:210
Returns
number
getModifiers()
getModifiers(): readonly
AttributeModifier[]
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:227
The modifiers the value includes.
Returns
readonly AttributeModifier[]
getName()
getName():
string
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:206
Returns
string
getValue()
getValue():
number
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:222
Returns
number
networkSerialize()
networkSerialize(
stream):void
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:129
Writes one attribute as the AttributeData that UpdateAttributesPacket carries.
Protocol 2193 order: Min Value, Max Value, Current Value, Default Min Value, Default Max Value and Default Value as little-endian floats, Name as a hashed_string (a varuint-prefixed UTF-8 string on the wire), then Modifiers as a varuint32 count and that many AttributeModifier.
The default bounds are what the client falls back to when an attribute is reset. No bounds other than the live ones are tracked here, so they are sent as the live bounds - the same thing PocketMine does. Omitting them costs eight bytes per attribute and desynchronizes everything after it, which the client only notices once it reads a nonsensical string length further down the packet.
Each AttributeModifier is Id and Name as strings, Amount as a little-endian float, Operation and Operand as little-endian int32s and Is Serializable? as a byte.
Parameters
stream
The network stream.
Returns
void
See
https://mojang.github.io/bedrock-protocol-docs/1.26.60/packets/update-attributes-packet/
networkSerializeInitial()
networkSerializeInitial(
stream):void
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:159
Writes one attribute as the SyncedAttribute that AddActorPacket carries: Attribute Name, Min Value, Current Value, Max Value, with no defaults and no modifiers.
Note the order - the current value sits between the bounds here, where Attribute.networkSerialize puts it after them. Getting the two confused silently swaps an entity's health with its upper bound.
Parameters
stream
The network stream.
Returns
void
See
https://mojang.github.io/bedrock-protocol-docs/1.26.51/packets/add-actor-packet/
reset()
reset():
boolean
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:248
Restore the attribute to its default value.
Returns
boolean
true if the stored value actually changed.
setValue()
setValue(
value):boolean
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:236
Set the current value, clamped to the attribute's bounds.
Parameters
value
number
The wanted value.
Returns
boolean
true if the stored value actually changed.
networkDeserialize()
staticnetworkDeserialize(stream):Attribute
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:182
Reads one AttributeData, the inverse of Attribute.networkSerialize.
Parameters
stream
The network stream.
Returns
Attribute
The attribute.
networkDeserializeInitial()
staticnetworkDeserializeInitial(stream):Attribute
Defined in: protocol/src/bedrock/wire/structures/Attribute.ts:167
Reads the compact SyncedAttribute form sent when an actor first spawns.
Parameters
stream
Returns
Attribute