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 useapi.world.World.get_block_instance()
insteadHere’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 ofwater[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_blocksReturn 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 againstReturn 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
-
__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
-
__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_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 removeReturn 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
-
__weakref__
¶ list of weak references to the object (if defined)
-