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

+4 -2
View File
@@ -159,8 +159,10 @@ running Iris is the pack publisher's responsibility.
- Serve `Mantle.blocks()` in every invocation: the blocks placements wrote into the mantle, read-only, none where the - Serve `Mantle.blocks()` in every invocation: the blocks placements wrote into the mantle, read-only, none where the
dimension keeps no mantle or the chunk generates without it. A block a stage reads and writes back unchanged keeps dimension keeps no mantle or the chunk generates without it. A block a stage reads and writes back unchanged keeps
the host's own identity of it (a custom block of a content plugin stays one). the host's own identity of it (a custom block of a content plugin stays one).
- Answer `Mantle.isCarved(x, y, z)` in every invocation (false where the dimension keeps no mantle) and cover the chunk and the 16 blocks - Serve `Mantle.carved()` in every invocation, keeping the voids in the host's own form: a mantle stage's view writes them, a chunk
around it in a chunk stage's mantle, as the sampler does. stage's view only reads them (its writes throw UnsupportedOperationException), and a dimension that keeps no mantle holds none. Answer
`Mantle.isCarved(x, y, z)` (false where it holds none) and cover the chunk and the 16 blocks around it in a chunk stage's mantle, as the
sampler does.
- Name pack resources to services by `ResourceId` and convert to the host's keys at the host's edge; read a `ResourceId` - Name pack resources to services by `ResourceId` and convert to the host's keys at the host's edge; read a `ResourceId`
setting written as a bare pack key as the pack's id of that key. setting written as a bare pack key as the pack's id of that key.
- Answer `TerrainSampler.surfaceBiome(x, z)` (the id `biome(x, y, z).surfaceBiome()` gives), `surfaceKind`, `minWorldY()`, `surfaceBlock` (empty - Answer `TerrainSampler.surfaceBiome(x, z)` (the id `biome(x, y, z).surfaceBiome()` gives), `surfaceKind`, `minWorldY()`, `surfaceBlock` (empty
+11 -12
View File
@@ -625,9 +625,12 @@ made of. A biome that is no column's surface biome, such as the cave biome of a
The chunk stage's mantle covers the chunk and the 16 blocks around it like the sampler, so a decoration that attaches to a neighbor sees the blocks The chunk stage's mantle covers the chunk and the 16 blocks around it like the sampler, so a decoration that attaches to a neighbor sees the blocks
placements planned there. It writes registered layers inside the chunk's own 16 by 16 columns only: the mantle pipeline has finished around the placements planned there. It writes registered layers inside the chunk's own 16 by 16 columns only: the mantle pipeline has finished around the
chunk, and a neighbor may already be generated, so its mantle stays as the pipeline left it (a write outside throws, naming `Stage.mantle`). chunk, and a neighbor may already be generated, so its mantle stays as the pipeline left it (a write outside throws, naming `Stage.mantle`).
`Mantle.isCarved(x, y, z)` is the host's answer whether the cave planner carved a block, as `blocks()` is its read-only layer of planned blocks: a `Mantle.carved()` is the host's layer of carved voids (`CarvedVoid`: what fills the void, `OPEN`, `FLUID`, `LAVA` or `AIR`, and optionally the
void the planner marked need not show in the chunk (under a dimension above, the cave stage leaves it solid), and a stage that places something biome it shows), as `blocks()` is its layer of planned blocks. It is the one host layer a module writes: a mantle stage plans the voids
solid asks it. A yes-or-no question rather than a layer, because no module writes it and none needs to visit it. (Iris's cave carver does, thousands per chunk, so the plain fills are shared constants and the host keeps them in its own form), and a chunk
stage reads them, around its chunk as far as its mantle reaches, and cuts them out of its terrain. A chunk stage's writes throw, as the
mantle is complete when chunk stages run. A void the planner marked need not show in the chunk (under a dimension above, the cave stage
leaves it solid), so `Mantle.isCarved(x, y, z)` stays as the short question for a stage that places something solid.
`Mantle.setPlatformBiome(x, y, z, biome)` is the other way round: modules write it and only the host's biome pass reads it, in the host's own form `Mantle.setPlatformBiome(x, y, z, biome)` is the other way round: modules write it and only the host's biome pass reads it, in the host's own form
(Iris stores the platform's id for the biome), so it is a write rather than a layer a module could read back. It is general rather than a (Iris stores the platform's id for the biome), so it is a write rather than a layer a module could read back. It is general rather than a
floating-island call: any stage that makes a block belong elsewhere, such as an island floating over another biome, can set the biome it shows. floating-island call: any stage that makes a block belong elsewhere, such as an island floating over another biome, can set the biome it shows.
@@ -961,10 +964,9 @@ Why these lines:
have to know that rule, so the resources say it; a default method (namespace and key) serves a host without such characters. have to know that rule, so the resources say it; a default method (namespace and key) serves a host without such characters.
- **`TerrainSampler.caveBiome(x, y, z)`** is `biome(...).caveBiome()` without the region and the surface biome: a cave wall asks for the - **`TerrainSampler.caveBiome(x, y, z)`** is `biome(...).caveBiome()` without the region and the surface biome: a cave wall asks for the
cave biome around it five times per block, and the other two lookups were most of the cost. A default method keeps every sampler valid. cave biome around it five times per block, and the other two lookups were most of the cost. A default method keeps every sampler valid.
- **A chunk stage writes its own chunk's mantle.** Iris's cave stage stamps markers into the matter the platform reads, in the chunk it - **A chunk stage writes its own chunk's mantle.** A chunk stage may need to keep something beside the chunk it generates. Earlier the
generates. Earlier the chunk's mantle was read-only and a built-in facade reached past the view to the host's mantle; now the view lets chunk's mantle was read-only and a built-in facade reached past the view to the host's mantle; now the view lets any chunk stage write
any chunk stage write registered layers inside its own columns and reads the neighbors only, so no stage, built-in or not, needs a way registered layers inside its own columns and reads the neighbors only, so no stage, built-in or not, needs a way around it.
around it.
- **One `minWorldY()`, never defaulted**: all heights are above the dimension's bottom, but packs write some settings as - **One `minWorldY()`, never defaulted**: all heights are above the dimension's bottom, but packs write some settings as
absolute world Y (cave biome bands, floating island altitudes, structure bands). Those are converted by the module with absolute world Y (cave biome bands, floating island altitudes, structure bands). Those are converted by the module with
the platform's Y of the bottom. The world, the terrain sampler, platform starts and structure fits once called it the platform's Y of the bottom. The world, the terrain sampler, platform starts and structure fits once called it
@@ -1333,12 +1335,9 @@ structure placer behind `StructureHost`) are Iris's and live there.
What Iris's built-ins still ask through item 3, and why the API does not answer it yet. Each entry names what would let it go. What Iris's built-ins still ask through item 3, and why the API does not answer it yet. Each entry names what would let it go.
Everything else they once asked a facade (a running world's sky, studio flag, cave floors and loot tables, the world seeds per Everything else they once asked a facade (a running world's sky, studio flag, cave floors and loot tables, the world seeds per
feature, the layout at a column, the declarations of a biome or region, the rock of a column, whether the dimension has bedrock) is feature, the layout at a column, the declarations of a biome or region, the rock of a column, whether the dimension has bedrock, the voids the cave carver plans in the mantle) is
API now: `world.running()`, `world.seed(purpose)`, `TerrainSampler`, `FeatureSettings`, or the module's own settings. API now: `world.running()`, `world.seed(purpose)`, `TerrainSampler`, `FeatureSettings`, `Mantle.carved()`, or the module's own settings.
- **`MatterMantle`** (invocation). Carve plans its caves as VolmLib matter slices (`MatterCavern`, markers) that Iris and the
platform read back as slices. The API mantle has typed layers but no cavern layer; it goes when carve writes a layer the
API defines and Iris reads that instead.
- **`objects.ObjectRun`** (the input of a placement run, `PlacementRun.input`). The object and the module's own - **`objects.ObjectRun`** (the input of a placement run, `PlacementRun.input`). The object and the module's own
`objects.ObjectPlacement` settings that Iris's built-in placement stages read, and what they report back (the anchor `objects.ObjectPlacement` settings that Iris's built-in placement stages read, and what they report back (the anchor
height, which written blocks are the object's). The placement-level module settings no longer need it: the run carries height, which written blocks are the object's). The placement-level module settings no longer need it: the run carries
+3 -2
View File
@@ -181,8 +181,9 @@ ground of a biome somewhere else, such as a floating island, shapes and paints i
block show that platform biome instead of its column's, inside the stage's own chunk. block show that platform biome instead of its column's, inside the stage's own chunk.
`ctx.settings().declaredBy(biomeId, Type.class)` reads what a biome declares itself, such as a cave biome of a `BiomeSample`, which is no level of `ctx.settings().declaredBy(biomeId, Type.class)` reads what a biome declares itself, such as a cave biome of a `BiomeSample`, which is no level of
`at(...)`. A mantle stage's `ctx.terrain()` covers the chunk and the larger of its reach and 16 blocks around it; a chunk stage's `ctx.mantle()` covers the same area as its terrain. `ctx.mantle().blocks()` holds the blocks placements wrote into the mantle for the chunks to `at(...)`. A mantle stage's `ctx.terrain()` covers the chunk and the larger of its reach and 16 blocks around it; a chunk stage's `ctx.mantle()` covers the same area as its terrain. `ctx.mantle().blocks()` holds the blocks placements wrote into the mantle for the chunks to
take over, such as objects and structures; a chunk stage copies them in (Iris's `iris:matter`). `ctx.mantle().isCarved(x, y, z)` says whether the cave planner take over, such as objects and structures; a chunk stage copies them in (Iris's `iris:matter`). `ctx.mantle().carved()` is the layer of voids the cave planner carved (`CarvedVoid`: `OPEN`, `FLUID`, `LAVA` or `AIR`, optionally with a biome), and
carved a void there, whatever the chunk's blocks show. Stages only read both. A chunk stage may write the layers its module registered, inside `isCarved(x, y, z)` asks whether one is there, whatever the chunk's blocks show. A chunk stage only reads both; a mantle stage plans the voids
with `carved().set(...)`, and a chunk stage's write throws. A chunk stage may write the layers its module registered, inside
its own chunk's columns; around it, the mantle stays as the mantle stages left it. `blocks().oreFor(rock, ore)` gives the ore variant that suits the rock its own chunk's columns; around it, the mantle stays as the mantle stages left it. `blocks().oreFor(rock, ore)` gives the ore variant that suits the rock
(deepslate ores in deepslate), which the platform decides, and `PackBiome.vanillaBiome()` the biome vanilla's rules see a pack biome as. (deepslate ores in deepslate), which the platform decides, and `PackBiome.vanillaBiome()` the biome vanilla's rules see a pack biome as.
@@ -0,0 +1,64 @@
package com.volmit.mantle;
import com.volmit.resource.ResourceId;
import java.util.Objects;
import java.util.Optional;
/** A block the mantle holds as carved out: what fills the void once the chunk takes it over, and optionally the biome it shows.
* Instances are immutable and the four plain fills are shared constants ({@link #of}), so a carver marking thousands of blocks
* allocates nothing.
*
* @param fill what fills the void
* @param biome a pack biome the void shows instead of the cave biome its column would get; empty for the usual one
*/
public record CarvedVoid(Fill fill, Optional<ResourceId> biome) {
/** Cut open, and left to the dimension. */
public static final CarvedVoid OPEN = new CarvedVoid(Fill.OPEN, Optional.empty());
/** Filled with the dimension's fluid. */
public static final CarvedVoid FLUID = new CarvedVoid(Fill.FLUID, Optional.empty());
/** Filled with lava. */
public static final CarvedVoid LAVA = new CarvedVoid(Fill.LAVA, Optional.empty());
/** Filled with air, at any height. */
public static final CarvedVoid AIR = new CarvedVoid(Fill.AIR, Optional.empty());
public CarvedVoid {
Objects.requireNonNull(fill, "fill");
Objects.requireNonNull(biome, "biome");
}
/** The shared void of a fill, with no biome of its own. */
public static CarvedVoid of(Fill fill) {
return switch (Objects.requireNonNull(fill, "fill")) {
case OPEN -> OPEN;
case FLUID -> FLUID;
case LAVA -> LAVA;
case AIR -> AIR;
};
}
/** This void's fill, showing {@code biome}. */
public CarvedVoid withBiome(ResourceId biome) {
return new CarvedVoid(fill, Optional.of(biome));
}
/** What fills a carved void. */
public enum Fill {
/** The solid is cut away and the dimension decides what is left: cave air, or lava at and below its lava height.
* Air and fluid the terrain already has there stay.
*/
OPEN,
/** The dimension's fluid, replacing what the terrain has there. */
FLUID,
/** Lava, replacing what the terrain has there. */
LAVA,
/** Cave air at any height, replacing fluid and lava as well. */
AIR
}
}
@@ -34,9 +34,16 @@ public interface Mantle {
*/ */
MantleLayer<BlockState> blocks(); MantleLayer<BlockState> blocks();
/** Whether the mantle holds a carved void at the position for the chunk to take over: a cave's air or fluid, planned /** The voids the mantle holds for chunks to take over: a cave's air or fluid, planned before the chunks were generated.
* before the chunks were generated. Also true where the chunk's own blocks show no void, such as under a dimension * Mantle stages write it ({@code set} plans a void, {@code remove} takes it back); a chunk stage only reads it, around
* stacked above. The host owns the carving; stages only ask. A dimension that keeps no mantle carves nothing. * its chunk as far as its mantle reaches, and its writes throw UnsupportedOperationException. A chunk stage takes the
* voids over into its chunk (Iris's {@code iris:carve} cuts them out of the terrain). The host owns this layer and keeps
* it in its own form, so it needs no registration. A dimension that keeps no mantle carves nothing.
*/
MantleLayer<CarvedVoid> carved();
/** Whether the mantle holds a carved void at the position, whether or not the chunk's own blocks show it, such as
* under a dimension stacked above: the same as {@code carved().get(x, y, z) != null}, for a stage that only asks.
*/ */
boolean isCarved(int x, int y, int z); boolean isCarved(int x, int y, int z);
@@ -48,4 +48,26 @@ class MantleValueTest {
assertThrows(NullPointerException.class, () -> new MantleKey<>("a:b", null)); assertThrows(NullPointerException.class, () -> new MantleKey<>("a:b", null));
assertThrows(IllegalArgumentException.class, () -> new MantleKey<>("a:b", int.class)); assertThrows(IllegalArgumentException.class, () -> new MantleKey<>("a:b", int.class));
} }
@Test
void carvedVoidsOfAPlainFillAreTheSharedConstants() {
for (var fill : CarvedVoid.Fill.values()) {
assertSame(CarvedVoid.of(fill), CarvedVoid.of(fill));
assertEquals(fill, CarvedVoid.of(fill).fill());
assertTrue(CarvedVoid.of(fill).biome().isEmpty());
}
assertSame(CarvedVoid.LAVA, CarvedVoid.of(CarvedVoid.Fill.LAVA));
}
@Test
void aCarvedVoidMayShowABiomeAndHasValueEquality() {
var biome = new com.volmit.resource.ResourceId("pack", "cave/lush");
var lush = CarvedVoid.AIR.withBiome(biome);
assertEquals(CarvedVoid.Fill.AIR, lush.fill());
assertEquals(biome, lush.biome().orElseThrow());
assertEquals(CarvedVoid.AIR.withBiome(biome), lush);
assertNotEquals(CarvedVoid.AIR, lush);
assertThrows(NullPointerException.class, () -> new CarvedVoid(null, java.util.Optional.empty()));
assertThrows(NullPointerException.class, () -> new CarvedVoid(CarvedVoid.Fill.OPEN, null));
}
} }
@@ -3,6 +3,7 @@ package com.volmit.host;
import com.volmit.block.BlockState; import com.volmit.block.BlockState;
import com.volmit.generation.ChunkContext; import com.volmit.generation.ChunkContext;
import com.volmit.geometry.BlockBox; import com.volmit.geometry.BlockBox;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle; import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit; import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey; 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;" 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"; + " 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 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 Mantle mantle;
private final BlockBox ownChunk; private final BlockBox ownChunk;
private final Map<MantleKey<?>, MantleLayer<?>> layers = new HashMap<>(); private final Map<MantleKey<?>, MantleLayer<?>> layers = new HashMap<>();
private MantleLayer<BlockState> blocks; private MantleLayer<BlockState> blocks;
private MantleLayer<CarvedVoid> carved;
ChunkMantle(Mantle mantle, int originX, int originZ) { ChunkMantle(Mantle mantle, int originX, int originZ) {
this.mantle = mantle; this.mantle = mantle;
@@ -47,10 +50,16 @@ final class ChunkMantle implements Mantle {
@Override @Override
public MantleLayer<BlockState> blocks() { public MantleLayer<BlockState> blocks() {
if (blocks == null) blocks = new ReadOnlyLayer<>(mantle.blocks()); if (blocks == null) blocks = new ReadOnlyLayer<>(mantle.blocks(), HOST_BLOCKS);
return blocks; return blocks;
} }
@Override
public MantleLayer<CarvedVoid> carved() {
if (carved == null) carved = new ReadOnlyLayer<>(mantle.carved(), CARVED_VOIDS);
return carved;
}
@Override @Override
public boolean isCarved(int x, int y, int z) { public boolean isCarved(int x, int y, int z) {
return mantle.isCarved(x, y, 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 @Override
public T get(int x, int y, int z) { public T get(int x, int y, int z) {
return layer.get(x, y, z); return layer.get(x, y, z);
@@ -123,12 +132,12 @@ final class ChunkMantle implements Mantle {
@Override @Override
public void set(int x, int y, int z, T value) { public void set(int x, int y, int z, T value) {
throw new UnsupportedOperationException(HOST_BLOCKS); throw new UnsupportedOperationException(reason);
} }
@Override @Override
public void remove(int x, int y, int z) { public void remove(int x, int y, int z) {
throw new UnsupportedOperationException(HOST_BLOCKS); throw new UnsupportedOperationException(reason);
} }
@Override @Override
@@ -138,7 +147,7 @@ final class ChunkMantle implements Mantle {
@Override @Override
public void clear(BlockBox area) { 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.block.BlockState;
import com.volmit.geometry.BlockBox; import com.volmit.geometry.BlockBox;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle; import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit; import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey; import com.volmit.mantle.MantleKey;
@@ -99,6 +100,7 @@ final class PlacementViews {
private final BlockBox allowedBounds; private final BlockBox allowedBounds;
private final Map<MantleKey<?>, MantleLayer<?>> layers = new HashMap<>(); private final Map<MantleKey<?>, MantleLayer<?>> layers = new HashMap<>();
private MantleLayer<BlockState> blocks; private MantleLayer<BlockState> blocks;
private MantleLayer<CarvedVoid> carved;
private RestrictedMantle(Mantle parent, BlockBox allowedBounds) { private RestrictedMantle(Mantle parent, BlockBox allowedBounds) {
this.parent = Objects.requireNonNull(parent, "parent"); this.parent = Objects.requireNonNull(parent, "parent");
@@ -131,6 +133,13 @@ final class PlacementViews {
return blocks; return blocks;
} }
@Override
public MantleLayer<CarvedVoid> carved() {
bounds();
if (carved == null) carved = new RestrictedMantleLayer<>(this, parent.carved());
return carved;
}
@Override @Override
public boolean isCarved(int x, int y, int z) { public boolean isCarved(int x, int y, int z) {
checkPosition(bounds(), x, y, z); checkPosition(bounds(), x, y, z);
@@ -21,6 +21,7 @@ import com.volmit.host.MantleRunner;
import com.volmit.host.StageTimings; import com.volmit.host.StageTimings;
import com.volmit.hunk.Hunk; import com.volmit.hunk.Hunk;
import com.volmit.geometry.BlockBox; import com.volmit.geometry.BlockBox;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.MantleLayer; import com.volmit.mantle.MantleLayer;
import com.volmit.resource.ResourceId; import com.volmit.resource.ResourceId;
import com.volmit.stage.ChunkStageContext; import com.volmit.stage.ChunkStageContext;
@@ -199,6 +200,12 @@ class ChunkPipelineTest {
setup.stages().define(probe).run(context -> { setup.stages().define(probe).run(context -> {
carved.add(String.valueOf(context.mantle().isCarved(6, 9, 2))); 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().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, TestContexts.generation(blocks, ColumnSettings.NONE, mantle.within(chunkArea)), TestContexts.SEED,
StageTimings.NONE); 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 @Test
@@ -3,6 +3,7 @@ package com.volmit.support;
import com.volmit.block.BlockState; import com.volmit.block.BlockState;
import com.volmit.geometry.BlockBox; import com.volmit.geometry.BlockBox;
import com.volmit.geometry.BlockPosition; import com.volmit.geometry.BlockPosition;
import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle; import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit; import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey; 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); 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. */ /** 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. */ /** 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); 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 BlockBox bounds() { return bounds; }
public <T> MantleLayer<T> layer(MantleKey<T> key) { return new Layer<>(key, bounds, true); } 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<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 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) { 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); 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); 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) { 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. */ /** The platform biome a stage set at the block; null where none did. */