BlockTranslator class

class PyMCTranslate.py3.api.version.translators.block.BlockTranslator(translation_manager, parent_version, database, raw_numerical_block_map, waterloggable, always_waterlogged, block_format, *_)[source]

Bases: BaseTranslator

base_names(namespace, force_blockstate=False)

A list of all the valid base names present in a given namespace for this object type.

Parameters
  • namespace (str) – A namespace string as found using the namespaces method

  • force_blockstate (bool) – True to get the blockstate format. False to get the native format (these are sometimes the same)

Return type

List[str]

Returns

A list of base names

property block_format: str

The native format of the blocks for this game version.

This will be one of “numerical”, “pseudo-numerical”, “blockstate” or “nbt-blockstate”.

“numerical” is the old storage format where both block id and data value were numerical values.

“pseudo-numerical” is the in-between Bedrock format where block ids were namespaced strings but data was still numerical.

“blockstate” is the new Java format where the block ids are all namespaced strings and the data is stored as properties in NBT.TAG_String format.

“nbt-blockstate” is the new Bedrock format where the block ids are all namespaced strings and the data is stored as properties in various NBT types.

from_universal(block, block_entity=None, force_blockstate=False, block_location=(0, 0, 0), get_block_callback=None)[source]

Translate the given Block object from the Universal format to the parent Version’s format.

Parameters
  • block (Block) – The block to translate

  • block_entity (Optional[BlockEntity]) – An optional block entity related to the block input

  • force_blockstate (bool) – True to get the blockstate format. False to get the native format (these are sometimes the same)

  • block_location (Tuple[int, int, int]) – The location of the block in the world

  • get_block_callback (Optional[Callable[[Tuple[int, int, int]], Tuple[Block, Optional[BlockEntity]]]]) – A callable with relative coordinates that returns a Block and optional BlockEntity

Return type

Union[Tuple[Block, Optional[BlockEntity], bool], Tuple[Entity, None, bool]]

Returns

There are two formats that can be returned. The first is a Block, optional BlockEntity and a bool. The second is an Entity, None and a bool. The bool specifies if block_location and get_block_callback are required to fully define the output data.

get_mapping_from_universal(namespace, base_name, force_blockstate=False)

Get the mapping file for the requested object from the universal format to this version format.

Parameters
  • namespace (str) – A namespace string as found using the namespaces method

  • base_name (str) – A base name string as found using the base_name method

  • force_blockstate (bool) – True to get the blockstate format. False to get the native format (these are sometimes the same)

Return type

List[dict]

Returns

A list of mapping functions to apply to the object

get_mapping_to_universal(namespace, base_name, force_blockstate=False)

Get the mapping file for the requested object from this version format to the universal format.

Parameters
  • namespace (str) – A namespace string as found using the namespaces method

  • base_name (str) – A base name string as found using the base_name method

  • force_blockstate (bool) – True to get the blockstate format. False to get the native format (these are sometimes the same)

Return type

List[dict]

Returns

A list of mapping functions to apply to the object

get_specification(namespace, base_name, force_blockstate=False)[source]

Get the specification file for the requested object.

Parameters
  • namespace (str) – A namespace string as found using the namespaces method

  • base_name (str) – A base name string as found using the base_name method

  • force_blockstate (bool) – True to get the blockstate format. False to get the native format (these are sometimes the same)

Return type

BlockSpecification

Returns

A custom dictionary with a better documented API.

is_waterloggable(namespace_str, always=False)[source]

A method to check if a block can be waterlogged. This method is only valid for Java blockstate format worlds, Other formats either don’t have waterlogged blocks or don’t have a limit on what can be stacked.

Parameters
  • namespace_str (str) – “<namespace>:<base_name>”

  • always – True to check if the block does not have a waterlogged property but is always waterlogged. eg: seagrass

Returns

Bool. True if it can be waterlogged. False if not or another format.

namespaces(force_blockstate=False)

A list of all the valid namespaces for this object type.

Parameters

force_blockstate (bool) – True to get the blockstate format. False to get the native format (these are sometimes the same)

Return type

List[str]

Returns

A list of all the namespaces

to_universal(block, block_entity=None, force_blockstate=False, block_location=(0, 0, 0), get_block_callback=None)[source]

Translate the given Block object and optional BlockEntity from the parent Version’s format to the Universal format.

Parameters
  • block (Block) – The block to translate

  • block_entity (Optional[BlockEntity]) – An optional block entity related to the block input

  • force_blockstate (bool) – True to get the blockstate format. False to get the native format (these are sometimes the same)

  • block_location (Tuple[int, int, int]) – The location of the block in the world

  • get_block_callback (Optional[Callable[[Tuple[int, int, int]], Tuple[Block, Optional[BlockEntity]]]]) – A callable with relative coordinates that returns a Block and optional BlockEntity

Return type

Tuple[Block, Optional[BlockEntity], bool]

Returns

A Block, optional BlockEntity and a bool. The bool specifies if block_location and get_block_callback are required to fully define the output data.