Deep cave pool fluid

- cavePools.deepFluid fills pools at or below cavePools.deepFluidMaxY, default world Y -128, unset by default
- A cave policy fluid still wins over the deep fluid
- The mixed-fluid check stops a pool rising past the line, so no pool straddles it
- CavePoolFiller takes the world minimum Y to place the line, and throws when the line is outside the world
- Settings reject an unknown or seam deepFluid, and both knobs join the fingerprint
- Default fingerprint and schema digest recaptured
This commit is contained in:
Brian Fopiano committed 2026-11-03 10:11:48 -05:00
1 parent c4a076b587
commit c76339df4e
9 files changed
+172 -20

No files matched your search

@@ -50,4 +50,12 @@ public class IrisCavePools {
@Required
@Description("Name of the fluid profile that fills cave pools. The hydrology policy fluid of the cave biome at the pool replaces it, then that of its region, then that of the dimension. A surface biome's policy never fills cave pools.")
private String fluid = "water";
@Description("Name of the fluid profile that fills pools at or below deepFluidMaxY. Unset keeps the same fluid at every depth. A hydrology policy that names a fluid still replaces it.")
private String deepFluid;
@MinNumber(-2032)
@MaxNumber(2031)
@Description("Highest world Y that deepFluid fills. No pool crosses this height: a pool rising from below stops at it.")
private int deepFluidMaxY = -128;
}
@@ -61,6 +61,8 @@ public final class HydrologySettings {
public static final int MAX_CAVE_POOL_RADIUS = 15;
private static final int CAVE_POOL_SPAN = 2 * MAX_CAVE_POOL_RADIUS + 1;
private static final int MAX_CAVE_POOL_AREA = CAVE_POOL_SPAN * CAVE_POOL_SPAN;
private static final int MIN_DEEP_FLUID_Y = -2032;
private static final int MAX_DEEP_FLUID_Y = 2031;
private static final int MAX_LAKE_AREA = LakeCandidate.MAX_EXTENT * LakeCandidate.MAX_EXTENT;
private static final int MAX_PREFETCH_RINGS = 4;
private static final int MAX_SEEDED_DENSITY = 64;
@@ -398,7 +400,11 @@ public final class HydrologySettings {
return new CavePools(config.isEnabled(), (float) config.getDensity(), config.getMinArea(), config.getMaxArea(),
config.getMaxDepth(), config.getRadius(),
intRange(config.getFreeboard(), "underground.cavePools.freeboard", RangeFloor.NON_NEGATIVE),
config.getFluid());
config.getFluid(), blankToNull(config.getDeepFluid()), config.getDeepFluidMaxY());
}
private static String blankToNull(String value) {
return value == null || value.isBlank() ? null : value;
}
private static Map<String, IrisMaterialPalette> fluids(List<IrisFluidProfile> profiles) {
@@ -596,6 +602,9 @@ public final class HydrologySettings {
if (!pools.enabled()) {
return;
}
if (pools.deepFluid() != null) {
requireWithin(pools.deepFluidMaxY(), MIN_DEEP_FLUID_Y, MAX_DEEP_FLUID_Y, "underground.cavePools.deepFluidMaxY");
}
if (pools.freeboard().max() >= pools.maxDepth()) {
throw new IllegalArgumentException("Hydrology underground.cavePools.freeboard max " + pools.freeboard().max()
+ " must stay below maxDepth " + pools.maxDepth());
@@ -643,6 +652,9 @@ public final class HydrologySettings {
}
requireFillingFluid(ponds.fluid(), "ponds.fluid");
requireFillingFluid(underground.cavePools().fluid(), "underground.cavePools.fluid");
if (underground.cavePools().deepFluid() != null) {
requireFillingFluid(underground.cavePools().deepFluid(), "underground.cavePools.deepFluid");
}
}
public void requireFillingFluid(String name, String field) {
@@ -721,7 +733,8 @@ public final class HydrologySettings {
.add(inlets.halfWidth()).add(inlets.depth()).add(inlets.headroom()).add(inlets.roofClearance())
.add(inlets.chamberRadius())
.add(pools.enabled()).add(pools.density()).add(pools.minArea()).add(pools.maxArea())
.add(pools.maxDepth()).add(pools.radius()).add(pools.freeboard()).add(pools.fluid());
.add(pools.maxDepth()).add(pools.radius()).add(pools.freeboard()).add(pools.fluid())
.add(pools.deepFluid()).add(pools.deepFluidMaxY());
}
private void addFluids(Fingerprint hash) {
@@ -787,7 +800,7 @@ public final class HydrologySettings {
}
public record CavePools(boolean enabled, float density, int minArea, int maxArea, int maxDepth, int radius,
IntRange freeboard, String fluid) {
IntRange freeboard, String fluid, String deepFluid, int deepFluidMaxY) {
}
public record Underground(SeaInlets seaInlets, CavePools cavePools) {
@@ -33,11 +33,18 @@ public final class CavePoolFiller {
private final HydrologySettings.CavePools pools;
private final Set<String> fluids;
private final float density;
private final int deepLine;
public CavePoolFiller(HydrologySettings settings) {
public CavePoolFiller(HydrologySettings settings, int worldMinimumY) {
this.pools = settings.underground().cavePools();
this.fluids = settings.fluids().keySet();
this.density = settings.density();
this.deepLine = pools.deepFluidMaxY() - worldMinimumY;
int height = settings.maxY() - settings.minY();
if (pools.enabled() && pools.deepFluid() != null && (deepLine < 0 || deepLine >= height)) {
throw new IllegalStateException("Hydrology underground.cavePools.deepFluidMaxY " + pools.deepFluidMaxY()
+ " is outside this world, which spans Y " + worldMinimumY + " to " + (worldMinimumY + height - 1));
}
}
public void fill(int chunkX, int chunkZ, Supplier<? extends CarvedTerrain> terrain, MantleWriter writer, long seed) {
@@ -180,7 +187,10 @@ public final class CavePoolFiller {
private String fluid(CarvedTerrain carved, int x, int y, int z) {
String policy = carved.caveFluid(x, y, z);
return policy != null ? policy : pools.fluid();
if (policy != null) {
return policy;
}
return pools.deepFluid() != null && y <= deepLine ? pools.deepFluid() : pools.fluid();
}
private String siteFluid(CarvedTerrain carved, int x, int y, int z) {
@@ -88,7 +88,7 @@ public final class MantleHydrologyComponent extends IrisMantleComponent {
if (poolsActive()) {
HydrologySettings settings = runtime.settings();
Engine engine = getEngineMantle().getEngine();
new CavePoolFiller(settings).fill(chunkX, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, chunkX, chunkZ), writer,
new CavePoolFiller(settings, engine.getWorld().minHeight()).fill(chunkX, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, chunkX, chunkZ), writer,
settings.seed());
}
}
@@ -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 = 7576271788988330967L;
private static final long DEFAULT_FINGERPRINT = 3280677091802284252L;
@Test
public void densityIsBoundedAndChangesThePlanIdentity() {
@@ -48,6 +48,43 @@ public class HydrologySettingsTest {
}
}
@Test
public void deepFluidIsOptionalChangesThePlanIdentityAndMustBeAFillingFluid() {
HydrologySettings plain = compile(new IrisHydrology());
assertNull(plain.underground().cavePools().deepFluid());
assertEquals(-128, plain.underground().cavePools().deepFluidMaxY());
IrisHydrology blank = new IrisHydrology();
blank.getUnderground().getCavePools().setDeepFluid(" ");
assertNull(compile(blank).underground().cavePools().deepFluid());
assertEquals(plain.fingerprint(), compile(blank).fingerprint());
IrisHydrology deep = withLava(new IrisHydrology());
deep.getUnderground().getCavePools().setDeepFluid("lava");
HydrologySettings lava = compile(deep);
assertEquals("lava", lava.underground().cavePools().deepFluid());
IrisHydrology moved = withLava(new IrisHydrology());
moved.getUnderground().getCavePools().setDeepFluid("lava").setDeepFluidMaxY(-64);
assertTrue(lava.fingerprint() != compile(moved).fingerprint());
assertTrue(compile(withLava(new IrisHydrology())).fingerprint() != lava.fingerprint());
IrisHydrology unknown = new IrisHydrology();
unknown.getUnderground().getCavePools().setDeepFluid("magma");
assertRejected(unknown, "underground.cavePools.deepFluid");
IrisHydrology seam = withLava(new IrisHydrology());
seam.getFluids().getFirst().setSeam("lava");
seam.getUnderground().getCavePools().setDeepFluid("lava");
assertRejected(seam, "underground.cavePools.deepFluid");
IrisHydrology wild = withLava(new IrisHydrology());
wild.getUnderground().getCavePools().setDeepFluid("lava").setDeepFluidMaxY(4000);
assertRejected(wild, "underground.cavePools.deepFluidMaxY");
}
private static IrisHydrology withLava(IrisHydrology config) {
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
return config;
}
@Rule
public final TemporaryFolder temporary = new TemporaryFolder();
@@ -35,12 +35,13 @@ import static org.mockito.Mockito.when;
public class CavePoolFillerTest {
private static final long SEED = 1337L;
private static final int FLOOR = 50;
private static final int WORLD_MIN = -256;
@Test
public void globalDensityThinsCandidateColumnsBeforeSamplingCaves() {
IrisHydrology config = new IrisHydrology().setDensity(0.5D);
config.getUnderground().getCavePools().setDensity(8D);
CavePoolFiller filler = new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384));
CavePoolFiller filler = new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384), 0);
CarvedTerrain carved = mock(CarvedTerrain.class);
MantleWriter writer = mock(MantleWriter.class);
Set<Long> columns = new HashSet<>();
@@ -67,7 +68,7 @@ public class CavePoolFillerTest {
public void chunksWithoutAPoolSiteNeverOpenTheirCaves() {
IrisHydrology config = new IrisHydrology().setDensity(0.5D);
config.getUnderground().getCavePools().setDensity(0.05D);
CavePoolFiller filler = new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384));
CavePoolFiller filler = new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384), 0);
CarvedTerrain carved = mock(CarvedTerrain.class);
MantleWriter writer = mock(MantleWriter.class);
AtomicInteger opened = new AtomicInteger();
@@ -86,7 +87,7 @@ public class CavePoolFillerTest {
public void zeroGlobalDensityDoesNotReadCaves() {
IrisHydrology config = new IrisHydrology().setDensity(0D);
config.getUnderground().getCavePools().setDensity(8D);
CavePoolFiller filler = new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384));
CavePoolFiller filler = new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384), 0);
CarvedTerrain carved = mock(CarvedTerrain.class);
MantleWriter writer = mock(MantleWriter.class);
filler.fill(0, 0, () -> carved, writer, SEED);
@@ -163,10 +164,10 @@ public class CavePoolFillerTest {
MantleWriter forwardWriter = writer(forward);
MantleWriter reverseWriter = writer(reverse);
for (int index = 0; index < 9; index++) {
new CavePoolFiller(settings).fill(index % 3 - 1, index / 3 - 1, () -> world, forwardWriter, SEED);
new CavePoolFiller(settings, 0).fill(index % 3 - 1, index / 3 - 1, () -> world, forwardWriter, SEED);
}
for (int index = 8; index >= 0; index--) {
new CavePoolFiller(settings).fill(index % 3 - 1, index / 3 - 1, () -> world, reverseWriter, SEED);
new CavePoolFiller(settings, 0).fill(index % 3 - 1, index / 3 - 1, () -> world, reverseWriter, SEED);
}
assertFalse(forward.isEmpty());
@@ -197,10 +198,10 @@ public class CavePoolFillerTest {
Map<Long, HydrologyCaveCell> forward = new HashMap<>();
Map<Long, HydrologyCaveCell> reverse = new HashMap<>();
new CavePoolFiller(settings).fill(0, 0, () -> world, writer(forward), SEED);
new CavePoolFiller(settings).fill(1, 0, () -> world, writer(forward), SEED);
new CavePoolFiller(settings).fill(1, 0, () -> world, writer(reverse), SEED);
new CavePoolFiller(settings).fill(0, 0, () -> world, writer(reverse), SEED);
new CavePoolFiller(settings, 0).fill(0, 0, () -> world, writer(forward), SEED);
new CavePoolFiller(settings, 0).fill(1, 0, () -> world, writer(forward), SEED);
new CavePoolFiller(settings, 0).fill(1, 0, () -> world, writer(reverse), SEED);
new CavePoolFiller(settings, 0).fill(0, 0, () -> world, writer(reverse), SEED);
assertFalse(wetCells(forward, "water").isEmpty());
assertFalse(wetCells(forward, "lava").isEmpty());
@@ -269,6 +270,72 @@ public class CavePoolFillerTest {
}), unknown, 0, 0));
}
@Test
public void deepFluidFillsPoolsAtOrBelowTheLineInWorldHeight() {
HydrologySettings below = deepSettings(52 + WORLD_MIN);
Map<Long, HydrologyCaveCell> deep = fillAt(below, room(0, 15, 0, 15, FLOOR, 52), 0, 0);
assertEquals(roomCells(FLOOR, 52), wetCells(deep, "lava"));
assertTrue(wetCells(deep, "water").isEmpty());
HydrologySettings above = deepSettings(FLOOR - 1 + WORLD_MIN);
Map<Long, HydrologyCaveCell> shallow = fillAt(above, room(0, 15, 0, 15, FLOOR, 52), 0, 0);
assertEquals(roomCells(FLOOR, 52), wetCells(shallow, "water"));
assertTrue(wetCells(shallow, "lava").isEmpty());
}
@Test
public void poolReachingTheLineStopsAtItAndNeverStraddles() {
HydrologySettings settings = deepSettings(51 + WORLD_MIN);
Map<Long, HydrologyCaveCell> written = fillAt(settings, roomWithSill(), 0, 0);
assertEquals(roomCells(FLOOR, 51), wetCells(written, "lava"));
assertTrue(wetCells(written, "water").isEmpty());
}
@Test
public void unsetDeepFluidKeepsThePoolFluidAtAnyDepth() {
Map<Long, HydrologyCaveCell> written = fillAt(settings(pools -> pools.setFreeboard(new KList<>(0, 0)).setDeepFluidMaxY(300)),
roomWithSill(), 0, 0);
assertEquals(roomCells(FLOOR, 52), wetCells(written, "water"));
}
@Test
public void cavePolicyWinsOverTheDeepFluid() {
VoxelWorld world = roomWithSill();
world.policyFluid(x -> "water");
Map<Long, HydrologyCaveCell> written = fillAt(deepSettings(52 + WORLD_MIN), world, 0, 0);
assertEquals(roomCells(FLOOR, 52), wetCells(written, "water"));
assertTrue(wetCells(written, "lava").isEmpty());
}
@Test
public void deepAndShallowPoolsOverOneAnotherShareOnlyRockWhateverTheChunkOrder() {
VoxelWorld world = room(0, 15, 0, 15, FLOOR, 52);
world.carve(0, 15, 0, 15, 54, 57);
world.carve(16, 16, 8, 8, 57, 58);
HydrologySettings settings = HydrologySettings.compile(deepConfig(52 + WORLD_MIN, 8D), SEED, 63, 0, 512);
Map<Long, HydrologyCaveCell> forward = new HashMap<>();
Map<Long, HydrologyCaveCell> reverse = new HashMap<>();
new CavePoolFiller(settings, WORLD_MIN).fill(0, 0, () -> world, writer(forward), SEED);
new CavePoolFiller(settings, WORLD_MIN).fill(1, 0, () -> world, writer(forward), SEED);
new CavePoolFiller(settings, WORLD_MIN).fill(1, 0, () -> world, writer(reverse), SEED);
new CavePoolFiller(settings, WORLD_MIN).fill(0, 0, () -> world, writer(reverse), SEED);
assertFalse(wetCells(forward, "lava").isEmpty());
assertFalse(wetCells(forward, "water").isEmpty());
assertGuard(forward, 8, 53, 8);
assertEquals(forward, reverse);
assertNoMixedBodies(forward);
}
@Test
public void deepFluidLineOutsideTheWorldFailsClosed() {
HydrologySettings below = deepSettings(WORLD_MIN - 1);
assertThrows(IllegalStateException.class, () -> new CavePoolFiller(below, WORLD_MIN));
HydrologySettings above = deepSettings(WORLD_MIN + 512);
assertThrows(IllegalStateException.class, () -> new CavePoolFiller(above, WORLD_MIN));
new CavePoolFiller(deepSettings(WORLD_MIN + 511), WORLD_MIN);
}
@Test
public void foreignCellsAndDisabledPoolsWriteNothing() {
VoxelWorld feature = roomWithSill();
@@ -324,7 +391,7 @@ public class CavePoolFillerTest {
private static Map<Long, HydrologyCaveCell> fill(HydrologySettings settings, VoxelWorld world, int chunkX, int chunkZ) {
Map<Long, HydrologyCaveCell> written = new HashMap<>();
new CavePoolFiller(settings).fill(chunkX, chunkZ, () -> world, writer(written), SEED);
new CavePoolFiller(settings, 0).fill(chunkX, chunkZ, () -> world, writer(written), SEED);
return written;
}
@@ -350,6 +417,23 @@ public class CavePoolFillerTest {
return HydrologySettings.compile(config, SEED, 63, 0, 384);
}
private static IrisHydrology deepConfig(int deepFluidMaxY, double density) {
IrisHydrology config = new IrisHydrology().setEnabled(true);
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
config.getUnderground().getCavePools().setDensity(density).setFreeboard(new KList<>(0, 0)).setDeepFluid("lava").setDeepFluidMaxY(deepFluidMaxY);
return config;
}
private static HydrologySettings deepSettings(int deepFluidMaxY) {
return HydrologySettings.compile(deepConfig(deepFluidMaxY, 1D), SEED, 63, 0, 512);
}
private static Map<Long, HydrologyCaveCell> fillAt(HydrologySettings settings, VoxelWorld world, int chunkX, int chunkZ) {
Map<Long, HydrologyCaveCell> written = new HashMap<>();
new CavePoolFiller(settings, WORLD_MIN).fill(chunkX, chunkZ, () -> world, writer(written), SEED);
return written;
}
private static Set<Long> wetCells(Map<Long, HydrologyCaveCell> written, String fluid) {
Set<Long> cells = new HashSet<>();
for (Map.Entry<Long, HydrologyCaveCell> entry : written.entrySet()) {
@@ -456,7 +456,7 @@ public class MantleCarvedTerrainTest {
rasterizer.write(inlet, 0, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
SeaInletRasterizer.HistoricalChunks.NONE);
}
new CavePoolFiller(settings).fill(0, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, 0, chunkZ), writer, SEED);
new CavePoolFiller(settings, 0).fill(0, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, 0, chunkZ), writer, SEED);
}
return cells;
}
@@ -306,7 +306,7 @@ public class IrisCarveModifierHydrologyTest {
IrisHydrology config = new IrisHydrology().setEnabled(true);
config.getUnderground().getCavePools().setDensity(1D).setFreeboard(new KList<>(0, 0));
Map<Long, HydrologyCaveCell> written = new HashMap<>();
new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384))
new CavePoolFiller(HydrologySettings.compile(config, SEED, 63, 0, 384), 0)
.fill(0, 0, SealedRoom::new, recordingWriter(written), SEED);
Matter[] sections = new Matter[SECTIONS];
Set<String> wallFluids = new HashSet<>();
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "c87139f807de29aa444923b6b0a1f85dc8de882ea8cf13ea3818fbdaeb352ae6";
private static final String EXPECTED_SCHEMA_DIGEST = "f88d6e65ab17d253dbfb816c1d6e69fdcd600ff0318c6285ce08d7228ae6f51a";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,