Expand description
Chunk storage for the ghast Minecraft Java Edition client library.
One world type per protocol version (v1_8::World, v1_12::World, v1_16_5::World,
v26_1::World, v26_2::World, v26_3::World, each behind the feature of its
module’s name) decodes the version’s chunk and block-change packets into a version-independent
ColumnMap of Columns made of compact Sections.
- Loaded vs unloaded is explicit.
v1_8::World::block_statereturnsNonefor a column the server has not sent (or has unloaded); it never reports air there. Behaviour code must treatNoneas “unknown”. Only theghast_physics::BlockViewimplementation (featurephysics) maps unloaded columns to air, because that is exactly what the vanilla client’s empty chunk does and what the physics must reproduce. - Vanilla decoding. States are stored as vanilla reads them: unknown 1.8
id << 4 | metavalues and unregistered metas, unknown 1.16.5 palette ids and out-of-range palette indices all read as air. Packet handling follows the vanilla client (ground-up chunks replace the column, partial chunks for unloaded columns are ignored, block changes in unloaded columns are ignored, respawn into the same dimension keeps the world, …). See each method. - Cheap lookups. A block lookup is one hash of the column position plus one or two array reads; all-air sections are not stored.
- Never panics on server data. Malformed chunk data returns a
WorldError. A 1.8 chunk shorter than its mask is applied as far as the vanilla client gets before its copy fails (a ground-up chunk still loads its column, as vanilla does); a malformed 1.16 section unloads the column.
use ghast_world::{WorldConfig, v1_8::World};
let mut world = World::new(WorldConfig::default());
assert_eq!(world.block_state(0, 64, 0), None); // nothing loaded yet: unknown, not airModules§
- climate
- Biome climate (26.1): what
Biome.getPrecipitationAtreads — the precipitation flag, the base temperature, the frozen-ocean temperature modifier — and the height-adjusted temperature with the game’s fixed-seed temperature noises (Biome.TEMPERATURE_NOISE,FROZEN_TEMPERATURE_NOISE,BIOME_INFO_NOISE:PerlinSimplexNoiseoverSimplexNoiseseeded by aLegacyRandomSource). Checked against the real classes:tests/golden/26.1/biome_climate.jsonl.gz. - packed
- 1.16+ “compact long arrays”: fixed-width unsigned values packed into 64-bit words, lowest
bits first, where (since 1.16) a value never spans two words —
64 / bitsvalues per word, the remaining high bits of each word are padding. - paletted
- Compact chunk sections for the modern (1.18+, 26.x) worlds: block states kept packed with a small palette, at the smallest power-of-two width that holds the section’s distinct states.
- v1_8
- The 1.8.x (protocol 47) world:
id << 4 | metasections,map_chunk,map_chunk_bulk, block changes and explosions. - v1_12
- The 1.12.2 (protocol 340) world: paletted
id << 4 | metasections,map_chunk,unload_chunk, block changes and explosions. The first member of the 1.9 – 1.12 chunk family (same section format since 1.9; 1.9.4 added the block entity list tomap_chunk). - v1_16_5
- The 1.16.5 (protocol 754) world: paletted sections,
map_chunk,unload_chunk, block changes (1.16.2+ section-positionmulti_block_change), explosions and the client’s view window. - v26_1
- The 26.1 (protocol 775, 26.1 – 26.1.2) world: dimension heights from the configuration-phase
registries, compact paletted sections (
crate::paletted),level_chunk_with_lightwithout its light data,forget_level_chunk, block and section updates, biomes, block entities, chunk batches, the world border and the client’s chunk window. - v26_2
- The 26.1 (protocol 775, 26.1 – 26.1.2) world: dimension heights from the configuration-phase
registries, compact paletted sections (
crate::paletted),level_chunk_with_lightwithout its light data,forget_level_chunk, block and section updates, biomes, block entities, chunk batches, the world border and the client’s chunk window. - v26_3
- The 26.1 (protocol 775, 26.1 – 26.1.2) world: dimension heights from the configuration-phase
registries, compact paletted sections (
crate::paletted),level_chunk_with_lightwithout its light data,forget_level_chunk, block and section updates, biomes, block entities, chunk batches, the world border and the client’s chunk window.
Structs§
- Border
- World border state: centre, diameter (possibly moving) and warning settings.
- Chunk
Pos - Position of a chunk column (block coordinates
>> 4). - Column
- A loaded chunk column: 16 sections (
None= all air), biomes and optional light. - Column
Map - The loaded columns. Version-independent; the version worlds wrap it.
Cis the column type (the legacyColumnby default; the modern worlds use their own). - Direct
- Direct storage: the raw state of every block.
- Indexed
- Indexed storage: one byte per block into a palette of at most 256 states.
- Section
Light - 1.8 light of one section, as sent in the chunk packet (never recomputed locally).
- Shared
Chunks - A process-wide store that lets the worlds of many bots hold one copy of each identical chunk section (16×16×16 blocks) instead of one copy per bot.
- World
Config - What a world keeps besides block states.
Enums§
- Applied
- What applying a packet did.
- Biomes
- Biome data of a column as the server sent it.
- Block
Entity - A block entity’s data as the server sent it.
- Section
- A non-empty chunk section (see the module docs).
- World
Error - Malformed world data from the server. 1.8 leaves the column the way vanilla does (see
v1_8::World::apply_chunk_data); 1.12 and 1.16 unload it.
Constants§
- MAX_Y
- Build height: highest block Y + 1.
- MIN_Y
- Lowest block Y (inclusive).
- SECTIONS
- Number of sections in a column (both 1.8 and 1.16.5 have a fixed 0..256 build height).
- SECTION_
VOLUME - Number of blocks in a section.
Functions§
- block_
index - Index of a block inside its section:
y << 8 | z << 4 | xon the low four bits of each coordinate (vanilla’s order in both 1.8 and 1.16).