Mod-owned terrain recipes
The shipping terrain path is a server declaration in the WASM game manifest. Flagship uses the same declaration and host loader available to other mods. The engine owns the evaluator, validation, exact/coarse generation, caching and persistence; the mod owns its recipe, biomes, material names and default choice.
Authoring
In the guest’s Plugin::build:
app.add_terrain_recipe(
"overworld",
include_str!("../assets/terrain/world.ron"),
Some(include_str!("../assets/terrain/baked.ron")),
true,
);
The arguments are a local provider id, procedural recipe RON, optional baked heightfield recipe RON, and whether it is the default. A terrain-only plugin is valid. Declarations appear only in the server manifest. Manifest format 11 requires rebuilding existing WASM mods; older versions fail with a rebuild message rather than being decoded under a different layout.
The host prefixes the local id with the authenticated package id, regardless
of a guest’s claimed plugin namespace. For Flagship the key is
flagship-game:overworld. Duplicate keys fail. A nonempty catalog needs exactly
one default unless the host selects a key explicitly; multiple defaults fail
instead of choosing by load order.
Native hosts discover directory and .mod archive providers alongside bundled
mods, honoring directory overrides and package dependency/collision checks. Disk
providers use the ordinary game-module sandbox; manifest reads do not fire
world-ready hooks. Terrain preflight errors are fatal, and a selected provider
that is later disabled by the orchestrator prevents world startup.
Native hosts support the
MANIFOLD_TERRAIN_RECIPE=package:local-id override. Browser singleplayer selects
the catalog default. Empty catalogs are permitted for native engine harnesses;
they use the existing flat test world. A requested missing provider is an error.
The current evaluator is the versioned scripted Cartesian terrain implementation.
Recipes are limited to 1 MiB, four to 64 biomes, seven validated stage kinds,
bounded spawn radii/heights and feature spacing/chance. Material names resolve
against the final block registry and unknown names fail at boot. The v1 evaluator
uses biome slots 0–3 as lowland, shore, snow and exposed terrain for baked fields;
procedural trees use slot 0. These are evaluator semantics, not Flagship block
names. Use the game-owned recipes in game/flagship-game/assets/terrain/ as complete
examples. Semantic recipe/biome ids inside RON contribute to content hashing; they
do not grant registration authority in that namespace.
This contract installs data into the existing WorldGenerator path, including its
exact generation, certified coarse pages and semantic identities. It does not
execute arbitrary guest callbacks for each voxel. New bounded stage operators,
composable contributions and richer biome rules remain extensions of the terrain
design; do not bypass the shared evaluator or introduce a Flagship-only hook.
Saves and compatibility
Native and browser OPFS saves bind terrain_recipe_v1 in world_meta to UTF-8
<provider-key>\n<resolved-recipe-identity-hex>. The identity includes the seed,
recipe parameters and material names; baked worlds also include the artifact
digest. Reopening with changed content/provider fails before generation. Restore
the original mod or create a new world; do not delete this binding as a migration.
Flat native harness saves receive a distinct binding too.
Because of this binding, a save does not store the chunks nobody changed. A generated
chunk whose provenance is still the bound recipe’s untouched base is not marked dirty.
It is evicted without a row and regenerated when it loads again
(WorldSpace::bind_regeneration). This is one rule, shared by saving and eviction,
in water spaces too. A chunk qualifies only when all of these hold:
- The space’s generator declares
regeneration_inputs():Someof the SHA-256 digests of the external artifacts it reads. The default isNone, so every generated chunk is saved. Scripted mod terrain declares it (procedural with no inputs; baked with its field’s digest, and its water network’s when present), as do flat and synthetic terrain. - The host bound that exact recipe identity, as above.
- The save pins every input (#590): it holds the artifact’s bytes verbatim
(
terrain_bake_v1,water_network_v1), and they still match their SHA-256 trailer (SaveStore::pinned_artifacts). A digest in the recipe proves which bytes generated the chunks; the pin proves they will still exist, so an unsaved chunk never outlives them. A corrupt or missing row pins nothing, and that world saves every chunk. The refusal is logged at open, naming the unpinned digest. - Nothing has written the chunk. Every edit, including water, promotes provenance to
Editedfor good, so a chunk changed and changed back is still saved. As a backstop, a chunk whose cell changed without an edit marking it is saved, with an error logged, at the next save or before eviction. It is never regenerated over.
A changed recipe would regenerate those chunks differently, which is why the binding refuses to open the world and names both terrains. Committed chunk digests for the scripted stress world fail CI if generation changes without changing the recipe identity.
Adopting a changed terrain. A dedicated server operator can open such a world
under the installed terrain with --regenerate-untouched
(WorldSource::ExistingRegeneratingUntouched). Each step fails closed:
- Validate. Read the world without writing to it, then check that the installed
generator regenerates bit for bit from what the save pins
(
manifold_world::regeneration_check). An unpinned artifact is refused by its digest. - Back up and verify. Copy the world directory beside itself as
<world>.pre-regenerate-<unix seconds>and verify the copy file by file (path, size, SHA-256). A failed or mismatched backup stops here, and the world is byte for byte as it was. - Rebind and prune. In one transaction (
manifold_saves_types::regenerate:: rebind_and_prune, shared by every redb store):- The world is bound to the installed recipe.
- Chunk rows that are untouched base of another recipe, without block component extras, are removed. Every edited, authored or undecodable row is kept, so seams where an edited chunk meets regenerated terrain are expected.
- Far LOD above level 0 that was derived from the old recipe goes with them: regenerable sections are dropped, and edit overlays become rebuild tombstones.
The backup is kept; the operator deletes it. A world already bound to the installed terrain has nothing to regenerate. Browser singleplayer has no entry point yet (#620).
A save without a provider binding adopts the installed recipe on first open; subsequent opens enforce it. That save may have been generated with different settings. Back up the world before changing its content set. Frozen fixtures verify procedural and baked recipe identities and generated output.
MANIFOLD_TERRAIN_BAKE imports an immutable field only into a new native world,
which persists it in terrain_bake_v1. Reopening uses those saved bytes and the
mod’s baked palette. Browser singleplayer reads the same seed, baked bytes and
recipe binding from its OPFS save; there is still no browser UI for importing a
new bake. Multiplayer browser clients consume the server’s streamed world.
Diagnostic tools take the recipe explicitly: lod-oracle --recipe FILE and
baked_probe <artifact> <blocks-dir> <recipe.ron> [--chunks repetitions].
Regression coverage
- A terrain-only guest emits its declaration through the ordinary manifest path.
- A non-Flagship provider installs and generates with a non-Flagship palette.
- Unknown materials, missing/default conflicts, duplicate ids and namespace spoofing fail; explicit selection is independent of declaration order.
- The compiled Flagship WASM guest is decoded by the real loader and compared with frozen recipe identities and generated chunks.
- Existing exact/coarse and baked terrain corpora remain compatibility checks.
- Save tests check idempotent binding, reopen and rejected recipe/provider changes.
- D-RB:
manifold-worldworld_spacetests cover the skip, the sticky edit, the write backstop, fail-closed binding and the input pin.scripted_terrain’s committed digests catch a generation change.manifold-server’sbaked_regenerationcreates a world from a bake file, deletes the file, and reopens it: the untouched chunk regenerates from the save’s pinned field to the same bytes; a corrupt pinned row is no pin.assert-save-skip-untouched.mjschecks on the browser that untouched chunks reload regenerated to the same bytes, and that an edited chunk reloads from the save.
Run the focused integration gates from the repository root:
cargo test -p flagship --test suite terrain_mod::
cargo test -p manifold-wasm-host-core --lib terrain_fold
cargo test -p manifold-mod-substrate --test terrain_recipe
cargo test -p manifold-saves --test suite roundtrip::terrain_recipe_binding
# After the normal browser build and e2e npm install:
node crates/manifold-host-web/e2e/assert-terrain-mod.mjs
Optional water networks
Water-enabled baked worlds attach their persisted water network through
TerrainCatalog::install_with_water_network. The selected mod still owns the
baked recipe and material palette; the water path does not substitute an
engine-owned recipe. A network requires a matching baked field, and the resolved
generator identity includes the network. Native save reopen validates the stored
network before binding the provider and recipe identity.