Accessing Blocks

There are two things that are generated by block definitions - blocks themselves, with their specific settings, Shapes and rotations, and Block Families which are sets of blocks that are considered to be variations of the same block.

If a block doesn’t define a shape, or defines multiple shapes, then it is made available as a full block via the uri moduleName:blockName, where the _moduleName_ is the id of the containing module or engine for build in blocks. The blockName is the filename of the block (ignoring the extension). It can also be requested in any shape by using the uri blockModule:blockName:shapeModule:shapeName.

The engine provides an api to access blocks, the BlockManager. For example to get a stair pointing to the left from BirchTrunk.block (defined in the core module), inject the block manager:

@In
private BlockManager blockManager;

And then access the block via its URI:

Block block = blockManager.getBlock("core:BirchTrunk:engine:stair.LEFT");

This will lookup the block core:BirchTrunk, using the shape engine:stair and use the block from this family which is rotated to the left.

../../_images/stair_block.jpg

Note

If a block has a shaped defined it can only be requested using the block uri, and its shape is fixed.

For example, a ladder has always a shape of verticalOffsetPlane, as defined in ladder.block.

...
"shape": "engine:verticalOffsetPlane",
...

In this case it is not possible to get an engine:stair instance of the ladder block.