Block class

class PyMCTranslate.py3.api.amulet_objects.block.Block(namespace, base_name, properties=None, extra_blocks=None)[source]

Bases: object

Important

If you are using PyMCTranslate in conjunction with amulet_core you must use the amulet_core equivalent of this class

Class to handle data about various blockstates and allow for extra blocks to be created and interacted with.

Here’s a few examples on how create a Block object with extra blocks:

Creating a new Block object with the base of stone and has an extra block of water[level=1]:

>>> stone = blockstate_to_block("minecraft:stone")
>>> water_level_1 = blockstate_to_block("minecraft:water[level=1]")
>>> stone_with_extra_block = stone + water_level_1
>>> repr(stone_with_extra_block)
'Block(minecraft:stone, minecraft:water[level=1])'

Creating a new Block object using the namespace and base_name:

>>> granite = Block(namespace="minecraft", base_name="granite")

Creating a new Block object with another layer of extra blocks:

>>> stone_water_granite = stone_with_extra_block + granite # Doesn't modify any of the other objects
>>> repr(stone_water_granite)
'Block(minecraft:stone, minecraft:water[level=1], minecraft:granite)'

Creating a new Block object by removing an extra block from all layers:

Note: This removes all instances of the Block object from extra blocks

>>> stone_granite = stone_water_granite - water_level_1 # Doesn't modify any of the other objects either
>>> repr(stone_granite)
'Block(minecraft:stone, minecraft:granite)'

Creating a new Block object by removing a specific layer:

>>> oak_log_axis_x = blockstate_to_block("minecraft:oak_log[axis=x]")
>>> stone_water_granite_water_oak_log = stone_water_granite + water_level_1 + oak_log_axis_x
>>> repr(stone_water_granite_water_oak_log)
'Block(minecraft:stone, minecraft:water[level=1], minecraft:granite, minecraft:water[level=1], minecraft:oak_log[axis=x])'
>>> stone_granite_water_oak_log = stone_water_granite_water_oak_log.remove_layer(0)
>>> repr(stone_granite_water_oak_log)
'Block(minecraft:stone, minecraft:granite, minecraft:water[level=1], minecraft:oak_log[axis=x])'
property base_block

Returns the block without any extra blocks

Return type

Block

Returns

A Block object

property base_name

The base name of the blockstate represented by the Block object (IE: stone, dirt)

Return type

str

Returns

The base name of the blockstate

property block_tuple

Returns the stack of blocks represented by this object as a tuple. This is a tuple of base_block and extra_blocks :rtype: Tuple[Block, …] :return: A tuple of Block objects

property blockstate

The full blockstate string of the blockstate represented by the Block object (IE: minecraft:stone, minecraft:oak_log[axis=x])

Return type

str

Returns

The blockstate string

property extra_blocks

Returns a tuple of the extra blocks contained in the Block instance

Return type

Tuple[Block, …]

Returns

A tuple of Block objects

property namespace

The namespace of the blockstate represented by the Block object (IE: minecraft)

Return type

str

Returns

The namespace of the blockstate

property namespaced_name

The namespace:base_name of the blockstate represented by the Block object (IE: minecraft:stone)

Return type

str

Returns

The namespace:base_name of the blockstate

property properties

The mapping of properties of the blockstate represented by the Block object (IE: {“level”: “1”})

Return type

Dict[str, Union[TAG_Byte, TAG_Short, TAG_Int, TAG_Long, TAG_String]]

Returns

A dictionary of the properties of the blockstate