Expand description
Chunk persistence module.
This module handles saving and loading chunks to/from disk using a sector-based region file format. Each region file contains a 32×32 grid of chunks.
§Format Overview
Region files use a fixed 8KB header containing chunk locations, followed by 4KB-aligned sectors for chunk data. Only the header is kept in memory; chunk data is read on-demand via file seeking.
┌─────────────────────────────────────────────────────┐
│ Magic (4 bytes): "STLR" │
│ Version (2 bytes) + Padding (2 bytes) │
├─────────────────────────────────────────────────────┤
│ Header: 1024 entries × 8 bytes = 8KB │
│ Each entry: offset (u32) + size (u24) + flags (u8)│
├─────────────────────────────────────────────────────┤
│ Chunk data in 4KB sectors (zstd compressed) │
└─────────────────────────────────────────────────────┘§Key Features
- No memory duplication: chunks are loaded directly to runtime format
- Lazy loading: only reads chunks when needed, not entire regions
- Fast existence checks: just read 8 bytes from header
- Per-chunk block state and biome palettes for self-contained chunks
- Power-of-2 bit packing for efficient storage (1, 2, 4, 8, 16 bits)
- Homogeneous section optimization (single block type = no bit array)
- zstd compression per-chunk for good compression ratios
Modules§
- bit_
pack 🔒 - Bit packing utilities for chunk persistence.
- format 🔒
- Data structures for the chunk persistence format.
- ram_
only 🔒 - region_
manager 🔒 - Region file manager with seek-based chunk access.
- registry
- Runtime registry for world storage backends.
- storage 🔒
Structs§
- Chunk
Entry - Entry in the chunk location table.
- Loaded
Chunk - Runtime chunk data loaded from persistence.
- Persistent
Block Entity - A block entity (tile entity) stored with a chunk.
- Persistent
Block State - A block state with its identifier and properties.
- Persistent
Bounding Box - A structure bounding box stored as six scalar coordinates.
- Persistent
Chunk - A persistent chunk containing sections and metadata.
- Persistent
Desert Pyramid Piece Data - Persisted desert pyramid piece payload.
- Persistent
Entity - An entity stored with a chunk.
- Persistent
Heightmap - A heightmap stored with a chunk.
- Persistent
Jigsaw Junction - A persisted jigsaw junction used by Beardifier terrain adaptation.
- Persistent
Jigsaw Piece Data - Steel-native persistent state for a jigsaw pool piece.
- Persistent
Jungle Temple Piece Data - Persisted jungle temple piece payload.
- Persistent
Light Data - Chunk-owned light data stored with a chunk.
- Persistent
Mineshaft Piece Data - Persisted mineshaft piece payload.
- Persistent
Ocean Monument Child Piece - Persisted internal ocean monument child piece.
- Persistent
Ocean Monument Piece Data - Persisted ocean monument building payload.
- Persistent
Ocean Monument Room Data - Persisted ocean monument room snapshot.
- Persistent
Poi - A point of interest’s occupancy state stored with a chunk.
- Persistent
Structure Piece - A structure piece stored with a chunk.
- Persistent
Structure Reference - A structure reference entry stored with a chunk.
- Persistent
Structure Start - A structure start stored with a chunk.
- Persistent
Swamp HutPiece Data - Persisted swamp hut piece payload.
- Persistent
Template Piece Data - Persisted template-backed non-jigsaw piece data.
- Persistent
Tick - A scheduled tick stored with a chunk.
- Prepared
Chunk Save - Prepared chunk data ready to be saved asynchronously.
Created by
prepare_chunk_saveduring the holder’s snapshot-preparation phase. - RamOnly
Storage - In-memory chunk storage.
- Region
Header - Region header containing chunk location table.
- Region
Manager - Manages region files with seek-based chunk access.
- Region
Pos - Position of a region in region coordinates.
- SimpleRAM
Chunk - Represents a simple in-memory prepared chunk save.
Enums§
- Chunk
Storage - Chunk storage backend.
- Persistent
Biome Data - Biome data for a section (4×4×4 = 64 cells).
- Persistent
Light Section - One persisted chunk-owned light section.
- Persistent
Mineshaft Piece Kind - Persisted piece-specific mineshaft data.
- Persistent
Nether Fortress Piece Data - Persisted piece-specific nether fortress data.
- Persistent
Ocean Monument Child Piece Kind - Persisted ocean monument child piece variant.
- Persistent
Pool Element - Persisted pool element selected during jigsaw assembly.
- Persistent
Procedural Piece Data - Persisted procedural piece data.
- Persistent
Processor List - Persisted processor list holder for single pool elements.
- Persistent
Section - A 16×16×16 section of a chunk.
- Persistent
Stronghold Piece Data - Persisted piece-specific stronghold data.
- Persistent
Stronghold Small Door Type - Persisted stronghold door variant.
- Persistent
Structure Piece Payload - Persisted type-specific structure piece placement data.
- Persistent
Template Placement Adjustment - Persisted template position adjustment.
- Persistent
Template Processor List - Persisted processors for template-backed non-jigsaw pieces.
Constants§
- BIOMES_
PER_ SECTION - Total biome cells in a section.
- BIOME_
SIZE - Number of biome cells per section side (4×4×4 = 64 biomes per section).
- BLOCKS_
PER_ SECTION - Total blocks in a section.
- CHUNKS_
PER_ REGION - Total chunks in a region.
- CHUNK_
TABLE_ SIZE - Size of the chunk location table (1024 entries × 8 bytes).
- FILE_
HEADER_ SIZE - Size of the file header (magic + version + padding).
- FIRST_
DATA_ SECTOR - First sector where chunk data can be stored.
Header takes
ceil(TOTAL_HEADER_SIZE/SECTOR_SIZE) = 3 sectors (8 + 8192 = 8200 bytes). - FORMAT_
VERSION - Current format version. Increment when making breaking changes.
v3: Added entity persistence (
PersistentEntity). v4: Added scheduled tick persistence (PersistentTick). v5: Added heightmap persistence (PersistentHeightmap). v6: Added structure start and structure reference persistence. v7: Added POI persistence (PersistentPoi). v8: Added typed jigsaw piece-state persistence. v9: Added proto chunk carving mask persistence and typed packed chunk references. v10: Added template piece clip and postprocess persistence. v11: Added template piece placement adjustment persistence. v12: Added igloo template marker, placement adjustment, and postprocess persistence. v13: Split template processor persistence and added ruined-portal processors. v14: Added buried treasure procedural piece persistence. v15: Added procedural structure-piece payload persistence. v16: Added entity fall distance persistence. v17: Added entityNoGravitypersistence. v18: Added entityInvulnerablepersistence. v19: Added shared entity save-data persistence. v20: Added chunk-owned light section persistence. v21: Matched vanilla scheduled-tick persistence by rebuilding sub-tick order on load. v22: Preserve Vanilla pendingDUMMYblock entities across chunk stages. - MAX_
CHUNK_ SIZE - Maximum chunk size in bytes (16MB - should be plenty).
- REGION_
MAGIC - Magic bytes for region file identification: “STLR” (Steel Region)
- REGION_
SIZE - Number of chunks per region side (32×32 = 1024 chunks per region).
- SECTION_
SIZE - Number of blocks per section side (16×16×16 = 4096 blocks per section).
- SECTOR_
SIZE - Sector size in bytes (4KB, matches modern disk physical sectors).
- TOTAL_
HEADER_ SIZE - Total header size (file header + chunk table).