Read settings per column with every level as its own entry, add the mantle pipeline, host types and the one-option shorthand

Settings no longer resolve to one value per type. FeatureSettings.at(type, x, z) returns one entry per
level that declares the type at that column (dimension, region, surface biome, placement), each with
its level, source and value; levels stack and a module decides what several mean. Conditional stage
bodies receive every configured entry. Chunk and mantle runners collect a chunk's settings themselves,
so a stage runs when any column of the chunk configures it.

Work that writes the mantle or reaches beyond its chunk moves to a new MANTLE pipeline (Stage.mantle,
MantleRunner) that the host runs around a chunk before it generates. Chunk stages may no longer declare
a reach or mantle writes and see the mantle read-only.

Built-in settings may hold host types the host describes itself (ModuleHost.describingHostTypesIn,
ValueKind.HostKind); pack modules cannot. FeatureSchema.shorthand() names the only option of settings
packs may write as a bare value.
This commit is contained in:
piexel committed 2026-10-08 11:31:03 +02:00
1 parent 09df1af88e
commit 97ac2a2982
61 files changed
+1316 -184

No files matched your search

@@ -1,28 +1,54 @@
package com.volmit.example;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.Feature;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.example.chunk.GrassModule;
import com.volmit.example.chunk.GrassSettings;
import com.volmit.example.chunk.TerrainModule;
import com.volmit.example.chunk.VeinModule;
import com.volmit.example.chunk.VeinSettings;
import com.volmit.host.ArrayHunk;
import com.volmit.host.ChunkRunner;
import com.volmit.host.ConfiguredSettings;
import com.volmit.host.DiscoveredModule;
import com.volmit.host.LoadedModules;
import com.volmit.host.MantleRunner;
import com.volmit.host.StageGraphBuilder;
import com.volmit.hunk.Hunk;
import com.volmit.mantle.BlockBox;
import com.volmit.resource.ResourceId;
import com.volmit.stage.Pipeline;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.support.ColumnSettings;
import com.volmit.support.MemoryMantle;
import com.volmit.support.TestContexts;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
/** The chunk pipeline runs on the same graph machinery as placement. */
/** The chunk pipeline runs on the same graph machinery as placement; the mantle pipeline feeds it. */
class ChunkPipelineTest {
private static final int SIZE = 4;
private static final int HEIGHT = 8;
private static final int CHUNK = 16;
private static final int MIN_Y = -64;
private static final int MAX_Y = 320;
private static final BlockState AIR = new BlockState("minecraft:air");
private static final BlockState GRASS = new BlockState("minecraft:grass_block");
private static final ResourceId DIMENSION = ResourceId.parse("pack:dimension/overworld");
private static final ResourceId PLAINS = ResourceId.parse("pack:biome/plains");
private static final ResourceId SWAMP = ResourceId.parse("pack:biome/swamp");
@Feature(id = "test:levels", name = "Levels", targets = {Target.DIMENSION, Target.BIOME})
static final class Marker implements IrisFeature {}
private static ChunkRunner runner() {
var builder = new StageGraphBuilder();
@@ -35,15 +61,19 @@ class ChunkPipelineTest {
return new ChunkRunner(graph);
}
private static Hunk<BlockState> generate(ConfiguredSettings settings) {
private static Hunk<BlockState> generate(ColumnSettings settings) {
var blocks = new ArrayHunk<>(BlockState.class, SIZE, HEIGHT, SIZE, AIR);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks)), TestContexts.SEED, settings);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks), settings, null), TestContexts.SEED);
return blocks;
}
private static Entry<GrassSettings> grass(ResourceId biome) {
return new Entry<>(Target.BIOME, biome, new GrassSettings());
}
@Test
void decorationReadsTerrainOutputWhenConfigured() {
var blocks = generate(ConfiguredSettings.of(new GrassSettings()));
var blocks = generate(ColumnSettings.everywhere(grass(PLAINS)));
for (int x = 0; x < SIZE; x++) {
for (int z = 0; z < SIZE; z++) {
@@ -57,9 +87,90 @@ class ChunkPipelineTest {
@Test
void decorationIsInactiveWithoutItsSettings() {
var blocks = generate(ConfiguredSettings.none());
var blocks = generate(ColumnSettings.NONE);
int height = TerrainModule.surfaceHeight(0, 0);
assertEquals(TerrainModule.STONE, blocks.get(0, height - 1, 0));
}
@Test
void aStageRunsWhenAnyColumnHasItsSettingsAndReadsThemPerColumn() {
var farCorner = new ColumnSettings((x, z) -> x == CHUNK - 1 && z == CHUNK - 1 ? List.of(grass(PLAINS)) : List.of());
var blocks = generate(farCorner);
assertEquals(TerrainModule.STONE, blocks.get(0, TerrainModule.surfaceHeight(0, 0) - 1, 0),
"the stage ran because one column has grass, but this column has none");
var border = new ColumnSettings((x, z) -> x < 2 ? List.of(grass(PLAINS)) : List.of());
blocks = generate(border);
assertEquals(GRASS, blocks.get(1, TerrainModule.surfaceHeight(1, 0) - 1, 0));
assertEquals(TerrainModule.STONE, blocks.get(2, TerrainModule.surfaceHeight(2, 0) - 1, 0));
}
@Test
void levelsStackAndTheBodyGetsEveryDistinctEntryOfTheChunkInLevelOrder() {
var dimension = new Entry<>(Target.DIMENSION, DIMENSION, new Marker());
var plains = new Entry<>(Target.BIOME, PLAINS, new Marker());
var swamp = new Entry<>(Target.BIOME, SWAMP, new Marker());
var received = new ArrayList<List<ResourceId>>();
var stage = Stage.chunk("test:levels/read");
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:levels", "Levels", "1"); }
public void install(StageGraph graph) {
graph.define(stage).when(Marker.class).run((context, entries) -> {
received.add(entries.stream().map(Entry::source).toList());
received.add(context.settings().at(Marker.class, 0, 0).stream().map(Entry::source).toList());
});
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var settings = new ColumnSettings((x, z) -> List.of(dimension, x < 8 ? swamp : plains));
new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(TestContexts.generation(Map.of(), settings, null), TestContexts.SEED);
assertEquals(List.of(List.of(DIMENSION, SWAMP, PLAINS), List.of(DIMENSION, SWAMP)), received,
"the body sees every level of every column, a column read that column's levels");
}
@Test
void mantleStagesWriteBeyondTheirChunkAndChunkStagesReadTheirOwnPart() {
var loaded = LoadedModules.load(List.of(DiscoveredModule.builtIn(new VeinModule())), Map.of(), Set.of(), Set.of());
assertEquals(VeinModule.REACH, loaded.mantle().reach().blocks());
assertEquals(Map.of(VeinModule.ORE.id(), VeinModule.REACH), loaded.mantle().reach().mantleLayers());
var mantle = new MemoryMantle();
var veins = ColumnSettings.everywhere(new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, -60)));
var reachArea = new BlockBox(-VeinModule.REACH, MIN_Y, -VeinModule.REACH, CHUNK + VeinModule.REACH, MAX_Y, CHUNK + VeinModule.REACH);
new MantleRunner(loaded.mantle()).generate(TestContexts.mantle(0, 0, veins, mantle.within(reachArea)), TestContexts.SEED);
assertEquals(1, mantle.get(VeinModule.ORE, 18, -60, 7), "the vein runs on into the next chunk");
var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, AIR);
var chunkArea = new BlockBox(0, MIN_Y, 0, CHUNK, MAX_Y, CHUNK);
new ChunkRunner(loaded.chunk()).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED);
assertEquals(VeinModule.ORE_BLOCK, blocks.get(7, 4, 7));
assertEquals(VeinModule.ORE_BLOCK, blocks.get(15, 4, 7));
assertEquals(AIR, blocks.get(6, 4, 7));
}
@Test
void chunkStagesReadTheMantleButCannotWriteIt() {
var stage = Stage.chunk("test:writer/work");
var mantle = new MemoryMantle();
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:writer", "Writer", "1"); }
public void install(StageGraph graph) {
graph.define(stage).run(context -> context.mantle().layer(VeinModule.ORE).set(0, 0, 0, 1));
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var inputs = TestContexts.generation(Map.of(), ColumnSettings.NONE, mantle.within(new BlockBox(0, MIN_Y, 0, CHUNK, MAX_Y, CHUNK)));
var failure = assertThrows(UnsupportedOperationException.class,
() -> new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(inputs, TestContexts.SEED));
assertEquals("Chunk stages read the mantle but do not write it; write it from a mantle stage (Stage.mantle),"
+ " which runs before the chunks it reaches", failure.getMessage());
assertNull(mantle.get(VeinModule.ORE, 0, 0, 0));
}
}
@@ -38,6 +38,7 @@ import static org.junit.jupiter.api.Assertions.*;
/** The ported slice of Iris's place() lifecycle, composed only from module-owned stages. */
class PlacementLifecyclePortTest {
private static final ResourceId PLACEMENT = ResourceId.parse("pack:object/tree");
private static final BlockState PLANKS = new BlockState("minecraft:oak_planks");
private static final int ANCHOR_GROUND = 10;
private static final int SURROUNDING_GROUND = 7;
@@ -149,7 +150,7 @@ class PlacementLifecyclePortTest {
@Test
void placesObjectThenStiltSnowAndMossFromTypedOutputs() {
var edit = place(resolve(PlacementModules.all()),
ConfiguredSettings.of(new StiltSettings(), new SnowSettings(2), new MossSettings()));
ConfiguredSettings.placement(PLACEMENT, new StiltSettings(), new SnowSettings(2), new MossSettings()));
var bottom = placed(0, 0, 0);
var corner = placed(1, 0, 0);
@@ -191,17 +192,17 @@ class PlacementLifecyclePortTest {
modules.add(capModule);
var graph = resolve(modules);
var withoutStilt = place(graph, ConfiguredSettings.of(new SnowSettings(), new MossSettings()));
var withoutStilt = place(graph, ConfiguredSettings.placement(PLACEMENT, new SnowSettings(), new MossSettings()));
assertEquals(TestTerrain.AIR, withoutStilt.publishedAt(5, 20, 5));
assertEquals(MossModule.MOSS, withoutStilt.publishedAt(0, ANCHOR_GROUND - 1, 0));
var withStilt = place(graph, ConfiguredSettings.of(new StiltSettings()));
var withStilt = place(graph, ConfiguredSettings.placement(PLACEMENT, new StiltSettings()));
assertEquals(PLANKS, withStilt.publishedAt(5, 20, 5));
}
@Test
void loadingThePortCatalogsEveryConditioningSettingsType() {
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of());
var loaded = LoadedModules.load(PlacementModules.builtIns(), Map.of(), Set.of(), Set.of());
assertEquals(List.of("example:moss", "iris:snow", "iris:stilt"),
loaded.catalog().settings().stream().map(settings -> settings.id().toString()).toList());
@@ -3,12 +3,17 @@ package com.volmit.example.chunk;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import java.util.List;
/** Third-party decoration: tops terrain columns using the terrain module's typed output. */
/** Third-party decoration: tops terrain columns using the terrain module's typed output. It runs where any
* column of the chunk has grass and reads the settings per column, so a biome border inside the chunk
* keeps grass on its own side.
*/
public final class GrassModule implements IrisModule {
public static final ChunkStage<Void> TOP = Stage.chunk("example:grass/top");
@@ -25,16 +30,17 @@ public final class GrassModule implements IrisModule {
.run(GrassModule::cover);
}
private static void cover(ChunkStageContext context, GrassSettings grass) {
var top = grass.block();
private static void cover(ChunkStageContext context, List<Entry<GrassSettings>> inChunk) {
var heights = context.output(TerrainModule.SURFACE);
var blocks = context.hunk(BlockState.class);
for (int x = 0; x < blocks.getWidth(); x++) {
for (int z = 0; z < blocks.getDepth(); z++) {
var here = context.settings().at(GrassSettings.class, context.originX() + x, context.originZ() + z);
int height = heights.at(x, z);
if (height > 0) {
blocks.set(x, height - 1, z, top);
if (here.isEmpty() || height <= 0) {
continue;
}
blocks.set(x, height - 1, z, here.getLast().value().block()); // the most specific level wins here
}
}
}
@@ -0,0 +1,77 @@
package com.volmit.example.chunk;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.mantle.BlockBox;
import com.volmit.mantle.MantleCodec;
import com.volmit.mantle.MantleKey;
import com.volmit.mantle.MantleLifetime;
import com.volmit.stage.ChunkStage;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.MantleStage;
import com.volmit.stage.MantleStageContext;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
/** Work across chunks: a mantle stage plans veins into the mantle, past its own chunk, and a chunk stage
* later turns its own chunk's part of the mantle into blocks. The two pipelines meet only in the mantle.
*/
public final class VeinModule implements IrisModule {
public static final MantleKey<Integer> ORE = new MantleKey<>("example:veins/ore", Integer.class);
public static final MantleStage<Void> PLAN = Stage.mantle("example:veins/plan");
public static final ChunkStage<Void> PLACE = Stage.chunk("example:veins/place");
public static final BlockState ORE_BLOCK = new BlockState("minecraft:iron_ore");
public static final int REACH = 16;
private static final int CHUNK_WIDTH = 16;
private static final int CHUNK_CENTRE = 7;
private static final int PLANNED = 1;
@Override
public ModuleInfo info() {
return ModuleInfo.of("example:veins", "Veins", "1.0.0");
}
@Override
public void install(StageGraph graph) {
graph.define(PLAN).when(VeinSettings.class).reach(REACH).writesMantle(ORE).run(VeinModule::plan);
graph.define(PLACE).run(VeinModule::place);
}
@Override
public void register(FeatureRegistry registry) {
registry.registerMantle(ORE, MantleLifetime.GENERATION, new IntegerCodec());
}
/** One vein per level that configures veins at the chunk's centre column: levels stack. */
private static void plan(MantleStageContext context, List<Entry<VeinSettings>> inChunk) {
int startX = context.originX() + CHUNK_CENTRE;
int z = context.originZ() + CHUNK_CENTRE;
var ore = context.mantle().layer(ORE);
for (var vein : context.settings().at(VeinSettings.class, startX, z)) {
for (int step = 0; step < Math.min(vein.value().length(), REACH + CHUNK_WIDTH - CHUNK_CENTRE); step++) {
ore.set(startX + step, vein.value().y(), z, PLANNED);
}
}
}
private static void place(ChunkStageContext context) {
var blocks = context.hunk(BlockState.class);
var chunk = new BlockBox(context.originX(), context.originY(), context.originZ(),
context.originX() + blocks.getWidth(), context.originY() + blocks.getHeight(), context.originZ() + blocks.getDepth());
context.mantle().layer(ORE).visit(chunk, (x, y, z, planned) ->
blocks.set(x - context.originX(), y - context.originY(), z - context.originZ(), ORE_BLOCK));
}
private static final class IntegerCodec implements MantleCodec<Integer> {
public int version() { return 0; }
public void write(DataOutput output, Integer value) throws IOException { output.writeInt(value); }
public Integer read(DataInput input, int storedVersion) throws IOException { return input.readInt(); }
}
}
@@ -0,0 +1,31 @@
package com.volmit.example.chunk;
import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
@Desc("Plans a horizontal ore vein from the centre of each chunk, which may run into the next chunk")
@Feature(id = "example:veins", name = "Veins", targets = {FeatureAttachment.Target.DIMENSION, FeatureAttachment.Target.BIOME})
public final class VeinSettings implements IrisFeature {
@Desc("Blocks along X, starting at the chunk's centre column")
private int length = 12;
@Desc("World height of the vein")
private int y = -60;
public VeinSettings() {}
public VeinSettings(int length, int y) {
this.length = length;
this.y = y;
}
public int length() {
return length;
}
public int y() {
return y;
}
}
@@ -0,0 +1,13 @@
package com.volmit.example.hosttypes;
import java.util.List;
/** Stands for a host class such as Iris's material palette: the host describes it in studio itself. */
public final class Palette {
private List<String> blocks = List.of("minecraft:stone");
private Object anything;
public List<String> blocks() {
return blocks;
}
}
@@ -3,6 +3,7 @@ package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.PlacementStage;
import com.volmit.stage.PlacementStageContext;
@@ -10,6 +11,7 @@ import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.stage.StageRef;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
/** Third-party module: turns the ground under the anchor into moss. It requires the core
@@ -33,7 +35,8 @@ public final class MossModule implements IrisModule {
.run(MossModule::spread);
}
private static void spread(PlacementStageContext context, MossSettings moss) {
private static void spread(PlacementStageContext context, List<Entry<MossSettings>> settings) {
var moss = settings.getFirst().value(); // a placement declares its settings once
var anchor = context.output(AnchorModule.HEIGHT).anchor();
var access = context.access();
int groundY = anchor.y() - 1;
@@ -3,6 +3,7 @@ package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.BlockStage;
import com.volmit.stage.PlacementStage;
@@ -11,6 +12,7 @@ import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.stage.StageRef;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
/** Port of PlacementModuleSnow: collect written tops, then cover them after the finishing work
@@ -40,7 +42,8 @@ public final class SnowModule implements IrisModule {
.run(SnowModule::cover);
}
private static void cover(PlacementStageContext context, SnowSettings snow) {
private static void cover(PlacementStageContext context, List<Entry<SnowSettings>> settings) {
var snow = settings.getFirst().value(); // a placement declares its settings once
var layer = SNOW.withProperty("layers", Integer.toString(snow.layers()));
var access = context.access();
for (var top : context.output(COLLECT).tops()) {
@@ -2,6 +2,7 @@ package com.volmit.example.placement;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.object.ObjectBlock;
import com.volmit.placement.PlacedBlock;
import com.volmit.stage.BlockStage;
@@ -10,6 +11,7 @@ import com.volmit.stage.PlacementStageContext;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.world.BlockPosition;
import java.util.List;
import java.util.Optional;
/** Port of PlacementModuleStilt: collect the lowest layer per block, then fill down after writes. */
@@ -34,7 +36,8 @@ public final class StiltModule implements IrisModule {
.run(StiltModule::fill);
}
private static void fill(PlacementStageContext context, StiltSettings stilt) {
private static void fill(PlacementStageContext context, List<Entry<StiltSettings>> settings) {
var stilt = settings.getFirst().value(); // a placement declares its settings once
var anchor = context.output(AnchorModule.HEIGHT);
for (var block : context.output(BOUNDS).lowestLayer()) {
var bottom = anchor.worldPosition(context.request(), block.position());
@@ -0,0 +1,22 @@
package com.volmit.example.terrain;
import com.volmit.FeatureRegistry;
import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.stage.StageGraph;
/** A built-in module whose settings use host types; it only registers them. */
public final class LayersModule implements IrisModule {
@Override
public ModuleInfo info() {
return ModuleInfo.of("iris:layers", "Layers", "test");
}
@Override
public void install(StageGraph graph) {}
@Override
public void register(FeatureRegistry registry) {
registry.registerSettings(LayersSettings.class);
}
}
@@ -0,0 +1,19 @@
package com.volmit.example.terrain;
import com.volmit.FeatureAttachment;
import com.volmit.IrisFeature;
import com.volmit.config.Desc;
import com.volmit.config.Feature;
import com.volmit.example.hosttypes.Palette;
import java.util.List;
/** Built-in settings holding host types, written in pack JSON as a bare list: {@code "layers": [...]}. */
@Feature(id = "iris:layers", name = "Layers", alias = "layers", targets = FeatureAttachment.Target.BIOME)
public final class LayersSettings implements IrisFeature {
@Desc("Rock layers from the surface down")
private List<Palette> layers = List.of();
public List<Palette> layers() {
return layers;
}
}