Serve Mantle.carved over the cavern slice, delete the MatterMantle offers

CarvedVoids is IrisApi's carved-void layer over the mantle's MatterCavern slice,
which stays the storage form every other reader uses: the liquid byte is the
fill and a custom biome key is a pack biome id. It remembers the slices it
touched last, writes the shared constants and reads an area in order from a flat
grid, so the carver's per-block writes and the apply stage's visit stay cheap.
Placements and edits see it read-only. MatterMantle, OwnChunkMatter and the
loaded-chunk reads behind them are gone.
This commit is contained in:
piexel committed 2026-11-06 12:23:06 +01:00
1 parent a6f1ccd1e7
commit a3cbb0e053
21 files changed
+901 -363

No files matched your search

@@ -0,0 +1,172 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.modules;
import com.volmit.geometry.BlockBox;
import com.volmit.mantle.CarvedVoid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* The carved voids found in an area, to be read back in {@link com.volmit.mantle.MantleLayer#visit}'s order: ascending X,
* then Y, then Z. The slices give them in no order, and a chunk holds thousands, so an area of a few chunks is laid out
* in a flat grid of void kinds, which is read in order without sorting; a larger area packs each void into a number
* that sorts.
*/
final class CarvedCells {
/** The cells above which an area is sorted instead of laid out. */
private static final int GRID_LIMIT_CELLS = 1 << 22;
private static final int MAX_KINDS = 255;
private static final int X_BITS = 18;
private static final int Y_BITS = 15;
private static final int Z_BITS = 18;
private static final int KIND_BITS = 8;
/** What a grid reuses from one visit to the next; a visit inside a visit lays its own grid out. */
static final class Scratch {
private byte[] kinds = new byte[0];
private boolean inUse;
}
/** Where a void lies in the area, relative to its first block. */
@FunctionalInterface
interface CellVisitor {
void accept(int relativeX, int relativeY, int relativeZ, CarvedVoid value);
}
private final int width;
private final int height;
private final int depth;
private final byte[] grid;
private final Scratch borrowed;
private final List<CarvedVoid> kinds = new ArrayList<>(List.of(CarvedVoid.OPEN, CarvedVoid.FLUID, CarvedVoid.LAVA, CarvedVoid.AIR));
private final Map<CarvedVoid, Integer> 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;
}
}
@@ -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 <https://www.gnu.org/licenses/>.
*/
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}.
*
* <p>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<CarvedVoid> {
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<MatterCavern> 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<MatterCavern> 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<CarvedVoid> 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<MatterCavern> 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<Matter> 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<Matter> chunk;
private final MatterSlice<?>[] bySection;
ChunkSlices(int chunkX, int chunkZ, MantleChunk<Matter> 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<MatterCavern> existing(int section) {
MatterSlice<MatterCavern> known = (MatterSlice<MatterCavern>) 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<MatterCavern> found = matter.getSlice(MatterCavern.class);
bySection[section] = found;
return found;
}
@SuppressWarnings("unchecked")
MatterSlice<MatterCavern> creating(int section) {
MatterSlice<MatterCavern> known = (MatterSlice<MatterCavern>) bySection[section];
if (known != null) {
return known;
}
MatterSlice<MatterCavern> created = chunk.getOrCreate(section).slice(MatterCavern.class);
bySection[section] = created;
return created;
}
}
}
@@ -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 <T> Optional<T> extension(Class<T> 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();
}
@@ -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 <T> Optional<T> extension(Class<T> 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() {
@@ -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<Matter> 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<Matter> loadedChunk(int chunkX, int chunkZ) {
return null;
}
}
private final BlockBox bounds;
private final Chunks chunks;
private final Map<String, MantleRegistration<?>> registrations;
private final PlannedBlocks plannedBlocks;
private final PackResourceIds ids;
private CarvedVoids carved;
private CarvedVoids carvedReadOnly;
private BufferedEdit openEdit;
IrisModuleMantle(BlockBox bounds, Chunks chunks, Collection<MantleRegistration<?>> registrations, PlannedBlocks plannedBlocks) {
IrisModuleMantle(BlockBox bounds, Chunks chunks, Collection<MantleRegistration<?>> 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<Matter> chunk(int chunkX, int chunkZ) {
return chunks.chunk(chunkX, chunkZ);
}
@Override
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
return chunks.loadedChunk(chunkX, chunkZ);
}
@Override
public <T> MantleLayer<T> layer(MantleKey<T> key) {
return new Layer<>(key, codecOf(key));
@@ -115,6 +105,22 @@ final class IrisModuleMantle implements Mantle, MatterMantle {
return plannedBlocks;
}
@Override
public MantleLayer<CarvedVoid> 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<CarvedVoid> 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<CarvedVoid> carved() {
requireOpen();
return carvedForEdit();
}
@Override
public boolean isCarved(int x, int y, int z) {
requireOpen();
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Matter> chunk(int chunkX, int chunkZ) {
if (chunkX != this.chunkX || chunkZ != this.chunkZ) {
return null;
}
return mantle.chunk(chunkX, chunkZ);
}
@Override
public MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ) {
return mantle.loadedChunk(chunkX, chunkZ);
}
}
@@ -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<Long, MantleChunk<Matter>> 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<Matter> loadedChunk(int chunkX, int chunkZ) {
Mantle<Matter> mantle = engine.getMantle().getMantle();
TectonicPlate<Matter> 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);
@@ -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<CarvedVoid> carved() {
return new StoredRange<>(placement.carved());
}
@Override
public boolean isCarved(int x, int y, int z) {
if (!bounds.contains(x, y, z)) {