amulet.api.registry.block_manager module

class amulet.api.registry.block_manager.BlockManager(blocks=())[source]

Bases: BaseRegistry

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

__init__(blocks=())[source]

Creates a new BlockManager object

__len__()[source]

The number of blocks in the registry.

>>> len(level.block_palette)
10
__contains__(item)[source]

Is the given Block already in the registry.

>>> block in level.block_palette
True
>>> 7 in level.block_palette
True
Parameters

item (Block) – The block or index to check.

Return type

bool

__iter__()[source]

Iterate through all blocks in the registry.

>>> for block in level.block_palette:
>>>     ...
property blocks: Tuple[Block, ...][source]

The blocks in the registry as a tuple.

values()[source]

The blocks in the registry as a tuple.

Return type

Tuple[Block, ...]

items()[source]

A generator of the block indexes and the block objects.

Return type

Generator[Tuple[int, Block], None, None]

__getitem__(item)[source]

If a Block object is passed to this function, it will return the internal ID/index of the blockstate.

If an int is given, this method will return the Block object at that specified index.

>>> level.block_palette[block]
7
>>> level.block_palette[7]
block
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

:raises KeyError if the requested item is not present.

get_add_block(block)[source]

Adds a Block object to the internal Block object/ID mappings.

If the Block already exists in the mappings, 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

register(block)[source]

An alias of get_add_block().

Adds a Block object to the internal Block object/ID mappings.

If the Block already exists in the mappings, 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