Docs: VanillaStructures replaces the vanilla structure hook; the API carries no fit values

README shows a provider, every method and the memo; DESIGN records why the hook became a service, why shift and reach
replace the adjustment value, what a chunk's StructureFit gives and why memos replace a persisted fit; CONTRACTS
lists the new types and what the host must do for them.
This commit is contained in:
piexel committed 2026-10-10 03:55:56 +02:00
1 parent 4755e24407
commit 6f52a20b25
3 files changed
+100 -64

No files matched your search

+21 -13
View File
@@ -27,8 +27,8 @@ types that carry them and lists what the Iris adapter still owes.
| Geometry and mantle registration | `FeatureRegistry`, host `ModuleRegistry`, `FeatureCatalog` |
| Block states and palettes | `BlockState`, `BlockRegistry`, `BlockPalette`, `BlockSpec` (`BlockRegistry.resolve(BlockSpec)`, `blockEntity`), `PaletteSpec` and `PaletteSampler` (`BlockRegistry.palette`) |
| Noise from pack-described styles | `NoiseStyle`, `StyledRange`, `PackResources.noise()`, `NoiseFactory`, `NoiseSampler` |
| Values in settings | `BlockSpec`, `PaletteSpec`, `NoiseStyle`, `StyledRange`, `Range`, `BlockPosition`, `StructureTerrain`, `StructureStilts`, `YBand`, `JigsawOverrides`, `Object` as `ValueKind.AnyKind` |
| Decisions over the platform's own structures | `VanillaStructureHook` (`rule`, `adjustment`, `starts`, `setup`), `VanillaStructureRule`, `VanillaStructureContext`, `VanillaStructureAdjustment`, `VanillaStructureFit`, `VanillaStructureStart`, `VanillaStructureStartContext`, `VanillaStructureSetup`, `FeatureRegistry.registerVanillaStructureHook`, host `FeatureCatalog.vanillaStructureHooks()` |
| Values in settings | `BlockSpec`, `PaletteSpec`, `NoiseStyle`, `StyledRange`, `Range`, `BlockPosition`, `JigsawOverrides`, `Object` as `ValueKind.AnyKind` |
| Decisions over and fit of the platform's own structures | service `VanillaStructures` (`rule`, `starts`, `shift`, `reach`, `beforePieces`, `afterPieces`, `setup`), `VanillaStructureRule`, `VanillaStructureContext`, `VanillaStructureStart`, `VanillaStructureStartContext`, `VanillaStructureSetup`, `PlatformStart`, `StartMemo`, `StartReach`, `StructureFit` (`Start`, `Piece`, `ColumnVisitor`), `StructureStep`, `TerrainAdaptation`, `PieceKind`, `TemplateCells`, `world.BlockAccess`, host `FeatureCatalog.registrations(service)` |
| Pack-scoped resolution | `ResourceId`, `ResourceKey<T>`, `PackResources` (`find`, `ids`), `PackBiome`, `PackRegion` |
| Module-owned pack resources | `ResourceKind`, `FeatureRegistry.registerResourceKind`, `@ResourceRef`, host `ModuleHost.reservingFolders`, `FeatureCatalog.resourceKinds()`, `ResourceKindSchema`, `ValueKind.ResourceReferenceKind` |
| Module-owned pack checks | `Validator`, `ValidationContext`, `Problem`, `Severity`, `Subject`, `FeatureRegistry.registerValidator`, host `FeatureCatalog.validators()` |
@@ -87,8 +87,8 @@ kinds claim, or one the host reads itself, fails the pack load naming both owner
values, read once per pack snapshot. Validators only report: an `ERROR` blocks the pack, a `WARNING` is shown.
IrisApi's value types are values: the host decodes them like settings, and nothing changes them afterwards.
Noise belongs to the host; modules describe it and get samplers built from the description. A vanilla structure
hook answers per structure and world, never per position.
Noise belongs to the host; modules describe it and get samplers built from the description. A
`VanillaStructures` rule answers per structure and world, never per position.
There is no API version gating. Packs ship their module jars, so their compatibility with the
running Iris is the pack publisher's responsibility.
@@ -196,17 +196,25 @@ running Iris is the pack publisher's responsibility.
`tileData` into the host's block entity format.
- Build `BlockRegistry.palette(spec, seed)` pickers: blocks expanded by weight, the style's noise at (x, y, z) over
the zoom picks the entry, resolved as above, cached per pack snapshot; refuse a palette without a block to pick.
- Ask every vanilla structure hook (`catalog().vanillaStructureHooks()`) before the platform starts one of its
structures and when it locates one, combine the rules with `VanillaStructureRule.and`, keep the result per world,
structure and pack snapshot, and apply it on every platform: block the platform's starts of a blocked
structure, and report a structure a module places as that module's. A hook that throws fails naming its module.
- Ask `adjustment` per world, structure, underground flag and pack snapshot, compose with
`VanillaStructureAdjustment.then` in module id order, and apply it to the platform's own starts: keeping the source
height over a band over the host's repositioning, then the shift; fit the terrain before the pieces and build
stilts after. Convert API heights (above the bottom) to world Y at the boundary; `YBand` is world Y.
- Ask every `VanillaStructures` provider (`catalog().registrations(VanillaStructures.class)`, module id order) before
the platform starts one of its structures and when it locates one, combine the rules with `VanillaStructureRule.and`,
keep the result per world, structure and pack snapshot, and apply it on every platform: block the platform's starts
of a blocked structure, and report a structure a module places as that module's. A provider that throws or answers
nothing fails naming its module.
- Before publishing a start the platform made, add up every provider's `shift` for it (after the host's own
alignment of monuments and temples) and move the start by it, less where it would leave the world. Before
publishing any start, cover every provider's `reach` in its references (`PLATFORM`: the platform's own terrain
adaptation envelope), within Minecraft's reference range; a recorded envelope only grows.
- Per chunk, call every provider's `beforePieces` once before the platform places any piece of the chunk's starts,
then per start in placing order the platform's placement and `afterPieces`. Give `StructureFit` in the API's heights
(above the bottom, maxima exclusive): the processed template cells of a piece, its template columns, its legacy
template air, the surface per column without fluids and the dimension's natural block. `BlockAccess.is` answers
`AIR`, `SOLID`, `FLUID`, `LOG` and `LEAVES` as the platform's world does and refuses other traits.
- Persist every start's `StartMemo` with its ownership record, unchanged, and hand it back in `reach` and
`StructureFit`; a start without a memo stays without one.
- Ask `starts` per chunk, in module id order, refuse a start outside the chunk asked for, keep the first start per
structure, let a start take the chunk from a platform start only when it says so or the structure is `REPLACE`d,
apply its jigsaw overrides and fit, record its identity with every start the host publishes, and ask again (same
apply its jigsaw overrides, keep its memo, record its identity with every start the host publishes, and ask again (same
answer) when locating or verifying a start found in the world.
- Ask `setup` per dimension before its worlds build their structure state and when installing data packs; multiply
frequencies per structure set (0.01 to 16), protect the platform's definitions in every installed data pack once
+38 -28
View File
@@ -798,11 +798,13 @@ Why these lines:
## Vanilla structures
Minecraft, data packs and mods register structures the platform starts on its own. Iris blocks some (a pack
replaces them with its own structures), lets others generate, and places some itself. The decisions belonged
to core (`NativeStructurePlacementPlanner`, `NativeStructureGenerationPolicy`) reading feature classes. A module
now states them with a `VanillaStructureHook`, registered in `register`; the host applies them on every
platform.
replaces them with its own structures), lets others generate, places some itself, and fits all of them to its
terrain. The decisions and the fit belonged to core and the platform adapters, reading feature classes. A module now
states them through the `VanillaStructures` service; the host applies them on every platform.
- **A service, every provider asked.** `@Service(Providers.ALL)`: each module that takes part in the platform's
structures answers for its part, in module id order. It was a dedicated hook registry; a service is the one way
modules answer host questions, so the catalog, ordering and failure naming are the services' own.
- **A rule per structure, not per start.** `rule(structure, context)` answers `GENERATE`, `ALSO_PLACE`,
`REPLACE` or `BLOCK` for one structure id in one world. The platform asks per start, but also when it locates
a structure, which has no position; and an answer that depended on the position could block a start
@@ -812,31 +814,39 @@ platform.
but a module places is reported, and located, as the module's. `and` combines two modules' rules, so the
result never depends on module order.
- **The context is the world's pack.** `resources()` and `settings()` (`PackSettings`: the dimension and every
region and biome it can reach), the same view reaches are worked out from. A hook that needs the world's own
state gets it the way stages do.
- **Placing starts: `starts(chunkX, chunkZ, context)`, a hook method, not a service.** The question is the same
hook's (which platform structures does this module own), asked per chunk because the platform generates per chunk,
and its answers sit next to the rule a module gives the same structures. A start carries everything the platform
needs and nothing it can work out: structure, chunk, height above the bottom, surface or underground, whether it
takes the chunk from a platform start, jigsaw overrides, the fit, and an identity the host persists with the start
so a start found in a saved world can be traced to its placement. Several placements of one module that start one
structure in one chunk are the module's to resolve; across modules the host keeps the first in module id order.
The context is the `PackWorld` (seed, state) plus a `TerrainSampler`, not raw seeds: a start that needs heights
asks the host's terrain, like a stage does.
- **The platform's own starts get an adjustment, a second per-structure method.** `importedStructures`' vertical
moves (`yShift`, `yBand`, `preserveSourceY`) and fit apply to starts the platform makes, which no module returns, so
they cannot ride on `VanillaStructureStart`. They are a per-structure answer like the rule (cached the same way,
with the platform's underground-step flag as the only extra input), so `adjustment(structure, underground,
context)`. A separate value rather than a richer rule keeps the rule's order-free `and`; adjustments compose in
module id order (`then`), which is what one module's list of matching entries always did.
- **Fit values are value types, the host keeps Iris's classes.** `StructureTerrain`, `StructureStilts`, `YBand` and
`JigsawOverrides` read the JSON Iris's classes read, so settings can hold them and packs keep their JSON. The host
converts them into its own classes for the platform code, which also persists the fit of every start it publishes:
the stored JSON stays the same. Modes, shapes and heightmaps are API enums because the host implements each one.
region and biome it can reach), the same view reaches are worked out from.
- **Placing starts: `starts(chunkX, chunkZ, context)`.** Asked per chunk because the platform generates per chunk. A
start carries everything the platform needs and nothing it can work out: structure, chunk, height above the
bottom, surface or underground, whether it takes the chunk from a platform start, jigsaw overrides, a memo, and an
identity the host persists with the start so a start found in a saved world can be traced to its placement. Across
modules the host keeps the first start per structure and chunk in module id order. The context is the `PackWorld`
plus a `TerrainSampler`.
- **No fit values in the API.** How a start meets the terrain (Iris's SOURCE, PRESERVE, VACUUM, ENCASE, BORE,
FORCE_CARVE, stilts, bands) is a feature's vocabulary; an API type would freeze one feature's choices. The API gives
a module what it needs to fit: the platform start's place (`shift`), how far a start changes terrain (`reach`) and
the chunk around the pieces (`beforePieces`, `afterPieces`). The host keeps only what every platform needs: move and
clamp a start, wrap its references, place its pieces.
- **Shift and reach, not an adjustment value.** A start the platform makes is moved by the sum of every module's
`shift(PlatformStart, context)`. `PlatformStart` gives what a module needs to decide (bounds, underground, aligned
by the host, the dimension's bottom, the surface per column) without platform types. `reach` is asked for every
start before it is published, so the platform hands it to every chunk whose terrain a module changes; `PLATFORM`
means the platform's own adaptation envelope, so a module that changes nothing more need not know it.
- **The fit sees one chunk at a time.** `StructureFit` is a chunk's area and its starts in placing order, each with
its pieces: box, kind (`FIXED` built in code, `RIGID` and `TERRAIN_MATCHING` jigsaw pieces), ground level, jigsaw
junctions, the template's cells after the platform's processors (`TemplateCells`, with removed blocks and the
number of template blocks read, so a module can bound its work), template columns and legacy template air. Blocks
go through `BlockAccess`: `get`, `column` and `set` work on plain states, traits and tags answer the platform's own
questions, so a fit scans millions of cells without a value per block. `state(type, factory)` holds a module's
object for the chunk from `beforePieces` to the last `afterPieces`, the only place a fit keeps state.
- **A memo instead of a persisted fit.** A start a module places carries a `StartMemo` (two texts, the module's to
fill). The host stores it with the start's ownership record and hands it back in `reach` and in every chunk's
`StructureFit`, so a start fits the same in every chunk it reaches, also after a restart or a pack change. Iris's
structure module writes its terrain and stilts JSON there, in the two places records always held them, so records
written before read the same.
- **Setup before a world exists: `setup(context)`.** Structure set frequencies and protecting the platform's
definitions from installed data packs are decided when the platform builds its structure state or the host
installs data packs, before any world of the dimension runs. The context is the dimension's settings without an
engine. Frequencies multiply across modules; protection holds when any module asks for it.
installs data packs, before any world of the dimension runs. Frequencies multiply across modules; protection holds
when any module asks for it.
## Pack resource kinds
@@ -996,7 +1006,7 @@ This is an inventory of where each existing family should land, not a claim that
| Cave profiles, carving, cave fluids and decoration | Chunk stages + typed carve layers |
| Floating islands and child biomes | Terrain/biome sampling + chunk and placement stages |
| Structures, jigsaw pools and foundations | Structure assembly producing placement requests |
| Imported/native structures and ownership | `VanillaStructureHook` (rule, adjustment, starts, setup); host native-generation adapter per platform |
| Imported/native structures and ownership | `VanillaStructures` service (rule, starts, shift, reach, beforePieces, afterPieces, setup); host native-generation bridge per platform |
| Terrain layers, fluids, bedrock, interpolation | Terrain providers + chunk stages |
| Region/biome selection | Biome providers + platform biome writer |
| Image maps, noise expressions, pack injection | Compiled immutable pack resources |
+41 -23
View File
@@ -52,7 +52,7 @@ public final class MossModule implements IrisModule {
`IrisModule.register(FeatureRegistry)` stays for non-stage contributions: geometry generators,
mantle layers, settings no stage names (see Settings for studio), pack resource kinds, validators,
lifecycle hooks, services and vanilla structure hooks (see below). Their feature ids, mantle keys and kind ids are the module id or start with it and `/`,
lifecycle hooks and services (see below). Their feature ids, mantle keys and kind ids are the module id or start with it and `/`,
like stage ids: `iris:snow` or `iris:snow/depth` for module `iris:snow`. A settings type named in `when(...)` needs a feature id that at least one
module naming it owns in that sense, or its owner must have registered it, so another module may
still condition its stages on it, as moss does on `iris:snow`.
@@ -295,6 +295,7 @@ final class RuinsObjects implements ObjectsAt {
| `Loot` | `ALL` | The loot tables a container draws from at a `Site` (`Table` of the pack, `PlatformTable` with the seed to draw it with), in the order their items are added, and the `ItemDrop`s one table gives there. The host puts them together, tells listeners, creates the stacks and shuffles the container. |
| `BlockDrops` | `ALL` | What a module drops for a broken block: `ItemDrop`s, and whether the platform's own drops of the block are replaced. |
| `EntitySpawns` | `ALL` | A `Plan` of entities to spawn in a chunk or at a marker, each `Attempt` an `EntitySpec` with the block, light range and surface it needs; how many appeared (`spawned`); what a marker means (`MarkerRule`); one entity of the pack on request. The host checks light, surface and free space, spawns, and applies the spec. |
| `VanillaStructures` | `ALL` | Rules, starts, shifts and reaches for the platform's own structures, and fitting the terrain to the starts in one chunk through the `BlockAccess` the host hands over (see Vanilla structures). |
```
Service example.Clock is provided by module example:alpha from modules/alpha.jar already, and module example:beta from modules/beta.jar provides it too; a pack has one provider of it (Providers.ONE), so remove one of them
@@ -504,51 +505,68 @@ own enum or settings class with the same JSON, and applies a rotation through `O
## Vanilla structures
A module decides over the platform's own structures, the ones Minecraft, data packs and mods register, with a
`VanillaStructureHook`: the platform keeps generating one (`GENERATE`), the module places it as well
`VanillaStructures` service provider: the platform keeps generating one (`GENERATE`), the module places it as well
(`ALSO_PLACE`), the module places it instead and the platform's own starts are blocked (`REPLACE`), or nobody
generates it (`BLOCK`).
```java
public void register(FeatureRegistry registry) {
registry.registerVanillaStructureHook((structure, world) ->
world.settings().declared(CastleSettings.class).stream()
registry.registerService(VanillaStructures.class, new VanillaStructures() {
@Override
public VanillaStructureRule rule(ResourceId structure, VanillaStructureContext world) {
return world.settings().declared(CastleSettings.class).stream()
.anyMatch(castle -> castle.value().replaces().equals(structure.toString()))
? VanillaStructureRule.REPLACE : VanillaStructureRule.GENERATE);
? VanillaStructureRule.REPLACE : VanillaStructureRule.GENERATE;
}
});
}
```
The host asks every hook of the pack once per world, structure and pack snapshot, before the platform starts the
structure and when it locates it, so a hook decides from the pack, never from a position. Rules combine: a
structure is blocked when any module blocks it, and placed by a module when any module places it. The host applies
the result on every platform it runs on.
The host asks every provider of the pack, in module id order. It asks `rule` once per world, structure and pack
snapshot, before the platform starts the structure and when it locates it, so a provider decides from the pack, never
from a position. Rules combine: a structure is blocked when any module blocks it, and placed by a module when any
module places it. The host applies the result on every platform it runs on.
A hook has three more methods, each with a default that changes nothing, so a hook that only rules stays a lambda:
Every method has a default that changes nothing, so a provider implements only what it takes part in:
- `adjustment(structure, underground, context)`: how the platform's own starts of a structure are moved (`shifted`,
`withYBand` in world Y, `keepingSourceY`) and fitted (`VanillaStructureFit`: a `StructureTerrain` fitting before
the pieces are placed, `StructureStilts` foundation columns after). Asked and kept like the rule; adjustments of
several modules apply one after the other in module id order (`then`: shifts add up, a later band or fit part wins).
- `starts(chunkX, chunkZ, context)`: the platform structures the module starts in that chunk itself. A
`VanillaStructureStart` names the structure, its height above the bottom (`underground()` puts the structure's
lowest block there; otherwise it sits on the surface), whether it takes the chunk from a platform start of the same
structure, a stable `identity` the host records with it, `JigsawOverrides` for jigsaw structures and a fit. The
context gives the world (`PackWorld`) and a `TerrainSampler` over the chunk. Answer from the world and chunk only:
the host asks again when it locates structures and when it checks starts it finds in the world.
structure, a stable `identity` the host records with it, `JigsawOverrides` for jigsaw structures and a `StartMemo`.
The context gives the world (`PackWorld`) and a `TerrainSampler` over the chunk. Answer from the world and chunk
only: the host asks again when it locates structures and when it checks starts it finds in the world.
- `shift(start, context)`: how many blocks one of the platform's own starts moves up or down before the host
publishes it. A `PlatformStart` gives its bounds, whether the platform generates it underground, whether the host
aligns it itself (ocean monuments to the sea, desert and jungle temples to the terrain; a shift then applies on top),
the dimension's bottom and the terrain's surface per column. Shifts of several modules add up; the host keeps the
start inside the world.
- `reach(structure, underground, memo, context)`: how far around its pieces the module changes the terrain for a
start (`StartReach.blocks(n)`, or `PLATFORM` for no further than the platform's own terrain adaptation). The host
hands the start to every chunk any module's reach covers.
- `beforePieces(fit)` and `afterPieces(fit, placed)`: around the platform placing the pieces of the starts in one
chunk. `StructureFit` is that chunk: its area, the world's blocks (`BlockAccess`, written in batches), the terrain's
surface and natural block per column, and every start with its structure, step, the platform's terrain adaptation,
memo and pieces (box, kind, ground level, jigsaw junctions, the processed template cells, template columns and
legacy air). `state(type, factory)` keeps one object per chunk for the module, from `beforePieces` to the last
`afterPieces`.
- `setup(context)`: before any world of the dimension exists, how often each structure set starts (`withFrequency`,
multipliers of several modules multiply) and whether the data packs the host installs must leave the platform's own
structure definitions alone (`protectingVanillaDefinitions`, for every pack once any dimension asks for it).
```java
@Override
public List<VanillaStructureStart> starts(int chunkX, int chunkZ, VanillaStructureStartContext context) {
if (!castleChunk(context.world().seed(), chunkX, chunkZ)) return List.of();
int surface = (int) context.terrain().column((chunkX << 4) + 8, (chunkZ << 4) + 8).surfaceY();
return List.of(VanillaStructureStart.at(ResourceId.parse("minecraft:village_plains"), chunkX, chunkZ, surface)
.withFit(VanillaStructureFit.SOURCE.withTerrain(StructureTerrain.of(StructureTerrain.Mode.VACUUM))));
.withMemo(new StartMemo("{\"mode\":\"VACUUM\"}", "")));
}
```
`StructureTerrain`, `StructureStilts`, `YBand` and `JigsawOverrides` are value types like `PaletteSpec`: settings may
hold them, and packs write them as Iris always read them.
How a start meets the terrain is the module's: the API has no fit values. A `StartMemo` is two texts the module gives
a start it places; the host persists them with the start and hands them back in `reach` and in every chunk's
`StructureFit`, so every chunk the start reaches fits it the same way, also after a restart. `JigsawOverrides` is a
value type like `PaletteSpec`: settings may hold it, and packs write it as Iris always read it.
## Host side
@@ -654,8 +672,8 @@ A pack without jars logs `Pack overworld uses no modules: no jars in its modules
`LoadedModules.load` installs every module, catalogs the settings types named in `when(...)`
together with explicitly registered settings, geometry and mantle registrations, resource kinds and
validators and vanilla structure hooks (`catalog().resourceKinds()`, `catalog().validators()`,
`catalog().vanillaStructureHooks()`), describes them and resolves the pipelines. Graph errors
validators and service providers (`catalog().resourceKinds()`, `catalog().validators()`,
`catalog().registrations(service)`), describes them and resolves the pipelines. Graph errors
(missing requirement, cycle, a stage outside its module's id, duplicate, cross-pipeline edge) fail
here, at pack load, and so do duplicate module ids and feature ids or mantle keys outside the
module's id, and a settings key two features take at one target or that is a reserved host field. Errors about one module name its jar or "host classpath", and so does a module
@@ -780,7 +798,7 @@ failures. `LifecycleRunnerTest` checks hook order, warm-ups after the starts (ea
fails, and that every stop runs. `WorldStateExampleTest` (`example/world`) has a chunk stage, a service and a hook share
one world's state, and a new world start empty. `PackSchemaTest` also describes settings holding IrisApi's value types (`BlockSpec`, `NoiseStyle`,
`StyledRange`, `Range`, `BlockPosition`) and `Object`, and `SettingsValuesTest` checks the value types themselves
and how vanilla structure rules combine. `ModuleRegistryTest` also checks the order of vanilla structure hooks. `DiscoveredModuleTest`
and how vanilla structure rules combine. `ModuleRegistryTest` also checks the order of service providers. `DiscoveredModuleTest`
checks that `info()` is read once. `LoadedPackTest` loads a pack with
built-ins and checks that a failed load and `close()` leave nothing open. `PackJarSnapshotTest` checks
that classes come from the copies, that the original can be replaced while loaded, that copies go