The Region class

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

Represents a schematic region.

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

  • y (int) – the Y coordinate of the region in the schematic

  • z (int) – the Z coordinate of the region in the schematic

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

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

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

Raises:

ValueError – if either width, height or length is 0

allblockpos()
Returns:

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

Return type:

Iterator[tuple[int, int, int]]

as_schematic(name='Unnamed', author='', description='', mc_version=2975)

Creates a schematic that contains that region at the origin.

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

  • author (str) – an author for the schematic

  • description (str) – a description for the schematic

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

Return type:

Schematic

property entities

The entities within the region. :type: list[Entity]

static from_sponge_nbt(nbt)

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 (nbtlib.tag.Compound) – 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.

Return type:

tuple[Region, int]

static from_structure_nbt(structure)

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

Parameters:

structure (Compound) – 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

Return type:

tuple[Region, str]

static fromnbt(nbt)

Read a region from an NBT tag.

Parameters:

nbt (Compound) – an NBT tag to read the region from

Return type:

Region

getblock(x, y, z)

Get a BlockState in the region.

Parameters:
  • x (int) – the X coordinate to get the block at

  • y (int) – the Y coordinate to get the block at

  • z (int) – the Z coordinate to get the block at

Return type:

BlockState

getblockcount()

Counts the number of blocks in the region.

Returns:

the number of non-air blocks in the region

Return type:

int

getvolume()

Computes this region’s volume.

Returns:

this region volume in blocks

Return type:

int

property height

The height of the region. This property is read only. :type: int

property length

The length of the region. This property is read only. :type: int

maxschemx()
Returns:

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

Return type:

int

maxschemy()
Returns:

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

Return type:

int

maxschemz()
Returns:

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

Return type:

int

maxx()
Returns:

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

Return type:

int

maxy()
Returns:

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

Return type:

int

maxz()
Returns:

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

Return type:

int

minschemx()
Returns:

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

Return type:

int

minschemy()
Returns:

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

Return type:

int

minschemz()
Returns:

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

Return type:

int

minx()
Returns:

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

Return type:

int

miny()
Returns:

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

Return type:

int

minz()
Returns:

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

Return type:

int

setblock(x, y, z, block)

Set a BlockState in the region.

Parameters:
  • x (int) – the X coordinate to set the block at

  • y (int) – the Y coordinate to set the block at

  • z (int) – the Z coordinate to set the block at

  • block (BlockState) – the new block state

property tile_entities

The tile entities within the region. :type: list[TileEntity]

to_sponge_nbt(mc_version=2975, gzipped=True, byteorder='big')

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 (int) – Minecraft data version that is being emulated (https://minecraft.fandom.com/wiki/Data_version). Should not be critical for newer versions of Minecraft.

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

  • byteorder (str) – 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.

Return type:

File

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

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

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

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

  • byteorder (str) – 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.

Return type:

File

property width

The width of the region. This property is read only. :type: int

property x

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

xrange()
Returns:

the range of coordinates this region contains along its X axis

Return type:

range

property y

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

yrange()
Returns:

the range of coordinates this region contains along its Y axis

Return type:

range

property z

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

zrange()
Returns:

the range of coordinates this region contains along its Z axis

Return type:

range