Blocks & Chunks
Last updated
Last updated
In HYTOPIA, a world's terrain is made up of blocks. A block is a 1x1x1 sized cube or any subdivided shape that can fit within a 1x1x1 cube.
These blocks are then organized and arranged in a structure called a chunk, which is made up by 16x16x16 blocks (4,096).
Blocks also have textures, which are a single image applied to all faces for the block, or alternatively can be a texture image for each face of the block.
Manipulating blocks and chunks is key to creating games that have dynamic terrain, or terrain that can be constructed / destructed by players (Think similar to breaking/placing blocks in Minecraft).
The BlockType, BlockTypeRegistry, Chunk and ChunkLattice classes are all key to managing and manipulating the terrain blocks of a world.
Let's explore some very common uses of blocks, block types and chunks.
Here's a quick example showcasing setting and removing blocks. We'll set or remove a block every 1 second based on if a block is already set or not.
Note: With HYTOPIA, you must register a new block type with the world.blockTypeRegistry before it can be set as a block in the world. You can learn about the BlockTypeRegistry here.
Within HYTOPIA, blocks are fixed cubes that cannot be translated or rotated. Think of them like the ground, walls, etc that are unmovable.
In some cases, you may want blocks that can interact with the physical world, be pushed around, perhaps a block that is a moving platform, etc. For this, you'll want to use Block Entities.
We strongly recommend you check out the following guides to get a better idea of different things you can do with block types, a block type registry, chunks and a chunk lattice.