From f3d1ff8d13433e40c383fe1b0aee33ca54f03446 Mon Sep 17 00:00:00 2001 From: piexel Date: Sat, 10 Oct 2026 18:05:50 +0200 Subject: [PATCH] Mantle.caverns(): where the mantle carved voids for a chunk to take over, read-only like the planned blocks --- .../java/com/volmit/host/PlacementViews.java | 6 ++++ .../java/com/volmit/host/ReadOnlyMantle.java | 5 ++++ src/main/java/com/volmit/mantle/Mantle.java | 7 +++++ .../com/volmit/example/ChunkPipelineTest.java | 28 +++++++++++++++++++ .../java/com/volmit/support/MemoryMantle.java | 9 ++++++ 5 files changed, 55 insertions(+) diff --git a/src/main/java/com/volmit/host/PlacementViews.java b/src/main/java/com/volmit/host/PlacementViews.java index ff05e219e..212a820d5 100644 --- a/src/main/java/com/volmit/host/PlacementViews.java +++ b/src/main/java/com/volmit/host/PlacementViews.java @@ -111,6 +111,12 @@ final class PlacementViews { bounds(); return new RestrictedMantleLayer<>(this, parent.blocks()); } + + @Override + public MantleLayer caverns() { + bounds(); + return new RestrictedMantleLayer<>(this, parent.caverns()); + } } private static final class RestrictedMantleLayer implements MantleLayer { diff --git a/src/main/java/com/volmit/host/ReadOnlyMantle.java b/src/main/java/com/volmit/host/ReadOnlyMantle.java index 577e41c60..15cbeede6 100644 --- a/src/main/java/com/volmit/host/ReadOnlyMantle.java +++ b/src/main/java/com/volmit/host/ReadOnlyMantle.java @@ -36,6 +36,11 @@ final class ReadOnlyMantle implements Mantle { return new ReadOnlyLayer<>(mantle.blocks()); } + @Override + public MantleLayer caverns() { + return new ReadOnlyLayer<>(mantle.caverns()); + } + @Override public MantleEdit edit() { throw new UnsupportedOperationException(READ_ONLY); diff --git a/src/main/java/com/volmit/mantle/Mantle.java b/src/main/java/com/volmit/mantle/Mantle.java index 06fd93357..f424bbe2a 100644 --- a/src/main/java/com/volmit/mantle/Mantle.java +++ b/src/main/java/com/volmit/mantle/Mantle.java @@ -32,6 +32,13 @@ public interface Mantle { */ MantleLayer blocks(); + /** Where the mantle holds a carved void for the chunk to take over: a cave's air or fluid, planned before the chunks + * were generated. Present ({@code true}) at carved positions, absent elsewhere, also where the chunk's own blocks + * show no void, such as under a dimension stacked above. The host owns this layer, so it needs no registration. + * Stages read it only, and writes throw UnsupportedOperationException. A dimension that keeps no mantle holds none. + */ + MantleLayer caverns(); + /** Only one edit may be active per view. Parent reads remain allowed, but parent * mutations are prohibited until the edit ends (IllegalStateException). */ diff --git a/src/test/java/com/volmit/example/ChunkPipelineTest.java b/src/test/java/com/volmit/example/ChunkPipelineTest.java index a64959768..22401bdef 100644 --- a/src/test/java/com/volmit/example/ChunkPipelineTest.java +++ b/src/test/java/com/volmit/example/ChunkPipelineTest.java @@ -185,6 +185,34 @@ class ChunkPipelineTest { assertThrows(UnsupportedOperationException.class, () -> mantle.within(chunkArea).blocks().set(0, 0, 0, stone)); } + @Test + void chunkStagesReadWhereTheMantleCarvedVoidsButCannotCarveAny() { + var mantle = new MemoryMantle(); + mantle.carve(6, 9, 2); + var chunkArea = new BlockBox(0, BOTTOM, 0, CHUNK, TOP, CHUNK); + var carved = new ArrayList(); + var probe = Stage.chunk("test:caves/probe"); + IrisModule module = new IrisModule() { + public ModuleInfo info() { return ModuleInfo.of("test:caves", "Caves", "1"); } + public void install(StageGraph graph) { + graph.define(probe).run(context -> { + var caverns = context.mantle().caverns(); + carved.add(String.valueOf(caverns.get(6, 9, 2))); + carved.add(String.valueOf(caverns.get(6, 10, 2))); + }); + } + }; + var builder = new StageGraphBuilder(); + builder.install(DiscoveredModule.builtIn(module)); + var blocks = new ArrayHunk<>(BlockState.class, CHUNK, HEIGHT, CHUNK, AIR); + + new ChunkRunner(builder.resolve(Pipeline.CHUNK)).generate( + TestContexts.generation(Map.of(BlockState.class, blocks), ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED); + + assertEquals(List.of("true", "null"), carved); + assertThrows(UnsupportedOperationException.class, () -> mantle.within(chunkArea).caverns().set(0, 0, 0, true)); + } + @Test void theRunnerReportsHowLongEachStageThatRanTook() { var timed = new ArrayList(); diff --git a/src/test/java/com/volmit/support/MemoryMantle.java b/src/test/java/com/volmit/support/MemoryMantle.java index 88c77b8a0..da9dc3136 100644 --- a/src/test/java/com/volmit/support/MemoryMantle.java +++ b/src/test/java/com/volmit/support/MemoryMantle.java @@ -21,6 +21,9 @@ public final class MemoryMantle { /** Where the planned blocks are kept; the host owns them, so no module registers this layer. */ private static final MantleKey PLANNED_BLOCKS = new MantleKey<>("host:planned-blocks", BlockState.class); + /** Where the carved voids are kept; the host owns them, so no module registers this layer. */ + private static final MantleKey CAVERNS = new MantleKey<>("host:caverns", Boolean.class); + private final Map> layers = new HashMap<>(); /** A view that accepts reads and writes inside {@code bounds} only. */ @@ -29,6 +32,7 @@ public final class MemoryMantle { public BlockBox bounds() { return bounds; } public MantleLayer layer(MantleKey key) { return new Layer<>(key, bounds, true); } public MantleLayer blocks() { return new Layer<>(PLANNED_BLOCKS, bounds, false); } + public MantleLayer caverns() { return new Layer<>(CAVERNS, bounds, false); } public MantleEdit edit() { throw new UnsupportedOperationException("Edits are not used in these tests"); } }; } @@ -38,6 +42,11 @@ public final class MemoryMantle { values(PLANNED_BLOCKS).put(new BlockPosition(x, y, z), block); } + /** Carves a void into the mantle, as the cave planner would; stages only read them. */ + public void carve(int x, int y, int z) { + values(CAVERNS).put(new BlockPosition(x, y, z), Boolean.TRUE); + } + public T get(MantleKey key, int x, int y, int z) { return key.type().cast(values(key).get(new BlockPosition(x, y, z))); }