kindsWithBiome = new HashMap<>();
+ private long[] sortable;
+ private int sortableSize;
+
+ CarvedCells(BlockBox area, Scratch scratch) {
+ this.width = area.maxX() - area.minX();
+ this.height = area.maxY() - area.minY();
+ this.depth = area.maxZ() - area.minZ();
+ long cells = (long) width * height * depth;
+ if (cells > GRID_LIMIT_CELLS) {
+ requireSortable(width, height, depth);
+ this.grid = null;
+ this.borrowed = null;
+ this.sortable = new long[256];
+ return;
+ }
+ if (scratch.inUse) {
+ this.grid = new byte[(int) cells];
+ this.borrowed = null;
+ return;
+ }
+ if (scratch.kinds.length < cells) {
+ scratch.kinds = new byte[(int) cells];
+ }
+ Arrays.fill(scratch.kinds, 0, (int) cells, (byte) 0);
+ scratch.inUse = true;
+ this.grid = scratch.kinds;
+ this.borrowed = scratch;
+ }
+
+ void add(int relativeX, int relativeY, int relativeZ, CarvedVoid value) {
+ int kind = kindOf(value);
+ if (grid != null) {
+ grid[(relativeX * height + relativeY) * depth + relativeZ] = (byte) kind;
+ return;
+ }
+ if (sortableSize == sortable.length) {
+ sortable = Arrays.copyOf(sortable, sortableSize * 2);
+ }
+ sortable[sortableSize++] = ((long) relativeX << (Y_BITS + Z_BITS + KIND_BITS))
+ | ((long) relativeY << (Z_BITS + KIND_BITS))
+ | ((long) relativeZ << KIND_BITS)
+ | kind;
+ }
+
+ void forEachInOrder(CellVisitor visitor) {
+ if (grid != null) {
+ try {
+ forEachInGrid(visitor);
+ } finally {
+ release();
+ }
+ return;
+ }
+ Arrays.sort(sortable, 0, sortableSize);
+ for (int index = 0; index < sortableSize; index++) {
+ long cell = sortable[index];
+ visitor.accept((int) (cell >>> (Y_BITS + Z_BITS + KIND_BITS)),
+ (int) ((cell >>> (Z_BITS + KIND_BITS)) & mask(Y_BITS)),
+ (int) ((cell >>> KIND_BITS) & mask(Z_BITS)),
+ kinds.get((int) (cell & mask(KIND_BITS)) - 1));
+ }
+ }
+
+ /** Gives the borrowed grid back; a visit does it by itself, a collection that failed must do it. */
+ void release() {
+ if (borrowed != null) {
+ borrowed.inUse = false;
+ }
+ }
+
+ private void forEachInGrid(CellVisitor visitor) {
+ int cell = 0;
+ for (int relativeX = 0; relativeX < width; relativeX++) {
+ for (int relativeY = 0; relativeY < height; relativeY++) {
+ for (int relativeZ = 0; relativeZ < depth; relativeZ++, cell++) {
+ int kind = grid[cell];
+ if (kind != 0) {
+ visitor.accept(relativeX, relativeY, relativeZ, kinds.get((kind & 0xff) - 1));
+ }
+ }
+ }
+ }
+ }
+
+ /** The kind of a void, counted from 1: the four plain fills, then the voids that show a biome in the order they were found. */
+ private int kindOf(CarvedVoid value) {
+ if (value.biome().isEmpty()) {
+ return value.fill().ordinal() + 1;
+ }
+ return kindsWithBiome.computeIfAbsent(value, ignored -> {
+ if (kinds.size() >= MAX_KINDS) {
+ throw new IllegalStateException("An area holds more kinds of carved void than a view reads at once, " + MAX_KINDS);
+ }
+ kinds.add(value);
+ return kinds.size();
+ });
+ }
+
+ private static void requireSortable(int width, int height, int depth) {
+ if (width > mask(X_BITS) || height > mask(Y_BITS) || depth > mask(Z_BITS)) {
+ throw new IllegalArgumentException("An area of " + width + " by " + height + " by " + depth
+ + " blocks is larger than a view of the carved voids reads at once");
+ }
+ }
+
+ private static long mask(int bits) {
+ return (1L << bits) - 1;
+ }
+}
diff --git a/core/src/main/java/art/arcane/iris/core/modules/CarvedVoids.java b/core/src/main/java/art/arcane/iris/core/modules/CarvedVoids.java
new file mode 100644
index 000000000..ec09acc8f
--- /dev/null
+++ b/core/src/main/java/art/arcane/iris/core/modules/CarvedVoids.java
@@ -0,0 +1,278 @@
+/*
+ * Iris is a World Generator for Minecraft Servers
+ * Copyright (c) 2026 Arcane Arts (Volmit Software)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package art.arcane.iris.core.modules;
+
+import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
+import art.arcane.volmlib.util.matter.Matter;
+import art.arcane.volmlib.util.matter.MatterCavern;
+import art.arcane.volmlib.util.matter.MatterSlice;
+import com.volmit.geometry.BlockBox;
+import com.volmit.mantle.CarvedVoid;
+import com.volmit.mantle.MantleLayer;
+import com.volmit.mantle.MantleVisitor;
+import com.volmit.resource.ResourceId;
+
+import java.util.Objects;
+
+/**
+ * The voids Iris's mantle holds for chunks to take over, IrisApi's {@link com.volmit.mantle.Mantle#carved()}, over the
+ * chunks one invocation may touch. Iris stores them as the cavern slice of the mantle ({@link MatterCavern}), which its
+ * own readers (the cave floors, the structure anchors, the biome pass) read as it is; this layer translates at the edge:
+ * a cavern's liquid byte is the void's fill, and a custom biome key is a pack biome id. A cavern of any other liquid
+ * reads as {@link CarvedVoid#OPEN}.
+ *
+ * The carver calls {@link #set} for thousands of blocks of one chunk, so the layer remembers the slices of the chunks
+ * it touched last and the voids it writes are the shared constants. A view belongs to one invocation and one thread, as
+ * IrisApi's mantle does.
+ */
+final class CarvedVoids implements MantleLayer {
+ static final byte LIQUID_OPEN = 0;
+ static final byte LIQUID_FLUID = 1;
+ static final byte LIQUID_LAVA = 2;
+ static final byte LIQUID_AIR = 3;
+
+ private static final MatterCavern STORED_OPEN = new MatterCavern(true, "", LIQUID_OPEN);
+ private static final MatterCavern STORED_FLUID = new MatterCavern(true, "", LIQUID_FLUID);
+ private static final MatterCavern STORED_LAVA = new MatterCavern(true, "", LIQUID_LAVA);
+ private static final MatterCavern STORED_AIR = new MatterCavern(true, "", LIQUID_AIR);
+
+ private static final int CHUNK_SHIFT = 4;
+ private static final int SECTION_SHIFT = 4;
+ private static final int LOCAL_MASK = 15;
+ private static final int RECENT_CHUNKS = 8;
+ private static final String READ_ONLY = "This view only reads the carved voids; mantle stages write them on the mantle itself";
+
+ private final BlockBox bounds;
+ private final IrisModuleMantle.Chunks chunks;
+ private final PackResourceIds ids;
+ private final boolean writable;
+ private final ChunkSlices[] recent = new ChunkSlices[RECENT_CHUNKS];
+ private final CarvedCells.Scratch gridScratch = new CarvedCells.Scratch();
+
+ CarvedVoids(BlockBox bounds, IrisModuleMantle.Chunks chunks, PackResourceIds ids, boolean writable) {
+ this.bounds = bounds;
+ this.chunks = chunks;
+ this.ids = ids;
+ this.writable = writable;
+ }
+
+ @Override
+ public CarvedVoid get(int x, int y, int z) {
+ requireInside(x, y, z);
+ MatterSlice slice = slicesAt(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT).existing(y >> SECTION_SHIFT);
+ if (slice == null) {
+ return null;
+ }
+ MatterCavern cavern = slice.get(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK);
+ return cavern == null ? null : toApi(cavern);
+ }
+
+ @Override
+ public void set(int x, int y, int z, CarvedVoid value) {
+ requireWritable();
+ Objects.requireNonNull(value, "value");
+ requireInside(x, y, z);
+ slicesAt(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT).creating(y >> SECTION_SHIFT)
+ .set(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK, toStored(value));
+ }
+
+ @Override
+ public void remove(int x, int y, int z) {
+ requireWritable();
+ requireInside(x, y, z);
+ MatterSlice slice = slicesAt(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT).existing(y >> SECTION_SHIFT);
+ if (slice != null) {
+ slice.set(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK, null);
+ }
+ }
+
+ @Override
+ public void visit(BlockBox area, MantleVisitor visitor) {
+ Objects.requireNonNull(visitor, "visitor");
+ requireInside(area);
+ collect(area).forEachInOrder((relativeX, relativeY, relativeZ, carvedVoid) ->
+ visitor.accept(area.minX() + relativeX, area.minY() + relativeY, area.minZ() + relativeZ, carvedVoid));
+ }
+
+ @Override
+ public void clear(BlockBox area) {
+ requireWritable();
+ requireInside(area);
+ collect(area).forEachInOrder((relativeX, relativeY, relativeZ, carvedVoid) ->
+ remove(area.minX() + relativeX, area.minY() + relativeY, area.minZ() + relativeZ));
+ }
+
+ private CarvedCells collect(BlockBox area) {
+ CarvedCells collected = new CarvedCells(area, gridScratch);
+ try {
+ collectChunks(area, collected);
+ } catch (RuntimeException failure) {
+ collected.release();
+ throw failure;
+ }
+ return collected;
+ }
+
+ private void collectChunks(BlockBox area, CarvedCells collected) {
+ int firstSection = area.minY() >> SECTION_SHIFT;
+ int lastSection = (area.maxY() - 1) >> SECTION_SHIFT;
+ for (int chunkX = area.minX() >> CHUNK_SHIFT; chunkX <= (area.maxX() - 1) >> CHUNK_SHIFT; chunkX++) {
+ for (int chunkZ = area.minZ() >> CHUNK_SHIFT; chunkZ <= (area.maxZ() - 1) >> CHUNK_SHIFT; chunkZ++) {
+ ChunkSlices slices = slicesAt(chunkX, chunkZ);
+ for (int section = firstSection; section <= lastSection; section++) {
+ collectSection(slices.existing(section), chunkX << CHUNK_SHIFT, section << SECTION_SHIFT, chunkZ << CHUNK_SHIFT, area, collected);
+ }
+ }
+ }
+ }
+
+ private void collectSection(MatterSlice slice, int originX, int originY, int originZ, BlockBox area, CarvedCells collected) {
+ if (slice == null) {
+ return;
+ }
+ slice.iterateSync((localX, localY, localZ, cavern) -> {
+ int x = originX + localX;
+ int y = originY + localY;
+ int z = originZ + localZ;
+ if (cavern != null && area.contains(x, y, z)) {
+ collected.add(x - area.minX(), y - area.minY(), z - area.minZ(), toApi(cavern));
+ }
+ });
+ }
+
+ private ChunkSlices slicesAt(int chunkX, int chunkZ) {
+ int slot = (chunkX * 31 + chunkZ) & (RECENT_CHUNKS - 1);
+ ChunkSlices known = recent[slot];
+ if (known != null && known.chunkX == chunkX && known.chunkZ == chunkZ) {
+ return known;
+ }
+ MantleChunk chunk = chunks.chunk(chunkX, chunkZ);
+ if (chunk == null) {
+ throw new IllegalStateException("Mantle chunk " + chunkX + ", " + chunkZ + " is inside " + bounds + " but was not prepared");
+ }
+ ChunkSlices created = new ChunkSlices(chunkX, chunkZ, chunk);
+ recent[slot] = created;
+ return created;
+ }
+
+ private CarvedVoid toApi(MatterCavern cavern) {
+ CarvedVoid plain = switch (cavern.getLiquid()) {
+ case LIQUID_FLUID -> CarvedVoid.FLUID;
+ case LIQUID_LAVA -> CarvedVoid.LAVA;
+ case LIQUID_AIR -> CarvedVoid.AIR;
+ default -> CarvedVoid.OPEN;
+ };
+ String biomeKey = cavern.getCustomBiome();
+ return biomeKey == null || biomeKey.isEmpty() ? plain : plain.withBiome(ids.of(biomeKey));
+ }
+
+ private MatterCavern toStored(CarvedVoid value) {
+ if (value == CarvedVoid.OPEN) {
+ return STORED_OPEN;
+ }
+ if (value == CarvedVoid.FLUID) {
+ return STORED_FLUID;
+ }
+ if (value == CarvedVoid.LAVA) {
+ return STORED_LAVA;
+ }
+ if (value == CarvedVoid.AIR) {
+ return STORED_AIR;
+ }
+ return new MatterCavern(true, value.biome().map(this::biomeKey).orElse(""), liquidOf(value.fill()));
+ }
+
+ private static byte liquidOf(CarvedVoid.Fill fill) {
+ return switch (fill) {
+ case OPEN -> LIQUID_OPEN;
+ case FLUID -> LIQUID_FLUID;
+ case LAVA -> LIQUID_LAVA;
+ case AIR -> LIQUID_AIR;
+ };
+ }
+
+ /** The key Iris's biome loader knows the biome by: its path inside this pack, or the whole id for another namespace's. */
+ private String biomeKey(ResourceId biome) {
+ return biome.namespace().equals(ids.namespace()) ? biome.path() : biome.toString();
+ }
+
+ private void requireWritable() {
+ if (!writable) {
+ throw new UnsupportedOperationException(READ_ONLY);
+ }
+ }
+
+ private void requireInside(int x, int y, int z) {
+ if (!bounds.contains(x, y, z)) {
+ throw new IndexOutOfBoundsException("Block " + x + ", " + y + ", " + z + " is outside the mantle this invocation prepared, " + bounds);
+ }
+ }
+
+ private void requireInside(BlockBox area) {
+ Objects.requireNonNull(area, "area");
+ if (!bounds.contains(area)) {
+ throw new IndexOutOfBoundsException("Area " + area + " is not inside the mantle this invocation prepared, " + bounds);
+ }
+ }
+
+ /** The cavern slices of one mantle chunk's sections, found once. */
+ private static final class ChunkSlices {
+ private final int chunkX;
+ private final int chunkZ;
+ private final MantleChunk chunk;
+ private final MatterSlice>[] bySection;
+
+ ChunkSlices(int chunkX, int chunkZ, MantleChunk chunk) {
+ this.chunkX = chunkX;
+ this.chunkZ = chunkZ;
+ this.chunk = chunk;
+ this.bySection = new MatterSlice>[chunk.sectionCount()];
+ }
+
+ /** The section's cavern slice, or null when it has none; nothing is created. */
+ @SuppressWarnings("unchecked")
+ MatterSlice existing(int section) {
+ MatterSlice known = (MatterSlice) bySection[section];
+ if (known != null) {
+ return known;
+ }
+ if (!chunk.exists(section)) {
+ return null;
+ }
+ Matter matter = chunk.get(section);
+ if (matter == null || !matter.hasSlice(MatterCavern.class)) {
+ return null;
+ }
+ MatterSlice found = matter.getSlice(MatterCavern.class);
+ bySection[section] = found;
+ return found;
+ }
+
+ @SuppressWarnings("unchecked")
+ MatterSlice creating(int section) {
+ MatterSlice known = (MatterSlice) bySection[section];
+ if (known != null) {
+ return known;
+ }
+ MatterSlice created = chunk.getOrCreate(section).slice(MatterCavern.class);
+ bySection[section] = created;
+ return created;
+ }
+ }
+}
diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java b/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java
index 58e8990de..a1922e745 100644
--- a/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java
+++ b/core/src/main/java/art/arcane/iris/core/modules/IrisGenerationContext.java
@@ -18,7 +18,6 @@
package art.arcane.iris.core.modules;
-import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.spi.PlatformBlockState;
import com.volmit.block.BlockState;
@@ -44,7 +43,6 @@ final class IrisGenerationContext implements GenerationContext {
/** The mantle too reaches this far around the chunk; chunks beyond its own are pinned when a stage first reads them. */
private static final int MANTLE_MARGIN_BLOCKS = 16;
private static final int CHUNK_WIDTH = 16;
- private static final int CHUNK_SHIFT = 4;
private final Engine engine;
private final int originX;
@@ -73,7 +71,7 @@ final class IrisGenerationContext implements GenerationContext {
this.settings = new ChunkModuleSettings(engine, ids);
BlockBox chunk = ApiHeights.columns(engine, originX - MANTLE_MARGIN_BLOCKS, originZ - MANTLE_MARGIN_BLOCKS,
originX + CHUNK_WIDTH + MANTLE_MARGIN_BLOCKS, originZ + CHUNK_WIDTH + MANTLE_MARGIN_BLOCKS);
- this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers, PlannedBlocks.of(engine, chunk, mantleChunks, states));
+ this.mantle = new IrisModuleMantle(chunk, mantleChunks, mantleLayers, PlannedBlocks.of(engine, chunk, mantleChunks, states), ids);
}
@Override
@@ -106,15 +104,12 @@ final class IrisGenerationContext implements GenerationContext {
return blocks;
}
- /** Iris's own view of the chunk, and the matter of its own chunk with loaded-only reads of its neighbours. */
+ /** Iris's own view of the chunk. */
@Override
public Optional extension(Class type) {
if (type == IrisChunk.class) {
return HostExtensions.as(type, irisChunk);
}
- if (type == MatterMantle.class) {
- return HostExtensions.as(type, new OwnChunkMatter(mantle, originX >> CHUNK_SHIFT, originZ >> CHUNK_SHIFT));
- }
return Optional.empty();
}
diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java b/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java
index 5c76d00cd..348fa7186 100644
--- a/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java
+++ b/core/src/main/java/art/arcane/iris/core/modules/IrisMantleGenerationContext.java
@@ -18,7 +18,6 @@
package art.arcane.iris.core.modules;
-import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.util.common.data.B;
import com.volmit.config.FeatureSettings;
@@ -67,7 +66,7 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
BlockBox reach = ApiHeights.columns(engine, originX - reachBlocks, originZ - reachBlocks,
originX + CHUNK_WIDTH + reachBlocks, originZ + CHUNK_WIDTH + reachBlocks);
PlannedBlocks plannedBlocks = PlannedBlocks.of(engine, reach, chunks, new PlatformBlockStates(B::getState));
- this.mantle = new IrisModuleMantle(reach, chunks, layers, plannedBlocks);
+ this.mantle = new IrisModuleMantle(reach, chunks, layers, plannedBlocks, ids);
}
@Override
@@ -95,19 +94,15 @@ final class IrisMantleGenerationContext implements MantleGenerationContext {
return mantle;
}
- /** Iris's own view of the chunk, and the matter of the mantle as far as the stage reaches. */
+ /** Iris's own view of the chunk. */
@Override
public Optional extension(Class type) {
if (type == IrisMantleChunk.class) {
return HostExtensions.as(type, irisChunk);
}
- if (type == MatterMantle.class) {
- return HostExtensions.as(type, mantle);
- }
return Optional.empty();
}
-
/** The chunk's mantle as Iris's object placer writes it, within the chunk's reach. */
@Override
public PlacementTerrain placementTerrain() {
diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisModuleMantle.java b/core/src/main/java/art/arcane/iris/core/modules/IrisModuleMantle.java
index 6f75ee06c..8ab12706c 100644
--- a/core/src/main/java/art/arcane/iris/core/modules/IrisModuleMantle.java
+++ b/core/src/main/java/art/arcane/iris/core/modules/IrisModuleMantle.java
@@ -27,8 +27,8 @@ import art.arcane.iris.spi.IrisPlatforms;
import com.volmit.block.BlockState;
import com.volmit.resource.ResourceId;
import com.volmit.host.MantleRegistration;
-import art.arcane.iris.builtin.MatterMantle;
import com.volmit.geometry.BlockBox;
+import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle;
import com.volmit.data.Codec;
import com.volmit.mantle.MantleEdit;
@@ -58,7 +58,7 @@ import java.util.stream.Collectors;
* lose each other's layers. {@link #edit()} buffers changes across layers until they are committed; while an
* edit is open, the view itself only reads.
*/
-final class IrisModuleMantle implements Mantle, MatterMantle {
+final class IrisModuleMantle implements Mantle {
private static final int CHUNK_SHIFT = 4;
private static final int SECTION_SHIFT = 4;
private static final int LOCAL_MASK = 15;
@@ -70,24 +70,24 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
/** The mantle chunk at chunk coordinates, or null when it is outside what the invocation prepared. */
interface Chunks {
MantleChunk chunk(int chunkX, int chunkZ);
-
- /** The chunk if the world holds it in memory, whether or not the invocation reaches it; never loads one. */
- default MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return null;
- }
}
private final BlockBox bounds;
private final Chunks chunks;
private final Map> registrations;
private final PlannedBlocks plannedBlocks;
+ private final PackResourceIds ids;
+ private CarvedVoids carved;
+ private CarvedVoids carvedReadOnly;
private BufferedEdit openEdit;
- IrisModuleMantle(BlockBox bounds, Chunks chunks, Collection> registrations, PlannedBlocks plannedBlocks) {
+ IrisModuleMantle(BlockBox bounds, Chunks chunks, Collection> registrations, PlannedBlocks plannedBlocks,
+ PackResourceIds ids) {
this.bounds = bounds;
this.chunks = chunks;
this.registrations = registrations.stream().collect(Collectors.toMap(registration -> registration.key().id(), Function.identity()));
this.plannedBlocks = plannedBlocks;
+ this.ids = ids;
}
@Override
@@ -95,16 +95,6 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
return bounds;
}
- @Override
- public MantleChunk chunk(int chunkX, int chunkZ) {
- return chunks.chunk(chunkX, chunkZ);
- }
-
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return chunks.loadedChunk(chunkX, chunkZ);
- }
-
@Override
public MantleLayer layer(MantleKey key) {
return new Layer<>(key, codecOf(key));
@@ -115,6 +105,22 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
return plannedBlocks;
}
+ @Override
+ public MantleLayer carved() {
+ if (carved == null) {
+ carved = new CarvedVoids(bounds, chunks, ids, true);
+ }
+ return carved;
+ }
+
+ /** What an edit shows of the carved voids: they are planned on the mantle itself, as platform biomes are. */
+ private MantleLayer carvedForEdit() {
+ if (carvedReadOnly == null) {
+ carvedReadOnly = new CarvedVoids(bounds, chunks, ids, false);
+ }
+ return carvedReadOnly;
+ }
+
@Override
public boolean isCarved(int x, int y, int z) {
return new MantleCaverns(bounds, chunks).isCarved(x, y, z);
@@ -277,6 +283,12 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
return plannedBlocks;
}
+ @Override
+ public MantleLayer carved() {
+ requireOpen();
+ return carvedForEdit();
+ }
+
@Override
public boolean isCarved(int x, int y, int z) {
requireOpen();
diff --git a/core/src/main/java/art/arcane/iris/core/modules/OwnChunkMatter.java b/core/src/main/java/art/arcane/iris/core/modules/OwnChunkMatter.java
deleted file mode 100644
index 08acfe568..000000000
--- a/core/src/main/java/art/arcane/iris/core/modules/OwnChunkMatter.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Iris is a World Generator for Minecraft Servers
- * Copyright (c) 2026 Arcane Arts (Volmit Software)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-package art.arcane.iris.core.modules;
-
-import art.arcane.iris.builtin.MatterMantle;
-import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
-import art.arcane.volmlib.util.matter.Matter;
-
-/**
- * The matter mantle of a chunk invocation: its own chunk, which a chunk stage writes as it writes the mantle layers of
- * its own chunk, and its neighbours only as far as the world already holds them in memory.
- */
-final class OwnChunkMatter implements MatterMantle {
- private final MatterMantle mantle;
- private final int chunkX;
- private final int chunkZ;
-
- OwnChunkMatter(MatterMantle mantle, int chunkX, int chunkZ) {
- this.mantle = mantle;
- this.chunkX = chunkX;
- this.chunkZ = chunkZ;
- }
-
- @Override
- public MantleChunk chunk(int chunkX, int chunkZ) {
- if (chunkX != this.chunkX || chunkZ != this.chunkZ) {
- return null;
- }
- return mantle.chunk(chunkX, chunkZ);
- }
-
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return mantle.loadedChunk(chunkX, chunkZ);
- }
-}
diff --git a/core/src/main/java/art/arcane/iris/core/modules/PinnedMantleChunks.java b/core/src/main/java/art/arcane/iris/core/modules/PinnedMantleChunks.java
index 06921b851..a45da4eb6 100644
--- a/core/src/main/java/art/arcane/iris/core/modules/PinnedMantleChunks.java
+++ b/core/src/main/java/art/arcane/iris/core/modules/PinnedMantleChunks.java
@@ -19,9 +19,7 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.engine.framework.Engine;
-import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
-import art.arcane.volmlib.util.mantle.runtime.TectonicPlate;
import art.arcane.volmlib.util.matter.Matter;
import java.util.HashMap;
@@ -32,10 +30,6 @@ import java.util.Map;
* released together once the placement is committed or discarded.
*/
final class PinnedMantleChunks implements IrisModuleMantle.Chunks, AutoCloseable {
- /** A tectonic plate holds 32 by 32 chunks. */
- private static final int PLATE_SHIFT = 5;
- private static final int PLATE_MASK = (1 << PLATE_SHIFT) - 1;
-
private final Engine engine;
private final Map> pinned = new HashMap<>();
@@ -48,16 +42,6 @@ final class PinnedMantleChunks implements IrisModuleMantle.Chunks, AutoCloseable
return pinned.computeIfAbsent(key(chunkX, chunkZ), ignored -> engine.getMantle().getMantle().getChunk(chunkX, chunkZ).use());
}
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- Mantle mantle = engine.getMantle().getMantle();
- TectonicPlate plate = mantle.getLoadedRegions().get(Mantle.key(chunkX >> PLATE_SHIFT, chunkZ >> PLATE_SHIFT));
- if (plate == null || plate.isClosed()) {
- return null;
- }
- return plate.get(chunkX & PLATE_MASK, chunkZ & PLATE_MASK);
- }
-
@Override
public synchronized void close() {
pinned.values().forEach(MantleChunk::release);
diff --git a/core/src/main/java/art/arcane/iris/core/modules/PlacementMantle.java b/core/src/main/java/art/arcane/iris/core/modules/PlacementMantle.java
index e70dd72bf..72ef33109 100644
--- a/core/src/main/java/art/arcane/iris/core/modules/PlacementMantle.java
+++ b/core/src/main/java/art/arcane/iris/core/modules/PlacementMantle.java
@@ -23,6 +23,7 @@ import art.arcane.iris.util.common.data.B;
import com.volmit.block.BlockState;
import com.volmit.host.MantleRegistration;
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;
@@ -53,7 +54,8 @@ final class PlacementMantle implements Mantle, AutoCloseable {
this.storedBounds = ApiHeights.columns(engine, area.minX(), area.minZ(), area.maxX(), area.maxZ());
this.chunks = new PinnedMantleChunks(engine);
PlannedBlocks plannedBlocks = PlannedBlocks.of(engine, storedBounds, chunks, new PlatformBlockStates(B::getState));
- this.placement = new IrisModuleMantle(storedBounds, chunks, layers, plannedBlocks).edit();
+ this.placement = new IrisModuleMantle(storedBounds, chunks, layers, plannedBlocks,
+ new PackResourceIds(engine.getData().getDataFolder())).edit();
}
@Override
@@ -71,6 +73,11 @@ final class PlacementMantle implements Mantle, AutoCloseable {
return new StoredRange<>(placement.blocks());
}
+ @Override
+ public MantleLayer carved() {
+ return new StoredRange<>(placement.carved());
+ }
+
@Override
public boolean isCarved(int x, int y, int z) {
if (!bounds.contains(x, y, z)) {
diff --git a/core/src/test/java/art/arcane/iris/core/modules/InMemoryMantle.java b/core/src/test/java/art/arcane/iris/core/modules/InMemoryMantle.java
index 3387bd5dc..7c20900cd 100644
--- a/core/src/test/java/art/arcane/iris/core/modules/InMemoryMantle.java
+++ b/core/src/test/java/art/arcane/iris/core/modules/InMemoryMantle.java
@@ -13,9 +13,13 @@ import art.arcane.volmlib.util.matter.IrisMatter;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterSlice;
import com.volmit.data.Codec;
+import com.volmit.geometry.BlockBox;
+import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.MantleKey;
+import com.volmit.mantle.MantleLayer;
import java.io.DataOutputStream;
+import java.io.File;
import java.util.HashMap;
import java.util.Map;
@@ -25,6 +29,8 @@ import static org.mockito.Mockito.when;
/** A mantle held in memory, for tests of what stages write into it. Bind an engine to it before the engine's mantle is used. */
public final class InMemoryMantle {
+ public static final int REACH_BLOCKS = 1024;
+
private final int sections;
private final Map> chunks = new HashMap<>();
@@ -34,6 +40,12 @@ public final class InMemoryMantle {
this.sections = sections;
}
+ /** The carved voids of this mantle as a mantle stage writes them, over the columns from -{@link #REACH_BLOCKS} up to {@link #REACH_BLOCKS}. */
+ public MantleLayer carved() {
+ BlockBox reach = new BlockBox(-REACH_BLOCKS, 0, -REACH_BLOCKS, REACH_BLOCKS, sections * 16, REACH_BLOCKS);
+ return new CarvedVoids(reach, this::chunk, new PackResourceIds(new File("test")), true);
+ }
+
public MantleChunk chunk(int chunkX, int chunkZ) {
return chunks.computeIfAbsent(((long) chunkX << 32) ^ (chunkZ & 0xffffffffL), ignored ->
new MantleChunk<>(sections, chunkX, chunkZ, new Sections(), MantleHooks.NONE));
diff --git a/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java b/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java
index 4b9b082c9..ff0ee24aa 100644
--- a/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java
+++ b/core/src/test/java/art/arcane/iris/core/modules/IrisModuleMantleTest.java
@@ -18,7 +18,6 @@
package art.arcane.iris.core.modules;
-import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.SeedManager;
@@ -37,7 +36,9 @@ import art.arcane.volmlib.util.mantle.runtime.MantleHooks;
import art.arcane.volmlib.util.matter.IrisMatter;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterBiomeInject;
+import art.arcane.volmlib.util.matter.MatterCavern;
import art.arcane.volmlib.util.matter.MatterSlice;
+import com.volmit.mantle.CarvedVoid;
import com.volmit.resource.ResourceId;
import com.volmit.block.BlockState;
import com.volmit.IrisModule;
@@ -73,7 +74,9 @@ import java.util.Set;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -85,6 +88,7 @@ public class IrisModuleMantleTest {
private static final int WORLD_MIN_HEIGHT = -64;
private static final int SECTIONS = 4;
private static final int HEIGHT = SECTIONS * 16;
+ private static final PackResourceIds IDS = new PackResourceIds(new java.io.File("pack"));
private static final MantleKey MARKS = new MantleKey<>("iris:marks/mark", String.class);
private static final MantleKey DEPTHS = new MantleKey<>("iris:marks/depth", Integer.class);
private static final Codec TEXT = new Codec<>() {
@@ -117,7 +121,7 @@ public class IrisModuleMantleTest {
}
private IrisModuleMantle mantle(BlockBox bounds) {
- return new IrisModuleMantle(bounds, this::chunk, LAYERS, PlannedBlocks.none(bounds));
+ return new IrisModuleMantle(bounds, this::chunk, LAYERS, PlannedBlocks.none(bounds), IDS);
}
/** The form the floating islands' sky biomes always had: the platform's id for the biome, as a custom inject, at the height above the bottom. */
@@ -148,22 +152,111 @@ public class IrisModuleMantleTest {
}
@Test
- public void theMatterSideGivesTheMantleChunksTheInvocationReachesAndNoOthers() {
- IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
- MatterMantle matter = mantle;
+ public void carvedVoidsAreKeptAsTheCavernsIrisReadsAndReadBackAsTheirFills() {
+ IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 32, HEIGHT, 32));
- org.junit.Assert.assertSame(chunk(3, 4), matter.chunk(3, 4));
- org.junit.Assert.assertNull("nothing is loaded that the host did not say is", matter.loadedChunk(3, 4));
+ mantle.carved().set(-3, 7, 20, CarvedVoid.OPEN);
+ mantle.carved().set(5, 40, 5, CarvedVoid.FLUID);
+ mantle.carved().set(6, 40, 5, CarvedVoid.LAVA);
+ mantle.carved().set(7, 40, 5, CarvedVoid.AIR);
+
+ assertEquals(new MatterCavern(true, "", (byte) 0), chunk(-1, 1).get(13, 7, 4, MatterCavern.class));
+ assertEquals(new MatterCavern(true, "", (byte) 1), chunk(0, 0).get(5, 40, 5, MatterCavern.class));
+ assertEquals(new MatterCavern(true, "", (byte) 2), chunk(0, 0).get(6, 40, 5, MatterCavern.class));
+ assertEquals(new MatterCavern(true, "", (byte) 3), chunk(0, 0).get(7, 40, 5, MatterCavern.class));
+ assertSame(CarvedVoid.OPEN, mantle.carved().get(-3, 7, 20));
+ assertSame(CarvedVoid.FLUID, mantle.carved().get(5, 40, 5));
+ assertSame(CarvedVoid.LAVA, mantle.carved().get(6, 40, 5));
+ assertSame(CarvedVoid.AIR, mantle.carved().get(7, 40, 5));
+ assertNull(mantle.carved().get(8, 40, 5));
+ assertTrue(mantle.isCarved(5, 40, 5));
+ assertFalse(mantle.isCarved(8, 40, 5));
}
@Test
- public void aChunkInvocationsMatterHoldsItsOwnChunkAndReadsNeighboursOnlyWhenLoaded() {
- IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 48, HEIGHT, 48));
- MatterMantle own = new OwnChunkMatter(mantle, 1, 1);
+ public void cavernsOfAnyOtherLiquidReadAsOpenAndKeepTheirCustomBiomeAsAPackId() {
+ IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
+ chunk(0, 0).getOrCreate(0).slice(MatterCavern.class).set(1, 2, 3, new MatterCavern(true, "", (byte) 9));
+ chunk(0, 0).getOrCreate(0).slice(MatterCavern.class).set(2, 2, 3, new MatterCavern(true, "cave/lush", (byte) 3));
- org.junit.Assert.assertSame(chunk(1, 1), own.chunk(1, 1));
- org.junit.Assert.assertNull("a neighbour is no chunk of the invocation's own", own.chunk(2, 1));
- org.junit.Assert.assertNull("a neighbour the world does not hold is not read", own.loadedChunk(2, 1));
+ assertSame(CarvedVoid.OPEN, mantle.carved().get(1, 2, 3));
+ assertEquals(CarvedVoid.AIR.withBiome(IDS.of("cave/lush")), mantle.carved().get(2, 2, 3));
+
+ mantle.carved().set(3, 2, 3, CarvedVoid.LAVA.withBiome(IDS.of("cave/lush")));
+ assertEquals(new MatterCavern(true, "cave/lush", (byte) 2), chunk(0, 0).get(3, 2, 3, MatterCavern.class));
+ }
+
+ @Test
+ public void carvedVoidsVisitInOrderAndClearOnlyTheirArea() {
+ IrisModuleMantle mantle = mantle(new BlockBox(-16, 0, -16, 32, HEIGHT, 32));
+ mantle.carved().set(17, 5, 3, CarvedVoid.LAVA);
+ mantle.carved().set(-2, 9, 3, CarvedVoid.OPEN);
+ mantle.carved().set(-2, 4, 20, CarvedVoid.FLUID);
+ mantle.carved().set(-2, 4, 3, CarvedVoid.AIR);
+ List visited = new java.util.ArrayList<>();
+
+ mantle.carved().visit(new BlockBox(-16, 0, -16, 32, HEIGHT, 32), (x, y, z, carved) -> visited.add(x + "," + y + "," + z + " " + carved.fill()));
+
+ assertEquals(List.of("-2,4,3 AIR", "-2,4,20 FLUID", "-2,9,3 OPEN", "17,5,3 LAVA"), visited);
+
+ mantle.carved().clear(new BlockBox(-16, 0, -16, 0, HEIGHT, 32));
+ assertNull(mantle.carved().get(-2, 9, 3));
+ assertSame(CarvedVoid.LAVA, mantle.carved().get(17, 5, 3));
+ mantle.carved().remove(17, 5, 3);
+ assertFalse(mantle.isCarved(17, 5, 3));
+ }
+
+ @Test
+ public void carvedVoidsOfAnAreaTooLargeToLayOutVisitInTheSameOrder() {
+ BlockBox wide = new BlockBox(0, 0, 0, 1024, HEIGHT, 80);
+ IrisModuleMantle mantle = mantle(wide);
+ CarvedVoid lush = CarvedVoid.AIR.withBiome(IDS.of("cave/lush"));
+ mantle.carved().set(1000, 5, 70, CarvedVoid.LAVA);
+ mantle.carved().set(3, 9, 70, lush);
+ mantle.carved().set(3, 9, 5, CarvedVoid.OPEN);
+ mantle.carved().set(3, 2, 75, CarvedVoid.FLUID);
+ mantle.carved().set(500, 63, 0, lush);
+ List visited = new java.util.ArrayList<>();
+
+ mantle.carved().visit(wide, (x, y, z, carved) -> visited.add(x + "," + y + "," + z + " " + carved.fill() + carved.biome().map(id -> " " + id.path()).orElse("")));
+
+ assertEquals(List.of("3,2,75 FLUID", "3,9,5 OPEN", "3,9,70 AIR cave/lush", "500,63,0 AIR cave/lush", "1000,5,70 LAVA"), visited);
+ }
+
+ @Test
+ public void aVisitInsideAVisitReadsItsOwnArea() {
+ IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
+ mantle.carved().set(1, 2, 3, CarvedVoid.OPEN);
+ mantle.carved().set(4, 5, 6, CarvedVoid.LAVA);
+ List visited = new java.util.ArrayList<>();
+
+ mantle.carved().visit(new BlockBox(0, 0, 0, 16, HEIGHT, 16), (x, y, z, outer) -> {
+ visited.add("outer " + outer.fill());
+ mantle.carved().visit(new BlockBox(4, 5, 6, 5, 6, 7), (nx, ny, nz, inner) -> visited.add("inner " + inner.fill()));
+ });
+
+ assertEquals(List.of("outer OPEN", "inner LAVA", "outer LAVA", "inner LAVA"), visited);
+ }
+
+ @Test
+ public void carvedVoidsStayInsideTheMantleAnInvocationPrepared() {
+ IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
+
+ assertThrows(IndexOutOfBoundsException.class, () -> mantle.carved().set(16, 5, 5, CarvedVoid.OPEN));
+ assertThrows(IndexOutOfBoundsException.class, () -> mantle.carved().get(5, HEIGHT, 5));
+ assertThrows(IndexOutOfBoundsException.class, () -> mantle.carved().visit(new BlockBox(0, 0, 0, 17, 1, 1), (x, y, z, carved) -> { }));
+ }
+
+ @Test
+ public void anEditOnlyReadsTheCarvedVoids() {
+ IrisModuleMantle mantle = mantle(new BlockBox(0, 0, 0, 16, HEIGHT, 16));
+ mantle.carved().set(1, 2, 3, CarvedVoid.OPEN);
+
+ try (MantleEdit edit = mantle.edit()) {
+ assertSame(CarvedVoid.OPEN, edit.carved().get(1, 2, 3));
+ assertThrows(UnsupportedOperationException.class, () -> edit.carved().set(1, 2, 4, CarvedVoid.OPEN));
+ assertThrows(UnsupportedOperationException.class, () -> edit.carved().remove(1, 2, 3));
+ }
}
@Test
@@ -278,7 +371,7 @@ public class IrisModuleMantleTest {
public void aCommitThatCannotReachEveryChunkPublishesNothing() {
BlockBox bounds = new BlockBox(0, 0, 0, 32, HEIGHT, 16);
IrisModuleMantle mantle = new IrisModuleMantle(bounds, (chunkX, chunkZ) -> chunkX == 0 ? chunk(chunkX, chunkZ) : null, LAYERS,
- PlannedBlocks.none(bounds));
+ PlannedBlocks.none(bounds), IDS);
MantleEdit edit = mantle.edit();
edit.layer(MARKS).set(1, 4, 1, "first");
edit.layer(MARKS).set(20, 4, 1, "unprepared");
@@ -344,7 +437,7 @@ public class IrisModuleMantleTest {
new IrisMantleChunk(engine, null, 0, 0, null));
BlockBox neighborBounds = new BlockBox(16, 0, 0, 32, HEIGHT, 16);
- IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds));
+ IrisModuleMantle neighbor = new IrisModuleMantle(neighborBounds, this::chunk, pack.catalog().mantle(), PlannedBlocks.none(neighborBounds), IDS);
assertEquals("vein", neighbor.layer(planned).get(20, 34, 3));
}
assertTrue(chunks.containsKey(1L << 32));
diff --git a/core/src/test/java/art/arcane/iris/core/modules/PlacementMantleTest.java b/core/src/test/java/art/arcane/iris/core/modules/PlacementMantleTest.java
index 593a8d3e3..d534e2739 100644
--- a/core/src/test/java/art/arcane/iris/core/modules/PlacementMantleTest.java
+++ b/core/src/test/java/art/arcane/iris/core/modules/PlacementMantleTest.java
@@ -1,7 +1,10 @@
package art.arcane.iris.core.modules;
+import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.UsableBlockPlatform;
import art.arcane.iris.engine.framework.Engine;
+import art.arcane.volmlib.util.matter.MatterCavern;
+import com.volmit.mantle.CarvedVoid;
import com.volmit.placement.PlacementTerrain;
import com.volmit.host.MantleRegistration;
import com.volmit.geometry.BlockBox;
@@ -14,6 +17,7 @@ import org.junit.Test;
import java.io.DataInput;
import java.io.DataOutput;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -21,6 +25,7 @@ import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -55,6 +60,9 @@ public class PlacementMantleTest {
private Engine engine() {
Engine engine = mock(Engine.class);
when(engine.getHeight()).thenReturn(HEIGHT);
+ IrisData data = mock(IrisData.class);
+ when(data.getDataFolder()).thenReturn(new File("pack"));
+ when(engine.getData()).thenReturn(data);
storage.bindTo(engine);
return engine;
}
@@ -67,6 +75,18 @@ public class PlacementMantleTest {
return storage.value(MARKS, TEXT, x, Y, z);
}
+ @Test
+ public void aPlacementReadsTheCarvedVoidsButNeverWritesThem() {
+ storage.chunk(0, 0).getOrCreate(Y >> 4).slice(MatterCavern.class).set(1, Y & 15, 1, new MatterCavern(true, "", (byte) 1));
+ TerrainEdit placement = edit(engine());
+
+ assertSame(CarvedVoid.FLUID, placement.mantle().carved().get(1, Y, 1));
+ assertNull(placement.mantle().carved().get(2, Y, 1));
+ assertThrows(UnsupportedOperationException.class, () -> placement.mantle().carved().set(2, Y, 1, CarvedVoid.OPEN));
+ assertThrows(UnsupportedOperationException.class, () -> placement.mantle().carved().remove(1, Y, 1));
+ assertThrows(IndexOutOfBoundsException.class, () -> placement.mantle().carved().get(100, Y, 1));
+ }
+
@Test
public void writesReachTheMantleTogetherWhenThePlacementCommits() {
TerrainEdit placement = edit(engine());
diff --git a/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveAnchorsTest.java b/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveAnchorsTest.java
index 631bbfc6f..a5dc37e67 100644
--- a/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveAnchorsTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveAnchorsTest.java
@@ -2,7 +2,7 @@ package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.carve.CaveAnchorMode;
import art.arcane.iris.modules.objects.CarvedSpace;
-import art.arcane.iris.modules.objects.Cavern;
+import com.volmit.mantle.CarvedVoid;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.resource.ResourceId;
import com.volmit.world.BiomeSample;
@@ -92,8 +92,8 @@ public class CaveAnchorsTest {
}
return column;
});
- when(cave.cavernAt(anyInt(), anyInt(), anyInt())).thenAnswer(call ->
- isCarved(call.getArgument(1)) ? Optional.of(new Cavern(true, (byte) 0)) : Optional.empty());
+ when(cave.voidAt(anyInt(), anyInt(), anyInt())).thenAnswer(call ->
+ isCarved(call.getArgument(1)) ? Optional.of(CarvedVoid.OPEN) : Optional.empty());
return cave;
}
diff --git a/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveCarvingTest.java b/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveCarvingTest.java
index 95d431c84..b976bedd6 100644
--- a/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveCarvingTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveCarvingTest.java
@@ -18,14 +18,11 @@
package art.arcane.iris.engine.mantle.components;
-import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.core.modules.CarveTestTerrain;
import art.arcane.iris.core.modules.CarveTestWorld;
import art.arcane.iris.core.modules.InMemoryMantle;
import art.arcane.iris.engine.object.TestSettings;
-import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
-import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterCavern;
import com.volmit.config.Level;
import com.volmit.config.Range;
@@ -102,20 +99,9 @@ public class CaveCarvingTest {
BiomeSample sample = new BiomeSample(CarveTestWorld.id("region"), CarveTestWorld.id("plains"), Optional.of(CarveTestWorld.id("cave/lush")));
return new BiomeSample(sample.region(), sample.surfaceBiome(), Optional.of(caveBiomeOf.apply(sample)));
});
- MatterMantle matter = new MatterMantle() {
- @Override
- public MantleChunk chunk(int chunkX, int chunkZ) {
- return mantle.chunk(chunkX, chunkZ);
- }
-
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return null;
- }
- };
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), 1337L, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
- new CaveCarving(world, carveWorld, false, (x, z) -> false).carve(matter, terrain, 0, 0);
+ new CaveCarving(world, carveWorld, false, (x, z) -> false).carve(mantle.carved(), terrain, 0, 0);
int[] count = new int[1];
mantle.chunk(0, 0).iterate(MatterCavern.class, (x, y, z, cavern) -> count[0]++);
diff --git a/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveFloorMarkingTest.java b/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveFloorMarkingTest.java
new file mode 100644
index 000000000..302e546d6
--- /dev/null
+++ b/core/src/test/java/art/arcane/iris/engine/mantle/components/CaveFloorMarkingTest.java
@@ -0,0 +1,109 @@
+package art.arcane.iris.engine.mantle.components;
+
+import art.arcane.iris.core.modules.CarveTestTerrain;
+import art.arcane.iris.core.modules.CarveTestWorld;
+import art.arcane.iris.core.modules.InMemoryMantle;
+import com.volmit.mantle.CarvedVoid;
+import com.volmit.mantle.MantleLayer;
+import com.volmit.placement.PlacedMarker;
+import com.volmit.placement.PlacementTerrain;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+
+/** The floors of the caves a chunk was planned with are marked for the spawners: one in sixteen of the runs of three or more voids, by seed and position alone. */
+public class CaveFloorMarkingTest {
+ private static final int HEIGHT = 128;
+ private static final int FLUID_HEIGHT = 40;
+ private static final int SURFACE = 100;
+ private static final int FLOOR_Y = 10;
+ private static final int CEILING_Y = 13;
+
+ private final InMemoryMantle mantle = new InMemoryMantle(HEIGHT / 16);
+ private final List marks = new ArrayList<>();
+ private final PlacementTerrain placement = mock(PlacementTerrain.class);
+ private CarveTestTerrain terrain;
+ private MantleLayer voids;
+
+ @Before
+ public void setUp() {
+ voids = mantle.carved();
+ terrain = new CarveTestTerrain(0, 0, HEIGHT, FLUID_HEIGHT, (x, z) -> SURFACE);
+ doAnswer(call -> marks.add(call.getArgument(0))).when(placement).mark(any());
+ }
+
+ @Test
+ public void everyMarkIsTheLowestBlockOfARunAndTheSameSeedMarksTheSameFloors() {
+ carveEveryColumn(FLOOR_Y, CEILING_Y, CarvedVoid.OPEN);
+
+ mark(1L);
+ List first = List.copyOf(marks);
+ marks.clear();
+ mark(1L);
+
+ assertTrue("about one in sixteen of the 256 floors", !first.isEmpty() && first.size() < 64);
+ assertEquals(first, marks);
+ for (PlacedMarker marker : first) {
+ PlacedMarker.PackMarker floor = (PlacedMarker.PackMarker) marker;
+ assertEquals("cave_floor", floor.key());
+ assertEquals(FLOOR_Y, floor.position().y());
+ }
+ marks.clear();
+ mark(2L);
+ assertTrue("another seed rolls other floors", !marks.equals(first));
+ }
+
+ @Test
+ public void runsShorterThanThreeBlocksHaveNoFloor() {
+ carveEveryColumn(FLOOR_Y, FLOOR_Y + 1, CarvedVoid.OPEN);
+
+ mark(1L);
+
+ assertTrue(marks.isEmpty());
+ }
+
+ @Test
+ public void openVoidsHeldByTheTerrainsFluidAreNotCaveFloorsButExplicitOnesAre() {
+ terrain = new CarveTestTerrain(0, 0, HEIGHT, 60, (x, z) -> 20);
+ carveEveryColumn(FLUID_HEIGHT + 5, FLUID_HEIGHT + 8, CarvedVoid.OPEN);
+ mark(1L);
+ assertTrue("water above the sea floor", marks.isEmpty());
+
+ carveEveryColumn(FLUID_HEIGHT + 5, FLUID_HEIGHT + 8, CarvedVoid.AIR);
+ mark(1L);
+ assertTrue(!marks.isEmpty());
+ }
+
+ @Test
+ public void nothingBelowADimensionStackedAboveItsFloorIsMarked() {
+ terrain = new CarveTestTerrain(0, 0, HEIGHT, FLUID_HEIGHT, (x, z) -> SURFACE).upperDimension((x, z) -> FLOOR_Y + 2);
+ carveEveryColumn(FLOOR_Y, CEILING_Y, CarvedVoid.OPEN);
+
+ mark(1L);
+
+ assertTrue("only two blocks of the run lie below the dimension above", marks.isEmpty());
+ }
+
+ private void mark(long seed) {
+ CarveWorld world = new CarveWorld(new CarveTestWorld().resources().noise(), seed, HEIGHT, FLUID_HEIGHT, 8, CarveTestWorld.MIN_HEIGHT);
+ new CaveFloorMarking(world, false).mark(voids, terrain, placement, 0, 0);
+ }
+
+ private void carveEveryColumn(int floorY, int ceilingY, CarvedVoid carvedVoid) {
+ for (int x = 0; x < 16; x++) {
+ for (int z = 0; z < 16; z++) {
+ for (int y = floorY; y <= ceilingY; y++) {
+ voids.set(x, y, z, carvedVoid);
+ }
+ }
+ }
+ }
+}
diff --git a/core/src/test/java/art/arcane/iris/engine/mantle/components/IrisCaveCarver3DNearParityTest.java b/core/src/test/java/art/arcane/iris/engine/mantle/components/IrisCaveCarver3DNearParityTest.java
index 8557f6461..9b71723f1 100644
--- a/core/src/test/java/art/arcane/iris/engine/mantle/components/IrisCaveCarver3DNearParityTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/mantle/components/IrisCaveCarver3DNearParityTest.java
@@ -1,17 +1,16 @@
package art.arcane.iris.engine.mantle.components;
-import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.builtin.carve.CaveFieldModule;
import art.arcane.iris.modules.carve.CaveProfile;
import art.arcane.iris.core.modules.CarveTestWorld;
import art.arcane.iris.modules.terrain.FluidPaletteSettings;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.object.TestSettings;
-import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
-import art.arcane.volmlib.util.matter.Matter;
-import art.arcane.volmlib.util.matter.MatterCavern;
-import art.arcane.volmlib.util.matter.MatterSlice;
import com.volmit.config.Range;
+import com.volmit.geometry.BlockBox;
+import com.volmit.mantle.CarvedVoid;
+import com.volmit.mantle.MantleLayer;
+import com.volmit.mantle.MantleVisitor;
import com.volmit.noise.NoiseSampler;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -30,11 +29,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
public class IrisCaveCarver3DNearParityTest {
private static final int SURFACE_CEILING_FADE_DEPTH = 12;
@@ -50,10 +44,6 @@ public class IrisCaveCarver3DNearParityTest {
private static Field profileField;
private static Field surfaceBreakDensityField;
private static Field thresholdNoiseField;
- private static Field carveAirField;
- private static Field carveFluidField;
- private static Field carveLavaField;
- private static Field carveForcedAirField;
@BeforeClass
public static void setupReflection() throws Exception {
@@ -67,14 +57,6 @@ public class IrisCaveCarver3DNearParityTest {
surfaceBreakDensityField.setAccessible(true);
thresholdNoiseField = IrisCaveCarver3D.class.getDeclaredField("thresholdNoise");
thresholdNoiseField.setAccessible(true);
- carveAirField = IrisCaveCarver3D.class.getDeclaredField("carveAir");
- carveAirField.setAccessible(true);
- carveFluidField = IrisCaveCarver3D.class.getDeclaredField("carveFluid");
- carveFluidField.setAccessible(true);
- carveLavaField = IrisCaveCarver3D.class.getDeclaredField("carveLava");
- carveLavaField.setAccessible(true);
- carveForcedAirField = IrisCaveCarver3D.class.getDeclaredField("carveForcedAir");
- carveForcedAirField.setAccessible(true);
}
@Test
@@ -299,7 +281,7 @@ public class IrisCaveCarver3DNearParityTest {
new IrisCaveCarver3D(engine, supportedProfile).carve(
firstCapture.writer, chunkX, chunkZ, fullWeights(), 0D, 0D, null, surfaceHeights, null, null, supportPlan);
int candidateCount = countLiquid(firstCapture, (byte) 1);
- supportPlan.resolve(firstCapture.writer.chunk(chunkX, chunkZ));
+ supportPlan.resolve(firstCapture.writer, chunkX << 4, chunkZ << 4, firstCapture.worldHeight);
CaveProfile repeatedProfile = TestSettings.with(createFluidProfile(), "densityThreshold", cupThreshold, "fluidMinDepthBelowSurface", 0, "fluidRequiresFloor", true);
WriterCapture secondCapture = createWriterCapture(80);
@@ -321,19 +303,15 @@ public class IrisCaveCarver3DNearParityTest {
@Test
public void finalFluidSupportRejectsUnknownNeighborChunkEdges() {
WriterCapture capture = createWriterCapture(80);
- MantleChunk chunk = capture.writer.chunk(0, 0);
- MatterSlice slice = chunk.getOrCreate(3).slice(MatterCavern.class);
- MatterCavern fluid = new MatterCavern(true, "", (byte) 1);
- MatterCavern air = new MatterCavern(true, "", (byte) 0);
int y = 56;
int z = 8;
- slice.set(0, y & 15, z, fluid);
- slice.set(8, y & 15, z, fluid);
+ capture.writer.set(0, y, z, CarvedVoid.FLUID);
+ capture.writer.set(8, y, z, CarvedVoid.FLUID);
CaveFluidSupportPlan supportPlan = new CaveFluidSupportPlan();
- supportPlan.add(0, y, z, fluid, air);
- supportPlan.add(8, y, z, fluid, air);
+ supportPlan.add(0, y, z);
+ supportPlan.add(8, y, z);
- supportPlan.resolve(chunk);
+ supportPlan.resolve(capture.writer, 0, 0, capture.worldHeight);
assertEquals(Byte.valueOf((byte) 0), capture.carvedLiquids.get(cellKey(0, y, z)));
assertEquals(Byte.valueOf((byte) 1), capture.carvedLiquids.get(cellKey(8, y, z)));
@@ -361,7 +339,7 @@ public class IrisCaveCarver3DNearParityTest {
null, Range.of(fluidY - 1D, fluidY - 1D), fluidSupportPlan);
assertEquals(Byte.valueOf((byte) 1), capture.carvedLiquids.get(fluidCell));
- fluidSupportPlan.resolve(capture.writer.chunk(chunkX, chunkZ));
+ fluidSupportPlan.resolve(capture.writer, chunkX << 4, chunkZ << 4, capture.worldHeight);
assertEquals(Byte.valueOf((byte) 0), capture.carvedLiquids.get(fluidCell));
}
@@ -500,14 +478,10 @@ public class IrisCaveCarver3DNearParityTest {
return elapsed;
}
- private int carveNaiveExact(IrisCaveCarver3D carver, MatterMantle writer, int worldHeight, int chunkX, int chunkZ, double[] columnWeights, Range worldYRange, int[] precomputedSurfaceHeights) throws Exception {
+ private int carveNaiveExact(IrisCaveCarver3D carver, MantleLayer writer, int worldHeight, int chunkX, int chunkZ, double[] columnWeights, Range worldYRange, int[] precomputedSurfaceHeights) throws Exception {
CaveProfile profile = (CaveProfile) profileField.get(carver);
NoiseSampler surfaceBreakDensity = (NoiseSampler) surfaceBreakDensityField.get(carver);
NoiseSampler thresholdNoise = (NoiseSampler) thresholdNoiseField.get(carver);
- MatterCavern carveAir = (MatterCavern) carveAirField.get(carver);
- MatterCavern carveFluid = (MatterCavern) carveFluidField.get(carver);
- MatterCavern carveLava = (MatterCavern) carveLavaField.get(carver);
- MatterCavern carveForcedAir = (MatterCavern) carveForcedAirField.get(carver);
double[] resolvedWeights = columnWeights;
if (resolvedWeights == null || resolvedWeights.length < 256) {
@@ -539,7 +513,7 @@ public class IrisCaveCarver3DNearParityTest {
double[] passThreshold = new double[256];
double[] verticalEdgeFade = computeVerticalEdgeFade(profile, minY, maxY);
double[] surfaceClosureThreshold = computeSurfaceClosureThresholds(profile, minY, maxY);
- MatterCavern[] matterByY = computeMatterByY(profile, carveAir, carveLava, carveForcedAir, minY, maxY);
+ CarvedVoid[] voidByY = computeVoidByY(profile, minY, maxY);
int x0 = chunkX << 4;
int z0 = chunkZ << 4;
@@ -571,12 +545,6 @@ public class IrisCaveCarver3DNearParityTest {
}
}
- @SuppressWarnings("unchecked")
- MantleChunk chunk = writer.chunk(chunkX, chunkZ);
- if (chunk == null) {
- return 0;
- }
-
int carved = 0;
for (int localX = 0; localX < 16; localX++) {
int x = x0 + localX;
@@ -608,14 +576,11 @@ public class IrisCaveCarver3DNearParityTest {
continue;
}
- Matter sectionMatter = chunk.getOrCreate(y >> 4);
- MatterSlice cavernSlice = sectionMatter.slice(MatterCavern.class);
- MatterCavern verticalMatter = matterByY[y - minY];
- boolean aquifer = verticalMatter == carveAir
+ CarvedVoid verticalVoid = voidByY[y - minY];
+ boolean aquifer = verticalVoid == CarvedVoid.OPEN
&& y <= fluidMaxY[columnIndex]
&& (boolean) aquiferCandidateMethod.invoke(carver, x, y, z, localThreshold);
- MatterCavern matter = aquifer ? carveFluid : verticalMatter;
- cavernSlice.set(localX, y & 15, localZ, matter);
+ writer.set(x, y, z, aquifer ? CarvedVoid.FLUID : verticalVoid);
carved++;
}
}
@@ -720,26 +685,26 @@ public class IrisCaveCarver3DNearParityTest {
return verticalEdgeFade;
}
- private MatterCavern[] computeMatterByY(CaveProfile profile, MatterCavern carveAir, MatterCavern carveLava, MatterCavern carveForcedAir, int minY, int maxY) {
- MatterCavern[] matterByY = new MatterCavern[Math.max(0, maxY - minY + 1)];
+ private CarvedVoid[] computeVoidByY(CaveProfile profile, int minY, int maxY) {
+ CarvedVoid[] voidByY = new CarvedVoid[Math.max(0, maxY - minY + 1)];
boolean allowLava = profile.allowLava();
int lavaHeight = LAVA_HEIGHT;
for (int y = minY; y <= maxY; y++) {
int offset = y - minY;
if (allowLava && y <= lavaHeight) {
- matterByY[offset] = carveLava;
+ voidByY[offset] = CarvedVoid.LAVA;
continue;
}
if (!allowLava && y <= lavaHeight) {
- matterByY[offset] = carveForcedAir;
+ voidByY[offset] = CarvedVoid.AIR;
continue;
}
- matterByY[offset] = carveAir;
+ voidByY[offset] = CarvedVoid.OPEN;
}
- return matterByY;
+ return voidByY;
}
private CarveWorld createEngine(int worldHeight, int sampledHeight) {
@@ -826,68 +791,62 @@ public class IrisCaveCarver3DNearParityTest {
}
private WriterCapture createWriterCapture(int worldHeight) {
- @SuppressWarnings("unchecked")
- MantleChunk chunk = mock(MantleChunk.class);
- Map sections = new HashMap<>();
- Map> sectionCells = new HashMap<>();
Set carvedCells = new HashSet<>();
Map carvedLiquids = new HashMap<>();
-
- doAnswer(invocation -> sections.get(invocation.getArgument(0, Integer.class))).when(chunk).get(anyInt());
- doAnswer(invocation -> {
- int sectionIndex = invocation.getArgument(0);
- Matter section = sections.get(sectionIndex);
- if (section != null) {
- return section;
- }
-
- Matter created = createSection(sectionIndex, sectionCells, carvedCells, carvedLiquids);
- sections.put(sectionIndex, created);
- return created;
- }).when(chunk).getOrCreate(anyInt());
-
- MatterMantle mantle = new MatterMantle() {
- @Override
- public MantleChunk chunk(int chunkX, int chunkZ) {
- return chunk;
- }
-
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return null;
- }
- };
- return new WriterCapture(mantle, carvedCells, carvedLiquids);
+ return new WriterCapture(new CapturingVoids(carvedCells, carvedLiquids), worldHeight, carvedCells, carvedLiquids);
}
- private Matter createSection(int sectionIndex, Map> sectionCells, Set carvedCells, Map carvedLiquids) {
- Matter matter = mock(Matter.class);
- @SuppressWarnings("unchecked")
- MatterSlice slice = mock(MatterSlice.class);
- Map localCells = sectionCells.computeIfAbsent(sectionIndex, key -> new HashMap<>());
+ /** The carved voids of one chunk, recorded by the chunk's local X and Z and the height, with the carver's liquid code of each fill. */
+ private static final class CapturingVoids implements MantleLayer {
+ private final Map voids = new HashMap<>();
+ private final Set carvedCells;
+ private final Map carvedLiquids;
- doReturn(slice).when(matter).slice(MatterCavern.class);
- doReturn(slice).when(matter).getSlice(MatterCavern.class);
- doAnswer(invocation -> {
- int localX = invocation.getArgument(0);
- int localY = invocation.getArgument(1);
- int localZ = invocation.getArgument(2);
- return localCells.get(packLocal(localX, localY, localZ));
- }).when(slice).get(anyInt(), anyInt(), anyInt());
- doAnswer(invocation -> {
- int localX = invocation.getArgument(0);
- int localY = invocation.getArgument(1);
- int localZ = invocation.getArgument(2);
- MatterCavern value = invocation.getArgument(3);
- localCells.put(packLocal(localX, localY, localZ), value);
- int worldY = (sectionIndex << 4) + localY;
- String cellKey = cellKey(localX, worldY, localZ);
- carvedCells.add(cellKey);
- carvedLiquids.put(cellKey, value.getLiquid());
- return null;
- }).when(slice).set(anyInt(), anyInt(), anyInt(), any(MatterCavern.class));
+ private CapturingVoids(Set carvedCells, Map carvedLiquids) {
+ this.carvedCells = carvedCells;
+ this.carvedLiquids = carvedLiquids;
+ }
- return matter;
+ @Override
+ public CarvedVoid get(int x, int y, int z) {
+ return voids.get(position(x, y, z));
+ }
+
+ @Override
+ public void set(int x, int y, int z, CarvedVoid value) {
+ voids.put(position(x, y, z), value);
+ String cell = x - ((x >> 4) << 4) + ":" + y + ":" + (z - ((z >> 4) << 4));
+ carvedCells.add(cell);
+ carvedLiquids.put(cell, liquidCode(value));
+ }
+
+ @Override
+ public void remove(int x, int y, int z) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void visit(BlockBox area, MantleVisitor visitor) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void clear(BlockBox area) {
+ throw new UnsupportedOperationException();
+ }
+
+ private static long position(int x, int y, int z) {
+ return ((long) x << 40) ^ ((long) y << 20) ^ (z & 0xfffffL);
+ }
+
+ private static byte liquidCode(CarvedVoid value) {
+ return switch (value.fill()) {
+ case OPEN -> 0;
+ case FLUID -> 1;
+ case LAVA -> 2;
+ case AIR -> 3;
+ };
+ }
}
private double[] fullWeights() {
@@ -1083,12 +1042,14 @@ public class IrisCaveCarver3DNearParityTest {
}
private static final class WriterCapture {
- private final MatterMantle writer;
+ private final MantleLayer writer;
+ private final int worldHeight;
private final Set carvedCells;
private final Map carvedLiquids;
- private WriterCapture(MatterMantle writer, Set carvedCells, Map carvedLiquids) {
+ private WriterCapture(MantleLayer writer, int worldHeight, Set carvedCells, Map carvedLiquids) {
this.writer = writer;
+ this.worldHeight = worldHeight;
this.carvedCells = carvedCells;
this.carvedLiquids = carvedLiquids;
}
diff --git a/core/src/test/java/art/arcane/iris/engine/mantle/components/ObjectPlacingCaveAnchorTest.java b/core/src/test/java/art/arcane/iris/engine/mantle/components/ObjectPlacingCaveAnchorTest.java
index 7bf454f42..ba1244133 100644
--- a/core/src/test/java/art/arcane/iris/engine/mantle/components/ObjectPlacingCaveAnchorTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/mantle/components/ObjectPlacingCaveAnchorTest.java
@@ -1,6 +1,6 @@
package art.arcane.iris.engine.mantle.components;
-import art.arcane.iris.modules.objects.Cavern;
+import com.volmit.mantle.CarvedVoid;
import com.volmit.resource.ResourceId;
import org.junit.Test;
@@ -10,9 +10,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ObjectPlacingCaveAnchorTest {
- private static final byte AIR = 0;
- private static final byte WATER = 1;
- private static final byte LAVA = 2;
@Test
public void biomeOwnedPlacementsRejectForeignCaveBands() {
@@ -27,23 +24,19 @@ public class ObjectPlacingCaveAnchorTest {
@Test
public void dryPlacementsRejectFluidAndDefaultLavaCells() {
- assertFalse(CaveAnchors.acceptsFluid(false, cavern(WATER), 20, 8));
- assertFalse(CaveAnchors.acceptsFluid(false, cavern(LAVA), 20, 8));
- assertFalse(CaveAnchors.acceptsFluid(false, cavern(AIR), 8, 8));
- assertTrue(CaveAnchors.acceptsFluid(false, cavern(AIR), 9, 8));
+ assertFalse(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.FLUID), 20, 8));
+ assertFalse(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.LAVA), 20, 8));
+ assertFalse(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.OPEN), 8, 8));
+ assertTrue(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.OPEN), 9, 8));
}
@Test
public void explicitWetAndForcedAirPlacementsRemainEligible() {
- assertTrue(CaveAnchors.acceptsFluid(true, cavern(WATER), 20, 8));
- assertTrue(CaveAnchors.acceptsFluid(false, cavern(Cavern.FORCED_AIR_LIQUID), 0, 8));
+ assertTrue(CaveAnchors.acceptsFluid(true, Optional.of(CarvedVoid.FLUID), 20, 8));
+ assertTrue(CaveAnchors.acceptsFluid(false, Optional.of(CarvedVoid.AIR), 0, 8));
assertFalse(CaveAnchors.acceptsFluid(true, Optional.empty(), 20, 8));
}
- private static Optional cavern(byte liquid) {
- return Optional.of(new Cavern(liquid == AIR, liquid));
- }
-
private static ResourceId biome(String key) {
return new ResourceId("test", key);
}
diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java b/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java
index 83e633482..f27d034e0 100644
--- a/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java
+++ b/core/src/test/java/art/arcane/iris/engine/modifier/ApiChunk.java
@@ -18,9 +18,6 @@
package art.arcane.iris.engine.modifier;
-import art.arcane.iris.builtin.MatterMantle;
-import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
-import art.arcane.volmlib.util.matter.Matter;
import com.volmit.noise.NoiseSampler;
import art.arcane.iris.builtin.IrisStages;
import art.arcane.iris.builtin.IrisSeedPurposes;
@@ -65,6 +62,7 @@ import com.volmit.host.StageGraphBuilder;
import com.volmit.host.StageTimings;
import com.volmit.hunk.Hunk;
import com.volmit.item.ItemRegistry;
+import com.volmit.mantle.CarvedVoid;
import com.volmit.mantle.Mantle;
import com.volmit.mantle.MantleEdit;
import com.volmit.mantle.MantleKey;
@@ -350,7 +348,7 @@ public final class ApiChunk implements GenerationContext {
@Override
public Optional extension(Class type) {
- return type == MatterMantle.class ? Optional.of(type.cast(new ChunkMantle())) : Optional.empty();
+ return Optional.empty();
}
@Override
@@ -518,20 +516,7 @@ public final class ApiChunk implements GenerationContext {
}
}
- private final class ChunkMantle implements Mantle, MatterMantle {
- private final MantleChunk noCaves = mock(MantleChunk.class);
-
- /** The matter of the chunk: none; a test of caves brings its own mantle. */
- @Override
- public MantleChunk chunk(int chunkX, int chunkZ) {
- return noCaves;
- }
-
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return null;
- }
-
+ private final class ChunkMantle implements Mantle {
@Override
public BlockBox bounds() {
return chunkColumns();
@@ -547,6 +532,11 @@ public final class ApiChunk implements GenerationContext {
return new PlannedLayer();
}
+ @Override
+ public MantleLayer carved() {
+ return new CarvedLayer();
+ }
+
@Override
public boolean isCarved(int x, int y, int z) {
return carved.contains(new BlockPosition(x, y, z));
@@ -563,6 +553,40 @@ public final class ApiChunk implements GenerationContext {
}
}
+ /** The carved positions as open voids; a chunk stage only reads them. */
+ private final class CarvedLayer implements MantleLayer {
+ @Override
+ public CarvedVoid get(int x, int y, int z) {
+ return carved.contains(new BlockPosition(x, y, z)) ? CarvedVoid.OPEN : null;
+ }
+
+ @Override
+ public void set(int x, int y, int z, CarvedVoid value) {
+ throw new UnsupportedOperationException("Carved voids are read-only");
+ }
+
+ @Override
+ public void remove(int x, int y, int z) {
+ throw new UnsupportedOperationException("Carved voids are read-only");
+ }
+
+ @Override
+ public void visit(BlockBox area, MantleVisitor visitor) {
+ List positions = new ArrayList<>(carved);
+ positions.sort(VISIT_ORDER);
+ for (BlockPosition position : positions) {
+ if (area.contains(position.x(), position.y(), position.z())) {
+ visitor.accept(position.x(), position.y(), position.z(), CarvedVoid.OPEN);
+ }
+ }
+ }
+
+ @Override
+ public void clear(BlockBox area) {
+ throw new UnsupportedOperationException("Carved voids are read-only");
+ }
+ }
+
private final class PlannedLayer implements MantleLayer {
@Override
public BlockState get(int x, int y, int z) {
diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingBoundarySupportTest.java b/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingBoundarySupportTest.java
index 303bf9c5a..0dedd19ae 100644
--- a/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingBoundarySupportTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingBoundarySupportTest.java
@@ -1,16 +1,13 @@
package art.arcane.iris.engine.modifier;
-import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.core.modules.CarveTestWorld;
import art.arcane.iris.engine.mantle.components.CarveWorld;
-import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
-import art.arcane.volmlib.util.matter.Matter;
-import art.arcane.volmlib.util.matter.MatterCavern;
-import art.arcane.volmlib.util.matter.MatterSlice;
import com.volmit.block.BlockState;
import com.volmit.host.ArrayHunk;
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.world.BiomeSample;
import com.volmit.world.TerrainSample;
@@ -44,25 +41,12 @@ public class CaveApplyingBoundarySupportTest {
public void boundaryBiomeUsesCustomMatterAtItsOwnY() {
ResourceId resolvedCeiling = CarveTestWorld.id("cave/ceiling");
CaveApplying modifier = new CaveApplying(world, new CarveWorld(world.resources().noise(), 1L, 384, 127, 8, CarveTestWorld.MIN_HEIGHT), false);
- MantleChunk mantleChunk = mock(MantleChunk.class);
- Matter floorMatter = mock(Matter.class);
- Matter ceilingMatter = mock(Matter.class);
- MatterSlice floorSlice = mock(MatterSlice.class);
- MatterSlice ceilingSlice = mock(MatterSlice.class);
- doReturn(true).when(mantleChunk).exists(0);
- doReturn(true).when(mantleChunk).exists(2);
- doReturn(floorMatter).when(mantleChunk).get(0);
- doReturn(ceilingMatter).when(mantleChunk).get(2);
- doReturn(true).when(floorMatter).hasSlice(MatterCavern.class);
- doReturn(true).when(ceilingMatter).hasSlice(MatterCavern.class);
- doReturn(floorSlice).when(floorMatter).getSlice(MatterCavern.class);
- doReturn(ceilingSlice).when(ceilingMatter).getSlice(MatterCavern.class);
- doReturn(new MatterCavern(true, "custom/floor", (byte) 0)).when(floorSlice).get(1, 6, 2);
- doReturn(null).when(ceilingSlice).get(1, CEILING_Y & 15, 2);
+ MantleLayer voids = mock(MantleLayer.class);
+ doReturn(CarvedVoid.OPEN.withBiome(CarveTestWorld.id("custom/floor"))).when(voids).get(33, 6, 34);
TerrainSampler terrain = new CaveBiomeTerrain((x, y, z) -> y == CEILING_Y ? Optional.of(resolvedCeiling) : Optional.empty());
- CaveApplying.Application application = modifier.new Application(chunkOnly(mantleChunk), mantleChunk, terrain, 2, 2, new ArrayHunk<>(BlockState.class, 16, 64, 16, AIR),
+ CaveApplying.Application application = modifier.new Application(voids, terrain, 2, 2, new ArrayHunk<>(BlockState.class, 16, 64, 16, AIR),
new RecordingCaveDressing());
- Map customBiomeCache = new HashMap<>();
+ Map customBiomeCache = new HashMap<>();
ResourceId floor = application.resolveCaveBoundaryBiome(1, 6, 2, 40, 44, customBiomeCache);
ResourceId ceiling = application.resolveCaveBoundaryBiome(1, CEILING_Y, 2, 40, 44, customBiomeCache);
@@ -91,20 +75,6 @@ public class CaveApplyingBoundarySupportTest {
assertTrue(CaveApplying.hasStableCaveFloorSupport(output, 0, 6, 0, classes));
}
- private static MatterMantle chunkOnly(MantleChunk chunk) {
- return new MatterMantle() {
- @Override
- public MantleChunk chunk(int chunkX, int chunkZ) {
- return chunk;
- }
-
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return null;
- }
- };
- }
-
/** Terrain that knows cave biomes only. */
private record CaveBiomeTerrain(CaveBiomeAt biomes) implements TerrainSampler {
interface CaveBiomeAt {
diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingFluidIntentTest.java b/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingFluidIntentTest.java
index 42bf027f6..16011c02f 100644
--- a/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingFluidIntentTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingFluidIntentTest.java
@@ -1,7 +1,7 @@
package art.arcane.iris.engine.modifier;
-import art.arcane.volmlib.util.matter.MatterCavern;
import com.volmit.block.BlockState;
+import com.volmit.mantle.CarvedVoid;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
@@ -12,10 +12,10 @@ import static org.junit.Assert.assertTrue;
public class CaveApplyingFluidIntentTest {
@Test
public void explicitCavernIntentsOverrideExistingFluid() {
- MatterCavern airIntent = new MatterCavern(true, "", (byte) 0);
- MatterCavern fluidIntent = new MatterCavern(true, "", (byte) 1);
- MatterCavern lavaIntent = new MatterCavern(true, "", (byte) 2);
- MatterCavern forcedAirIntent = new MatterCavern(true, "", (byte) 3);
+ CarvedVoid airIntent = CarvedVoid.OPEN;
+ CarvedVoid fluidIntent = CarvedVoid.FLUID;
+ CarvedVoid lavaIntent = CarvedVoid.LAVA;
+ CarvedVoid forcedAirIntent = CarvedVoid.AIR;
BlockState fluid = new BlockState("minecraft:water");
BlockState lava = new BlockState("minecraft:lava");
BlockState air = new BlockState("minecraft:cave_air");
diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingTest.java b/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingTest.java
index 3c0b69798..65dc733b1 100644
--- a/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/modifier/CaveApplyingTest.java
@@ -18,7 +18,6 @@
package art.arcane.iris.engine.modifier;
-import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.core.modules.CarveTestTerrain;
import art.arcane.iris.core.modules.CarveTestWorld;
import art.arcane.iris.core.modules.InMemoryMantle;
@@ -26,7 +25,6 @@ import art.arcane.iris.engine.mantle.components.CarveWorld;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterCavern;
-import art.arcane.volmlib.util.matter.MatterMarker;
import com.volmit.block.BlockState;
import com.volmit.host.ArrayHunk;
import com.volmit.hunk.Hunk;
@@ -121,48 +119,29 @@ public class CaveApplyingTest {
}
@Test
- public void markersAreStampedFromTheSeedAndPositionAlone() {
- for (int x = 0; x < 16; x++) {
- for (int z = 0; z < 16; z++) {
- carve(x, z, CAVE_FLOOR_Y, CAVE_CEILING_Y, AIR_CAVERN);
- }
- }
+ public void aCaveInTheNeighbouringChunkWallsTheBorderBlocksNextToIt() {
+ carve(1, 0, 0, CAVE_Z, CAVE_FLOOR_Y, CAVE_CEILING_Y, AIR_CAVERN);
- apply(false);
- int first = markers();
- blocks = new ArrayHunk<>(BlockState.class, 16, HEIGHT, 16, STONE);
apply(false);
- assertTrue("about one in sixteen of the 512 floors and ceilings", first > 0 && first < 128);
- assertEquals(first, markers());
+ assertEquals("the wall against the neighbour's cave", WALL, blocks.get(15, CAVE_FLOOR_Y + 1, CAVE_Z));
+ assertEquals("rock one block further in", STONE, blocks.get(14, CAVE_FLOOR_Y + 1, CAVE_Z));
+ assertEquals("rock beside the cave's rows", STONE, blocks.get(15, CAVE_FLOOR_Y + 1, CAVE_Z + 3));
}
private void carve(int x, int z, int floorY, int ceilingY, MatterCavern cavern) {
- MantleChunk chunk = mantle.chunk(0, 0);
+ carve(0, 0, x, z, floorY, ceilingY, cavern);
+ }
+
+ private void carve(int chunkX, int chunkZ, int x, int z, int floorY, int ceilingY, MatterCavern cavern) {
+ MantleChunk chunk = mantle.chunk(chunkX, chunkZ);
for (int y = floorY; y <= ceilingY; y++) {
chunk.getOrCreate(y >> 4).slice(MatterCavern.class).set(x, y & 15, z, cavern);
}
}
private void apply(boolean upperDimensionCarving) {
- MatterMantle matter = new MatterMantle() {
- @Override
- public MantleChunk chunk(int chunkX, int chunkZ) {
- return mantle.chunk(chunkX, chunkZ);
- }
-
- @Override
- public MantleChunk loadedChunk(int chunkX, int chunkZ) {
- return null;
- }
- };
CarveWorld carveWorld = new CarveWorld(world.resources().noise(), 1337L, HEIGHT, FLUID_HEIGHT, LAVA_HEIGHT, CarveTestWorld.MIN_HEIGHT);
- new CaveApplying(world, carveWorld, upperDimensionCarving).apply(matter, terrain, 0, 0, blocks, dressing);
- }
-
- private int markers() {
- int[] count = new int[1];
- mantle.chunk(0, 0).iterate(MatterMarker.class, (x, y, z, marker) -> count[0]++);
- return count[0];
+ new CaveApplying(world, carveWorld, upperDimensionCarving).apply(mantle.carved(), terrain, 0, 0, blocks, dressing);
}
}
diff --git a/core/src/test/java/art/arcane/iris/engine/modifier/IrisCarveScratchTest.java b/core/src/test/java/art/arcane/iris/engine/modifier/IrisCarveScratchTest.java
index d03e4cea1..adac5757b 100644
--- a/core/src/test/java/art/arcane/iris/engine/modifier/IrisCarveScratchTest.java
+++ b/core/src/test/java/art/arcane/iris/engine/modifier/IrisCarveScratchTest.java
@@ -1,6 +1,7 @@
package art.arcane.iris.engine.modifier;
-import art.arcane.volmlib.util.matter.MatterCavern;
+import com.volmit.mantle.CarvedVoid;
+import com.volmit.resource.ResourceId;
import org.junit.Test;
import java.util.HashMap;
@@ -16,27 +17,27 @@ public class IrisCarveScratchTest {
@Test
public void wallBufferResizesAndReplacesWithoutLosingEntries() {
CarveWallBuffer buffer = new CarveWallBuffer(2);
- Map expected = new HashMap<>();
+ Map expected = new HashMap<>();
for (int index = 0; index < 24; index++) {
int x = index & 15;
int y = 20 + index;
int z = (index * 3) & 15;
- MatterCavern cavern = new MatterCavern(true, "cave-" + index, (byte) 0);
+ CarvedVoid cavern = CarvedVoid.OPEN.withBiome(new ResourceId("test", "cave-" + index));
buffer.put(x, y, z, cavern);
expected.put(key(x, y, z), cavern);
}
- MatterCavern replacement = new MatterCavern(true, "replacement", (byte) 0);
+ CarvedVoid replacement = CarvedVoid.OPEN.withBiome(new ResourceId("test", "replacement"));
buffer.put(5, 25, 15, replacement);
expected.put(key(5, 25, 15), replacement);
assertSame(replacement, buffer.get(5, 25, 15));
assertNull(buffer.get(5, 26, 15));
- Map actual = new HashMap<>();
+ Map actual = new HashMap<>();
buffer.forEach((x, y, z, cavern) -> actual.put(key(x, y, z), cavern));
assertEquals(expected.keySet(), actual.keySet());
- for (Map.Entry entry : expected.entrySet()) {
+ for (Map.Entry entry : expected.entrySet()) {
assertSame(entry.getValue(), actual.get(entry.getKey()));
}
}
@@ -44,11 +45,10 @@ public class IrisCarveScratchTest {
@Test
public void resetClearsReusableState() {
IrisCarveScratch scratch = new IrisCarveScratch();
- MatterCavern cavern = new MatterCavern(true, "cave", (byte) 0);
scratch.columnMasks[0].add(12);
scratch.boundaryMasks[0].add(13);
- scratch.walls.put(1, 12, 2, cavern);
- scratch.customBiomeCache.put("cave", null);
+ scratch.walls.put(1, 12, 2, CarvedVoid.OPEN);
+ scratch.customBiomeCache.put(new ResourceId("test", "cave"), null);
scratch.customCaveBiomePresent = true;
scratch.reset();