Skip to content

Support Sponge Schematic version 2 and 3 (.schem) - #42

Open
Qalipso wants to merge 2 commits into
stuffbydavid:masterfrom
Qalipso:feat/sponge-schematic-v2-v3
Open

Qalipso wants to merge 2 commits into
stuffbydavid:masterfrom
Qalipso:feat/sponge-schematic-v2-v3

Conversation

@Qalipso

@Qalipso Qalipso commented Aug 21, 2026

Copy link
Copy Markdown

Builds on #41, which this branch contains as its first commit.

Problem

builder_read_schematic rejects any schematic whose Version tag is above 1:

if (version > 1)
{
    log("Schematic error", "Unsupported format, version too high")
    return false
}

WorldEdit and the other current tools write version 2 and version 3 files with a .schem extension, so they cannot be opened at all — and .schem is not in the scenery file dialog, asset_load or asset_exts either.

Format differences handled

version 1 version 2 version 3
root compound Schematic Schematic ""Schematic
palette Palette Palette Blocks.Palette
block indices BlockData BlockData Blocks.Data
block entities TileEntities BlockEntities Blocks.BlockEntities

Block entity objects carry Id and Pos in all three versions, so builder_read_schematic_tile_entities works unchanged once the right list is picked up.

Change

  • builder_read_schematic resolves the palette, block data and block entity list per version.
  • res_load_scenery unwraps the version 3 root compound.
  • The format check compares the tag type of Blocks rather than its value, so a version 3 Blocks compound is recognised while a legacy MCEdit Blocks byte array still takes the legacy path.
  • .schem added to the scenery file dialog, asset_load and asset_exts.

Verification

  • The new GML was transliterated line for line and run against real gzipped NBT files: versions 1, 2 and 3 with palettes of 64, 300 and 4096 entries all decode with zero mismatches and resolve the correct block entity list, and a legacy MCEdit schematic is still detected as legacy. A deliberate mutation of the decode loop was caught.
  • CppGen was run over GmProject and reports Success!.
  • As with the parent PR I could not build and run the application, so this has not been exercised through the UI.

CppProject/Generated is left untouched and needs a CppGen run to pick this up.

🤖 Generated with Claude Code

The Sponge Schematic specification stores BlockData as an array of varints, but
builder_read_schematic_blocks reads one raw byte per block. Palette indices below
128 encode as a single byte so small schematics load correctly, while anything
with a larger palette desynchronises after the first multi-byte index and almost
every block comes out wrong.

builder_read_schematic now decodes the varints once into big endian integers
appended to the file buffer and points sch_blockdata_array at them, reusing the
existing TAG_Int_Array code path. Schematics with 128 or fewer palette entries
keep the original single byte path and are unaffected.

A truncated BlockData array logs a warning and leaves the remaining blocks empty
instead of aborting the load.
Mine-imator only accepted Sponge Schematic version 1 and rejected anything newer
with "Unsupported format, version too high". WorldEdit and every other current
tool write version 2 or 3 as .schem, so those files could not be opened at all.

Version 2 keeps the version 1 layout and renames TileEntities to BlockEntities.
Version 3 nests the schematic inside the unnamed root compound and moves Palette,
Data and BlockEntities into a Blocks compound. builder_read_schematic now resolves
all three layouts and res_load_scenery unwraps the version 3 root.

The format check no longer treats a version 3 schematic as a legacy one by
comparing the tag type of Blocks, so a legacy Blocks byte array still takes the
legacy path.

.schem is accepted by the scenery file dialog, drag and drop and asset_exts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant