Enforce hydrology ranges at compile

- Compile rejects prefetchRings outside 0..4, fillEpsilon not above 0 and seeded cup density outside 0..64
- Compile rejects negative tier widthFactor and depthRatio, waterfallMinimumDrop below 2 and shoreDepth below 1
- Compile rejects negative maxFill, lakes.maxArea above 2048 squared and seaInlets.spacing below 1
- Compile rejects enabled cave pools whose freeboard max reaches maxDepth or whose maxArea exceeds 961
- Lake and cave pool area schema maxima match the compiled bounds; schema digest recaptured
- Engine start checks dimension, region and biome policy fluids whether or not cave pools are enabled
- Pack validation warns on written tiers without halfWidth or bankBand and on useMantle false or RIVER_HYDROLOGY disabled
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 03:05:32 -05:00
1 parent 720b9ac967
commit 5ef47f016e
9 files changed
+344 -17

No files matched your search

@@ -907,8 +907,9 @@ public class HydrologyRuntimeTest {
@Test
@SuppressWarnings("unchecked")
public void createChecksEveryReachableBiomeFluidWhileCavePoolsAreEnabled() throws Exception {
public void createChecksEveryPolicyFluidWhetherCavePoolsAreOnOrOff() throws Exception {
IrisDimension dimension = new IrisDimension().setRegions(new KList<>("tropical"));
dimension.setLoadKey("main");
dimension.setHydrology(new IrisHydrology().setEnabled(true).setDensity(0D));
IrisRegion tropical = new IrisRegion().setLandBiomes(new KList<>("volcanoes"));
tropical.setLoadKey("tropical");
@@ -932,6 +933,20 @@ public class HydrologyRuntimeTest {
assertTrue(failure.getMessage(), failure.getMessage().contains("'magma'") && failure.getMessage().contains("volcanoes"));
dimension.getHydrology().getUnderground().getCavePools().setEnabled(false);
assertEquals("Unknown hydrology fluid profile 'magma' in biome 'volcanoes' hydrologyPolicy.fluid; fluids defines [water]",
assertThrows(IllegalArgumentException.class, () -> HydrologyRuntime.create(engine, complex)).getMessage());
volcanoes.setHydrologyPolicy(null);
tropical.setHydrologyPolicy(new IrisHydrologyPolicy().setFluid("magma"));
assertEquals("Unknown hydrology fluid profile 'magma' in region 'tropical' hydrologyPolicy.fluid; fluids defines [water]",
assertThrows(IllegalArgumentException.class, () -> HydrologyRuntime.create(engine, complex)).getMessage());
tropical.setHydrologyPolicy(null);
dimension.setHydrologyPolicy(new IrisHydrologyPolicy().setFluid("magma"));
assertEquals("Unknown hydrology fluid profile 'magma' in dimension 'main' hydrologyPolicy.fluid; fluids defines [water]",
assertThrows(IllegalArgumentException.class, () -> HydrologyRuntime.create(engine, complex)).getMessage());
dimension.setHydrologyPolicy(new IrisHydrologyPolicy().setFluid("water"));
assertDisabled(HydrologyRuntime.create(engine, complex));
}
@@ -325,6 +325,18 @@ public class HydrologySettingsTest {
assertRejected(cavePools, "underground.cavePools.minArea");
}
@Test
public void compileBoundsTheSeededCupDensity() {
for (double invalid : new double[]{-0.5D, 64.5D, Double.NaN, Double.POSITIVE_INFINITY}) {
IrisHydrology config = new IrisHydrology();
config.getPonds().getSeeded().setDensity(invalid);
assertRejected(config, "ponds.seeded.density must stay within 0..64, got " + invalid);
}
IrisHydrology densest = new IrisHydrology();
densest.getPonds().getSeeded().setDensity(64D);
assertEquals(64f, compile(densest).ponds().seeded().density(), 0f);
}
@Test
public void compileRejectsCavePoolsThatReachPastTheNeighbouringChunks() {
IrisHydrology wide = new IrisHydrology();
@@ -32,8 +32,8 @@ public class PackHydrologyValidatorTest {
{
"enabled": true,
"tiers": [
{"name": "stream", "minCatchment": 1500, "halfWidth": [0.5, 2], "fluid": "water"},
{"name": "river", "minCatchment": 20000, "halfWidth": [2, 64], "fluid": "lava"}
{"name": "stream", "minCatchment": 1500, "halfWidth": [0.5, 2], "bankBand": 0, "fluid": "water"},
{"name": "river", "minCatchment": 20000, "halfWidth": [2, 64], "bankBand": 32, "fluid": "lava"}
],
"ponds": {"freeboard": [0, 2], "fluid": "lava",
"seeded": {"radius": [4, 12], "depth": [2, 8], "channelSpacing": [48, 160]}},
@@ -426,6 +426,186 @@ public class PackHydrologyValidatorTest {
assertContains(result.getBlockingErrors(), "ponds.freeboard has its min above its max.");
}
@Test
public void rejectsSeaInletSpacingBelowOne() throws Exception {
File pack = pack(dimension("{\"enabled\": true, \"underground\": {\"seaInlets\": {\"spacing\": 0}}}", ""));
write(pack, "dimensions/edge.json", dimension("{\"enabled\": true, \"underground\": {\"seaInlets\": {\"spacing\": 1}}}", ""));
assertEquals(List.of("Dimension 'main'.hydrology does not compile: Hydrology underground.seaInlets.spacing must be at least 1, got 0"),
validate(pack).errors());
}
@Test
public void rejectsPrefetchRingsOutsideZeroToFour() throws Exception {
File pack = pack(dimension("{\"enabled\": true, \"prefetchRings\": 5}", ""));
write(pack, "dimensions/low.json", dimension("{\"enabled\": true, \"prefetchRings\": -1}", ""));
write(pack, "dimensions/edge.json", dimension("{\"enabled\": true, \"prefetchRings\": 4}", ""));
assertEquals(List.of(
"Dimension 'low'.hydrology does not compile: Hydrology prefetchRings must stay within 0..4, got -1",
"Dimension 'main'.hydrology does not compile: Hydrology prefetchRings must stay within 0..4, got 5"), validate(pack).errors());
}
@Test
public void rejectsSeededPondDensityOutsideZeroToSixtyFour() throws Exception {
File pack = pack(dimension("{\"enabled\": true, \"ponds\": {\"seeded\": {\"density\": 64.5}}}", ""));
write(pack, "dimensions/low.json", dimension("{\"enabled\": true, \"ponds\": {\"seeded\": {\"density\": -1}}}", ""));
write(pack, "dimensions/edge.json", dimension("{\"enabled\": true, \"ponds\": {\"seeded\": {\"density\": 64}}}", ""));
assertEquals(List.of(
"Dimension 'low'.hydrology does not compile: Hydrology ponds.seeded.density must stay within 0..64, got -1.0",
"Dimension 'main'.hydrology does not compile: Hydrology ponds.seeded.density must stay within 0..64, got 64.5"),
validate(pack).errors());
}
@Test
public void rejectsFillEpsilonAtOrBelowZero() throws Exception {
File pack = pack(dimension("{\"enabled\": true, \"drainage\": {\"fillEpsilon\": 0}}", ""));
write(pack, "dimensions/low.json", dimension("{\"enabled\": true, \"drainage\": {\"fillEpsilon\": -0.001}}", ""));
write(pack, "dimensions/edge.json", dimension("{\"enabled\": true, \"drainage\": {\"fillEpsilon\": 0.00001}}", ""));
assertEquals(List.of(
"Dimension 'low'.hydrology does not compile: Hydrology drainage.fillEpsilon must be a finite value above 0, got -0.001",
"Dimension 'main'.hydrology does not compile: Hydrology drainage.fillEpsilon must be a finite value above 0, got 0.0"),
validate(pack).errors());
}
@Test
public void rejectsWaterfallMinimumDropBelowTwo() throws Exception {
File pack = pack(dimension("""
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0},
{"name": "river", "minCatchment": 20000, "halfWidth": [2, 8], "bankBand": 32, "waterfallMinimumDrop": 1}]}
""", ""));
write(pack, "dimensions/edge.json", dimension("""
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0, "waterfallMinimumDrop": 2}]}
""", ""));
assertEquals(List.of("Dimension 'main'.hydrology does not compile: Hydrology tiers[1].waterfallMinimumDrop must be at least 2, got 1"),
validate(pack).errors());
}
@Test
public void rejectsShoreDepthBelowOne() throws Exception {
File pack = pack(dimension("""
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0, "materials": {"shoreDepth": 0}}]}
""", ""));
write(pack, "dimensions/ponds.json", dimension("{\"enabled\": true, \"ponds\": {\"materials\": {\"shoreDepth\": 0}}}", ""));
write(pack, "dimensions/edge.json", dimension("""
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0, "materials": {"shoreDepth": 1}}],
"ponds": {"materials": {"shoreDepth": 1}}}
""", ""));
assertEquals(List.of(
"Dimension 'main'.hydrology does not compile: Hydrology tiers[0].materials.shoreDepth must be at least 1, got 0",
"Dimension 'ponds'.hydrology does not compile: Hydrology ponds.materials.shoreDepth must be at least 1, got 0"),
validate(pack).errors());
}
@Test
public void rejectsNegativeWidthFactorDepthRatioAndMaxFill() throws Exception {
File pack = pack(dimension("""
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0, "widthFactor": -1}]}
""", ""));
write(pack, "dimensions/ratio.json", dimension("""
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0, "depthRatio": -0.1}]}
""", ""));
write(pack, "dimensions/fill.json", dimension("{\"enabled\": true, \"deformation\": {\"maxFill\": -1}}", ""));
write(pack, "dimensions/edge.json", dimension("""
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0, "widthFactor": 0, "depthRatio": 0}],
"deformation": {"maxFill": 0}}
""", ""));
assertEquals(List.of(
"Dimension 'fill'.hydrology does not compile: Hydrology deformation.maxFill must be at least 0, got -1",
"Dimension 'main'.hydrology does not compile: Hydrology tiers[0].widthFactor must be a finite value of at least 0, got -1.0",
"Dimension 'ratio'.hydrology does not compile: Hydrology tiers[0].depthRatio must be a finite value of at least 0, got -0.1"),
validate(pack).errors());
}
@Test
public void rejectsCavePoolFreeboardThatReachesMaxDepth() throws Exception {
File pack = pack(dimension("{\"enabled\": true, \"underground\": {\"cavePools\": {\"maxDepth\": 2, \"freeboard\": [0, 2]}}}", ""));
write(pack, "dimensions/edge.json", dimension("""
{"enabled": true, "underground": {"cavePools": {"maxDepth": 3, "freeboard": [0, 2]}}}
""", ""));
write(pack, "dimensions/off.json", dimension("""
{"enabled": true, "underground": {"cavePools": {"enabled": false, "maxDepth": 2, "freeboard": [0, 2]}}}
""", ""));
assertEquals(List.of(
"Dimension 'main'.hydrology does not compile: Hydrology underground.cavePools.freeboard max 2 must stay below maxDepth 2"),
validate(pack).errors());
}
@Test
public void rejectsLakesWiderThanTheLakeExtent() throws Exception {
File pack = pack(dimension("{\"enabled\": true, \"lakes\": {\"maxArea\": 4194305}}", ""));
write(pack, "dimensions/edge.json", dimension("{\"enabled\": true, \"lakes\": {\"maxArea\": 4194304}}", ""));
assertEquals(List.of("Dimension 'main'.hydrology does not compile: Hydrology lakes.maxArea must not go above 4194304"
+ " (2048 by 2048 blocks, the widest a lake can span), got 4194305"), validate(pack).errors());
}
@Test
public void rejectsCavePoolsWiderThanTheirReach() throws Exception {
File pack = pack(dimension("{\"enabled\": true, \"underground\": {\"cavePools\": {\"maxArea\": 962}}}", ""));
write(pack, "dimensions/edge.json", dimension("{\"enabled\": true, \"underground\": {\"cavePools\": {\"maxArea\": 961}}}", ""));
write(pack, "dimensions/off.json", dimension("""
{"enabled": true, "underground": {"cavePools": {"enabled": false, "maxArea": 962}}}
""", ""));
assertEquals(List.of("Dimension 'main'.hydrology does not compile: Hydrology underground.cavePools.maxArea must not go above 961"
+ " (31 by 31 blocks, the widest a pool can spread), got 962"), validate(pack).errors());
}
@Test
public void rejectsRegionAndDimensionPolicyFluidsWhileCavePoolsAreOff() throws Exception {
File pack = pack(dimension("""
{"enabled": true, "underground": {"cavePools": {"enabled": false}}, "fluids": [{"name": "water"}]}
""", "\"hydrologyPolicy\": {\"fluid\": \"brine\"},"));
write(pack, "regions/region.json", """
{"landBiomes": ["biome"], "hydrologyPolicy": {"fluid": "tar"}}
""");
assertEquals(List.of(
"Dimension 'main'.hydrologyPolicy.fluid names fluid 'brine', which Dimension 'main'.hydrology.fluids does not define [water].",
"Region 'region'.hydrologyPolicy.fluid names fluid 'tar', which Dimension 'main'.hydrology.fluids does not define [water]."),
validate(pack).errors());
}
@Test
public void warnsWhenAWrittenTierLeavesHalfWidthOrBankBandUnset() throws Exception {
PackHydrologyValidator.Validation validation = validate(pack(dimension("""
{"enabled": true, "tiers": [
{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 4},
{"name": "river", "minCatchment": 20000, "bankBand": 32},
{"name": "major", "minCatchment": 320000, "halfWidth": [8, 16]}]}
""", "")));
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
assertEquals(List.of(
"Dimension 'main'.hydrology.tiers[1] ('river') does not set halfWidth, so it takes the default [0.5, 2.0].",
"Dimension 'main'.hydrology.tiers[2] ('major') does not set bankBand, so it takes the default 0"
+ " and leaves the ground beside its channels as it is."), validation.warnings());
assertTrue(validate(pack(dimension("{\"enabled\": true}", ""))).warnings().isEmpty());
}
@Test
public void warnsWhenTheMantleCannotWriteHydrology() throws Exception {
File pack = pack(dimension("{\"enabled\": true}", "\"useMantle\": false,"));
write(pack, "dimensions/other.json", dimension("{\"enabled\": true}", "\"disabledComponents\": [\"RIVER_HYDROLOGY\"],"));
write(pack, "dimensions/off.json", dimension("{\"enabled\": false}", "\"useMantle\": false,"));
PackHydrologyValidator.Validation validation = validate(pack);
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
assertEquals(List.of(
"Dimension 'main' sets useMantle to false while hydrology is enabled, so the falling water at waterfalls and cascades,"
+ " sea inlets and cave pools are not generated.",
"Dimension 'other' disables the RIVER_HYDROLOGY component while hydrology is enabled, so the falling water at waterfalls"
+ " and cascades, sea inlets and cave pools are not generated."), validation.warnings());
}
private PackHydrologyValidator.Validation validate(File pack) {
File[] dimensions = new File(pack, "dimensions").listFiles(
file -> file.isFile() && file.getName().endsWith(".json"));
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "34e32452b3e79ed5608e2e71fffeeae85ca99ec5c5c84970eedc9fa7b1c68a04";
private static final String EXPECTED_SCHEMA_DIGEST = "33c7287d91f9b38d96e156aa3eb317331befaa2092cf848d04cdbd0e3e7a3cd6";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,