Add Mantle.carved, the host-owned layer of carved voids

CarvedVoid says what fills a carved block (open, fluid, lava or air) and
optionally the biome it shows; the plain fills are shared constants so a carver
allocates nothing per block. A mantle stage writes the layer, a chunk stage
reads it and its writes throw. Placements and edits see it read-only.
This commit is contained in:
piexel committed 2026-11-06 12:19:51 +01:00
1 parent cf0e49e34d
commit 6c8fa31a7b
10 files changed
+151 -28

No files matched your search

@@ -3,6 +3,7 @@ package com.volmit.host;
import com.volmit.block.BlockState;
import com.volmit.generation.ChunkContext;
import com.volmit.geometry.BlockBox;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey;
@@ -21,11 +22,13 @@ final class ChunkMantle implements Mantle {
private static final String NEIGHBOUR_WRITE = "A chunk stage writes the mantle of its own chunk only;"
+ " write around it from a mantle stage (Stage.mantle), which runs before the chunks it reaches";
private static final String HOST_BLOCKS = "The mantle's blocks are written by placements, not by stages";
private static final String CARVED_VOIDS = "Carved voids are planned by mantle stages (Stage.mantle), not by chunk stages";
private final Mantle mantle;
private final BlockBox ownChunk;
private final Map<MantleKey<?>, MantleLayer<?>> layers = new HashMap<>();
private MantleLayer<BlockState> blocks;
private MantleLayer<CarvedVoid> carved;
ChunkMantle(Mantle mantle, int originX, int originZ) {
this.mantle = mantle;
@@ -47,10 +50,16 @@ final class ChunkMantle implements Mantle {
@Override
public MantleLayer<BlockState> blocks() {
if (blocks == null) blocks = new ReadOnlyLayer<>(mantle.blocks());
if (blocks == null) blocks = new ReadOnlyLayer<>(mantle.blocks(), HOST_BLOCKS);
return blocks;
}
@Override
public MantleLayer<CarvedVoid> carved() {
if (carved == null) carved = new ReadOnlyLayer<>(mantle.carved(), CARVED_VOIDS);
return carved;
}
@Override
public boolean isCarved(int x, int y, int z) {
return mantle.isCarved(x, y, z);
@@ -115,7 +124,7 @@ final class ChunkMantle implements Mantle {
}
}
private record ReadOnlyLayer<T>(MantleLayer<T> layer) implements MantleLayer<T> {
private record ReadOnlyLayer<T>(MantleLayer<T> layer, String reason) implements MantleLayer<T> {
@Override
public T get(int x, int y, int z) {
return layer.get(x, y, z);
@@ -123,12 +132,12 @@ final class ChunkMantle implements Mantle {
@Override
public void set(int x, int y, int z, T value) {
throw new UnsupportedOperationException(HOST_BLOCKS);
throw new UnsupportedOperationException(reason);
}
@Override
public void remove(int x, int y, int z) {
throw new UnsupportedOperationException(HOST_BLOCKS);
throw new UnsupportedOperationException(reason);
}
@Override
@@ -138,7 +147,7 @@ final class ChunkMantle implements Mantle {
@Override
public void clear(BlockBox area) {
throw new UnsupportedOperationException(HOST_BLOCKS);
throw new UnsupportedOperationException(reason);
}
}
}
@@ -2,6 +2,7 @@ package com.volmit.host;
import com.volmit.block.BlockState;
import com.volmit.geometry.BlockBox;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey;
@@ -99,6 +100,7 @@ final class PlacementViews {
private final BlockBox allowedBounds;
private final Map<MantleKey<?>, MantleLayer<?>> layers = new HashMap<>();
private MantleLayer<BlockState> blocks;
private MantleLayer<CarvedVoid> carved;
private RestrictedMantle(Mantle parent, BlockBox allowedBounds) {
this.parent = Objects.requireNonNull(parent, "parent");
@@ -131,6 +133,13 @@ final class PlacementViews {
return blocks;
}
@Override
public MantleLayer<CarvedVoid> carved() {
bounds();
if (carved == null) carved = new RestrictedMantleLayer<>(this, parent.carved());
return carved;
}
@Override
public boolean isCarved(int x, int y, int z) {
checkPosition(bounds(), x, y, z);
@@ -21,6 +21,7 @@ import com.volmit.host.MantleRunner;
import com.volmit.host.StageTimings;
import com.volmit.hunk.Hunk;
import com.volmit.geometry.BlockBox;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.MantleLayer;
import com.volmit.resource.ResourceId;
import com.volmit.stage.ChunkStageContext;
@@ -199,6 +200,12 @@ class ChunkPipelineTest {
setup.stages().define(probe).run(context -> {
carved.add(String.valueOf(context.mantle().isCarved(6, 9, 2)));
carved.add(String.valueOf(context.mantle().isCarved(6, 10, 2)));
carved.add(String.valueOf(context.mantle().carved().get(6, 9, 2)));
carved.add(String.valueOf(context.mantle().carved().get(6, 10, 2)));
carved.add(assertThrows(UnsupportedOperationException.class,
() -> context.mantle().carved().set(6, 10, 2, CarvedVoid.AIR)).getMessage());
carved.add(assertThrows(UnsupportedOperationException.class,
() -> context.mantle().carved().remove(6, 9, 2)).getMessage());
});
}
};
@@ -208,7 +215,8 @@ class ChunkPipelineTest {
TestContexts.generation(blocks, ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED,
StageTimings.NONE);
assertEquals(List.of("true", "false"), carved);
var cannotCarve = "Carved voids are planned by mantle stages (Stage.mantle), not by chunk stages";
assertEquals(List.of("true", "false", CarvedVoid.OPEN.toString(), "null", cannotCarve, cannotCarve), carved);
}
@Test
@@ -3,6 +3,7 @@ package com.volmit.support;
import com.volmit.block.BlockState;
import com.volmit.geometry.BlockBox;
import com.volmit.geometry.BlockPosition;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey;
@@ -23,7 +24,7 @@ public final class MemoryMantle {
private static final MantleKey<BlockState> 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<Boolean> CAVERNS = new MantleKey<>("host:caverns", Boolean.class);
private static final MantleKey<CarvedVoid> CAVERNS = new MantleKey<>("host:caverns", CarvedVoid.class);
/** Where the platform biomes stages set are kept; the host owns them, so no module registers this layer. */
private static final MantleKey<ResourceId> PLATFORM_BIOMES = new MantleKey<>("host:platform-biomes", ResourceId.class);
@@ -36,6 +37,7 @@ public final class MemoryMantle {
public BlockBox bounds() { return 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 MantleLayer<CarvedVoid> carved() { return new Layer<>(CAVERNS, bounds, true); }
public boolean isCarved(int x, int y, int z) { return new Layer<>(CAVERNS, bounds, false).get(x, y, z) != null; }
public void setPlatformBiome(int x, int y, int z, ResourceId biome) {
if (!bounds.contains(x, y, z)) throw new IndexOutOfBoundsException("Outside the mantle view: " + x + "," + y + "," + z);
@@ -50,9 +52,9 @@ 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. */
/** Carves an open void into the mantle, as the cave planner would. */
public void carve(int x, int y, int z) {
values(CAVERNS).put(new BlockPosition(x, y, z), Boolean.TRUE);
values(CAVERNS).put(new BlockPosition(x, y, z), CarvedVoid.OPEN);
}
/** The platform biome a stage set at the block; null where none did. */