amulet.level.formats.anvil_world package

class amulet.level.formats.anvil_world.AnvilFormat(path)[source]

Bases: WorldFormatWrapper[int]

This FormatWrapper class exists to interface with the Java world format.

__init__(path)[source]

Construct a new instance of AnvilFormat.

This should not be used directly. You should instead use amulet.load_format().

Parameters

path (str) – The file path to the serialised data.

static is_valid(path)[source]

Returns whether this format wrapper is able to load the given data.

Parameters

path (str) – The path of the data to load.

Return type

bool

Returns

True if the world can be loaded by this format wrapper, False otherwise.

property valid_formats: Dict[str, Tuple[bool, bool]][source]

The valid platform and version combinations that this object can accept.

This is used when setting the platform and version in the create_and_open method to verify that the platform and version are valid.

Returns

A dictionary mapping the platform to a tuple of two booleans to determine if numerical and blockstate are valid respectively.

property version: int[source]

The data version number that the world was last opened in. eg 2578

property root_tag: NamedTag[source]

The level.dat data for the level.

property level_name: str[source]

The name of the level.

property dimensions: List[str][source]

A list of all the dimensions contained in the world.

property has_lock: bool[source]

Verify that the world database can be read and written

pre_save_operation(level)[source]

Logic to run before saving. Eg recalculating height maps or lighting.

Must be a generator that yields a number and returns a bool.

The yielded number is the progress from 0 to 1.

The returned bool is if changes have been made.

Parameters

level (BaseLevel) – The level to apply modifications to.

Return type

Generator[float, None, bool]

Returns

Have any modifications been made.

unload()[source]

Unload data stored in the FormatWrapper class

all_chunk_coords(dimension)[source]

A generator of all chunk coords in the given dimension.

Return type

Iterable[Tuple[int, int]]

has_chunk(cx, cz, dimension)[source]

Does the chunk exist in the world database?

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

  • cz (int) – The z coordinate of the chunk.

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

Return type

bool

Returns

True if the chunk exists. Calling load_chunk on this chunk may still throw ChunkLoadError

put_raw_chunk_data(cx, cz, data, dimension)[source]

Commit the raw chunk data to the FormatWrapper cache.

Call save() to push all the cache data to the level.

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

  • cz (int) – The z coordinate of the chunk.

  • data (NamedTag) – The raw data to commit to the level.

  • dimension (str) – The dimension to load the data from.

get_raw_chunk_data(cx, cz, dimension)[source]

Return the raw data as loaded from disk.

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

  • cz (int) – The z coordinate of the chunk.

  • dimension (str) – The dimension to load the data from.

Return type

NamedTag

Returns

The raw chunk data.

all_player_ids()[source]

Returns a generator of all player ids that are present in the level

Return type

Iterable[str]

has_player(player_id)[source]

Test if a player id is present in the level.

Return type

bool

property can_add_dimension: bool[source]

Can external code register a new dimension.

If False register_dimension() will have no effect.

property changed: bool[source]

Has any data been pushed to the format wrapper that has not been saved to disk.

close()[source]

Close the level.

commit_chunk(chunk, dimension)[source]

Save a universal format chunk to the FormatWrapper database (not the level database)

Call save method to write changed chunks back to the level.

Parameters
  • chunk (Chunk) – The chunk object to translate and save.

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

create_and_open(platform, version, bounds=None, overwrite=False, **kwargs)[source]

Remove the data at the path and set up a new database.

You might want to call exists to check if something exists at the path and warn the user they are going to overwrite existing data before calling this method.

Parameters
  • platform (str) – The platform the data should use.

  • version (Union[int, Tuple[int, ...]]) – The version the data should use.

  • bounds (Union[SelectionGroup, Dict[str, Optional[SelectionGroup]], None]) – The bounds for each dimension. If one SelectionGroup is given it will be applied to all dimensions.

  • overwrite (bool) – Should an existing database be overwritten. If this is False and one exists and error will be thrown.

  • kwargs – Extra arguments as each implementation requires.

Returns

delete_chunk(cx, cz, dimension)[source]

Delete the given chunk from the level.

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

  • cz (int) – The z coordinate of the chunk.

  • dimension (str) – The dimension to load the data from.

property exists: bool[source]

Does some data exist at the specified path.

get_raw_player_data(player_id)[source]

Get the player data in the lowest level form.

Parameters

player_id (str) – The id of the player to get.

Return type

Any

Returns

property is_open: bool[source]

Has the object been opened.

load_chunk(cx, cz, dimension)[source]

Loads and creates a universal Chunk object from chunk coordinates.

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

  • cz (int) – The z coordinate of the chunk.

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

Return type

Chunk

Returns

The chunk at the given coordinates.

Raises

ChunkDoesNotExist: If the chunk does not exist (was deleted or never created) ChunkLoadError: If the chunk was not able to be loaded. Eg. If the chunk is corrupt or some error occurred when loading.

load_player(player_id)[source]

Gets the Player object that belongs to the specified player id

If no parameter is supplied, the data of the local player should be returned

Parameters

player_id (str) – The desired player id

Return type

Player

Returns

A Player instance

property max_world_version: Tuple[str, VersionNumberT][source]

The version the world was last opened in.

This should be greater than or equal to the chunk versions found within.

property multi_selection: bool[source]

Does this object support having multiple selection boxes.

If False it will be given exactly 1 selection.

If True can be given 0 or more.

open()[source]

Open the database for reading and writing.

property path: str[source]

The path to the data on disk.

property platform: str[source]

Platform string the data is stored in (eg “bedrock” / “java” / …)

register_dimension(dimension_identifier)[source]

Register a new dimension.

Parameters

dimension_identifier (Any) – The identifier for the dimension.

property requires_selection: bool[source]

Does this object require that a selection be defined when creating it from scratch?

save()[source]

Save the data back to the level.

property selection: SelectionGroup[source]

The area that all chunk data must fit within.

property sub_chunk_size: int[source]

The dimensions of a sub-chunk.

property translation_manager: TranslationManager[source]

The translation manager attached to the world.

property world_image_path: str[source]

The path to the world icon.