Skip to main content

Crate ghast_world

Crate ghast_world 

Source
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_state returns None for a column the server has not sent (or has unloaded); it never reports air there. Behaviour code must treat None as “unknown”. Only the ghast_physics::BlockView implementation (feature physics) 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 | meta values 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 air

Modules§

climate
Biome climate (26.1): what Biome.getPrecipitationAt reads — 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: PerlinSimplexNoise over SimplexNoise seeded by a LegacyRandomSource). 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 / bits values 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 | meta sections, map_chunk, map_chunk_bulk, block changes and explosions.
v1_12
The 1.12.2 (protocol 340) world: paletted id << 4 | meta sections, 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 to map_chunk).
v1_16_5
The 1.16.5 (protocol 754) world: paletted sections, map_chunk, unload_chunk, block changes (1.16.2+ section-position multi_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_light without 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_light without 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_light without 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.
ChunkPos
Position of a chunk column (block coordinates >> 4).
Column
A loaded chunk column: 16 sections (None = all air), biomes and optional light.
ColumnMap
The loaded columns. Version-independent; the version worlds wrap it. C is the column type (the legacy Column by 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.
SectionLight
1.8 light of one section, as sent in the chunk packet (never recomputed locally).
SharedChunks
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.
WorldConfig
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.
BlockEntity
A block entity’s data as the server sent it.
Section
A non-empty chunk section (see the module docs).
WorldError
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 | x on the low four bits of each coordinate (vanilla’s order in both 1.8 and 1.16).