amulet.api.level.base_level.chunk_manager package

class amulet.api.level.base_level.chunk_manager.ChunkManager(level, history_db)[source]

Bases: DatabaseHistoryManager

The ChunkManager class is a class that handles chunks within a world.

It handles the temporary database of chunks in RAM that can be directly modified.

It handles a serialised version of the chunks on disk to reduce RAM usage.

It also contains a history manager to allow undoing and redoing of changes.

DoesNotExistError[source]

alias of ChunkDoesNotExist

LoadError[source]

alias of ChunkLoadError

__init__(level, history_db)[source]

Construct a ChunkManager instance.

Should not be directly used by third party code.

Parameters

level (BaseLevel) – The world that this chunk manager is associated with

property level: BaseLevel[source]

The level that this chunk manager is associated with.

changed_chunks()[source]

The location of every chunk that has been changed since the last save.

Return type

Generator[Tuple[str, int, int], None, None]

unload(safe_area=None)[source]

Unload all chunks from the temporary database that are not in the safe area.

Parameters

safe_area (Optional[Tuple[str, int, int, int, int]]) – The area that should not be unloaded [dimension, min_chunk_x, min_chunk_z, max_chunk_x, max_chunk_z]. If None will unload all chunk data.

has_chunk(dimension, cx, cz)[source]

Is the chunk specified present in the level.

Parameters
  • dimension (str) – The dimension of the chunk to check.

  • cx (int) – The chunk x coordinate.

  • cz (int) – The chunk z coordinate.

Return type

bool

Returns

True if the chunk is present, False otherwise

all_chunk_coords(dimension)[source]

The coordinates of every chunk in this world.

This is the combination of chunks saved to the world and chunks yet to be saved.

Return type

Set[Tuple[int, int]]

get_chunk(dimension, cx, cz)[source]

Gets the Chunk object at the specified chunk coordinates.

This may be a Chunk instance if the chunk exists, None if it is known to not exist or ChunkDoesNotExist will be raised if there is no record so it is unknown if it exists or not.

Use has_chunk to check if there is a record of the chunk.

Parameters
  • dimension (str) – The dimension to get the chunk from

  • cx (int) – The X coordinate of the desired chunk

  • cz (int) – The Z coordinate of the desired chunk

Return type

Chunk

Returns

A Chunk instance or None

Raises

ChunkDoesNotExist: If the chunk does not exist (was deleted or never created)

put_chunk(chunk, dimension)[source]

Add a given chunk to the chunk manager.

Parameters
  • chunk (Chunk) – The Chunk to add to the chunk manager. It will be added at the location stored in Chunk.coordinates

  • dimension (str) – The dimension to add the chunk to.

delete_chunk(dimension, cx, cz)[source]

Delete a chunk from the chunk manager.

Parameters
  • cx (int) – The X coordinate of the chunk

  • cz (int) – The Z coordinate of the chunk

  • dimension (str) – The dimension to delete the chunk from.

property changed: bool[source]

Have there been modifications since the last save.

changed_entries()[source]

A generator of all the entry keys that have changed since the last save.

Return type

Generator[Any, None, None]

create_undo_point()[source]

Find what has changed since the last undo point and optionally create a new undo point.

Return type

bool

Returns

Was an undo point created. If there were no changes no snapshot will be created.

create_undo_point_iter()[source]

Find all entries in the temporary database that have changed since the last undo point and create a new undo point.

Return type

Generator[float, None, bool]

Returns

Was an undo point created. If there were no changes no snapshot will be created.

mark_saved()[source]

Let the class know that the current state has been saved.

purge()[source]

Unload all cached data. Effectively returns the class to its starting state.

redo()[source]

Redoes the last set of changes to the database

property redo_count: int[source]

The number of times the redo() method can be run.

restore_last_undo_point()[source]

Restore the state of the database to what it was when create_undo_point_iter() was last called.

undo()[source]

Undoes the last set of changes to the database

property undo_count: int[source]

The number of times the undo() method can be run.

unload_unchanged(*args, **kwargs)[source]

Unload all entries from RAM that have not been marked as changed.

property unsaved_changes: int[source]

The number of changes that have been made since the last save