mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 00:04:42 +00:00
Plan caves in Mantle.carved, drop MatterMantle
The carver, its fluid-support and orphan passes, CaveApplying and CarvedSpace read and write IrisApi's carved-void layer instead of VolmLib matter slices. Cave floors for the spawners are marked by the carve mantle stage through PlacementTerrain.mark, from the planned voids; cave ceiling markers, which nothing read, are gone. CaveApplying reads the 16 blocks around its chunk through the chunk stage's mantle view, not only the neighbours already in memory. MatterMantle and the module's Cavern are deleted.
This commit is contained in:
1 parent
fa7c3a0abf
commit
62e33edfe3
17 files changed
+398
-604
No files matched your search
@@ -202,8 +202,8 @@ none of the jar's modules (`IrisModuleHost.JAR_MODULE_IDS`, which a test keeps e
|
||||
`art.arcane.iris.builtin` also holds what the compiled-in built-ins and the jar must share, because each sees its own copy of
|
||||
every other class. The facades among them are interfaces Iris implements and offers through IrisApi's extension point, never
|
||||
through the thread or a cast: a module asks `world.extension(X.class)` for what belongs to a world (`StructureHost`),
|
||||
`context.extension(X.class)` for what belongs to one invocation (`MatterMantle`
|
||||
in a chunk or mantle stage) and `settings.extension(X.class)` for a reach worked out
|
||||
`context.extension(X.class)` for what belongs to one invocation (`IrisChunk` in a chunk stage, `IrisMantleChunk` in a mantle stage) and
|
||||
`settings.extension(X.class)` for a reach worked out
|
||||
before any world exists, each with `.orElseThrow()`, since a built-in runs only where Iris offers them. Iris's per-feature world seeds are
|
||||
IrisApi purpose seeds: `world.seed(IrisSeedPurposes.CARVE)` (`iris:seed/carve`), by the API's rule like any module's. What the
|
||||
built-ins keep with a world across restarts, such as the spawner cooldowns (`SpawnCooldownBook`), they save through
|
||||
@@ -218,10 +218,10 @@ placement's own states). Its types answer with IrisApi, VolmLib and built-in val
|
||||
`iris:prepare/transforms`, lives in the exposed package too, because `IrisStages` names it. `iris:post` reads its switches
|
||||
(`postProcessingWalls`, `postProcessingSlabs`) and the biome's `wall` and `slab` as module settings through its context.
|
||||
|
||||
`iris:carve` also reads the mantle's matter slices through `MatterMantle` (the chunk of `MatterCavern`s and markers it plans and
|
||||
applies, which the platform and the rest of Iris read as slices, not as module layers). A mantle stage gets the whole mantle; a
|
||||
chunk stage gets its own chunk and the neighbors the world already holds in memory, which is all the cave apply stage ever read,
|
||||
so it writes nothing outside its chunk. What a
|
||||
`iris:carve` plans its caves in IrisApi's host-owned `Mantle.carved()` layer (`CarvedVoid`: open, fluid, lava or air, and optionally a
|
||||
biome), which Iris keeps in its own form for the platform and the rest of Iris to read. The mantle stage writes it; the apply stage
|
||||
reads it, and one block beyond its chunk to wall the caves that cross the border. The cave floors the spawners use are marked by the mantle
|
||||
stage with `PlacementTerrain.mark(PackMarker("cave_floor"))`. What a
|
||||
cave's walls, floor and ceiling get comes from the terrain and decorant built-ins of the same jar (`modules.terrain.BiomeLayers`,
|
||||
`modules.terrain.TerrainPalettes`, the biome decorators), through carve's own `CaveDressing`, which tests replace with fixed blocks.
|
||||
A cave's dimension, region and biome settings are found by the id the layout's biome samples carry (`DeclaredByLevel`), its
|
||||
|
||||
@@ -57,6 +57,7 @@ include art/arcane/iris/engine/mantle/components/CarveWorld.class
|
||||
include art/arcane/iris/engine/mantle/components/CaveCarveScratch*.class
|
||||
include art/arcane/iris/engine/mantle/components/CaveCarving*.class
|
||||
include art/arcane/iris/engine/mantle/components/CaveFieldModuleState.class
|
||||
include art/arcane/iris/engine/mantle/components/CaveFloorMarking*.class
|
||||
include art/arcane/iris/engine/mantle/components/CaveFluidSupportPlan*.class
|
||||
include art/arcane/iris/engine/mantle/components/IrisCaveCarver3D*.class
|
||||
include art/arcane/iris/engine/mantle/components/SurfaceFluidBoundaryPlan*.class
|
||||
|
||||
@@ -1,45 +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.builtin;
|
||||
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
|
||||
/**
|
||||
* Iris's mantle as the matter slices it stores, for the built-ins whose data the platform and the rest of Iris read as
|
||||
* slices rather than through a {@link com.volmit.mantle.MantleLayer}: caves ({@code MatterCavern}) and markers. The
|
||||
* slices are VolmLib's own types, which a pack module may use as well. Iris offers it as an extension of its mantle and
|
||||
* chunk invocations: {@code context.extension(MatterMantle.class)}.
|
||||
*
|
||||
* <p>A chunk invocation's matter mantle holds its own chunk only, which the stage may write, as a chunk stage writes the
|
||||
* mantle of its own chunk; it reads its neighbours through {@link #loadedChunk} alone.
|
||||
*
|
||||
* <p>Heights are as the mantle stores them: above the dimension's bottom. A chunk the invocation reaches is pinned for
|
||||
* as long as the invocation runs; callers neither release it nor keep it afterwards.
|
||||
*/
|
||||
public interface MatterMantle {
|
||||
/** The mantle chunk at chunk coordinates {@code chunkX}, {@code chunkZ}, or null outside what the invocation reaches. */
|
||||
MantleChunk<Matter> chunk(int chunkX, int chunkZ);
|
||||
|
||||
/**
|
||||
* The mantle chunk at those coordinates if the world holds it in memory, wherever it is, or null. It is never loaded
|
||||
* or created for the call and not pinned, so read it at once and do not keep it.
|
||||
*/
|
||||
MantleChunk<Matter> loadedChunk(int chunkX, int chunkZ);
|
||||
}
|
||||
@@ -18,11 +18,9 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -31,7 +29,6 @@ public final class CarveOrphanSweep {
|
||||
private static final int CHUNK_AREA = CHUNK_SIZE * CHUNK_SIZE;
|
||||
private static final int BAND_FLOOR_MARGIN = 4;
|
||||
private static final int MAX_ORPHAN_CELLS = 16;
|
||||
private static final MatterCavern ORPHAN_CAVERN = new MatterCavern(true, "", (byte) 0);
|
||||
private static final ThreadLocal<SweepScratch> SCRATCH = ThreadLocal.withInitial(SweepScratch::new);
|
||||
|
||||
public interface CarveAccess {
|
||||
@@ -42,34 +39,24 @@ public final class CarveOrphanSweep {
|
||||
default boolean isProtected(int localX, int y, int localZ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cheap pre-check: may any block in [minY, maxY] be carved at all? Default true keeps
|
||||
* every implementor correct; the mantle-backed access answers from section slice
|
||||
* presence so an uncarved chunk skips the full band fill + scan.
|
||||
*/
|
||||
default boolean mayContainCarvedCells(int minY, int maxY) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private CarveOrphanSweep() {
|
||||
}
|
||||
|
||||
/** Sweeps the chunk whose first block is {@code originX}, {@code originZ}. */
|
||||
static int sweepChunk(
|
||||
MantleChunk<Matter> chunk,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int originX,
|
||||
int originZ,
|
||||
int[] surfaceHeights,
|
||||
int maxSurfaceBreakDepth,
|
||||
int worldCeilingY,
|
||||
int[] surfaceFluidBoundaryStartY,
|
||||
int fluidHeight
|
||||
) {
|
||||
if (chunk == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return sweep(surfaceHeights, maxSurfaceBreakDepth, 0, worldCeilingY,
|
||||
new MantleCarveAccess(chunk, surfaceFluidBoundaryStartY, fluidHeight));
|
||||
new MantleCarveAccess(voids, originX, originZ, surfaceFluidBoundaryStartY, fluidHeight));
|
||||
}
|
||||
|
||||
public static int sweep(int[] surfaceHeights, int maxSurfaceBreakDepth, int worldFloorY, int worldCeilingY, CarveAccess access) {
|
||||
@@ -95,12 +82,6 @@ public final class CarveOrphanSweep {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!access.mayContainCarvedCells(bandFloor, bandTop)) {
|
||||
// Same early return the carvedPresent check reaches, without zero-filling and
|
||||
// scanning the whole band first.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bandHeight = bandTop - bandFloor + 1;
|
||||
int cellCount = bandHeight * CHUNK_AREA;
|
||||
SweepScratch scratch = SCRATCH.get();
|
||||
@@ -228,34 +209,28 @@ public final class CarveOrphanSweep {
|
||||
}
|
||||
|
||||
private static final class MantleCarveAccess implements CarveAccess {
|
||||
private final MantleChunk<Matter> chunk;
|
||||
private final MantleLayer<CarvedVoid> voids;
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final int[] surfaceFluidBoundaryStartY;
|
||||
private final int fluidHeight;
|
||||
private MatterSlice<MatterCavern> cachedSlice;
|
||||
private int cachedSectionIndex = -1;
|
||||
|
||||
private MantleCarveAccess(MantleChunk<Matter> chunk, int[] surfaceFluidBoundaryStartY, int fluidHeight) {
|
||||
this.chunk = chunk;
|
||||
private MantleCarveAccess(MantleLayer<CarvedVoid> voids, int originX, int originZ, int[] surfaceFluidBoundaryStartY, int fluidHeight) {
|
||||
this.voids = voids;
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.surfaceFluidBoundaryStartY = surfaceFluidBoundaryStartY;
|
||||
this.fluidHeight = fluidHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int localX, int y, int localZ) {
|
||||
MatterSlice<MatterCavern> cavernSlice = resolveSlice(y >> 4);
|
||||
if (cavernSlice == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MatterCavern cavern = cavernSlice.get(localX, y & 15, localZ);
|
||||
return cavern != null && cavern.isCavern();
|
||||
return voids.get(originX + localX, y, originZ + localZ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markCarved(int localX, int y, int localZ) {
|
||||
chunk.getOrCreate(y >> 4).slice(MatterCavern.class).set(localX, y & 15, localZ, ORPHAN_CAVERN);
|
||||
cachedSectionIndex = -1;
|
||||
cachedSlice = null;
|
||||
voids.set(originX + localX, y, originZ + localZ, CarvedVoid.OPEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -263,30 +238,6 @@ public final class CarveOrphanSweep {
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(localX, localZ);
|
||||
return SurfaceFluidBoundaryPlan.protects(surfaceFluidBoundaryStartY, columnIndex, y, fluidHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayContainCarvedCells(int minY, int maxY) {
|
||||
int minSection = Math.max(0, minY >> 4);
|
||||
int maxSection = Math.min(chunk.sectionCount() - 1, maxY >> 4);
|
||||
for (int sectionIndex = minSection; sectionIndex <= maxSection; sectionIndex++) {
|
||||
Matter section = chunk.get(sectionIndex);
|
||||
if (section != null && section.getSlice(MatterCavern.class) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private MatterSlice<MatterCavern> resolveSlice(int sectionIndex) {
|
||||
if (sectionIndex == cachedSectionIndex) {
|
||||
return cachedSlice;
|
||||
}
|
||||
|
||||
Matter section = sectionIndex >= 0 && sectionIndex < chunk.sectionCount() ? chunk.get(sectionIndex) : null;
|
||||
cachedSlice = section == null ? null : section.getSlice(MatterCavern.class);
|
||||
cachedSectionIndex = sectionIndex;
|
||||
return cachedSlice;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class SweepScratch {
|
||||
|
||||
@@ -20,9 +20,9 @@ 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 art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
@@ -76,7 +76,7 @@ final class CaveAnchors {
|
||||
int candidateY = anchorY(rng, candidateX, candidateZ, search);
|
||||
if (candidateY < 0
|
||||
|| biomeConflicts(candidateX, candidateY, candidateZ, expectedCaveBiome)
|
||||
|| !acceptsFluid(underwater, carved.cavernAt(candidateX, candidateY, candidateZ), candidateY, caveLavaHeight)) {
|
||||
|| !acceptsFluid(underwater, carved.voidAt(candidateX, candidateY, candidateZ), candidateY, caveLavaHeight)) {
|
||||
continue;
|
||||
}
|
||||
return new Anchor(candidateX, candidateY, candidateZ);
|
||||
@@ -84,14 +84,14 @@ final class CaveAnchors {
|
||||
return null;
|
||||
}
|
||||
|
||||
static boolean acceptsFluid(boolean underwater, Optional<Cavern> cavern, int y, int lavaHeight) {
|
||||
if (cavern.isEmpty()) {
|
||||
static boolean acceptsFluid(boolean underwater, Optional<CarvedVoid> carvedVoid, int y, int lavaHeight) {
|
||||
if (carvedVoid.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (underwater || cavern.get().liquid() == Cavern.FORCED_AIR_LIQUID) {
|
||||
if (underwater || carvedVoid.get().fill() == CarvedVoid.Fill.AIR) {
|
||||
return true;
|
||||
}
|
||||
return cavern.get().air() && y > lavaHeight;
|
||||
return carvedVoid.get().fill() == CarvedVoid.Fill.OPEN && y > lavaHeight;
|
||||
}
|
||||
|
||||
/** One above the highest height an anchor may sit at, or 0 when none may. */
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
|
||||
final class CaveCarveScratch {
|
||||
final int[] columnMaxY = new int[256];
|
||||
@@ -64,9 +62,7 @@ final class CaveCarveScratch {
|
||||
int activeModuleCount;
|
||||
double[] verticalEdgeFade = new double[0];
|
||||
double[] surfaceClosureThreshold = new double[0];
|
||||
MatterCavern[] matterByY = new MatterCavern[0];
|
||||
Matter[] sectionMatter = new Matter[0];
|
||||
MatterSlice<?>[] sectionSlices = new MatterSlice<?>[0];
|
||||
CarvedVoid[] voidByY = new CarvedVoid[0];
|
||||
int adaptiveGeometryStep = -1;
|
||||
int adaptiveGeometryAxisCells = -1;
|
||||
boolean fullWeightsInitialized;
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.modules.carve.CaveProfile;
|
||||
import art.arcane.iris.engine.object.terrain.carving.CarvingResolver;
|
||||
import art.arcane.iris.engine.object.terrain.carving.DeclaredCaveProfiles;
|
||||
import art.arcane.iris.engine.object.terrain.carving.ResolvedCarvingEntry;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import com.volmit.config.Range;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.BiomeSample;
|
||||
import com.volmit.world.PackBiome;
|
||||
@@ -94,8 +95,8 @@ public class CaveCarving {
|
||||
this.upperDimensionCarving = upperDimensionCarving;
|
||||
}
|
||||
|
||||
/** Carves the caves of the chunk at chunk coordinates {@code x}, {@code z} into {@code mantle}, reading the terrain around it from {@code terrain}. */
|
||||
public void carve(MatterMantle mantle, TerrainSampler terrain, int x, int z) {
|
||||
/** Carves the caves of the chunk at chunk coordinates {@code x}, {@code z} into {@code voids}, reading the terrain around it from {@code terrain}. */
|
||||
public void carve(MantleLayer<CarvedVoid> voids, TerrainSampler terrain, int x, int z) {
|
||||
BlendScratch blendScratch = BLEND_SCRATCH.get();
|
||||
int[] chunkSurfaceHeights = prepareChunkSurfaceHeights(x, z, terrain, blendScratch.chunkSurfaceHeights);
|
||||
List<WeightedProfile> weightedProfiles = resolveWeightedProfiles(x, z, terrain);
|
||||
@@ -112,17 +113,19 @@ public class CaveCarving {
|
||||
);
|
||||
CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan();
|
||||
for (WeightedProfile weightedProfile : weightedProfiles) {
|
||||
carveProfile(weightedProfile, mantle, x, z, chunkSurfaceHeights, surfaceFluidBoundaryStartY, fluidSupportPlan);
|
||||
carveProfile(weightedProfile, voids, x, z, chunkSurfaceHeights, surfaceFluidBoundaryStartY, fluidSupportPlan);
|
||||
}
|
||||
|
||||
if (upperDimensionCarving && hasUpperDimension(terrain, x, z)) {
|
||||
carveUpperTerrain(terrain, weightedProfiles, mantle, x, z, fluidSupportPlan);
|
||||
carveUpperTerrain(terrain, weightedProfiles, voids, x, z, fluidSupportPlan);
|
||||
}
|
||||
fluidSupportPlan.resolve(mantle.chunk(x, z));
|
||||
fluidSupportPlan.resolve(voids, PowerOfTwoCoordinates.chunkToBlock(x), PowerOfTwoCoordinates.chunkToBlock(z), world.height());
|
||||
|
||||
if (!weightedProfiles.isEmpty()) {
|
||||
CarveOrphanSweep.sweepChunk(
|
||||
mantle.chunk(x, z),
|
||||
voids,
|
||||
PowerOfTwoCoordinates.chunkToBlock(x),
|
||||
PowerOfTwoCoordinates.chunkToBlock(z),
|
||||
chunkSurfaceHeights,
|
||||
maxSurfaceBreakDepth(weightedProfiles),
|
||||
world.height() - 1,
|
||||
@@ -144,16 +147,16 @@ public class CaveCarving {
|
||||
return maxDepth;
|
||||
}
|
||||
|
||||
private void carveProfile(WeightedProfile weightedProfile, MatterMantle mantle, int cx, int cz,
|
||||
private void carveProfile(WeightedProfile weightedProfile, MantleLayer<CarvedVoid> voids, int cx, int cz,
|
||||
int[] chunkSurfaceHeights, int[] surfaceFluidBoundaryStartY,
|
||||
CaveFluidSupportPlan fluidSupportPlan) {
|
||||
IrisCaveCarver3D carver = getCarver(weightedProfile.profile);
|
||||
carver.carve(mantle, cx, cz, weightedProfile.columnWeights, MIN_WEIGHT, THRESHOLD_PENALTY,
|
||||
carver.carve(voids, cx, cz, weightedProfile.columnWeights, MIN_WEIGHT, THRESHOLD_PENALTY,
|
||||
weightedProfile.worldYRange, chunkSurfaceHeights, surfaceFluidBoundaryStartY, null, fluidSupportPlan);
|
||||
}
|
||||
|
||||
private void carveUpperTerrain(TerrainSampler terrain, List<WeightedProfile> normalProfiles,
|
||||
MatterMantle mantle, int cx, int cz,
|
||||
MantleLayer<CarvedVoid> voids, int cx, int cz,
|
||||
CaveFluidSupportPlan fluidSupportPlan) {
|
||||
int chunkHeight = world.height();
|
||||
int worldMinHeight = world.minHeight();
|
||||
@@ -198,7 +201,7 @@ public class CaveCarving {
|
||||
constrainedRange = upperYRange;
|
||||
}
|
||||
IrisCaveCarver3D carver = getCarver(weightedProfile.profile);
|
||||
carver.carve(mantle, cx, cz, weightedProfile.columnWeights, MIN_WEIGHT, THRESHOLD_PENALTY,
|
||||
carver.carve(voids, cx, cz, weightedProfile.columnWeights, MIN_WEIGHT, THRESHOLD_PENALTY,
|
||||
constrainedRange, ceilingSurfaceHeights, null, fullVerticalRange, fluidSupportPlan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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.engine.mantle.components;
|
||||
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.geometry.BlockPosition;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.placement.PlacedMarker;
|
||||
import com.volmit.placement.PlacementTerrain;
|
||||
import com.volmit.world.TerrainSampler;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
/**
|
||||
* Marks the floors of the caves {@link CaveCarving} planned in a chunk, which the host's cave spawning reads: the lowest
|
||||
* block of each vertical run of at least three carved blocks, one floor in sixteen. The runs are those the chunk stage
|
||||
* cuts, minus the blocks it leaves alone: under a dimension stacked above that carving does not go through, and open voids
|
||||
* the terrain holds fluid in. The roll is seed-derived and keyed by position alone, never random, because the markers
|
||||
* persist in the mantle: the same seed marks the same floors on every run.
|
||||
*/
|
||||
public final class CaveFloorMarking {
|
||||
static final String CAVE_FLOOR_MARKER = "cave_floor";
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
private static final int CHUNK_AREA = CHUNK_SIZE * CHUNK_SIZE;
|
||||
private static final int MIN_RUN_LENGTH = 3;
|
||||
private static final long FLOOR_MARKER_SALT = 0xC2B2AE3D27D4EB4FL;
|
||||
private static final long ROLL_MASK = 15L;
|
||||
private static final ThreadLocal<BitSet[]> COLUMNS = ThreadLocal.withInitial(() -> {
|
||||
BitSet[] columns = new BitSet[CHUNK_AREA];
|
||||
for (int index = 0; index < CHUNK_AREA; index++) {
|
||||
columns[index] = new BitSet();
|
||||
}
|
||||
return columns;
|
||||
});
|
||||
|
||||
private final CarveWorld world;
|
||||
private final boolean upperDimensionCarving;
|
||||
|
||||
public CaveFloorMarking(CarveWorld world, boolean upperDimensionCarving) {
|
||||
this.world = world;
|
||||
this.upperDimensionCarving = upperDimensionCarving;
|
||||
}
|
||||
|
||||
/** Marks the floors of the chunk at chunk coordinates {@code chunkX}, {@code chunkZ} in {@code placement}. */
|
||||
public void mark(MantleLayer<CarvedVoid> voids, TerrainSampler terrain, PlacementTerrain placement, int chunkX, int chunkZ) {
|
||||
int originX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int originZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
BitSet[] carvedColumns = COLUMNS.get();
|
||||
fillCarvedColumns(carvedColumns, voids, terrain, originX, originZ);
|
||||
for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) {
|
||||
markColumn(carvedColumns[columnIndex], placement, originX + PowerOfTwoCoordinates.unpackLocal16X(columnIndex),
|
||||
originZ + (columnIndex & (CHUNK_SIZE - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
private void fillCarvedColumns(BitSet[] carvedColumns, MantleLayer<CarvedVoid> voids, TerrainSampler terrain, int originX, int originZ) {
|
||||
int[] surfaceHeights = new int[CHUNK_AREA];
|
||||
int[] upperSurfaceHeights = upperDimensionCarving || terrain.upperDimensionY(originX, originZ).isEmpty() ? null : new int[CHUNK_AREA];
|
||||
for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) {
|
||||
carvedColumns[columnIndex].clear();
|
||||
int worldX = originX + PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int worldZ = originZ + (columnIndex & (CHUNK_SIZE - 1));
|
||||
surfaceHeights[columnIndex] = terrain.surfaceHeight(worldX, worldZ);
|
||||
if (upperSurfaceHeights != null) {
|
||||
upperSurfaceHeights[columnIndex] = terrain.upperDimensionY(worldX, worldZ).getAsInt();
|
||||
}
|
||||
}
|
||||
|
||||
int fluidHeight = terrain.fluidHeight();
|
||||
voids.visit(new BlockBox(originX, 0, originZ, originX + CHUNK_SIZE, world.height(), originZ + CHUNK_SIZE), (x, y, z, carvedVoid) -> {
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(x - originX, z - originZ);
|
||||
if (y <= 0 || upperSurfaceHeights != null && y >= upperSurfaceHeights[columnIndex]) {
|
||||
return;
|
||||
}
|
||||
boolean terrainHoldsFluid = y > surfaceHeights[columnIndex] && y <= fluidHeight;
|
||||
if (carvedVoid.fill() == CarvedVoid.Fill.OPEN && terrainHoldsFluid) {
|
||||
return;
|
||||
}
|
||||
carvedColumns[columnIndex].set(y);
|
||||
});
|
||||
}
|
||||
|
||||
private void markColumn(BitSet carvedColumn, PlacementTerrain placement, int worldX, int worldZ) {
|
||||
int floor = carvedColumn.nextSetBit(0);
|
||||
while (floor >= 0) {
|
||||
int ceiling = carvedColumn.nextClearBit(floor) - 1;
|
||||
if (ceiling - floor + 1 >= MIN_RUN_LENGTH && floorRoll(worldX, floor, worldZ)) {
|
||||
placement.mark(new PlacedMarker.PackMarker(new BlockPosition(worldX, floor, worldZ), CAVE_FLOOR_MARKER));
|
||||
}
|
||||
floor = carvedColumn.nextSetBit(ceiling + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/** One in sixteen, from a SplitMix64 finalizer over the carve seed, the position and a salt. */
|
||||
private boolean floorRoll(int x, int y, int z) {
|
||||
long hash = (world.carveSeed() + FLOOR_MARKER_SALT) ^ art.arcane.volmlib.util.math.BlockPosition.toLong(x, y, z);
|
||||
hash = (hash ^ (hash >>> 30)) * 0xBF58476D1CE4E5B9L;
|
||||
hash = (hash ^ (hash >>> 27)) * 0x94D049BB133111EBL;
|
||||
hash ^= hash >>> 31;
|
||||
return (hash & ROLL_MASK) == 0L;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||
* 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
|
||||
@@ -18,103 +18,73 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/** The fluid voids a carver planned in one chunk, to be drained back to open voids where no solid cup holds them. */
|
||||
final class CaveFluidSupportPlan {
|
||||
private final IdentityHashMap<MatterCavern, FluidCandidateGroup> groups = new IdentityHashMap<>();
|
||||
private static final int MIN_SUPPORTED_NEIGHBOURS = 4;
|
||||
private static final int CHUNK_WIDTH = 16;
|
||||
private static final int COLUMN_BITS = 8;
|
||||
private static final int COLUMN_MASK = (1 << COLUMN_BITS) - 1;
|
||||
|
||||
void add(int localX, int y, int localZ, MatterCavern fluid, MatterCavern air) {
|
||||
FluidCandidateGroup group = groups.computeIfAbsent(fluid, key -> new FluidCandidateGroup(fluid, air));
|
||||
private final BitSet fluidPositions = new BitSet();
|
||||
|
||||
void add(int localX, int y, int localZ) {
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(localX, localZ);
|
||||
group.positions.set((y << 8) | columnIndex);
|
||||
fluidPositions.set((y << COLUMN_BITS) | columnIndex);
|
||||
}
|
||||
|
||||
void resolve(MantleChunk<Matter> chunk) {
|
||||
if (chunk == null) {
|
||||
groups.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for (Map.Entry<MatterCavern, FluidCandidateGroup> entry : groups.entrySet()) {
|
||||
FluidCandidateGroup group = entry.getValue();
|
||||
for (int position = group.positions.nextSetBit(0); position >= 0; position = group.positions.nextSetBit(position + 1)) {
|
||||
int y = position >>> 8;
|
||||
int columnIndex = position & 255;
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
MatterCavern current = getCavern(chunk, localX, y, localZ);
|
||||
if (current != group.fluid || hasCupSupport(chunk, localX, y, localZ)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Matter section = chunk.get(y >> 4);
|
||||
MatterSlice<MatterCavern> cavernSlice = section.getSlice(MatterCavern.class);
|
||||
cavernSlice.set(localX, y & 15, localZ, group.air);
|
||||
/** Turns every planned fluid void of the chunk at block origin {@code originX}, {@code originZ} that is no longer fluid or has no cup under it into an open void. */
|
||||
void resolve(MantleLayer<CarvedVoid> voids, int originX, int originZ, int worldHeight) {
|
||||
for (int position = fluidPositions.nextSetBit(0); position >= 0; position = fluidPositions.nextSetBit(position + 1)) {
|
||||
int y = position >>> COLUMN_BITS;
|
||||
int columnIndex = position & COLUMN_MASK;
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & (CHUNK_WIDTH - 1);
|
||||
int x = originX + localX;
|
||||
int z = originZ + localZ;
|
||||
if (voids.get(x, y, z) != CarvedVoid.FLUID || hasCupSupport(voids, originX, originZ, localX, y, localZ, worldHeight)) {
|
||||
continue;
|
||||
}
|
||||
voids.set(x, y, z, CarvedVoid.OPEN);
|
||||
}
|
||||
groups.clear();
|
||||
fluidPositions.clear();
|
||||
}
|
||||
|
||||
private static boolean hasCupSupport(MantleChunk<Matter> chunk, int localX, int y, int localZ) {
|
||||
if (localX <= 0 || localX >= 15 || localZ <= 0 || localZ >= 15
|
||||
|| y <= 1 || !isSolid(chunk, localX, y - 1, localZ)
|
||||
|| !isSolid(chunk, localX, y - 2, localZ)) {
|
||||
private static boolean hasCupSupport(MantleLayer<CarvedVoid> voids, int originX, int originZ, int localX, int y, int localZ, int worldHeight) {
|
||||
if (localX <= 0 || localX >= CHUNK_WIDTH - 1 || localZ <= 0 || localZ >= CHUNK_WIDTH - 1
|
||||
|| y <= 1 || !isSolid(voids, originX, originZ, localX, y - 1, localZ, worldHeight)
|
||||
|| !isSolid(voids, originX, originZ, localX, y - 2, localZ, worldHeight)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int support = 0;
|
||||
if (isSolid(chunk, localX + 1, y, localZ)) {
|
||||
if (isSolid(voids, originX, originZ, localX + 1, y, localZ, worldHeight)) {
|
||||
support++;
|
||||
}
|
||||
if (isSolid(chunk, localX - 1, y, localZ)) {
|
||||
if (isSolid(voids, originX, originZ, localX - 1, y, localZ, worldHeight)) {
|
||||
support++;
|
||||
}
|
||||
if (isSolid(chunk, localX, y, localZ + 1)) {
|
||||
if (isSolid(voids, originX, originZ, localX, y, localZ + 1, worldHeight)) {
|
||||
support++;
|
||||
}
|
||||
if (isSolid(chunk, localX, y, localZ - 1)) {
|
||||
if (isSolid(voids, originX, originZ, localX, y, localZ - 1, worldHeight)) {
|
||||
support++;
|
||||
}
|
||||
if (isSolid(chunk, localX, y + 1, localZ)) {
|
||||
if (isSolid(voids, originX, originZ, localX, y + 1, localZ, worldHeight)) {
|
||||
support++;
|
||||
}
|
||||
return support >= 4;
|
||||
return support >= MIN_SUPPORTED_NEIGHBOURS;
|
||||
}
|
||||
|
||||
private static boolean isSolid(MantleChunk<Matter> chunk, int localX, int y, int localZ) {
|
||||
if (localX < 0 || localX >= 16 || localZ < 0 || localZ >= 16) {
|
||||
private static boolean isSolid(MantleLayer<CarvedVoid> voids, int originX, int originZ, int localX, int y, int localZ, int worldHeight) {
|
||||
if (localX < 0 || localX >= CHUNK_WIDTH || localZ < 0 || localZ >= CHUNK_WIDTH) {
|
||||
return false;
|
||||
}
|
||||
MatterCavern cavern = getCavern(chunk, localX, y, localZ);
|
||||
return cavern == null || !cavern.isCavern();
|
||||
}
|
||||
|
||||
private static MatterCavern getCavern(MantleChunk<Matter> chunk, int localX, int y, int localZ) {
|
||||
Matter section = chunk.get(y >> 4);
|
||||
if (section == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
MatterSlice<MatterCavern> cavernSlice = section.getSlice(MatterCavern.class);
|
||||
return cavernSlice == null ? null : cavernSlice.get(localX, y & 15, localZ);
|
||||
}
|
||||
|
||||
private static final class FluidCandidateGroup {
|
||||
private final MatterCavern fluid;
|
||||
private final MatterCavern air;
|
||||
private final BitSet positions = new BitSet();
|
||||
|
||||
private FluidCandidateGroup(MatterCavern fluid, MatterCavern air) {
|
||||
this.fluid = fluid;
|
||||
this.air = air;
|
||||
}
|
||||
return y >= worldHeight || voids.get(originX + localX, y, originZ + localZ) == null;
|
||||
}
|
||||
}
|
||||
@@ -18,16 +18,13 @@
|
||||
|
||||
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.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.M;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
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.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.noise.NoiseSampler;
|
||||
import com.volmit.noise.NoiseStyle;
|
||||
import com.volmit.noise.StyledRange;
|
||||
@@ -37,10 +34,7 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class IrisCaveCarver3D {
|
||||
private static final byte LIQUID_AIR = 0;
|
||||
private static final byte LIQUID_FLUID = 1;
|
||||
private static final byte LIQUID_LAVA = 2;
|
||||
private static final byte LIQUID_FORCED_AIR = 3;
|
||||
private static final int LOCAL_MASK = 15;
|
||||
private static final int ADAPTIVE_MIN_PLANE_COLUMNS = 16;
|
||||
private static final int ADAPTIVE_DEEP_SAMPLE_STEP = 8;
|
||||
private static final double ADAPTIVE_LOCAL_RANGE_SCALE = 0.125D;
|
||||
@@ -57,10 +51,6 @@ public class IrisCaveCarver3D {
|
||||
private final int lavaHeight;
|
||||
private final CaveFieldModuleState[] modules;
|
||||
private final double inverseNormalization;
|
||||
private final MatterCavern carveAir;
|
||||
private final MatterCavern carveFluid;
|
||||
private final MatterCavern carveLava;
|
||||
private final MatterCavern carveForcedAir;
|
||||
private final double normalizationFactor;
|
||||
private final double baseWeight;
|
||||
private final double detailWeight;
|
||||
@@ -81,10 +71,6 @@ public class IrisCaveCarver3D {
|
||||
|
||||
public IrisCaveCarver3D(CarveWorld world, CaveProfile profile) {
|
||||
this.profile = profile;
|
||||
this.carveAir = new MatterCavern(true, "", LIQUID_AIR);
|
||||
this.carveFluid = new MatterCavern(true, "", LIQUID_FLUID);
|
||||
this.carveLava = new MatterCavern(true, "", LIQUID_LAVA);
|
||||
this.carveForcedAir = new MatterCavern(true, "", LIQUID_FORCED_AIR);
|
||||
List<CaveFieldModuleState> moduleStates = new ArrayList<>();
|
||||
|
||||
long carveSeed = world.carveSeed();
|
||||
@@ -127,7 +113,7 @@ public class IrisCaveCarver3D {
|
||||
}
|
||||
|
||||
public int carve(
|
||||
MatterMantle mantle,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
double[] columnWeights,
|
||||
@@ -136,11 +122,11 @@ public class IrisCaveCarver3D {
|
||||
Range worldYRange,
|
||||
int[] surfaceHeights
|
||||
) {
|
||||
return carve(mantle, chunkX, chunkZ, columnWeights, minWeight, thresholdPenalty, worldYRange, surfaceHeights, null);
|
||||
return carve(voids, chunkX, chunkZ, columnWeights, minWeight, thresholdPenalty, worldYRange, surfaceHeights, null);
|
||||
}
|
||||
|
||||
public int carve(
|
||||
MatterMantle mantle,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
double[] columnWeights,
|
||||
@@ -151,15 +137,15 @@ public class IrisCaveCarver3D {
|
||||
Range overrideVerticalRange
|
||||
) {
|
||||
CaveFluidSupportPlan fluidSupportPlan = new CaveFluidSupportPlan();
|
||||
int carved = carve(mantle, chunkX, chunkZ, columnWeights, minWeight, thresholdPenalty,
|
||||
int carved = carve(voids, chunkX, chunkZ, columnWeights, minWeight, thresholdPenalty,
|
||||
worldYRange, surfaceHeights, null, overrideVerticalRange, fluidSupportPlan);
|
||||
fluidSupportPlan.resolve(mantle.chunk(chunkX, chunkZ));
|
||||
fluidSupportPlan.resolve(voids, PowerOfTwoCoordinates.chunkToBlock(chunkX), PowerOfTwoCoordinates.chunkToBlock(chunkZ), worldHeight);
|
||||
return carved;
|
||||
}
|
||||
|
||||
/** {@code surfaceHeights} are the rounded heights of the chunk's columns, packed as {@link PowerOfTwoCoordinates#packLocal16}. */
|
||||
int carve(
|
||||
MatterMantle mantle,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int chunkX,
|
||||
int chunkZ,
|
||||
double[] columnWeights,
|
||||
@@ -205,11 +191,6 @@ public class IrisCaveCarver3D {
|
||||
return 0;
|
||||
}
|
||||
|
||||
MantleChunk<Matter> chunk = mantle.chunk(chunkX, chunkZ);
|
||||
if (chunk == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int x0 = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int z0 = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
int[] columnMaxY = scratch.columnMaxY;
|
||||
@@ -221,8 +202,7 @@ public class IrisCaveCarver3D {
|
||||
double[] clampedWeights = scratch.clampedColumnWeights;
|
||||
double[] verticalEdgeFade = prepareVerticalEdgeFadeTable(scratch, minY, maxY);
|
||||
prepareSurfaceClosureThresholdTable(scratch, minY, maxY);
|
||||
MatterCavern[] matterByY = prepareMatterByYTable(scratch, minY, maxY);
|
||||
prepareSectionCaches(scratch, minY, maxY);
|
||||
CarvedVoid[] voidByY = prepareVoidByYTable(scratch, minY, maxY);
|
||||
|
||||
// The threshold noise is constant for the carver, so it is built once (in the constructor) and the
|
||||
// min==max / flat-style short circuits are decided here, as Iris's styled range has always decided them.
|
||||
@@ -273,7 +253,7 @@ public class IrisCaveCarver3D {
|
||||
if (exactSampling) {
|
||||
if (adaptiveSampling) {
|
||||
carved = carvePassAdaptive(
|
||||
chunk,
|
||||
voids,
|
||||
x0,
|
||||
z0,
|
||||
minY,
|
||||
@@ -289,7 +269,7 @@ public class IrisCaveCarver3D {
|
||||
columnThreshold,
|
||||
clampedWeights,
|
||||
verticalEdgeFade,
|
||||
matterByY,
|
||||
voidByY,
|
||||
fluidRequiresFloor ? fluidSupportPlan : null,
|
||||
resolvedMinWeight,
|
||||
resolvedThresholdPenalty,
|
||||
@@ -298,7 +278,7 @@ public class IrisCaveCarver3D {
|
||||
);
|
||||
} else {
|
||||
carved = carvePassExact(
|
||||
chunk,
|
||||
voids,
|
||||
x0,
|
||||
z0,
|
||||
minY,
|
||||
@@ -312,7 +292,7 @@ public class IrisCaveCarver3D {
|
||||
columnThreshold,
|
||||
clampedWeights,
|
||||
verticalEdgeFade,
|
||||
matterByY,
|
||||
voidByY,
|
||||
fluidRequiresFloor ? fluidSupportPlan : null,
|
||||
resolvedMinWeight,
|
||||
resolvedThresholdPenalty,
|
||||
@@ -323,7 +303,7 @@ public class IrisCaveCarver3D {
|
||||
} else {
|
||||
int latticeStep = sampleStep;
|
||||
carved = carvePassLattice(
|
||||
chunk,
|
||||
voids,
|
||||
x0,
|
||||
z0,
|
||||
minY,
|
||||
@@ -338,7 +318,7 @@ public class IrisCaveCarver3D {
|
||||
columnThreshold,
|
||||
clampedWeights,
|
||||
verticalEdgeFade,
|
||||
matterByY,
|
||||
voidByY,
|
||||
fluidRequiresFloor ? fluidSupportPlan : null,
|
||||
resolvedMinWeight,
|
||||
resolvedThresholdPenalty,
|
||||
@@ -347,7 +327,7 @@ public class IrisCaveCarver3D {
|
||||
);
|
||||
if (carved == 0 && hasFallbackCandidates(columnMaxY, clampedWeights, minY, resolvedMinWeight)) {
|
||||
carved += carvePassFallback(
|
||||
chunk,
|
||||
voids,
|
||||
x0,
|
||||
z0,
|
||||
minY,
|
||||
@@ -362,7 +342,7 @@ public class IrisCaveCarver3D {
|
||||
columnThreshold,
|
||||
clampedWeights,
|
||||
verticalEdgeFade,
|
||||
matterByY,
|
||||
voidByY,
|
||||
fluidRequiresFloor ? fluidSupportPlan : null,
|
||||
resolvedMinWeight,
|
||||
resolvedThresholdPenalty,
|
||||
@@ -376,7 +356,7 @@ public class IrisCaveCarver3D {
|
||||
}
|
||||
|
||||
private int carvePassExact(
|
||||
MantleChunk<Matter> chunk,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int x0,
|
||||
int z0,
|
||||
int minY,
|
||||
@@ -390,7 +370,7 @@ public class IrisCaveCarver3D {
|
||||
double[] columnThreshold,
|
||||
double[] clampedWeights,
|
||||
double[] verticalEdgeFade,
|
||||
MatterCavern[] matterByY,
|
||||
CarvedVoid[] voidByY,
|
||||
CaveFluidSupportPlan fluidSupportPlan,
|
||||
double minWeight,
|
||||
double thresholdPenalty,
|
||||
@@ -430,7 +410,6 @@ public class IrisCaveCarver3D {
|
||||
for (int sectionIndex = minSection; sectionIndex <= maxSection; sectionIndex++) {
|
||||
int sectionMinY = Math.max(minY, PowerOfTwoCoordinates.chunkToBlock(sectionIndex));
|
||||
int sectionMaxY = Math.min(maxY, PowerOfTwoCoordinates.chunkToBlock(sectionIndex) + 15);
|
||||
MatterSlice<MatterCavern> cavernSlice = resolveCavernSlice(scratch, chunk, sectionIndex);
|
||||
|
||||
for (int y = sectionMinY; y <= sectionMaxY; y++) {
|
||||
int planeCount = 0;
|
||||
@@ -460,8 +439,7 @@ public class IrisCaveCarver3D {
|
||||
|
||||
classifyDensityPlane(scratch, x0, z0, y, planeColumnIndices, planeThresholdLimit, planeCount, planeCarve);
|
||||
int fadeIndex = y - minY;
|
||||
int localY = y & 15;
|
||||
MatterCavern verticalMatter = matterByY[fadeIndex];
|
||||
CarvedVoid verticalVoid = voidByY[fadeIndex];
|
||||
|
||||
if (skipExistingCarved) {
|
||||
for (int planeIndex = 0; planeIndex < planeCount; planeIndex++) {
|
||||
@@ -472,14 +450,14 @@ public class IrisCaveCarver3D {
|
||||
int columnIndex = planeColumnIndices[planeIndex];
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
if (cavernSlice.get(localX, localY, localZ) != null) {
|
||||
if (voids.get(x0 + localX, y, z0 + localZ) != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double localThreshold = planeThresholdLimit[planeIndex] * inverseNormalization;
|
||||
MatterCavern matter = resolveMatter(scratch, verticalMatter, x0 + localX, y, z0 + localZ,
|
||||
CarvedVoid carvedVoid = resolveVoid(scratch, verticalVoid, x0 + localX, y, z0 + localZ,
|
||||
columnIndex, fluidMaxY, localThreshold);
|
||||
writeCavern(cavernSlice, localX, y, localZ, matter, fluidSupportPlan);
|
||||
writeVoid(voids, x0 + localX, y, z0 + localZ, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
continue;
|
||||
@@ -494,9 +472,9 @@ public class IrisCaveCarver3D {
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
double localThreshold = planeThresholdLimit[planeIndex] * inverseNormalization;
|
||||
MatterCavern matter = resolveMatter(scratch, verticalMatter, x0 + localX, y, z0 + localZ,
|
||||
CarvedVoid carvedVoid = resolveVoid(scratch, verticalVoid, x0 + localX, y, z0 + localZ,
|
||||
columnIndex, fluidMaxY, localThreshold);
|
||||
writeCavern(cavernSlice, localX, y, localZ, matter, fluidSupportPlan);
|
||||
writeVoid(voids, x0 + localX, y, z0 + localZ, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
}
|
||||
@@ -506,7 +484,7 @@ public class IrisCaveCarver3D {
|
||||
}
|
||||
|
||||
private int carvePassAdaptive(
|
||||
MantleChunk<Matter> chunk,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int x0,
|
||||
int z0,
|
||||
int minY,
|
||||
@@ -522,7 +500,7 @@ public class IrisCaveCarver3D {
|
||||
double[] columnThreshold,
|
||||
double[] clampedWeights,
|
||||
double[] verticalEdgeFade,
|
||||
MatterCavern[] matterByY,
|
||||
CarvedVoid[] voidByY,
|
||||
CaveFluidSupportPlan fluidSupportPlan,
|
||||
double minWeight,
|
||||
double thresholdPenalty,
|
||||
@@ -568,7 +546,6 @@ public class IrisCaveCarver3D {
|
||||
for (int sectionIndex = minSection; sectionIndex <= maxSection; sectionIndex++) {
|
||||
int sectionMinY = Math.max(minY, PowerOfTwoCoordinates.chunkToBlock(sectionIndex));
|
||||
int sectionMaxY = Math.min(maxY, PowerOfTwoCoordinates.chunkToBlock(sectionIndex) + 15);
|
||||
MatterSlice<MatterCavern> cavernSlice = resolveCavernSlice(scratch, chunk, sectionIndex);
|
||||
|
||||
for (int y = sectionMinY; y <= sectionMaxY; y++) {
|
||||
int planeCount = 0;
|
||||
@@ -609,8 +586,7 @@ public class IrisCaveCarver3D {
|
||||
effectiveAdaptiveThresholdMargin
|
||||
);
|
||||
int fadeIndex = y - minY;
|
||||
int localY = y & 15;
|
||||
MatterCavern verticalMatter = matterByY[fadeIndex];
|
||||
CarvedVoid verticalVoid = voidByY[fadeIndex];
|
||||
|
||||
if (skipExistingCarved) {
|
||||
for (int planeIndex = 0; planeIndex < planeCount; planeIndex++) {
|
||||
@@ -621,14 +597,14 @@ public class IrisCaveCarver3D {
|
||||
int columnIndex = planeColumnIndices[planeIndex];
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
if (cavernSlice.get(localX, localY, localZ) != null) {
|
||||
if (voids.get(x0 + localX, y, z0 + localZ) != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double localThreshold = planeThresholdLimit[planeIndex] * inverseNormalization;
|
||||
MatterCavern matter = resolveMatter(scratch, verticalMatter, x0 + localX, y, z0 + localZ,
|
||||
CarvedVoid carvedVoid = resolveVoid(scratch, verticalVoid, x0 + localX, y, z0 + localZ,
|
||||
columnIndex, fluidMaxY, localThreshold);
|
||||
writeCavern(cavernSlice, localX, y, localZ, matter, fluidSupportPlan);
|
||||
writeVoid(voids, x0 + localX, y, z0 + localZ, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
continue;
|
||||
@@ -643,9 +619,9 @@ public class IrisCaveCarver3D {
|
||||
int localX = PowerOfTwoCoordinates.unpackLocal16X(columnIndex);
|
||||
int localZ = columnIndex & 15;
|
||||
double localThreshold = planeThresholdLimit[planeIndex] * inverseNormalization;
|
||||
MatterCavern matter = resolveMatter(scratch, verticalMatter, x0 + localX, y, z0 + localZ,
|
||||
CarvedVoid carvedVoid = resolveVoid(scratch, verticalVoid, x0 + localX, y, z0 + localZ,
|
||||
columnIndex, fluidMaxY, localThreshold);
|
||||
writeCavern(cavernSlice, localX, y, localZ, matter, fluidSupportPlan);
|
||||
writeVoid(voids, x0 + localX, y, z0 + localZ, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
}
|
||||
@@ -667,7 +643,7 @@ public class IrisCaveCarver3D {
|
||||
}
|
||||
|
||||
private int carvePassLattice(
|
||||
MantleChunk<Matter> chunk,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int x0,
|
||||
int z0,
|
||||
int minY,
|
||||
@@ -682,7 +658,7 @@ public class IrisCaveCarver3D {
|
||||
double[] columnThreshold,
|
||||
double[] clampedWeights,
|
||||
double[] verticalEdgeFade,
|
||||
MatterCavern[] matterByY,
|
||||
CarvedVoid[] voidByY,
|
||||
CaveFluidSupportPlan fluidSupportPlan,
|
||||
double minWeight,
|
||||
double thresholdPenalty,
|
||||
@@ -768,9 +744,7 @@ public class IrisCaveCarver3D {
|
||||
double density = sampleDensityOptimized(scratch, x, y, z);
|
||||
int stampMaxY = Math.min(maxY, y + 1);
|
||||
for (int yy = y; yy <= stampMaxY; yy++) {
|
||||
MatterCavern verticalMatter = matterByY[yy - minY];
|
||||
MatterSlice<MatterCavern> cavernSlice = resolveCavernSlice(scratch, chunk, PowerOfTwoCoordinates.floorDivPow2(yy, 4));
|
||||
int localY = yy & 15;
|
||||
CarvedVoid verticalVoid = voidByY[yy - minY];
|
||||
int fadeIndex = yy - minY;
|
||||
for (int columnIndex = 0; columnIndex < activeColumns; columnIndex++) {
|
||||
if (yy > tileTopY[columnIndex]) {
|
||||
@@ -795,17 +769,17 @@ public class IrisCaveCarver3D {
|
||||
int localZ = tileLocalZ[columnIndex];
|
||||
int worldX = x0 + localX;
|
||||
int worldZ = z0 + localZ;
|
||||
MatterCavern matter = resolveMatter(scratch, verticalMatter, worldX, yy, worldZ,
|
||||
CarvedVoid carvedVoid = resolveVoid(scratch, verticalVoid, worldX, yy, worldZ,
|
||||
index, fluidMaxY, localThreshold);
|
||||
if (skipExistingCarved) {
|
||||
if (cavernSlice.get(localX, localY, localZ) == null) {
|
||||
writeCavern(cavernSlice, localX, yy, localZ, matter, fluidSupportPlan);
|
||||
if (voids.get(worldX, yy, worldZ) == null) {
|
||||
writeVoid(voids, worldX, yy, worldZ, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
writeCavern(cavernSlice, localX, yy, localZ, matter, fluidSupportPlan);
|
||||
writeVoid(voids, worldX, yy, worldZ, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
}
|
||||
@@ -817,7 +791,7 @@ public class IrisCaveCarver3D {
|
||||
}
|
||||
|
||||
private int carvePassFallback(
|
||||
MantleChunk<Matter> chunk,
|
||||
MantleLayer<CarvedVoid> voids,
|
||||
int x0,
|
||||
int z0,
|
||||
int minY,
|
||||
@@ -832,7 +806,7 @@ public class IrisCaveCarver3D {
|
||||
double[] columnThreshold,
|
||||
double[] clampedWeights,
|
||||
double[] verticalEdgeFade,
|
||||
MatterCavern[] matterByY,
|
||||
CarvedVoid[] voidByY,
|
||||
CaveFluidSupportPlan fluidSupportPlan,
|
||||
double minWeight,
|
||||
double thresholdPenalty,
|
||||
@@ -877,20 +851,18 @@ public class IrisCaveCarver3D {
|
||||
if (density > localThreshold) {
|
||||
continue;
|
||||
}
|
||||
MatterCavern verticalMatter = matterByY[yy - minY];
|
||||
MatterCavern matter = resolveMatter(scratch, verticalMatter, x, yy, z,
|
||||
CarvedVoid verticalVoid = voidByY[yy - minY];
|
||||
CarvedVoid carvedVoid = resolveVoid(scratch, verticalVoid, x, yy, z,
|
||||
index, fluidMaxY, localThreshold);
|
||||
MatterSlice<MatterCavern> cavernSlice = resolveCavernSlice(scratch, chunk, PowerOfTwoCoordinates.floorDivPow2(yy, 4));
|
||||
int localY = yy & 15;
|
||||
if (skipExistingCarved) {
|
||||
if (cavernSlice.get(lx, localY, lz) == null) {
|
||||
writeCavern(cavernSlice, lx, yy, lz, matter, fluidSupportPlan);
|
||||
if (voids.get(x, yy, z) == null) {
|
||||
writeVoid(voids, x, yy, z, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
writeCavern(cavernSlice, lx, yy, lz, matter, fluidSupportPlan);
|
||||
writeVoid(voids, x, yy, z, carvedVoid, fluidSupportPlan);
|
||||
carved++;
|
||||
}
|
||||
}
|
||||
@@ -2111,58 +2083,35 @@ public class IrisCaveCarver3D {
|
||||
return activeCount;
|
||||
}
|
||||
|
||||
private MatterSlice<MatterCavern> resolveCavernSlice(CaveCarveScratch scratch, MantleChunk<Matter> chunk, int sectionIndex) {
|
||||
@SuppressWarnings("unchecked")
|
||||
MatterSlice<MatterCavern> cachedSlice = (MatterSlice<MatterCavern>) scratch.sectionSlices[sectionIndex];
|
||||
if (cachedSlice != null) {
|
||||
return cachedSlice;
|
||||
}
|
||||
|
||||
Matter sectionMatter = scratch.sectionMatter[sectionIndex];
|
||||
if (sectionMatter == null) {
|
||||
sectionMatter = chunk.getOrCreate(sectionIndex);
|
||||
scratch.sectionMatter[sectionIndex] = sectionMatter;
|
||||
}
|
||||
|
||||
MatterSlice<MatterCavern> resolvedSlice = sectionMatter.slice(MatterCavern.class);
|
||||
scratch.sectionSlices[sectionIndex] = resolvedSlice;
|
||||
return resolvedSlice;
|
||||
}
|
||||
|
||||
private MatterCavern[] prepareMatterByYTable(CaveCarveScratch scratch, int minY, int maxY) {
|
||||
private CarvedVoid[] prepareVoidByYTable(CaveCarveScratch scratch, int minY, int maxY) {
|
||||
int size = Math.max(0, maxY - minY + 1);
|
||||
if (scratch.matterByY.length < size) {
|
||||
scratch.matterByY = new MatterCavern[size];
|
||||
if (scratch.voidByY.length < size) {
|
||||
scratch.voidByY = new CarvedVoid[size];
|
||||
}
|
||||
|
||||
MatterCavern[] matterByY = scratch.matterByY;
|
||||
CarvedVoid[] voidByY = scratch.voidByY;
|
||||
boolean allowLava = profile.allowLava();
|
||||
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
int offset = y - minY;
|
||||
if (allowLava && y <= lavaHeight) {
|
||||
matterByY[offset] = carveLava;
|
||||
if (y > lavaHeight) {
|
||||
voidByY[offset] = CarvedVoid.OPEN;
|
||||
continue;
|
||||
}
|
||||
if (!allowLava && y <= lavaHeight) {
|
||||
matterByY[offset] = carveForcedAir;
|
||||
continue;
|
||||
}
|
||||
|
||||
matterByY[offset] = carveAir;
|
||||
voidByY[offset] = allowLava ? CarvedVoid.LAVA : CarvedVoid.AIR;
|
||||
}
|
||||
|
||||
return matterByY;
|
||||
return voidByY;
|
||||
}
|
||||
|
||||
private MatterCavern resolveMatter(CaveCarveScratch scratch, MatterCavern verticalMatter, int x, int y, int z,
|
||||
int columnIndex, int[] fluidMaxY, double localThreshold) {
|
||||
if (verticalMatter != carveLava
|
||||
private CarvedVoid resolveVoid(CaveCarveScratch scratch, CarvedVoid verticalVoid, int x, int y, int z,
|
||||
int columnIndex, int[] fluidMaxY, double localThreshold) {
|
||||
if (verticalVoid != CarvedVoid.LAVA
|
||||
&& y <= fluidMaxY[columnIndex]
|
||||
&& isAquiferCandidate(scratch, x, y, z, localThreshold)) {
|
||||
return carveFluid;
|
||||
return CarvedVoid.FLUID;
|
||||
}
|
||||
return verticalMatter;
|
||||
return verticalVoid;
|
||||
}
|
||||
|
||||
private boolean isAquiferCandidate(CaveCarveScratch scratch, int x, int y, int z, double localThreshold) {
|
||||
@@ -2212,27 +2161,10 @@ public class IrisCaveCarver3D {
|
||||
return sampleDensityOptimized(scratch, x, y, z) > threshold;
|
||||
}
|
||||
|
||||
private void writeCavern(MatterSlice<MatterCavern> cavernSlice, int localX, int y, int localZ,
|
||||
MatterCavern matter, CaveFluidSupportPlan fluidSupportPlan) {
|
||||
cavernSlice.set(localX, y & 15, localZ, matter);
|
||||
if (fluidSupportPlan != null && matter == carveFluid) {
|
||||
fluidSupportPlan.add(localX, y, localZ, carveFluid, carveAir);
|
||||
}
|
||||
}
|
||||
|
||||
private void prepareSectionCaches(CaveCarveScratch scratch, int minY, int maxY) {
|
||||
int minSection = Math.max(0, PowerOfTwoCoordinates.floorDivPow2(minY, 4));
|
||||
int maxSection = Math.max(minSection, PowerOfTwoCoordinates.floorDivPow2(maxY, 4));
|
||||
int requiredSections = maxSection + 1;
|
||||
if (scratch.sectionMatter.length < requiredSections) {
|
||||
scratch.sectionMatter = new Matter[requiredSections];
|
||||
scratch.sectionSlices = new MatterSlice<?>[requiredSections];
|
||||
return;
|
||||
}
|
||||
|
||||
for (int section = minSection; section <= maxSection; section++) {
|
||||
scratch.sectionMatter[section] = null;
|
||||
scratch.sectionSlices[section] = null;
|
||||
private void writeVoid(MantleLayer<CarvedVoid> voids, int x, int y, int z, CarvedVoid carvedVoid, CaveFluidSupportPlan fluidSupportPlan) {
|
||||
voids.set(x, y, z, carvedVoid);
|
||||
if (fluidSupportPlan != null && carvedVoid == CarvedVoid.FLUID) {
|
||||
fluidSupportPlan.add(x & LOCAL_MASK, y, z & LOCAL_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package art.arcane.iris.engine.mantle.components;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.builtin.anchor.PlaceTrait;
|
||||
import art.arcane.iris.builtin.objects.ObjectPlacement;
|
||||
import art.arcane.iris.builtin.objects.ObjectRun;
|
||||
@@ -62,7 +61,7 @@ final class ObjectChunk {
|
||||
this.world = context.world();
|
||||
this.terrain = context.placementTerrain();
|
||||
this.worldHeight = context.terrain().bounds().maxY();
|
||||
this.carved = new CarvedSpace(context.extension(MatterMantle.class).orElseThrow(), worldHeight);
|
||||
this.carved = new CarvedSpace(context.mantle().carved(), context.mantle().bounds());
|
||||
this.blocks = world.resources().blocks();
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.IrisSeedPurposes;
|
||||
import art.arcane.iris.builtin.IrisStages;
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.modules.carve.CarvingBiomeSettings;
|
||||
import art.arcane.iris.modules.carve.CarvingEnabledSettings;
|
||||
import art.arcane.iris.modules.carve.CarvingSettings;
|
||||
@@ -31,12 +30,15 @@ import art.arcane.iris.modules.carve.UpperDimensionCarvingSettings;
|
||||
import art.arcane.iris.modules.terrain.TerrainPalettes;
|
||||
import art.arcane.iris.engine.mantle.components.CarveWorld;
|
||||
import art.arcane.iris.engine.mantle.components.CaveCarving;
|
||||
import art.arcane.iris.engine.mantle.components.CaveFloorMarking;
|
||||
import com.volmit.IrisFeature;
|
||||
import com.volmit.IrisModule;
|
||||
import com.volmit.ModuleInfo;
|
||||
import com.volmit.ModuleSetup;
|
||||
import com.volmit.generation.ChunkContext;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.block.BlockTrait;
|
||||
@@ -83,14 +85,19 @@ public final class CarveModule implements IrisModule {
|
||||
if (!carves(context)) {
|
||||
return;
|
||||
}
|
||||
MatterMantle mantle = context.extension(MatterMantle.class).orElseThrow();
|
||||
caveCarving(context).carve(mantle, context.terrain(), context.chunkX(), context.chunkZ());
|
||||
MantleLayer<CarvedVoid> voids = context.mantle().carved();
|
||||
caveCarving(context).carve(voids, context.terrain(), context.chunkX(), context.chunkZ());
|
||||
caveFloorMarking(context).mark(voids, context.terrain(), context.placementTerrain(), context.chunkX(), context.chunkZ());
|
||||
}
|
||||
|
||||
private static void applyCaves(ChunkStageContext context) {
|
||||
MatterMantle mantle = context.extension(MatterMantle.class).orElseThrow();
|
||||
Hunk<BlockState> blocks = context.blocks();
|
||||
caveApplying(context).apply(mantle, context.terrain(), context.chunkX(), context.chunkZ(), blocks, CaveDressing.of(context));
|
||||
caveApplying(context).apply(context.mantle().carved(), context.terrain(), context.chunkX(), context.chunkZ(), blocks, CaveDressing.of(context));
|
||||
}
|
||||
|
||||
private static CaveFloorMarking caveFloorMarking(ChunkContext context) {
|
||||
return context.world().state(CaveFloorMarking.class, generating -> new CaveFloorMarking(carveWorld(generating, context.terrain()),
|
||||
upperDimensionCarving(context)));
|
||||
}
|
||||
|
||||
private static CaveCarving caveCarving(ChunkContext context) {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -28,7 +28,7 @@ final class CarveWallBuffer {
|
||||
private static final double LOAD_FACTOR = 0.75D;
|
||||
|
||||
private int[] keys;
|
||||
private MatterCavern[] values;
|
||||
private CarvedVoid[] values;
|
||||
private int mask;
|
||||
private int resizeAt;
|
||||
private int size;
|
||||
@@ -42,12 +42,12 @@ final class CarveWallBuffer {
|
||||
|
||||
keys = new int[capacity];
|
||||
Arrays.fill(keys, EMPTY_KEY);
|
||||
values = new MatterCavern[capacity];
|
||||
values = new CarvedVoid[capacity];
|
||||
mask = capacity - 1;
|
||||
resizeAt = Math.max(1, (int) (capacity * LOAD_FACTOR));
|
||||
}
|
||||
|
||||
void put(int x, int y, int z, MatterCavern value) {
|
||||
void put(int x, int y, int z, CarvedVoid value) {
|
||||
int key = pack(x, y, z);
|
||||
int index = mix(key) & mask;
|
||||
|
||||
@@ -72,7 +72,7 @@ final class CarveWallBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
MatterCavern get(int x, int y, int z) {
|
||||
CarvedVoid get(int x, int y, int z) {
|
||||
int key = pack(x, y, z);
|
||||
int index = mix(key) & mask;
|
||||
while (true) {
|
||||
@@ -94,9 +94,9 @@ final class CarveWallBuffer {
|
||||
continue;
|
||||
}
|
||||
|
||||
MatterCavern cavern = values[index];
|
||||
if (cavern != null) {
|
||||
consumer.accept(unpackX(key), unpackY(key), unpackZ(key), cavern);
|
||||
CarvedVoid carvedVoid = values[index];
|
||||
if (carvedVoid != null) {
|
||||
consumer.accept(unpackX(key), unpackY(key), unpackZ(key), carvedVoid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,25 +109,25 @@ final class CarveWallBuffer {
|
||||
|
||||
private void resize() {
|
||||
int[] oldKeys = keys;
|
||||
MatterCavern[] oldValues = values;
|
||||
CarvedVoid[] oldValues = values;
|
||||
int nextCapacity = oldKeys.length << 1;
|
||||
keys = new int[nextCapacity];
|
||||
Arrays.fill(keys, EMPTY_KEY);
|
||||
values = new MatterCavern[nextCapacity];
|
||||
values = new CarvedVoid[nextCapacity];
|
||||
mask = nextCapacity - 1;
|
||||
resizeAt = Math.max(1, (int) (nextCapacity * LOAD_FACTOR));
|
||||
size = 0;
|
||||
|
||||
for (int index = 0; index < oldKeys.length; index++) {
|
||||
int key = oldKeys[index];
|
||||
MatterCavern value = oldValues[index];
|
||||
CarvedVoid value = oldValues[index];
|
||||
if (key != EMPTY_KEY && value != null) {
|
||||
reinsert(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reinsert(int key, MatterCavern value) {
|
||||
private void reinsert(int key, CarvedVoid value) {
|
||||
int index = mix(key) & mask;
|
||||
while (keys[index] != EMPTY_KEY) {
|
||||
index = (index + 1) & mask;
|
||||
@@ -161,6 +161,6 @@ final class CarveWallBuffer {
|
||||
|
||||
@FunctionalInterface
|
||||
interface Consumer {
|
||||
void accept(int x, int y, int z, MatterCavern cavern);
|
||||
void accept(int x, int y, int z, CarvedVoid carvedVoid);
|
||||
}
|
||||
}
|
||||
@@ -18,20 +18,17 @@
|
||||
|
||||
package art.arcane.iris.engine.modifier;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
import art.arcane.iris.builtin.decorant.DecorationPart;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterMarker;
|
||||
import art.arcane.volmlib.util.matter.slices.MarkerMatter;
|
||||
import art.arcane.iris.engine.mantle.components.CarveWorld;
|
||||
import com.volmit.block.BlockRegistry;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.geometry.BlockBox;
|
||||
import com.volmit.hunk.Hunk;
|
||||
import com.volmit.mantle.CarvedVoid;
|
||||
import com.volmit.mantle.MantleLayer;
|
||||
import com.volmit.resource.PackResources;
|
||||
import com.volmit.resource.ResourceId;
|
||||
import com.volmit.world.PackWorld;
|
||||
@@ -47,18 +44,14 @@ import java.util.Map;
|
||||
* One per world, holding the carve stream's random.
|
||||
*/
|
||||
public class CaveApplying {
|
||||
private static final byte LIQUID_FLUID = 1;
|
||||
private static final byte LIQUID_FORCED_AIR = 3;
|
||||
private static final ThreadLocal<IrisCarveScratch> SCRATCH = ThreadLocal.withInitial(IrisCarveScratch::new);
|
||||
private static final int CAVE_BIOME_BLEND_RADIUS = 3;
|
||||
private static final int CAVE_BIOME_BLEND_CENTER_WEIGHT = 4;
|
||||
private static final int CAVE_BIOME_BLEND_TOTAL_WEIGHT = 8;
|
||||
private static final int CAVE_BIOME_CACHE_SIZE = 2048;
|
||||
private static final int CHUNK_SIZE = 16;
|
||||
private static final int CHUNK_AREA = 256;
|
||||
private static final int LAYER_DEPTH = 3;
|
||||
private static final long CEILING_MARKER_SALT = 0x9E3779B97F4A7C15L;
|
||||
private static final long FLOOR_MARKER_SALT = 0xC2B2AE3D27D4EB4FL;
|
||||
private static final MatterCavern BASIC_CAVERN = new MatterCavern(true, "", (byte) 0);
|
||||
|
||||
private final CarveWorld world;
|
||||
private final PackResources resources;
|
||||
@@ -82,27 +75,23 @@ public class CaveApplying {
|
||||
|
||||
/**
|
||||
* Applies the caves to the chunk at chunk coordinates {@code x}, {@code z}, whose blocks are {@code output}; the caves are in
|
||||
* {@code mantle}, {@code terrain} gives the heights and cave biomes around the chunk and {@code dressing} what its caves' walls,
|
||||
* floors and ceilings get.
|
||||
* {@code voids}, which reads one block beyond the chunk to wall the caves that cross its border, {@code terrain} gives the
|
||||
* heights and cave biomes around the chunk and {@code dressing} what its caves' walls, floors and ceilings get.
|
||||
*/
|
||||
public void apply(MatterMantle mantle, TerrainSampler terrain, int x, int z, Hunk<BlockState> output, CaveDressing dressing) {
|
||||
MantleChunk<Matter> mantleChunk = mantle.chunk(x, z);
|
||||
if (mantleChunk == null) {
|
||||
return;
|
||||
}
|
||||
new Application(mantle, mantleChunk, terrain, x, z, output, dressing).run();
|
||||
public void apply(MantleLayer<CarvedVoid> voids, TerrainSampler terrain, int x, int z, Hunk<BlockState> output, CaveDressing dressing) {
|
||||
new Application(voids, terrain, x, z, output, dressing).run();
|
||||
}
|
||||
|
||||
static boolean hasExplicitCarveIntent(MatterCavern cavern) {
|
||||
return cavern != null && (isFluidIntent(cavern) || cavern.isLava() || cavern.getLiquid() == LIQUID_FORCED_AIR);
|
||||
static boolean hasExplicitCarveIntent(CarvedVoid carvedVoid) {
|
||||
return carvedVoid != null && carvedVoid.fill() != CarvedVoid.Fill.OPEN;
|
||||
}
|
||||
|
||||
static boolean isFluidIntent(MatterCavern cavern) {
|
||||
return cavern != null && cavern.getLiquid() == LIQUID_FLUID;
|
||||
static boolean isFluidIntent(CarvedVoid carvedVoid) {
|
||||
return carvedVoid != null && carvedVoid.fill() == CarvedVoid.Fill.FLUID;
|
||||
}
|
||||
|
||||
static boolean shouldPreserveExistingFluid(MatterCavern cavern, boolean existingIsFluid) {
|
||||
return existingIsFluid && !hasExplicitCarveIntent(cavern);
|
||||
static boolean shouldPreserveExistingFluid(CarvedVoid carvedVoid, boolean existingIsFluid) {
|
||||
return existingIsFluid && !hasExplicitCarveIntent(carvedVoid);
|
||||
}
|
||||
|
||||
static boolean usesDefaultLava(int caveLavaHeight, int y) {
|
||||
@@ -113,17 +102,16 @@ public class CaveApplying {
|
||||
return surfaceIsOre && !belowIsSolid;
|
||||
}
|
||||
|
||||
static BlockState resolveExplicitCarveState(MatterCavern cavern, BlockState fluid, BlockState lava, BlockState air) {
|
||||
if (cavern == null) {
|
||||
static BlockState resolveExplicitCarveState(CarvedVoid carvedVoid, BlockState fluid, BlockState lava, BlockState air) {
|
||||
if (carvedVoid == null) {
|
||||
return null;
|
||||
}
|
||||
if (isFluidIntent(cavern)) {
|
||||
return fluid;
|
||||
}
|
||||
if (cavern.isLava()) {
|
||||
return lava;
|
||||
}
|
||||
return cavern.getLiquid() == LIQUID_FORCED_AIR ? air : null;
|
||||
return switch (carvedVoid.fill()) {
|
||||
case FLUID -> fluid;
|
||||
case LAVA -> lava;
|
||||
case AIR -> air;
|
||||
case OPEN -> null;
|
||||
};
|
||||
}
|
||||
|
||||
static boolean canReplaceCaveFloorLayer(Hunk<BlockState> output, int x, int y, int z, BlockState layer, CaveBlockClasses classes) {
|
||||
@@ -143,24 +131,26 @@ public class CaveApplying {
|
||||
|
||||
/** One chunk's application: the chunk's blocks, mantle and the caches its passes share. */
|
||||
final class Application {
|
||||
private final MatterMantle mantle;
|
||||
private final MantleChunk<Matter> mantleChunk;
|
||||
private final MantleLayer<CarvedVoid> voids;
|
||||
private final TerrainSampler terrain;
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
private final int chunkBlockX;
|
||||
private final int chunkBlockZ;
|
||||
private final Hunk<BlockState> output;
|
||||
private final CaveDressing dressing;
|
||||
private final CaveBlockClasses classes = new CaveBlockClasses(blocks);
|
||||
private final CaveBiomeCache caveBiomeCache = new CaveBiomeCache(CAVE_BIOME_CACHE_SIZE);
|
||||
private final IrisCarveScratch scratch = SCRATCH.get();
|
||||
|
||||
Application(MatterMantle mantle, MantleChunk<Matter> mantleChunk, TerrainSampler terrain, int chunkX, int chunkZ, Hunk<BlockState> output,
|
||||
Application(MantleLayer<CarvedVoid> voids, TerrainSampler terrain, int chunkX, int chunkZ, Hunk<BlockState> output,
|
||||
CaveDressing dressing) {
|
||||
this.mantle = mantle;
|
||||
this.mantleChunk = mantleChunk;
|
||||
this.voids = voids;
|
||||
this.terrain = terrain;
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
this.chunkBlockX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
this.chunkBlockZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
this.output = output;
|
||||
this.dressing = dressing;
|
||||
}
|
||||
@@ -171,9 +161,7 @@ public class CaveApplying {
|
||||
CarveColumnMask[] columnMasks = scratch.columnMasks;
|
||||
CarveColumnMask[] boundaryMasks = scratch.boundaryMasks;
|
||||
int[] surfaceHeights = scratch.surfaceHeights;
|
||||
Map<String, ResourceId> customBiomeCache = scratch.customBiomeCache;
|
||||
int chunkBlockX = PowerOfTwoCoordinates.chunkToBlock(chunkX);
|
||||
int chunkBlockZ = PowerOfTwoCoordinates.chunkToBlock(chunkZ);
|
||||
Map<ResourceId, ResourceId> customBiomeCache = scratch.customBiomeCache;
|
||||
boolean protectUpper = !upperDimensionCarving && terrain.upperDimensionY(chunkBlockX, chunkBlockZ).isPresent();
|
||||
int[] upperSurfaceHeights = protectUpper ? scratch.getOrCreateUpperSurfaceHeights() : null;
|
||||
for (int columnIndex = 0; columnIndex < CHUNK_AREA; columnIndex++) {
|
||||
@@ -189,17 +177,14 @@ public class CaveApplying {
|
||||
|
||||
int worldHeightSpan = world.height();
|
||||
int caveLavaHeight = world.lavaHeight();
|
||||
mantleChunk.iterate(MatterCavern.class, (xx, yy, zz, cavern) -> {
|
||||
if (cavern == null) {
|
||||
BlockBox ownColumns = new BlockBox(chunkBlockX, 0, chunkBlockZ, chunkBlockX + CHUNK_SIZE, worldHeightSpan, chunkBlockZ + CHUNK_SIZE);
|
||||
voids.visit(ownColumns, (xx, yy, zz, carvedVoid) -> {
|
||||
if (yy <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (yy >= worldHeightSpan || yy <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int rx = xx & 15;
|
||||
int rz = zz & 15;
|
||||
int rx = xx - chunkBlockX;
|
||||
int rz = zz - chunkBlockZ;
|
||||
int columnIndex = PowerOfTwoCoordinates.packLocal16(rx, rz);
|
||||
|
||||
if (upperSurfaceHeights != null && yy >= upperSurfaceHeights[columnIndex]) {
|
||||
@@ -207,15 +192,15 @@ public class CaveApplying {
|
||||
}
|
||||
|
||||
BlockState current = output.get(rx, yy, rz);
|
||||
boolean explicitCarveIntent = hasExplicitCarveIntent(cavern);
|
||||
boolean explicitCarveIntent = hasExplicitCarveIntent(carvedVoid);
|
||||
|
||||
if (shouldPreserveExistingFluid(cavern, classes.isFluid(current))) {
|
||||
if (shouldPreserveExistingFluid(carvedVoid, classes.isFluid(current))) {
|
||||
return;
|
||||
}
|
||||
|
||||
columnMasks[columnIndex].add(yy);
|
||||
|
||||
if (!cavern.getCustomBiome().isEmpty()) {
|
||||
if (carvedVoid.biome().isPresent()) {
|
||||
scratch.customCaveBiomePresent = true;
|
||||
}
|
||||
|
||||
@@ -225,8 +210,8 @@ public class CaveApplying {
|
||||
|
||||
if (explicitCarveIntent) {
|
||||
// Only a fluid cavern consumes the fluid sample, so never take it per voxel.
|
||||
BlockState fluid = isFluidIntent(cavern) ? dressing.fluidAt(chunkBlockX + rx, chunkBlockZ + rz) : null;
|
||||
BlockState carved = resolveExplicitCarveState(cavern, fluid, lava, caveAir);
|
||||
BlockState fluid = isFluidIntent(carvedVoid) ? dressing.fluidAt(chunkBlockX + rx, chunkBlockZ + rz) : null;
|
||||
BlockState carved = resolveExplicitCarveState(carvedVoid, fluid, lava, caveAir);
|
||||
output.set(rx, yy, rz, carved == null ? plainAir : carved);
|
||||
} else if (usesDefaultLava(caveLavaHeight, yy)) {
|
||||
output.set(rx, yy, rz, lava);
|
||||
@@ -241,13 +226,12 @@ public class CaveApplying {
|
||||
}
|
||||
addCrossChunkBoundaryWalls(walls, boundaryMasks, surfaceHeights);
|
||||
|
||||
walls.forEach((rx, yy, rz, cavern) -> {
|
||||
walls.forEach((rx, yy, rz, carvedVoid) -> {
|
||||
int worldX = rx + chunkBlockX;
|
||||
int worldZ = rz + chunkBlockZ;
|
||||
String customBiome = cavern.getCustomBiome();
|
||||
ResourceId biome = customBiome.isEmpty()
|
||||
ResourceId biome = carvedVoid.biome().isEmpty()
|
||||
? resolveCaveBiome(worldX, yy, worldZ)
|
||||
: resolveCustomBiome(customBiomeCache, customBiome);
|
||||
: resolveCustomBiome(customBiomeCache, carvedVoid.biome().get());
|
||||
|
||||
if (biome != null) {
|
||||
BlockState data = dressing.wall(biome, rng, worldX, yy, worldZ);
|
||||
@@ -304,16 +288,16 @@ public class CaveApplying {
|
||||
int yy = columnMask.nextSetBit(0);
|
||||
while (yy >= 0) {
|
||||
if (rz < 15 && !columnMasks[columnIndex + 1].contains(yy)) {
|
||||
walls.put(rx, yy, rz + 1, BASIC_CAVERN);
|
||||
walls.put(rx, yy, rz + 1, CarvedVoid.OPEN);
|
||||
}
|
||||
if (rx < 15 && !columnMasks[columnIndex + 16].contains(yy)) {
|
||||
walls.put(rx + 1, yy, rz, BASIC_CAVERN);
|
||||
walls.put(rx + 1, yy, rz, CarvedVoid.OPEN);
|
||||
}
|
||||
if (rz > 0 && !columnMasks[columnIndex - 1].contains(yy)) {
|
||||
walls.put(rx, yy, rz - 1, BASIC_CAVERN);
|
||||
walls.put(rx, yy, rz - 1, CarvedVoid.OPEN);
|
||||
}
|
||||
if (rx > 0 && !columnMasks[columnIndex - 16].contains(yy)) {
|
||||
walls.put(rx - 1, yy, rz, BASIC_CAVERN);
|
||||
walls.put(rx - 1, yy, rz, CarvedVoid.OPEN);
|
||||
}
|
||||
yy = columnMask.nextSetBit(yy + 1);
|
||||
}
|
||||
@@ -331,19 +315,19 @@ public class CaveApplying {
|
||||
int rz = columnIndex & 15;
|
||||
int yy = columnMask.nextSetBit(0);
|
||||
while (yy >= 0) {
|
||||
MatterCavern cavern = mantleChunk.get(rx, yy, rz, MatterCavern.class);
|
||||
if (cavern != null) {
|
||||
if (rz < 15 && mantleChunk.get(rx, yy, rz + 1, MatterCavern.class) == null) {
|
||||
walls.put(rx, yy, rz + 1, cavern);
|
||||
CarvedVoid carvedVoid = ownVoid(rx, yy, rz);
|
||||
if (carvedVoid != null) {
|
||||
if (rz < 15 && ownVoid(rx, yy, rz + 1) == null) {
|
||||
walls.put(rx, yy, rz + 1, carvedVoid);
|
||||
}
|
||||
if (rx < 15 && mantleChunk.get(rx + 1, yy, rz, MatterCavern.class) == null) {
|
||||
walls.put(rx + 1, yy, rz, cavern);
|
||||
if (rx < 15 && ownVoid(rx + 1, yy, rz) == null) {
|
||||
walls.put(rx + 1, yy, rz, carvedVoid);
|
||||
}
|
||||
if (rz > 0 && mantleChunk.get(rx, yy, rz - 1, MatterCavern.class) == null) {
|
||||
walls.put(rx, yy, rz - 1, cavern);
|
||||
if (rz > 0 && ownVoid(rx, yy, rz - 1) == null) {
|
||||
walls.put(rx, yy, rz - 1, carvedVoid);
|
||||
}
|
||||
if (rx > 0 && mantleChunk.get(rx - 1, yy, rz, MatterCavern.class) == null) {
|
||||
walls.put(rx - 1, yy, rz, cavern);
|
||||
if (rx > 0 && ownVoid(rx - 1, yy, rz) == null) {
|
||||
walls.put(rx - 1, yy, rz, carvedVoid);
|
||||
}
|
||||
}
|
||||
yy = columnMask.nextSetBit(yy + 1);
|
||||
@@ -363,39 +347,27 @@ public class CaveApplying {
|
||||
return;
|
||||
}
|
||||
|
||||
MantleChunk<Matter> west = mantle.loadedChunk(chunkX - 1, chunkZ);
|
||||
MantleChunk<Matter> east = mantle.loadedChunk(chunkX + 1, chunkZ);
|
||||
MantleChunk<Matter> north = mantle.loadedChunk(chunkX, chunkZ - 1);
|
||||
MantleChunk<Matter> south = mantle.loadedChunk(chunkX, chunkZ + 1);
|
||||
if (west == null && east == null && north == null && south == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int westBlockX = chunkBlockX - 1;
|
||||
int eastBlockX = chunkBlockX + CHUNK_SIZE;
|
||||
int northBlockZ = chunkBlockZ - 1;
|
||||
int southBlockZ = chunkBlockZ + CHUNK_SIZE;
|
||||
for (int yy = 1; yy <= maxY; yy++) {
|
||||
for (int offset = 0; offset < 16; offset++) {
|
||||
if (west != null) {
|
||||
tryAddBoundaryWall(west, walls, boundaryMasks, 0, yy, offset, 15, offset);
|
||||
}
|
||||
if (east != null) {
|
||||
tryAddBoundaryWall(east, walls, boundaryMasks, 15, yy, offset, 0, offset);
|
||||
}
|
||||
if (north != null) {
|
||||
tryAddBoundaryWall(north, walls, boundaryMasks, offset, yy, 0, offset, 15);
|
||||
}
|
||||
if (south != null) {
|
||||
tryAddBoundaryWall(south, walls, boundaryMasks, offset, yy, 15, offset, 0);
|
||||
}
|
||||
for (int offset = 0; offset < CHUNK_SIZE; offset++) {
|
||||
tryAddBoundaryWall(walls, boundaryMasks, 0, yy, offset, westBlockX, chunkBlockZ + offset);
|
||||
tryAddBoundaryWall(walls, boundaryMasks, CHUNK_SIZE - 1, yy, offset, eastBlockX, chunkBlockZ + offset);
|
||||
tryAddBoundaryWall(walls, boundaryMasks, offset, yy, 0, chunkBlockX + offset, northBlockZ);
|
||||
tryAddBoundaryWall(walls, boundaryMasks, offset, yy, CHUNK_SIZE - 1, chunkBlockX + offset, southBlockZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void tryAddBoundaryWall(MantleChunk<Matter> neighborChunk, CarveWallBuffer walls, CarveColumnMask[] boundaryMasks,
|
||||
int localX, int yy, int localZ, int neighborX, int neighborZ) {
|
||||
if (mantleChunk.get(localX, yy, localZ, MatterCavern.class) != null) {
|
||||
private void tryAddBoundaryWall(CarveWallBuffer walls, CarveColumnMask[] boundaryMasks,
|
||||
int localX, int yy, int localZ, int neighborBlockX, int neighborBlockZ) {
|
||||
if (ownVoid(localX, yy, localZ) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MatterCavern neighbor = neighborChunk.get(neighborX, yy, neighborZ, MatterCavern.class);
|
||||
CarvedVoid neighbor = voids.get(neighborBlockX, yy, neighborBlockZ);
|
||||
if (neighbor == null) {
|
||||
return;
|
||||
}
|
||||
@@ -405,7 +377,7 @@ public class CaveApplying {
|
||||
boundaryMasks[columnIndex].add(yy);
|
||||
}
|
||||
|
||||
private void processColumnFromMask(CarveColumnMask columnMask, int columnIndex, Map<String, ResourceId> customBiomeCache) {
|
||||
private void processColumnFromMask(CarveColumnMask columnMask, int columnIndex, Map<ResourceId, ResourceId> customBiomeCache) {
|
||||
if (columnMask == null || columnMask.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -448,7 +420,7 @@ public class CaveApplying {
|
||||
}
|
||||
|
||||
private void processBoundaryColumnFromMask(CarveColumnMask boundaryMask, CarveWallBuffer walls, int columnIndex,
|
||||
Map<String, ResourceId> customBiomeCache) {
|
||||
Map<ResourceId, ResourceId> customBiomeCache) {
|
||||
int firstHeight = boundaryMask.nextSetBit(0);
|
||||
if (firstHeight < 0) {
|
||||
return;
|
||||
@@ -477,7 +449,7 @@ public class CaveApplying {
|
||||
}
|
||||
|
||||
private void paintBoundaryZone(CarveWallBuffer walls, int rx, int rz, int worldX, int worldZ, int zoneFloor, int zoneCeiling,
|
||||
Map<String, ResourceId> customBiomeCache) {
|
||||
Map<ResourceId, ResourceId> customBiomeCache) {
|
||||
ResourceId floorBiome = resolveCaveBoundaryBiome(walls.get(rx, zoneFloor, rz), worldX, zoneFloor, worldZ, customBiomeCache);
|
||||
ResourceId ceilingBiome = resolveCaveBoundaryBiome(walls.get(rx, zoneCeiling, rz), worldX, zoneCeiling, worldZ, customBiomeCache);
|
||||
if (floorBiome == null && ceilingBiome == null) {
|
||||
@@ -527,19 +499,7 @@ public class CaveApplying {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1-in-16 marker roll from a SplitMix64 finalizer over (carve seed, block position, salt).
|
||||
* Deterministic per seed and position, thread-order independent, allocation free.
|
||||
*/
|
||||
private boolean markerRoll(int x, int y, int z, long salt) {
|
||||
long h = (world.carveSeed() + salt) ^ BlockPosition.toLong(x, y, z);
|
||||
h = (h ^ (h >>> 30)) * 0xBF58476D1CE4E5B9L;
|
||||
h = (h ^ (h >>> 27)) * 0x94D049BB133111EBL;
|
||||
h ^= h >>> 31;
|
||||
return (h & 15L) == 0L;
|
||||
}
|
||||
|
||||
private void processZone(CaveZone zone, int rx, int rz, int xx, int zz, Map<String, ResourceId> customBiomeCache) {
|
||||
private void processZone(CaveZone zone, int rx, int rz, int xx, int zz, Map<ResourceId, ResourceId> customBiomeCache) {
|
||||
int maxY = output.height();
|
||||
|
||||
if (zone.ceiling + 1 < maxY && classes.isDecorant(output.get(rx, zone.ceiling + 1, rz))) {
|
||||
@@ -550,17 +510,6 @@ public class CaveApplying {
|
||||
output.set(rx, zone.ceiling, rz, caveAir);
|
||||
}
|
||||
|
||||
// Seed-derived and position-keyed, never Math.random(): these markers persist into the
|
||||
// mantle and drive cave spawning, so the same seed must stamp the same markers on
|
||||
// every run and every platform. Inline mix, no allocation on this hot path.
|
||||
if (markerRoll(xx, zone.ceiling, zz, CEILING_MARKER_SALT)) {
|
||||
setMarker(rx, zone.ceiling, rz, MarkerMatter.CAVE_CEILING);
|
||||
}
|
||||
|
||||
if (markerRoll(xx, zone.floor, zz, FLOOR_MARKER_SALT)) {
|
||||
setMarker(rx, zone.floor, rz, MarkerMatter.CAVE_FLOOR);
|
||||
}
|
||||
|
||||
ResourceId floorBiome = resolveCaveBoundaryBiome(rx, zone.floor, rz, xx, zz, customBiomeCache);
|
||||
ResourceId ceilingBiome = resolveCaveBoundaryBiome(rx, zone.ceiling, rz, xx, zz, customBiomeCache);
|
||||
if (floorBiome == null && ceilingBiome == null) {
|
||||
@@ -586,30 +535,21 @@ public class CaveApplying {
|
||||
}
|
||||
}
|
||||
|
||||
private void setMarker(int localX, int y, int localZ, MatterMarker marker) {
|
||||
Matter section = mantleChunk.getOrCreate(y >> 4);
|
||||
section.<MatterMarker>slice(MatterMarker.class).set(localX, y & 15, localZ, marker);
|
||||
ResourceId resolveCaveBoundaryBiome(int x, int y, int z, int worldX, int worldZ, Map<ResourceId, ResourceId> customBiomeCache) {
|
||||
return resolveCaveBoundaryBiome(ownVoid(x, y, z), worldX, y, worldZ, customBiomeCache);
|
||||
}
|
||||
|
||||
ResourceId resolveCaveBoundaryBiome(int x, int y, int z, int worldX, int worldZ, Map<String, ResourceId> customBiomeCache) {
|
||||
return resolveCaveBoundaryBiome(cavernIfPresent(x, y, z), worldX, y, worldZ, customBiomeCache);
|
||||
}
|
||||
|
||||
private MatterCavern cavernIfPresent(int x, int y, int z) {
|
||||
int section = y >> 4;
|
||||
if (y < 0 || !mantleChunk.exists(section)) {
|
||||
/** The void at a block of this chunk; null where nothing is carved, and above or below the dimension. */
|
||||
private CarvedVoid ownVoid(int localX, int y, int localZ) {
|
||||
if (y < 0 || y >= world.height()) {
|
||||
return null;
|
||||
}
|
||||
Matter matter = mantleChunk.get(section);
|
||||
if (matter == null || !matter.hasSlice(MatterCavern.class)) {
|
||||
return null;
|
||||
}
|
||||
return matter.<MatterCavern>getSlice(MatterCavern.class).get(x & 15, y & 15, z & 15);
|
||||
return voids.get(chunkBlockX + localX, y, chunkBlockZ + localZ);
|
||||
}
|
||||
|
||||
ResourceId resolveCaveBoundaryBiome(MatterCavern cavern, int worldX, int y, int worldZ, Map<String, ResourceId> customBiomeCache) {
|
||||
if (cavern != null && !cavern.getCustomBiome().isEmpty()) {
|
||||
return resolveCustomBiome(customBiomeCache, cavern.getCustomBiome());
|
||||
ResourceId resolveCaveBoundaryBiome(CarvedVoid carvedVoid, int worldX, int y, int worldZ, Map<ResourceId, ResourceId> customBiomeCache) {
|
||||
if (carvedVoid != null && carvedVoid.biome().isPresent()) {
|
||||
return resolveCustomBiome(customBiomeCache, carvedVoid.biome().get());
|
||||
}
|
||||
return resolveCaveBiome(worldX, y, worldZ);
|
||||
}
|
||||
@@ -660,9 +600,8 @@ public class CaveApplying {
|
||||
return resolvedBiome;
|
||||
}
|
||||
|
||||
/** The id of the pack's biome with this key; null when the pack has none or it cannot be loaded. */
|
||||
private ResourceId existingBiomeId(String key) {
|
||||
ResourceId id = resources.idOf(key);
|
||||
/** The pack's biome with this id; null when the pack has none or it cannot be loaded. */
|
||||
private ResourceId existingBiomeId(ResourceId id) {
|
||||
try {
|
||||
return resources.find(PackResources.BIOMES, id).isPresent() ? id : null;
|
||||
} catch (IllegalStateException unreadable) {
|
||||
@@ -670,7 +609,7 @@ public class CaveApplying {
|
||||
}
|
||||
}
|
||||
|
||||
private ResourceId resolveCustomBiome(Map<String, ResourceId> customBiomeCache, String customBiome) {
|
||||
private ResourceId resolveCustomBiome(Map<ResourceId, ResourceId> customBiomeCache, ResourceId customBiome) {
|
||||
if (customBiomeCache.containsKey(customBiome)) {
|
||||
return customBiomeCache.get(customBiome);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ final class IrisCarveScratch {
|
||||
final CarveColumnMask[] boundaryMasks = new CarveColumnMask[256];
|
||||
final int[] surfaceHeights = new int[256];
|
||||
final CarveWallBuffer walls = new CarveWallBuffer(512);
|
||||
final Map<String, ResourceId> customBiomeCache = new HashMap<>();
|
||||
final Map<ResourceId, ResourceId> customBiomeCache = new HashMap<>();
|
||||
int[] upperSurfaceHeights;
|
||||
boolean customCaveBiomePresent;
|
||||
|
||||
|
||||
@@ -18,11 +18,9 @@
|
||||
|
||||
package art.arcane.iris.modules.objects;
|
||||
|
||||
import art.arcane.iris.builtin.MatterMantle;
|
||||
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 java.util.Optional;
|
||||
|
||||
@@ -31,84 +29,36 @@ import java.util.Optional;
|
||||
* are above the dimension's bottom; outside the mantle the invocation reaches nothing is carved.
|
||||
*/
|
||||
public final class CarvedSpace {
|
||||
private static final int CHUNK_SHIFT = 4;
|
||||
private static final int SECTION_SHIFT = 4;
|
||||
private static final int SECTION_HEIGHT = 16;
|
||||
private static final int LOCAL_MASK = 15;
|
||||
private static final byte CARVED = 1;
|
||||
private final MantleLayer<CarvedVoid> voids;
|
||||
private final BlockBox reach;
|
||||
|
||||
private final MatterMantle mantle;
|
||||
private final int worldHeight;
|
||||
|
||||
public CarvedSpace(MatterMantle mantle, int worldHeight) {
|
||||
this.mantle = mantle;
|
||||
this.worldHeight = worldHeight;
|
||||
public CarvedSpace(MantleLayer<CarvedVoid> voids, BlockBox reach) {
|
||||
this.voids = voids;
|
||||
this.reach = reach;
|
||||
}
|
||||
|
||||
/** Whether the position is carved. */
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return cavernData(x, y, z) != null;
|
||||
return voidAt(x, y, z).isPresent();
|
||||
}
|
||||
|
||||
/** Whether each height from 0 up to {@code height} is carved at the column, 1 for carved and 0 for not. */
|
||||
public byte[] column(int x, int z, int height) {
|
||||
int cappedHeight = Math.min(Math.max(height, 0), worldHeight);
|
||||
int cappedHeight = Math.min(Math.max(height, 0), reach.maxY());
|
||||
byte[] carvedColumn = new byte[cappedHeight];
|
||||
if (cappedHeight <= 0) {
|
||||
return carvedColumn;
|
||||
}
|
||||
MantleChunk<Matter> chunk = mantle.chunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT);
|
||||
if (chunk == null) {
|
||||
return carvedColumn;
|
||||
}
|
||||
int localX = x & LOCAL_MASK;
|
||||
int localZ = z & LOCAL_MASK;
|
||||
int lastSection = (cappedHeight - 1) >> SECTION_SHIFT;
|
||||
for (int section = 0; section <= lastSection; section++) {
|
||||
MatterSlice<MatterCavern> slice = cavernSlice(chunk, section);
|
||||
if (slice == null) {
|
||||
continue;
|
||||
}
|
||||
int sectionBaseY = section << SECTION_SHIFT;
|
||||
int sectionMaxY = Math.min(cappedHeight, sectionBaseY + SECTION_HEIGHT);
|
||||
for (int y = sectionBaseY; y < sectionMaxY; y++) {
|
||||
if (slice.get(localX, y & LOCAL_MASK, localZ) != null) {
|
||||
carvedColumn[y] = CARVED;
|
||||
}
|
||||
for (int y = 0; y < cappedHeight; y++) {
|
||||
if (reach.contains(x, y, z) && voids.get(x, y, z) != null) {
|
||||
carvedColumn[y] = 1;
|
||||
}
|
||||
}
|
||||
return carvedColumn;
|
||||
}
|
||||
|
||||
/** The void at the position; empty where nothing was carved. */
|
||||
public Optional<Cavern> cavernAt(int x, int y, int z) {
|
||||
MatterCavern cavern = cavernData(x, y, z);
|
||||
if (cavern == null || !cavern.isCavern()) {
|
||||
public Optional<CarvedVoid> voidAt(int x, int y, int z) {
|
||||
if (!reach.contains(x, y, z)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(new Cavern(cavern.isAir(), cavern.getLiquid()));
|
||||
}
|
||||
|
||||
private MatterCavern cavernData(int x, int y, int z) {
|
||||
if (y < 0 || y >= worldHeight) {
|
||||
return null;
|
||||
}
|
||||
MantleChunk<Matter> chunk = mantle.chunk(x >> CHUNK_SHIFT, z >> CHUNK_SHIFT);
|
||||
if (chunk == null) {
|
||||
return null;
|
||||
}
|
||||
MatterSlice<MatterCavern> slice = cavernSlice(chunk, y >> SECTION_SHIFT);
|
||||
return slice == null ? null : slice.get(x & LOCAL_MASK, y & LOCAL_MASK, z & LOCAL_MASK);
|
||||
}
|
||||
|
||||
private static MatterSlice<MatterCavern> cavernSlice(MantleChunk<Matter> chunk, int section) {
|
||||
if (!chunk.exists(section)) {
|
||||
return null;
|
||||
}
|
||||
Matter matter = chunk.get(section);
|
||||
if (matter == null || !matter.hasSlice(MatterCavern.class)) {
|
||||
return null;
|
||||
}
|
||||
return matter.getSlice(MatterCavern.class);
|
||||
return Optional.ofNullable(voids.get(x, y, z));
|
||||
}
|
||||
}
|
||||
@@ -1,29 +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.modules.objects;
|
||||
|
||||
/**
|
||||
* A carved void of the mantle, as the cave carver left it.
|
||||
*
|
||||
* @param air whether the void holds air
|
||||
* @param liquid the carver's liquid code for the void; {@link #FORCED_AIR_LIQUID} means air that stays air
|
||||
*/
|
||||
public record Cavern(boolean air, byte liquid) {
|
||||
public static final byte FORCED_AIR_LIQUID = 3;
|
||||
}
|
||||
Reference in new issue
Block a user