The BlockState class

Blocks in the schematic are represented by the BlockState class. It has a block identifier and block properties. E.g.

>>> block = BlockState("minecraft:oak_log", facing="up")
>>> block.id
"minecraft:oak_log"
>>> block["facing"]
"up"
>>> "facing" in block
True
class litemapy.BlockState(block_id: str, **properties: str)

Represents an in-game block. BlockState are immutable.

A block state has a block ID and a dictionary of properties.

Parameters:
  • block_id – the identifier of the block (e.g. minecraft:stone)

  • properties – the properties of the block state as keyword parameters (e.g. facing=”north”)

static from_nbt(nbt: Compound) BlockState

Reads a BlockState from an nbt tag.

static fromnbt(nbt: Compound) BlockState

Reads a BlockState from an nbt tag.

property id: str

The block’s identifier.

properties() Iterable[tuple[str, str]]

Exposes the properties of this BlockState using an iterator over its properties, in a similar fashion as dict.items().

Returns:

An iterable over the properties, as property, value tuples.

to_block_state_identifier(skip_empty: bool = True) str

Returns an identifier that represents the BlockState in the Sponge Schematic Format (version 2). Format: block_type[properties] Example: minecraft:oak_sign[rotation=0,waterlogged=false]

Parameters:

skip_empty – Whether empty brackets should be excluded if the BlockState has no properties.

Returns:

An identifier that represents the BlockState in a Sponge schematic.

to_nbt() Compound

Writes this block state to an nbt tag.

with_blockid(block_id: str) BlockState

Returns a new BlockState with the same properties as this one but a different block id.

Parameters:

block_id – the block id for the new BlockState

with_id(block_id: str) BlockState

Returns a new BlockState with the same properties as this one but a different block id.

Parameters:

block_id – the block id for the new BlockState

with_properties(**properties: str | None) BlockState

Returns a new copy of this BlockState with new values for the properties given in keyword arguments. Using None as a property value removes it.

Parameters:

properties – the new properties as keyword arguments

Returns:

A copy of this BlockState with the given properties updated to new values