blocks module

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

Bases: object

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

Important

Creating version specific block objects via the Block() constructor instead of using api.world.World.get_block_instance() is supported but not encouraged. To avoid possible caveats of doing this, make sure to either only instantiate blocks with Amulet blockstate data or use api.world.World.get_block_instance() instead

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])'
__add__(other)[source]

Allows for other Block objects to be added to this Block object’s extra_blocks

Parameters:other (Block) – The Block object to add to the end of this Block object’s extra_blocks
Return type:Block
Returns:A new Block object with the same data but with an additional Block at the end of extra_blocks
__eq__(other)[source]

Checks the equality of this Block object to another Block object

Parameters:other (Block) – The Block object to check against
Return type:bool
Returns:True if the Blocks objects are equal, False otherwise
__gt__(other)[source]

Allows blocks to be sorted so numpy.unique can be used on them

Return type:bool
__hash__()[source]

Hashes the Block object

Return type:int
Returns:A hash of the Block object
__init__(namespace, base_name, properties=None, extra_blocks=None)[source]

Initialize self. See help(type(self)) for accurate signature.

__repr__()[source]
Return type:str
Returns:The base blockstate string of the Block object along with the blockstate strings of included extra blocks
__sizeof__()[source]

Size of object in memory, in bytes.

__str__()[source]
Return type:str
Returns:The base blockstate string of the Block object
__sub__(other)[source]

Allows for other Block objects to be subtracted from this Block object’s extra_blocks

Parameters:other (Block) – The Block object to subtract from this Block objects’ extra_blocks
Return type:Block
Returns:A new Block object without any instances of the subtracted block in extra_blocks
base_block

Returns the block without any extra blocks

Return type:Block
Returns:A Block object
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
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
extra_blocks

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

Return type:Union[Tuple, Tuple[Block]]
Returns:A tuple of Block objects
namespace

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

Return type:str
Returns:The namespace of the blockstate
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
properties

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

Return type:Dict[str, _TAG_Value]
Returns:A dictionary of the properties of the blockstate
remove_layer(layer)[source]

Removes the Block object from the specified layer and returns the resulting new Block object

Parameters:layer (int) – The layer of extra block to remove
Return type:Block
Returns:A new instance of Block with the same data but with the extra block at specified layer removed
Raises:InvalidBlockException – Raised when you remove the base block from a Block with no other extra blocks
class amulet.api.block.BlockManager[source]

Bases: object

Class to handle the mappings between Block objects and their index-based internal IDs

__getitem__(item)[source]

If a Block object is passed to this function, it’ll return the internal ID/index of the blockstate. If an int is given, this method will return the Block object at that specified index.

Parameters:item – The Block object or int to get the mapping data of
Returns:An int if a Block object was supplied, a Block object if an int was supplied
__init__()[source]

Creates a new BlockManager object

__weakref__

list of weak references to the object (if defined)

get_add_block(block)[source]

Adds a Block object to the internal Block object/ID mappings. If the Block already exists in the mappings, then the existing ID is returned

Parameters:block (Block) – The Block to add to the manager
Return type:int
Returns:The internal ID of the Block