API reference / @jsprismarine/protocol / ItemInstanceUserData
Class: ItemInstanceUserData
Defined in: protocol/src/structure/ItemInstanceUserData.ts:35
The blob a NetworkItemStackDescriptor carries as its User Data Buffer: the item's NBT and its can-place-on and can-destroy lists.
Wire layout, after gophertunnel's itemUserData since the docs do not describe this type: a marker (int16 little endian) that is -1 when a compound follows and 0 otherwise. After -1 come one version byte (1) and the compound as plain little-endian NBT, without varints. Then Can Place On and Can Destroy, each a uint32 little-endian count followed by strings with an int16 little-endian length. A shield ends with its Blocking Tick (int64 little endian); nothing on the wire says whether it is there, so the reader has to be told. The docs have no page for this blob; the descriptor that carries it is at https://mojang.github.io/bedrock-protocol-docs/1.26.51/types/network-item-stack-descriptor/.
Extends
Constructors
Constructor
new ItemInstanceUserData(
userDataTag?,config?):ItemInstanceUserData
Defined in: protocol/src/structure/ItemInstanceUserData.ts:48
Creates the user data.
Parameters
userDataTag?
NBTTagCompound | null = null
The item's compound, or null when it has none. The marker is derived from this.
config?
ItemInstanceUserDataConfig = {}
The block lists and, for a shield, the blocking tick.
Returns
ItemInstanceUserData
Overrides
Properties
blockingTick
blockingTick:
bigint|null
Defined in: protocol/src/structure/ItemInstanceUserData.ts:41
The tick a shield started blocking on, or null for every other item.
canDestroyBlocks
canDestroyBlocks:
string[]
Defined in: protocol/src/structure/ItemInstanceUserData.ts:39
Block names the item may break.
canPlaceOnBlocks
canPlaceOnBlocks:
string[]
Defined in: protocol/src/structure/ItemInstanceUserData.ts:37
Block names the item may be placed on.
userDataTag
userDataTag:
NBTTagCompound|null=null
Defined in: protocol/src/structure/ItemInstanceUserData.ts:49
The item's compound, or null when it has none. The marker is derived from this.
Methods
deserialize()
deserialize(
stream,shield?):void
Defined in: protocol/src/structure/ItemInstanceUserData.ts:83
Reads the user data, replacing whatever the instance held.
Parameters
stream
The stream positioned at the marker.
shield?
boolean = false
Whether the item is a shield, so a Blocking Tick closes the blob. The caller knows this from the stack's item id; nothing in the blob says so.
Returns
void
Throws
Error when the marker is neither 0 nor -1, or the version byte is not 1.
Overrides
serialize()
serialize(
stream):void
Defined in: protocol/src/structure/ItemInstanceUserData.ts:59
Writes the marker, the compound when there is one, both block lists, and the blocking tick when set.
Parameters
stream
Returns
void
Overrides
deserialize()
staticdeserialize<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
The binary stream to deserialize from.
Returns
T
An instance of the class T.