Block Type Registry
Most games will have many block types, and keeping track of those block types is important for your own game systems and internal HYTOPIA systems.
This is where the BlockTypeRegistry comes into play. Allowing us to register, unregister, retrieve and iterate known BlockType instances of our world.
Accessing A BlockTypeRegistry
The BlockTypeRegistry is used as a singleton and automatically created for a given world instance.
You can access the block type registry for a world like this:
Registering Block Types
Before a block type can be set as a block at a coordinate in the world through world.chunkLattice.setBlock()
or chunk.setBlock()
, the block type must have been previously registered with the world.blockTypeRegistry
through world.blockTypeRegistry.registerBlockType()
or world.blockTypeRegistry.registerGenericBlockType()
.
In this example, let's dive into how to register a block type, as well as the difference between registerBlockType()
and registerGenericBlockType()
Other BlockTypeRegistry Usage
The BlockTypeRegistry exposes ways to iterate known block types, or get registered block types by ID. Here's an example:
Diving Deeper
The BlockTypeRegistry class is constantly evolving. You can find the latest BlockTypeRegistry API Reference here.
If there are features that we don't currently support for BlockTypeRegistry that you'd like to see added to the HYTOPIA SDK, you can submit a feature request here.
Last updated