The Region class

class litemapy.Region(x, y, z, width, height, length)

Represents a schematic region.

Parameters:
  • x – the X coordinate of the region in the schematic

  • y – the Y coordinate of the region in the schematic

  • z – the Z coordinate of the region in the schematic

  • width – the size of the region along the x-axis (can be negative!)

  • height – the size of the region along the y-axis (can be negative!)

  • length – the size of the region along the z-axis (can be negative!)

Raises:

ValueError – if either width, height or length is 0

allblockpos() Generator[tuple[int, int, int], None, None]
Returns:

an iterator over the coordinates this region contains in its own coordinate system

as_schematic(name: str = 'Unnamed', author: str = '', description: str = '', mc_version: int = 2975) Schematic

Creates a schematic that contains that region at the origin.

Parameters:
  • name – a name for both the region and the schematic

  • author – an author for the schematic

  • description – a description for the schematic

  • mc_version – The Minecraft data version (you are unlikely to ever need to use this)

block_positions() Generator[tuple[int, int, int], None, None]
Returns:

an iterator over the coordinates this region contains in its own coordinate system

count_blocks() int

Counts the number of blocks in the region.

Returns:

the number of non-air blocks in the region

property entities: list[Entity]

The entities within the region.

filter(function: Callable[[BlockState], BlockState]) None

Replaces all occurrences of BlockState with others by providing a mapping function. This method works with the palette directly and the mapping function is therefore only called once per block state type in the region, and not for every position. This is a lot faster than manually iterating over region coordinates.

Parameters:

function – a mapping function

static from_nbt(nbt: Compound) Region

Read a region from an NBT tag.

Parameters:

nbt – an NBT tag to read the region from

static from_sponge_nbt(nbt: Compound) tuple[Region, int]

Returns a Litematica Region based on an NBT Compound that conforms to the Sponge Schematic Format (version 2) used by mods like WorldEdit. Check the file format specification for more information.

Parameters:

nbt – The Sponge schematic NBT Compound.

Returns:

a Litematica Region built from the Sponge schematic and the Minecraft data version that the Sponge schematic was created for.

static from_structure_nbt(structure: Compound) tuple[Region, str]

Returns a Litematica Region based on an NBT Compound that conforms to Minecraft’s structure NBT files.

Parameters:

structure – The Minecraft structure NBT Compound.

Returns:

A Litematica Region built from the Minecraft structure and the Minecraft data version that the structure was created for

static fromnbt(nbt: Compound) Region

Read a region from an NBT tag.

Parameters:

nbt – an NBT tag to read the region from

getblockcount() int

Counts the number of blocks in the region.

Returns:

the number of non-air blocks in the region

getvolume() int

Computes this region’s volume.

Returns:

this region volume in blocks

property height: int

The height of the region. This property is read only.

property length: int

The length of the region. This property is read only.

max_schem_x() int
Returns:

the maximum X coordinate of this region in the schematics coordinate system

max_schem_y() int
Returns:

the maximum Y coordinate of this region in the schematics coordinate system

max_schem_z() int
Returns:

the maximum Z coordinate of this region in the schematics coordinate system

max_x() int
Returns:

the maximum X coordinate of this region in its own coordinate system

max_y() int
Returns:

the maximum Y coordinate of this region in its own coordinate system

max_z() int
Returns:

the maximum Z coordinate of this region in its own coordinate system

maxschemx() int
Returns:

the maximum X coordinate of this region in the schematics coordinate system

maxschemy() int
Returns:

the maximum Y coordinate of this region in the schematics coordinate system

maxschemz() int
Returns:

the maximum Z coordinate of this region in the schematics coordinate system

maxx() int
Returns:

the maximum X coordinate of this region in its own coordinate system

maxy() int
Returns:

the maximum Y coordinate of this region in its own coordinate system

maxz() int
Returns:

the maximum Z coordinate of this region in its own coordinate system

min_schem_x() int
Returns:

the minimum X coordinate of this region in the schematics coordinate system

min_schem_y() int
Returns:

the minimum Y coordinate of this region in the schematics coordinate system

min_schem_z() int
Returns:

the minimum Z coordinate of this region in the schematics coordinate system

min_x() int
Returns:

the minimum X coordinate of this region in its own coordinate system

min_y() int
Returns:

the minimum Y coordinate of this region in its own coordinate system

min_z() int
Returns:

the minimum Z coordinate of this region in its own coordinate system

minschemx() int
Returns:

the minimum X coordinate of this region in the schematics coordinate system

minschemy() int
Returns:

the minimum Y coordinate of this region in the schematics coordinate system

minschemz() int
Returns:

the minimum Z coordinate of this region in the schematics coordinate system

minx() int
Returns:

the minimum X coordinate of this region in its own coordinate system

miny() int
Returns:

the minimum Y coordinate of this region in its own coordinate system

minz() int
Returns:

the minimum Z coordinate of this region in its own coordinate system

property palette: tuple[BlockState, ...]

The palette used to store blocks within the region. Each entry in the palette is assured to be unique. Expected the first palette entry which is always “minecraft:air”, each entry is assured to have at least one instance in the region.

range_x() range
Returns:

the range of coordinates this region contains along its X axis

range_y() range
Returns:

the range of coordinates this region contains along its Y axis

range_z() range
Returns:

the range of coordinates this region contains along its Z axis

replace(replace: BlockState, replace_with: BlockState) None

Replace all occurrences of a BlockState with another. This method works with the palette directly, in O(1) time, and is therefore a lot more efficient than looping over the content.

Parameters:
  • replace – the blockstate to replace

  • replace_with – a new blockstate to replace the old one with

property tile_entities: list[TileEntity]

The tile entities within the region.

to_nbt() Compound

Write this region to an NBT tag.

to_sponge_nbt(mc_version: int = 2975, gzipped: bool = True, endianness: str = 'big') File

Returns the Region as an NBT Compound file that conforms to the Sponge Schematic Format (version 2) used by mods like WorldEdit. Check the file format specification for more information.

Parameters:
  • mc_version – Minecraft data version that is being emulated (https://minecraft.wiki/w/Data_version). Should not be critical for newer versions of Minecraft.

  • gzipped – Whether the NBT Compound file should be compressed (WorldEdit only works with gzipped files).

  • endianness – Endianness of the resulting NBT Compound file (‘big’ or ‘little’, WorldEdit only works with big endian files).

Returns:

The Region represented as a Sponge Schematic NBT Compound file.

to_structure_nbt(mc_version=2975, gzipped=True, byteorder='big') File

Returns the Region as an NBT Compound file that conforms to Minecraft’s structure NBT files.

Parameters:
  • mc_version – Minecraft data version that is being emulated (https://minecraft.wiki/w/Data_version). Should not be critical for newer versions of Minecraft.

  • gzipped – Whether the NBT Compound file should be compressed (Vanilla Minecraft only works with gzipped files).

  • byteorder – Endianness of the resulting NBT Compound file (‘big’ or ‘little’, Vanilla Minecraft only works with big endian files).

Returns:

The Region represented as a Minecraft structure NBT file.

volume() int

Computes this region’s volume.

Returns:

this region volume in blocks

property width: int

The width of the region. This property is read only.

property x: int

The X coordinate of the region within the schematic’s coordinate system. This property is read only.

xrange() range
Returns:

the range of coordinates this region contains along its X axis

property y: int

The Y coordinate of the region within the schematic’s coordinate system. This property is read only.

yrange() range
Returns:

the range of coordinates this region contains along its Y axis

property z: int

The Z coordinate of the region within the schematic’s coordinate system. The property is read only.

zrange() range
Returns:

the range of coordinates this region contains along its Z axis