Skip to content

API reference / @jsprismarine/prismarine / BlockState

Class: BlockState ​

Defined in: prismarine/src/block/state/BlockState.ts:24

A block, and the exact values of every property it carries.

minecraft:oak_log is not one block but three: one per pillar_axis. Treating the name alone as the identity is what made every oriented block render wrong, because all three collapsed onto whichever was registered last.

Instances are immutable: with returns a new state rather than mutating, so a state held in a chunk palette or handed to a plugin cannot be changed underneath its owner.

Constructors ​

Constructor ​

new BlockState(name, properties?): BlockState

Defined in: prismarine/src/block/state/BlockState.ts:28

Parameters ​

name ​

string

properties? ​

Record<string, BlockStateValue> = {}

Returns ​

BlockState

Properties ​

name ​

readonly name: string

Defined in: prismarine/src/block/state/BlockState.ts:25


properties ​

readonly properties: Readonly<Record<string, BlockStateValue>>

Defined in: prismarine/src/block/state/BlockState.ts:26

Accessors ​

[toStringTag] ​

Get Signature ​

get [toStringTag](): string

Defined in: prismarine/src/block/state/BlockState.ts:47

A stable textual form, properties in alphabetical order: minecraft:oak_log[pillar_axis=y]. Used as the cache key for runtime ids and in log messages.

Returns ​

string

Methods ​

equals() ​

equals(other): boolean

Defined in: prismarine/src/block/state/BlockState.ts:58

Parameters ​

other ​

BlockState

Returns ​

boolean


get() ​

get(property): BlockStateValue | undefined

Defined in: prismarine/src/block/state/BlockState.ts:39

Parameters ​

property ​

string

Returns ​

BlockStateValue | undefined


toNBT() ​

toNBT(types): NBTTagCompound

Defined in: prismarine/src/block/state/BlockState.ts:77

The {name, states} compound the runtime id is hashed from.

Two things here are load bearing rather than stylistic:

  • Properties are written in alphabetical order. The hash covers the serialised bytes, so a different order is a different id for the same block.
  • Each property keeps its vanilla NBT type. The tag type byte is part of those bytes, so writing facing_direction as a byte instead of an int yields an id the client cannot resolve.

The version field the vanilla dump carries is deliberately absent: it is not part of what gets hashed.

Parameters ​

types ​

Readonly<Record<string, BlockStatePropertyType>>

Returns ​

NBTTagCompound

See ​

https://gist.github.com/Alemiz112/504d0f79feac7ef57eda174b668dd345


toString() ​

toString(): string

Defined in: prismarine/src/block/state/BlockState.ts:51

Returns ​

string


with() ​

with(property, value): BlockState

Defined in: prismarine/src/block/state/BlockState.ts:35

Derives a state with one property changed.

Parameters ​

property ​

string

value ​

BlockStateValue

Returns ​

BlockState