API Refernce¶
Read and write Minecraft .mcstructure files.
- mcstructure.COMPABILITY_VERSION: int = 17959425¶
The compability version for a block. The four bytes making up this integer determine the game version number. For example,
17879555is01 10 D2 03in hex meaning1.16.210.03.
- mcstructure.STRUCTURE_MAX_SIZE: tuple[int, int, int] = (64, 384, 64)¶
The maximum size a structure can have. This does not apply for structures created externally and thus is not affect structures created with this library.
- mcstructure.is_valid_structure_name(name: str, *, with_prefix: bool = False) bool¶
Validates the structure name.
- mcstructure.has_suitable_size(size: tuple[int, int, int]) bool¶
Returns
Falseifsizeis greater than the size of structures that can be created within Minecraft.See also
- class mcstructure.Block(identifier: str, *, waterlogged: bool = False, block_entity_data: Sequence[Tag[Any, Any]] | None = None, tick_queue_data: Tag[Any, Any] | None = None, **states: str | bool | int)¶
- name¶
The name of the block.
Examples
Block("minecraft:beehive", honey_level=4) Block("minecraft:grass")
- Parameters:
identifier (str) – The identifier of the block (e.g. “minecraft:wool”).
states (dict[str, str | bool | int]) –
The block states such as
colororstone_type. This varies by every block.waterlogged (bool) – Whether this block is waterlogged.
block_entity_data (collections.abc.Sequence[nbtx.Tag[Any, Any]] | None) – Block entity data like the content of a container.
tick_queue_data (nbtx.Tag[Any, Any] | None)
- stringify(*, with_namespace: bool = True, with_states: bool = True) str¶
Returns a human-readable representation of the block.
This format matches the one used for commands like setblock.
- property namespace_and_name: tuple[str | None, str]¶
The namespace and the name of the block.
Examples
>>> from mcstructure import Block >>> >>> block = Block("minecraft:wool", color="red") >>> block.namespace_and_name ("minecraft", "wool") >>> >>> block = Block("foobar") >>> block.namespace_and_name (None, "foobar")
- class mcstructure.Structure(size: tuple[int, int, int], fill: Block | None = Block(identifier='minecraft:air', states={}, waterlogged=False, block_entity_data=None, tick_queue_data=None))¶
Class representing a Minecraft structure that consists of blocks and entities.
- structure¶
The numpy array representing the blocks in the structure. Each entry is an ID associated with a block present in
palette().
- entities¶
A list of entities the structure contains.
- _size¶
Size of the structure stored internally.
- _palette¶
Internal list of blocks that are used within the structure. The position of the block in the list represents its ID. Modification of this list should be done with caution and if you do so consider modifying
structureappropriately. Instead use methods likeset_block().
- Parameters:
- classmethod load(file: BinaryIO) Self¶
Loads a structure from a file.
Examples
from mcstructure import Structure with open("house.mcstructure", "rb") as f: struct = Structure.load(f)
- get_structure() ndarray[tuple[Any, ...], dtype[Any]]¶
Returns the structure as a numpy array filled with the corresponding block objects.
- as_nbt() TagCompound[Any, Any]¶
Serialize the structure as a NBT data.
Examples
from mcstructure import Structure struct = Structure((5, 5, 5), None) nbt = struct.as_nbt() print(nbt.pretty())
- dump(file: BinaryIO) None¶
Serialize the structure as a NBT file.
Examples
from mcstructure import Structure struct = Structure((5, 5, 5), None) with open("house.mcstructure", "wb") as f: struct.dump(f)
- Parameters:
file (BinaryIO) – File object to write to.
- Return type:
None
- set_block(coordinate: Tuple[int, int, int], block: Block | None) Self¶
Places a block in the structure.
- set_blocks(from_coordinate: Tuple[int, int, int], to_coordinate: Tuple[int, int, int], block: Block) Self¶
Fills an area in the structure with blocks.
Notes
Both start and end points are included.
- resize(size: tuple[int, int, int], fill: Block | None = Block(identifier='minecraft:air', states={}, waterlogged=False, block_entity_data=None, tick_queue_data=None)) Self¶
Resizes the structure.
This function erases blocks that are out of bounds and fill newly created space with
fill(default is air).