[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/protocol](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md) / Attribute

# Class: Attribute

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:50](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L50)

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](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L80)

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](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L256)

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](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L218)

#### Returns

`number`

***

### getMax()

> **getMax**(): `number`

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:214](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L214)

#### Returns

`number`

***

### getMin()

> **getMin**(): `number`

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:210](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L210)

#### Returns

`number`

***

### getModifiers()

> **getModifiers**(): readonly `AttributeModifier`[]

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:227](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L227)

The modifiers the value includes.

#### Returns

readonly `AttributeModifier`[]

***

### getName()

> **getName**(): `string`

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:206](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L206)

#### Returns

`string`

***

### getValue()

> **getValue**(): `number`

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:222](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L222)

#### Returns

`number`

***

### networkSerialize()

> **networkSerialize**(`stream`): `void`

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:129](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L129)

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

[`BinaryStream`](https://jsprismarine.dev/api/@jsprismarine/binaryutils/classes/BinaryStream.md)

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](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L159)

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](#networkserialize) puts it after them. Getting the two confused
silently swaps an entity's health with its upper bound.

#### Parameters

##### stream

[`BinaryStream`](https://jsprismarine.dev/api/@jsprismarine/binaryutils/classes/BinaryStream.md)

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](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L248)

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](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L236)

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()

> `static` **networkDeserialize**(`stream`): `Attribute`

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:182](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L182)

Reads one `AttributeData`, the inverse of [Attribute.networkSerialize](#networkserialize).

#### Parameters

##### stream

[`BinaryStream`](https://jsprismarine.dev/api/@jsprismarine/binaryutils/classes/BinaryStream.md)

The network stream.

#### Returns

`Attribute`

The attribute.

***

### networkDeserializeInitial()

> `static` **networkDeserializeInitial**(`stream`): `Attribute`

Defined in: [protocol/src/bedrock/wire/structures/Attribute.ts:167](https://github.com/JSPrismarine/JSPrismarine/blob/21088b69d7b227110b98eefd29702ff7304762ef/packages/protocol/src/bedrock/wire/structures/Attribute.ts#L167)

Reads the compact `SyncedAttribute` form sent when an actor first spawns.

#### Parameters

##### stream

[`BinaryStream`](https://jsprismarine.dev/api/@jsprismarine/binaryutils/classes/BinaryStream.md)

#### Returns

`Attribute`
