Skip to content

API reference / @jsprismarine/protocol / ItemStack

Class: ItemStack ​

Defined in: protocol/src/structure/ItemStack.ts:31

An item stack in the form that carries no stack net id - the docs' ItemStack.

The creative menu and every recipe use it, because nothing is tracking these stacks. It differs from NetworkItemStackDescriptor in two ways and not only in the missing Net Id Variant: the id is a varint32 here rather than two fixed bytes, and so is the block runtime id.

Wire layout: Id (varint32), Stack size (uint16 little endian), Aux value (varuint32), Block Runtime Id (varint32), then User Data Buffer (a varuint32 length and the bytes). An empty stack writes zero for every field after the id, including a zero length blob. https://mojang.github.io/bedrock-protocol-docs/1.26.51/types/network-item-stack-descriptor/

Extends ​

Constructors ​

Constructor ​

new ItemStack(runtimeId?, count?, meta?, blockRuntimeId?, userData?): ItemStack

Defined in: protocol/src/structure/ItemStack.ts:43

Creates a stack.

Parameters ​

runtimeId? ​

number = 0

Id, or 0 for an empty stack.

count? ​

number = 0

Stack size.

meta? ​

number = 0

Aux value.

blockRuntimeId? ​

number = 0

Block Runtime Id, or 0 when the item places no block.

userData? ​

Buffer = ...

User Data Buffer; an empty buffer when the stack carries none.

Returns ​

ItemStack

Overrides ​

NetworkStructure.constructor

Properties ​

blockRuntimeId ​

blockRuntimeId: number = 0

Defined in: protocol/src/structure/ItemStack.ts:47

Block Runtime Id, or 0 when the item places no block.


count ​

count: number = 0

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

Stack size.


meta ​

meta: number = 0

Defined in: protocol/src/structure/ItemStack.ts:46

Aux value.


runtimeId ​

runtimeId: number = 0

Defined in: protocol/src/structure/ItemStack.ts:44

Id, or 0 for an empty stack.


userData ​

userData: Buffer

Defined in: protocol/src/structure/ItemStack.ts:33

User Data Buffer, a serialized ItemInstanceUserData.

Methods ​

deserialize() ​

deserialize(stream): void

Defined in: protocol/src/structure/ItemStack.ts:82

Reads the stack in docs order. The user data blob is kept as bytes, not parsed.

Parameters ​

stream ​

NetworkBinaryStream

Returns ​

void

Overrides ​

NetworkStructure.deserialize


serialize() ​

serialize(stream): void

Defined in: protocol/src/structure/ItemStack.ts:71

Writes the stack in docs order. An empty stack writes zeroes for every field after the id.

Parameters ​

stream ​

NetworkBinaryStream

Returns ​

void

Overrides ​

NetworkStructure.serialize


toData() ​

toData(): ItemStackData

Defined in: protocol/src/structure/ItemStack.ts:60

The plain form, for a payload.

Returns ​

ItemStackData


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


from() ​

static from(stack): ItemStack

Defined in: protocol/src/structure/ItemStack.ts:55

Builds a stack from the plain form, filling in the empty blob.

Parameters ​

stack ​

ItemStackData

Returns ​

ItemStack