amulet.api.chunk package

class amulet.api.chunk.chunk.Chunk(cx, cz)[source]

Bases: Changeable

A class to represent a chunk that exists in a Minecraft world

__init__(cx, cz)[source]

Construct an instance of Chunk at the given coordinates.

Parameters
  • cx (int) – The x coordinate of the chunk (is not the same as block coordinates)

  • cz (int) – The z coordinate of the chunk (is not the same as block coordinates)

pickle()[source]

Serialise the data in the chunk using pickle and return the resulting bytes.

Return type

bytes

Returns

Pickled output.

classmethod unpickle(pickled_bytes, block_palette, biome_palette)[source]

Deserialise the pickled input and unpack the data into an instance of Chunk

Parameters
  • pickled_bytes (bytes) – The bytes returned from pickle()

  • block_palette (BlockManager) – The instance of BlockManager associated with the level.

  • biome_palette (BiomeManager) – The instance of BiomeManager associated with the level.

Return type

Chunk

Returns

An instance of Chunk containing the unpickled data.

property cx: int[source]

The chunk’s x coordinate

property cz: int[source]

The chunk’s z coordinate

property coordinates: Tuple[int, int][source]

The chunk’s x and z coordinates

property changed: bool[source]

Has the chunk changed since the last undo point. Is used to track which chunks have changed.

>>> chunk = Chunk(0, 0)
>>> # Run this to notify that the chunk data has changed.
>>> chunk.changed = True
Setter

Set this to True if you have modified the chunk in any way.

Returns

True if the chunk has been changed since the last undo point, False otherwise.

property changed_time: float[source]

The last time the chunk was changed

Used to track if the chunk was changed since the last save snapshot and if the chunk model needs rebuilding.

property blocks: Blocks[source]

The block array for the chunk.

This is a custom class that stores a numpy array per sub-chunk.

The values in the arrays are indexes into block_palette.

get_block(dx, y, dz)[source]

Get the universal Block object at the given location within the chunk.

Parameters
  • dx (int) – The x coordinate within the chunk. 0-15 inclusive

  • y (int) – The y coordinate within the chunk. This can be any integer.

  • dz (int) – The z coordinate within the chunk. 0-15 inclusive

Return type

Block

Returns

The universal Block object representation of the block at that location

set_block(dx, y, dz, block)[source]

Set the universal Block object at the given location within the chunk.

Parameters
  • dx (int) – The x coordinate within the chunk. 0-15 inclusive

  • y (int) – The y coordinate within the chunk. This can be any integer.

  • dz (int) – The z coordinate within the chunk. 0-15 inclusive

  • block (Block) – The universal Block object to set at the given location

property block_palette: BlockManager[source]

The block block_palette for the chunk.

Usually will refer to the level’s global block_palette.

property biomes: Biomes[source]

The biome array for the chunk.

This is a custom class that stores numpy arrays. See the Biomes documentation for more information.

The values in the arrays are indexes into biome_palette.

property biome_palette: BiomeManager[source]

The biome block_palette for the chunk.

Usually will refer to the level’s global biome_palette.

property entities: EntityList[source]

Property that returns the chunk’s entity list. Setting this property replaces the chunk’s entity list

Returns

A list of all the entities contained in the chunk

property block_entities: BlockEntityDict[source]

Property that returns the chunk’s block entity list. Setting this property replaces the chunk’s block entity list

Returns

A list of all the block entities contained in the chunk

property status: Status[source]

A class containing the chunk’s generation status.

property misc: dict[source]

Extra data that exists in a chunk but does not have its own location.

Data in here is not guaranteed to exist and may get moved at a later date.