mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
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:
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));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user