mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Mantle.caverns(): where the mantle carved voids for a chunk to take over, read-only like the planned blocks
This commit is contained in:
1 parent
d2d746734f
commit
f3d1ff8d13
5 files changed
+55
No files matched your search
@@ -111,6 +111,12 @@ final class PlacementViews {
|
||||
bounds();
|
||||
return new RestrictedMantleLayer<>(this, parent.blocks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
bounds();
|
||||
return new RestrictedMantleLayer<>(this, parent.caverns());
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RestrictedMantleLayer<T> implements MantleLayer<T> {
|
||||
|
||||
@@ -36,6 +36,11 @@ final class ReadOnlyMantle implements Mantle {
|
||||
return new ReadOnlyLayer<>(mantle.blocks());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleLayer<Boolean> caverns() {
|
||||
return new ReadOnlyLayer<>(mantle.caverns());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MantleEdit edit() {
|
||||
throw new UnsupportedOperationException(READ_ONLY);
|
||||
|
||||
@@ -32,6 +32,13 @@ public interface Mantle {
|
||||
*/
|
||||
MantleLayer<BlockState> 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<Boolean> caverns();
|
||||
|
||||
/** Only one edit may be active per view. Parent reads remain allowed, but parent
|
||||
* mutations are prohibited until the edit ends (IllegalStateException).
|
||||
*/
|
||||
|
||||
@@ -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<String>();
|
||||
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<String>();
|
||||
|
||||
@@ -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<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 final Map<String, TreeMap<BlockPosition, Object>> 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 <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<Boolean> 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> T get(MantleKey<T> key, int x, int y, int z) {
|
||||
return key.type().cast(values(key).get(new BlockPosition(x, y, z)));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user