Run each mantle stage as its own pass and let mantle stages work out their reach per pack

MantleRunner.generate(stage, inputs, seed) runs one mantle stage for one chunk. The host runs every
mantle stage as its own pass in resolved order, so a stage sees what earlier stages wrote into the
chunks around it. Activation still follows requires(...): the runner collects the settings of the stage
and of everything it requires, and only those. Because the stages of one chunk now run in different
invocations, mantle stages have no output (Stage.mantle declares Void) and pass data on through
mantle layers.

A mantle stage whose reach depends on the pack declares reach(PackReach). The host works it out once
per pack load from PackSettings, every entry the dimension and its regions and biomes declare, with
ResolvedStage.reachBlocks(settings); a negative result fails naming the stage. Placement and chunk
stages may not declare one, and ResolvedGraph.reach() throws for a mantle pipeline that has one.
VeinModule now sizes its reach from the pack's longest vein.
This commit is contained in:
piexel committed 2026-10-08 12:35:04 +02:00
1 parent 97ac2a2982
commit 50f51db8b2
25 files changed
+410 -89

No files matched your search

@@ -25,6 +25,7 @@ import com.volmit.stage.Pipeline;
import com.volmit.stage.Stage;
import com.volmit.stage.StageGraph;
import com.volmit.support.ColumnSettings;
import com.volmit.support.DeclaredSettings;
import com.volmit.support.MemoryMantle;
import com.volmit.support.TestContexts;
import java.util.ArrayList;
@@ -135,13 +136,14 @@ class ChunkPipelineTest {
@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 vein = new Entry<>(Target.BIOME, PLAINS, new VeinSettings(12, -60));
int reach = loaded.mantle().stages().getFirst().reachBlocks(new DeclaredSettings(vein));
assertEquals(3, reach, "a 12 block vein from the centre column runs 3 blocks into the next chunk");
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);
var reachArea = new BlockBox(-reach, MIN_Y, -reach, CHUNK + reach, MAX_Y, CHUNK + reach);
new MantleRunner(loaded.mantle()).generate(TestContexts.mantle(0, 0, veins, mantle.within(reachArea)), TestContexts.SEED);
new MantleRunner(loaded.mantle()).generate(VeinModule.PLAN,
TestContexts.mantle(0, 0, ColumnSettings.everywhere(vein), 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);
@@ -5,6 +5,7 @@ import com.volmit.IrisModule;
import com.volmit.ModuleInfo;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.config.PackSettings;
import com.volmit.mantle.BlockBox;
import com.volmit.mantle.MantleCodec;
import com.volmit.mantle.MantleKey;
@@ -22,13 +23,14 @@ 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.
* How far a vein runs past its chunk depends on the longest vein the pack configures, so the stage works
* its reach out when the pack loads.
*/
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;
@@ -40,7 +42,7 @@ public final class VeinModule implements IrisModule {
@Override
public void install(StageGraph graph) {
graph.define(PLAN).when(VeinSettings.class).reach(REACH).writesMantle(ORE).run(VeinModule::plan);
graph.define(PLAN).when(VeinSettings.class).reach(VeinModule::reach).writesMantle(ORE).run(VeinModule::plan);
graph.define(PLACE).run(VeinModule::place);
}
@@ -49,13 +51,19 @@ public final class VeinModule implements IrisModule {
registry.registerMantle(ORE, MantleLifetime.GENERATION, new IntegerCodec());
}
/** How far the longest vein any level of the pack declares runs past its chunk. */
public static int reach(PackSettings settings) {
int longest = settings.declared(VeinSettings.class).stream().mapToInt(vein -> vein.value().length()).max().orElse(0);
return Math.max(0, longest - (CHUNK_WIDTH - CHUNK_CENTRE));
}
/** 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++) {
for (int step = 0; step < vein.value().length(); step++) {
ore.set(startX + step, vein.value().y(), z, PLANNED);
}
}