Surface for ported built-ins: VINE trait, canPlaceOn, the sampler's fluid height and upper dimension, the mantle's planned blocks, a chunk sampler that covers the neighbors, stage timings from the chunk runner

This commit is contained in:
piexel committed 2026-10-10 08:35:10 +02:00
1 parent f8d85dcd5e
commit 6c0c072afe
11 files changed
+139 -5

No files matched your search

@@ -155,6 +155,47 @@ class ChunkPipelineTest {
assertEquals(AIR, blocks.get(6, 4, 7));
}
@Test
void chunkStagesCopyTheBlocksPlacementsPlannedButCannotPlanAny() {
var mantle = new MemoryMantle();
var stone = new BlockState("minecraft:stone");
mantle.plan(3, 2, 5, stone);
mantle.plan(4, 2, 5, AIR);
var chunkArea = new BlockBox(0, BOTTOM, 0, CHUNK, TOP, CHUNK);
var copy = Stage.chunk("test:copy/insert");
IrisModule module = new IrisModule() {
public ModuleInfo info() { return ModuleInfo.of("test:copy", "Copy", "1"); }
public void install(StageGraph graph) {
graph.define(copy).run(context -> {
var blocks = context.hunk(BlockState.class);
context.mantle().blocks().visit(chunkArea, (x, y, z, block) -> blocks.set(x, y, z, block));
});
}
};
var builder = new StageGraphBuilder();
builder.install(DiscoveredModule.builtIn(module));
var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, GRASS);
new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate(
TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED);
assertEquals(stone, blocks.get(3, 2, 5));
assertEquals(AIR, blocks.get(4, 2, 5), "air a placement planned replaces what the chunk had");
assertEquals(GRASS, blocks.get(5, 2, 5));
assertThrows(UnsupportedOperationException.class, () -> mantle.within(chunkArea).blocks().set(0, 0, 0, stone));
}
@Test
void theRunnerReportsHowLongEachStageThatRanTook() {
var timed = new ArrayList<String>();
var blocks = new ArrayHunk<>(BlockState.class, SIZE, HEIGHT, SIZE, AIR);
runner().generate(TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, null), TestContexts.SEED,
(stage, nanos) -> timed.add(stage.stage().id() + (nanos >= 0 ? "" : " ran backwards")));
assertEquals(List.of("iris:terrain/surface"), timed, "grass has no settings here, so it does not run and is not reported");
}
@Test
void chunkStagesReadTheMantleButCannotWriteIt() {
var stage = Stage.chunk("test:writer/work");
@@ -1,5 +1,6 @@
package com.volmit.support;
import com.volmit.block.BlockState;
import com.volmit.mantle.BlockBox;
import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit;
@@ -17,17 +18,26 @@ public final class MemoryMantle {
private static final Comparator<BlockPosition> VISIT_ORDER = Comparator.comparingInt(BlockPosition::x)
.thenComparingInt(BlockPosition::y).thenComparingInt(BlockPosition::z);
/** Where the planned blocks are kept; the host owns them, so no module registers this layer. */
private static final MantleKey<BlockState> PLANNED_BLOCKS = new MantleKey<>("host:planned-blocks", BlockState.class);
private final Map<String, TreeMap<BlockPosition, Object>> layers = new HashMap<>();
/** A view that accepts reads and writes inside {@code bounds} only. */
public Mantle within(BlockBox bounds) {
return new Mantle() {
public BlockBox bounds() { return bounds; }
public <T> MantleLayer<T> layer(MantleKey<T> key) { return new Layer<>(key, bounds); }
public <T> MantleLayer<T> layer(MantleKey<T> key) { return new Layer<>(key, bounds, true); }
public MantleLayer<BlockState> blocks() { return new Layer<>(PLANNED_BLOCKS, bounds, false); }
public MantleEdit edit() { throw new UnsupportedOperationException("Edits are not used in these tests"); }
};
}
/** Puts a planned block into the mantle, as a placement would; stages only read them. */
public void plan(int x, int y, int z, BlockState block) {
values(PLANNED_BLOCKS).put(new BlockPosition(x, y, z), block);
}
public <T> T get(MantleKey<T> key, int x, int y, int z) {
return key.type().cast(values(key).get(new BlockPosition(x, y, z)));
}
@@ -39,10 +49,12 @@ public final class MemoryMantle {
private final class Layer<T> implements MantleLayer<T> {
private final MantleKey<T> key;
private final BlockBox bounds;
private final boolean writable;
Layer(MantleKey<T> key, BlockBox bounds) {
Layer(MantleKey<T> key, BlockBox bounds, boolean writable) {
this.key = key;
this.bounds = bounds;
this.writable = writable;
}
public T get(int x, int y, int z) {
@@ -51,11 +63,13 @@ public final class MemoryMantle {
}
public void set(int x, int y, int z, T value) {
requireWritable();
requireInside(x, y, z);
values(key).put(new BlockPosition(x, y, z), key.type().cast(value));
}
public void remove(int x, int y, int z) {
requireWritable();
requireInside(x, y, z);
values(key).remove(new BlockPosition(x, y, z));
}
@@ -70,10 +84,15 @@ public final class MemoryMantle {
}
public void clear(BlockBox area) {
requireWritable();
if (!bounds.contains(area)) throw new IndexOutOfBoundsException("Outside the mantle view: " + area);
values(key).keySet().removeIf(position -> area.contains(position.x(), position.y(), position.z()));
}
private void requireWritable() {
if (!writable) throw new UnsupportedOperationException("Planned blocks are read-only to stages");
}
private void requireInside(int x, int y, int z) {
if (!bounds.contains(x, y, z)) throw new IndexOutOfBoundsException("Outside the mantle view: " + x + "," + y + "," + z);
}