Skip to content

API reference / @jsprismarine/protocol / DataItem

Class: DataItem ​

Defined in: protocol/src/structure/DataItem.ts:39

One DataItemEntry of a SynchedActorDataList, the typed entity data an actor carries.

Wire layout: ID (varuint32), then the Payload, a Cereal tagged variant. The variant writes its selector as a varuint32 (the alternative's index in the schema's oneOf, which the schema marks with x-control-value-type: uint32), and then the chosen alternative in full. Every alternative opens with its own Type byte (uint8 DataItemType), so the type is on the wire twice: once as the selector and once as the alternative's first field. The Value follows: Byte as int8, Short as int16 little endian, Int as varint32, Float as float little endian, String as a string, CompoundTag as network NBT, Pos as a BlockPos of three varint32, Int64 as varint64, Vec3 as three floats.

The selector is not a duplicate to drop. gophertunnel master (protocol 2193) writes Varuint32(dataType) then Uint8(legacyDataType) in Writer.EntityMetadata and its reader rejects an entry whose two disagree; a retail 1.26.51 client fails to join when the selector is missing. The alternative indices happen to equal the DataItemType values. https://mojang.github.io/bedrock-protocol-docs/1.26.51/types/data-item-entry/https://github.com/Sandertv/gophertunnel/blob/master/minecraft/protocol/writer.go

Extends ​

Constructors ​

Constructor ​

new DataItem(id, entry): DataItem

Defined in: protocol/src/structure/DataItem.ts:45

Creates a data item.

Parameters ​

id ​

number

The entity data key the value belongs to.

entry ​

DataItemEntry

The typed value to carry.

Returns ​

DataItem

Overrides ​

NetworkStructure.constructor

Methods ​

deserialize() ​

deserialize(stream): void

Defined in: protocol/src/structure/DataItem.ts:108

Reads the item from the stream.

Parameters ​

stream ​

NetworkBinaryStream

Returns ​

void

Throws ​

Error when the one-of selector and the alternative's type byte disagree, or when neither names a known DataItemType.

Overrides ​

NetworkStructure.deserialize


getId() ​

getId(): number

Defined in: protocol/src/structure/DataItem.ts:53

The entity data key this item sets.

Returns ​

number


getType() ​

getType(): DataItemType

Defined in: protocol/src/structure/DataItem.ts:58

The wire type of the value.

Returns ​

DataItemType


getValue() ​

getValue(): string | number | bigint | NBTTagCompound | Vec3 | BlockPos

Defined in: protocol/src/structure/DataItem.ts:63

The value, typed according to DataItem.getType.

Returns ​

string | number | bigint | NBTTagCompound | Vec3 | BlockPos


serialize() ​

serialize(stream): void

Defined in: protocol/src/structure/DataItem.ts:68

Writes the item in docs order: the id, the one-of selector, the alternative's type byte, the value.

Parameters ​

stream ​

NetworkBinaryStream

Returns ​

void

Overrides ​

NetworkStructure.serialize


deserialize() ​

static deserialize<T>(this, stream): T

Defined in: protocol/src/NetworkStructure.ts:28

Deserializes the network structure from a binary stream. The constructor runs with no arguments before the stream is read, so the class must tolerate that.

Type Parameters ​

T ​

T extends NetworkStructure

Parameters ​

this ​

Constructor<T>

stream ​

NetworkBinaryStream

The binary stream to deserialize from.

Returns ​

T

An instance of the class T.

Inherited from ​

NetworkStructure.deserialize