Add cave springs

- IrisCaveSprings: enabled false, density 0.05, fluid lava, minDepthBelowSurface 16, under hydrology.underground.caveSprings
- CaveSpringPlacer picks a seep in a rock wall of its own chunk with a hash of the seed and coordinates, reading only carved cells
- A seep holds one SPRING_SOURCE cell with UpdateMatter.ON, so the game's fluid ticks move it
- A spring is dropped when its opening is unroofed, or its flow within 15 blocks meets a foreign cell, an older chunk or ground closer than minDepthBelowSurface to the surface
- A structure placement that starts within 8 chunks drops the spring
- Pool walls replace a spring cell in either write order, so pools stay sealed
- A cave policy fluid replaces the spring fluid, unknown names fail the chunk, and settings reject bad knobs
- Default fingerprint and schema digest recaptured
This commit is contained in:
Brian Fopiano committed 2026-11-03 10:16:35 -05:00
1 parent c76339df4e
commit b64845dfed
21 files changed
+756 -22

No files matched your search

@@ -33,7 +33,7 @@ public class HydrologySettingsTest {
private static final int SEA_LEVEL = 62;
private static final int MIN_Y = -64;
private static final int MAX_Y = 320;
private static final long DEFAULT_FINGERPRINT = 3280677091802284252L;
private static final long DEFAULT_FINGERPRINT = 5305026471094945587L;
@Test
public void densityIsBoundedAndChangesThePlanIdentity() {
@@ -80,6 +80,34 @@ public class HydrologySettingsTest {
assertRejected(wild, "underground.cavePools.deepFluidMaxY");
}
@Test
public void caveSpringsAreOffByDefaultJoinThePlanIdentityAndFailClosed() {
HydrologySettings plain = compile(new IrisHydrology());
assertFalse(plain.underground().caveSprings().enabled());
assertEquals(0.05f, plain.underground().caveSprings().density(), 0f);
assertEquals("lava", plain.underground().caveSprings().fluid());
assertEquals(16, plain.underground().caveSprings().minDepthBelowSurface());
IrisHydrology on = withLava(new IrisHydrology());
on.getUnderground().getCaveSprings().setEnabled(true);
assertTrue(compile(on).underground().caveSprings().enabled());
assertTrue(compile(withLava(new IrisHydrology())).fingerprint() != compile(on).fingerprint());
IrisHydrology noLava = new IrisHydrology();
noLava.getUnderground().getCaveSprings().setEnabled(true);
assertRejected(noLava, "underground.caveSprings.fluid");
for (double invalid : new double[]{-0.01D, 2.01D, Double.NaN}) {
IrisHydrology dense = withLava(new IrisHydrology());
dense.getUnderground().getCaveSprings().setEnabled(true).setDensity(invalid);
assertRejected(dense, "underground.caveSprings.density");
}
for (int invalid : new int[]{-1, 257}) {
IrisHydrology deep = withLava(new IrisHydrology());
deep.getUnderground().getCaveSprings().setEnabled(true).setMinDepthBelowSurface(invalid);
assertRejected(deep, "underground.caveSprings.minDepthBelowSurface");
}
}
private static IrisHydrology withLava(IrisHydrology config) {
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
return config;
@@ -514,5 +514,10 @@ public class CavePoolFillerTest {
public String caveFluid(int x, int y, int z) {
return policyFluid.apply(x);
}
@Override
public boolean structureNear() {
return false;
}
}
}
@@ -0,0 +1,371 @@
package art.arcane.iris.generation.hydrology.underground;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.hydrology.config.IrisCaveSprings;
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.mantle.MantleWriter;
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.matter.MatterUpdate;
import art.arcane.volmlib.util.matter.slices.UpdateMatter;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.IntFunction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
public class CaveSpringPlacerTest {
private static final long SEED = 1337L;
private static final int FLOOR = 50;
private static final int CEILING = 70;
private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
@Test
public void placesOneSourceInARockWallAboveAnOpeningAndAsksForAnUpdate() {
World world = pillars();
Recorder recorder = new Recorder();
placer(springs -> {
}).place(0, 0, () -> world, recorder.writer, SEED);
assertFalse(recorder.cells.isEmpty());
for (Map.Entry<Long, HydrologyCaveCell> entry : recorder.cells.entrySet()) {
int x = x(entry.getKey());
int y = y(entry.getKey());
int z = z(entry.getKey());
assertEquals(HydrologyCaveAction.SPRING_SOURCE, entry.getValue().action());
assertEquals("lava", entry.getValue().fluidProfileKey());
assertEquals(0, x >> 4);
assertEquals(0, z >> 4);
assertEquals(CaveVoxel.SOLID, world.voxel(x, y, z));
assertEquals(CaveVoxel.SOLID, world.voxel(x, y + 1, z));
assertEquals(CaveVoxel.SOLID, world.voxel(x, y - 1, z));
boolean opening = false;
for (int[] side : SIDES) {
opening |= world.voxel(x + side[0], y, z + side[1]) == CaveVoxel.AIR
&& world.voxel(x + side[0], y - 1, z + side[1]) == CaveVoxel.AIR;
}
assertTrue("seep at " + x + "," + y + "," + z + " opens over a drop", opening);
assertSame(UpdateMatter.ON, recorder.updates.get(entry.getKey()));
}
assertEquals(recorder.cells.keySet(), recorder.updates.keySet());
}
@Test
public void disabledSpringsAndZeroDensityNeverOpenTheCaves() {
CarvedTerrain carved = mock(CarvedTerrain.class);
MantleWriter writer = mock(MantleWriter.class);
new CaveSpringPlacer(compile(new IrisHydrology())).place(0, 0, () -> carved, writer, SEED);
placer(springs -> springs.setDensity(0D)).place(0, 0, () -> carved, writer, SEED);
IrisHydrology thinned = config(springs -> springs.setDensity(2D)).setDensity(0D);
new CaveSpringPlacer(compile(thinned)).place(0, 0, () -> carved, writer, SEED);
verifyNoInteractions(carved, writer);
}
@Test
public void densityIsSitesPerChunk() {
World world = pillars();
CaveSpringPlacer placer = placer(springs -> springs.setDensity(0.05D));
int[] counter = new int[1];
for (int chunkX = 0; chunkX < 2048; chunkX++) {
placer.place(chunkX, 0, () -> {
counter[0]++;
return world;
}, new Recorder().writer, SEED);
}
int opened = counter[0];
assertTrue("0.05 sites a chunk open about 102 of 2048 chunks, opened " + opened, opened > 60 && opened < 150);
}
@Test
public void policyFluidReplacesTheSpringFluidAndAnUnknownOneFails() {
World policy = pillars();
policy.policyFluid = x -> "water";
Recorder recorder = new Recorder();
placer(springs -> {
}).place(0, 0, () -> policy, recorder.writer, SEED);
assertFalse(recorder.cells.isEmpty());
for (HydrologyCaveCell cell : recorder.cells.values()) {
assertEquals("water", cell.fluidProfileKey());
}
World unknown = pillars();
unknown.policyFluid = x -> "magma";
assertThrows(IllegalStateException.class, () -> placer(springs -> {
}).place(0, 0, () -> unknown, new Recorder().writer, SEED));
}
@Test
public void chunkOrderDoesNotMatter() {
World world = pillars();
CaveSpringPlacer placer = placer(springs -> {
});
Recorder forward = new Recorder();
List<int[]> chunks = new ArrayList<>();
for (int chunkX = -2; chunkX <= 2; chunkX++) {
for (int chunkZ = -2; chunkZ <= 2; chunkZ++) {
chunks.add(new int[]{chunkX, chunkZ});
}
}
for (int[] chunk : chunks) {
placer.place(chunk[0], chunk[1], () -> world, forward.writer, SEED);
}
Collections.shuffle(chunks, new Random(SEED));
Recorder shuffled = new Recorder();
for (int[] chunk : chunks) {
placer.place(chunk[0], chunk[1], () -> world, shuffled.writer, SEED);
}
assertFalse(forward.cells.isEmpty());
assertEquals(forward.cells, shuffled.cells);
assertEquals(forward.updates.keySet(), shuffled.updates.keySet());
}
@Test
public void staysMinDepthBelowTheSurfaceAlongTheSeepAndItsFlow() {
World shallow = pillars();
shallow.surface = CEILING + 3;
assertTrue(place(shallow, springs -> springs.setMinDepthBelowSurface(CEILING + 3 - FLOOR)).isEmpty());
World deep = pillars();
Map<Long, HydrologyCaveCell> written = place(deep, springs -> springs.setMinDepthBelowSurface(deep.surface - 58));
assertFalse(written.isEmpty());
for (long cell : written.keySet()) {
assertTrue(y(cell) <= 58);
}
World sloped = pillars();
sloped.surfaceAt = (x, z) -> x >= 8 ? FLOOR + 8 : 200;
assertTrue("the flow reaches ground too close to the surface",
place(sloped, springs -> springs.setMinDepthBelowSurface(16)).isEmpty());
}
@Test
public void aSeepThatWouldOpenOntoTheSurfaceIsDropped() {
World open = pillars();
open.carveOpenings(CEILING + 1, open.surface);
assertTrue(place(open, springs -> {
}).isEmpty());
}
@Test
public void foreignCellsInTheFlowAndHistoricChunksDropTheSpring() {
World bottom = pillars();
for (int x = -16; x < 32; x++) {
for (int z = -16; z < 32; z++) {
bottom.foreign(x, FLOOR, z);
}
}
assertTrue("cave lava, an aquifer or a room under the flow", place(bottom, springs -> {
}).isEmpty());
World historic = pillars();
historic.historicMinX = 8;
assertTrue("the flow reaches a chunk generated earlier", place(historic, springs -> {
}).isEmpty());
World own = pillars();
own.historicMinX = -64;
assertTrue("own chunk generated earlier", place(own, springs -> {
}).isEmpty());
}
@Test
public void structuresNearbyDropTheSpring() {
World world = pillars();
world.structures = true;
assertTrue(place(world, springs -> {
}).isEmpty());
}
@Test
public void poolWallsWinOverSpringsWhicheverChunkWritesFirst() {
World world = new World();
carvePillars(world, 0, 15);
HydrologySettings settings = compile(config(springs -> {
}));
CaveSpringPlacer placer = new CaveSpringPlacer(settings);
CavePoolFiller filler = new CavePoolFiller(settings, 0);
Recorder springsFirst = new Recorder();
placer.place(0, 0, () -> world, springsFirst.writer, SEED);
Map<Long, HydrologyCaveCell> placed = new HashMap<>(springsFirst.cells);
filler.fill(0, 0, () -> world, springsFirst.writer, SEED);
Recorder poolsFirst = new Recorder();
filler.fill(0, 0, () -> world, poolsFirst.writer, SEED);
placer.place(0, 0, () -> world, poolsFirst.writer, SEED);
assertEquals(springsFirst.cells, poolsFirst.cells);
Set<Long> replaced = new HashSet<>();
for (long cell : placed.keySet()) {
if (springsFirst.cells.get(cell).action() == HydrologyCaveAction.SEAL_GUARD) {
replaced.add(cell);
}
}
assertFalse("the scene puts a spring in a pool wall", replaced.isEmpty());
}
private static CaveSpringPlacer placer(Consumer<IrisCaveSprings> springs) {
return new CaveSpringPlacer(compile(config(springs)));
}
private static Map<Long, HydrologyCaveCell> place(World world, Consumer<IrisCaveSprings> springs) {
Recorder recorder = new Recorder();
placer(springs).place(0, 0, () -> world, recorder.writer, SEED);
return recorder.cells;
}
private static IrisHydrology config(Consumer<IrisCaveSprings> springs) {
IrisHydrology config = new IrisHydrology().setEnabled(true);
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
config.getUnderground().getCavePools().setDensity(8D).setMaxDepth(16).setMaxArea(961).setFreeboard(new KList<>(0, 0));
springs.accept(config.getUnderground().getCaveSprings().setEnabled(true).setDensity(2D));
return config;
}
private static HydrologySettings compile(IrisHydrology config) {
return HydrologySettings.compile(config, SEED, 63, 0, 384);
}
private static World pillars() {
World world = new World();
carvePillars(world, -16, 31);
return world;
}
private static void carvePillars(World world, int min, int max) {
world.carve(min, max, min, max, FLOOR, FLOOR + 1);
for (int x = min; x <= max; x++) {
for (int z = min; z <= max; z++) {
if (Math.floorMod(x + z, 2) == 1) {
world.carve(x, x, z, z, FLOOR, CEILING);
}
}
}
}
private static long key(int x, int y, int z) {
return ((long) (x + 4096) << 40) | ((long) y << 20) | (z + 4096);
}
private static int x(long key) {
return (int) (key >>> 40) - 4096;
}
private static int z(long key) {
return (int) (key & 0xFFFFF) - 4096;
}
private static int y(long key) {
return (int) ((key >>> 20) & 0xFFFFF);
}
private interface SurfaceAt {
int at(int x, int z);
}
private static final class Recorder {
private final Map<Long, HydrologyCaveCell> cells = new HashMap<>();
private final Map<Long, MatterUpdate> updates = new HashMap<>();
private final MantleWriter writer = mock(MantleWriter.class);
private Recorder() {
doAnswer(invocation -> {
long key = key(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2));
Object value = invocation.getArgument(3);
if (value instanceof HydrologyCaveCell cell) {
cells.put(key, cell);
} else {
updates.put(key, (MatterUpdate) value);
}
return null;
}).when(writer).setData(anyInt(), anyInt(), anyInt(), any());
when(writer.getDataIfPresent(anyInt(), anyInt(), anyInt(), eq(HydrologyCaveCell.class))).thenAnswer(invocation ->
cells.get(key(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2))));
doAnswer(invocation -> {
invocation.<Runnable>getArgument(2).run();
return null;
}).when(writer).withChunkFence(anyInt(), anyInt(), any(Runnable.class));
}
}
private static final class World implements CarvedTerrain {
private final Set<Long> air = new HashSet<>();
private final Set<Long> foreign = new HashSet<>();
private int surface = 200;
private SurfaceAt surfaceAt;
private IntFunction<String> policyFluid = x -> null;
private int historicMinX = Integer.MAX_VALUE;
private boolean structures;
void carve(int minX, int maxX, int minZ, int maxZ, int minY, int maxY) {
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
for (int y = minY; y <= maxY; y++) {
air.add(key(x, y, z));
}
}
}
}
void carveOpenings(int minY, int maxY) {
for (int x = -16; x < 32; x++) {
for (int z = -16; z < 32; z++) {
if (Math.floorMod(x + z, 2) == 1) {
carve(x, x, z, z, minY, maxY);
}
}
}
}
void foreign(int x, int y, int z) {
foreign.add(key(x, y, z));
}
@Override
public CaveVoxel voxel(int x, int y, int z) {
long key = key(x, y, z);
if (y <= 0 || y > surface(x, z) || x >= historicMinX || foreign.contains(key)) {
return CaveVoxel.FOREIGN;
}
return air.contains(key) ? CaveVoxel.AIR : CaveVoxel.SOLID;
}
@Override
public int surface(int x, int z) {
return surfaceAt == null ? surface : surfaceAt.at(x, z);
}
@Override
public String caveFluid(int x, int y, int z) {
return policyFluid.apply(x);
}
@Override
public boolean structureNear() {
return structures;
}
}
}
@@ -116,6 +116,8 @@ public class IrisCarveModifierHydrologyTest {
new HydrologyCaveCell(HydrologyCaveAction.WET_SOURCE, "water"), current, source, air));
assertSame(source, IrisCarveModifier.resolveHydrologyState(
new HydrologyCaveCell(HydrologyCaveAction.POOL_SOURCE, "water"), current, source, air));
assertSame(source, IrisCarveModifier.resolveHydrologyState(
new HydrologyCaveCell(HydrologyCaveAction.SPRING_SOURCE, "lava"), current, source, air));
assertSame(air, IrisCarveModifier.resolveHydrologyState(
new HydrologyCaveCell(HydrologyCaveAction.DRY_AIR, "water"), current, source, air));
}
@@ -442,5 +444,10 @@ public class IrisCarveModifierHydrologyTest {
public String caveFluid(int x, int y, int z) {
return null;
}
@Override
public boolean structureNear() {
return false;
}
}
}
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "f88d6e65ab17d253dbfb816c1d6e69fdcd600ff0318c6285ce08d7228ae6f51a";
private static final String EXPECTED_SCHEMA_DIGEST = "2557c97e7e5aab6b9691fa61be9477656d81e9107109965146b8be39b84ba6d8";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -0,0 +1,36 @@
package art.arcane.iris.structure.placement;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.generation.runtime.SeedManager;
import art.arcane.volmlib.util.collection.KList;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class StructurePlacementScopeStartsNearTest {
@Test
public void reportsAStartWithinTheReachAndNothingOutsideIt() {
IrisStructurePlacement dense = new IrisStructurePlacement().setDistribution(StructureDistribution.DENSITY).setDensity(1D);
assertTrue(StructurePlacementScope.startsNear(engine(new KList<>(dense)), 3, -2, 1));
IrisStructurePlacement never = new IrisStructurePlacement().setDistribution(StructureDistribution.DENSITY).setDensity(0D);
assertFalse(StructurePlacementScope.startsNear(engine(new KList<>(never)), 3, -2, 8));
assertFalse(StructurePlacementScope.startsNear(engine(new KList<>()), 3, -2, 8));
}
private static Engine engine(KList<IrisStructurePlacement> placements) {
Engine engine = mock(Engine.class);
SeedManager seeds = mock(SeedManager.class);
when(seeds.getMantle()).thenReturn(1337L);
when(engine.getSeedManager()).thenReturn(seeds);
IrisDimension dimension = new IrisDimension();
dimension.setStructures(placements);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getAllBiomes()).thenReturn(new KList<>());
return engine;
}
}
@@ -64,6 +64,7 @@ public class HydrologyCaveMatterTest {
codes.put(HydrologyCaveAction.DRY_AIR, 3);
codes.put(HydrologyCaveAction.SEAL_GUARD, 4);
codes.put(HydrologyCaveAction.POOL_SOURCE, 5);
codes.put(HydrologyCaveAction.SPRING_SOURCE, 6);
assertEquals(List.copyOf(codes.keySet()), List.of(HydrologyCaveAction.values()));
for (Map.Entry<HydrologyCaveAction, Integer> entry : codes.entrySet()) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
@@ -76,6 +77,10 @@ public class HydrologyCaveMatterTest {
assertTrue(pool.isWet());
assertTrue(pool.carves());
assertTrue(pool.asCavern().isWater());
HydrologyCaveCell spring = new HydrologyCaveCell(HydrologyCaveAction.SPRING_SOURCE, "lava");
assertTrue(spring.isWet());
assertTrue(spring.carves());
assertEquals(spring, matter.readNode(new DataInputStream(new ByteArrayInputStream(new byte[]{6, 0, 4, 'l', 'a', 'v', 'a', 0, 0}))));
}
@Test