Block
One voxel as a 16-bit value: block type in the high 12 bits, metadata in the low 4.
Location
| Header | include/GalaxyEggbert/Worlds/Block.hpp (header-only) |
|---|---|
| Namespace | GalaxyEggbert::Worlds |
| Block type names | include/GalaxyEggbert/BlockTypes.hpp (namespace GalaxyEggbert::BlockTypes) |
Purpose
Block is a small value type wrapping one uint16_t. It is what
World and Chunk store per cell and what the
palette of a chunk holds.
bits 15..4 block type 0..4095
bits 3..0 metadata 0..15
raw = (type << 4) | metadata raw 0 = Air
The block type is the icon number of the tile in the original game's terrain sheet
Content/icons/object-m.png, icons 0-440. BlockTypes.hpp names the ones
the code refers to, for example Ground = 10, Lava = 68,
HubDoor = 182, GoldDoor = 183, FlightBarrier = 214,
Saw = 378. What a type does (how it is drawn, whether it is solid, whether it
kills) is not in Block; it is looked up in the
BlockDefinitionRegistry.
worlds3d/ has a block with non-zero metadata, and no game
system interprets it; the editor's clipboard only carries it along when it swaps the icon of a turned or mirrored side fan or wind tile (src/GalaxyEggbert/Editor/Clipboard.cpp). Per-cell
state such as a turned plate or fan is stored as sparse extra metadata instead (see
The .vwr Format).Public API
Verified in Block.hpp as of 2026-11-10.
| Member | Description |
|---|---|
MetadataMask = 0x000F, TypeMask = 0x0FFF | Field masks. |
constexpr Block() | Air (raw 0). |
explicit constexpr Block(std::uint16_t rawValue) | From a packed value, no validation (used when reading palettes). |
static constexpr Block air() | The canonical air block. |
static Block make(std::uint16_t type, std::uint8_t metadata = 0) | Validated constructor; throws std::out_of_range if the type exceeds 4095 or the metadata 15. |
static Block make(std::uint16_t type, BlockMetadata metadata) | The same with a BlockMetadata helper. |
rawValue() | The packed 16 bits. |
type() | The 12-bit type. |
metadata() | The 4-bit metadata as uint8_t. |
blockMetadata() | The metadata as a BlockMetadata object. |
isAir() | rawValue() == 0. |
operator==, operator!= | Compare packed values. |
Usage
Opening a hub's completed world sign, from GalaxyEggbertGame::AdaptHubDoors() (src/GalaxyEggbertCNA/GalaxyEggbertGameMissions.cpp):
terrain.setBlock(x, y, z, GalaxyEggbert::Worlds::Block::make(
GalaxyEggbert::CompletedWorldSignIcon(terrain.getBlock(x, y, z).type())));
Reading a type for a registry lookup, from BlupiController:
const auto block = world.getBlock(gx, gy, gz);
return !block.isAir() && !GalaxyEggbert::GetBlockDefinition(block.type()).decor;
Tests
tests/GalaxyEggbert/Worlds/BlockTests.cpp:AirDefaultsToZeroAndIsAir,MakePacksAndUnpacksTypeAndMetadata,MakeSupportsMaximumValues,MakeThrowsForOutOfRangeValues,EqualityComparesPackedValue.
Related pages
- BlockMetadata, VoxelConfig, Chunk, World
- BlockDefinitionRegistry (what each type means)
- Tutorial: changing a block or object behaviour