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

@@ -24,12 +24,12 @@ public class IrisCavePools {
private double density = 0.15D;
@MinNumber(1)
@MaxNumber(4096)
@MaxNumber(961)
@Description("Smallest pool surface in square blocks.")
private int minArea = 6;
@MinNumber(1)
@MaxNumber(65536)
@MaxNumber(961)
@Description("Largest pool surface in square blocks.")
private int maxArea = 400;
@@ -16,12 +16,12 @@ public class IrisHydrologyLakes {
private boolean enabled = true;
@MinNumber(1024)
@MaxNumber(134217728)
@MaxNumber(4194304)
@Description("Smallest lake surface in square blocks.")
private int minArea = 65536;
@MinNumber(1024)
@MaxNumber(134217728)
@MaxNumber(4194304)
@Description("Largest lake surface in square blocks. Larger hollows are drained by a cut through their rim.")
private int maxArea = 4194304;
}
@@ -151,11 +151,9 @@ public final class HydrologyRuntime {
Objects.requireNonNull(complex, "Hydrology needs the engine's terrain complex");
HydrologySettings settings = HydrologySettings.compile(config, engine.getSeedManager().getBodies(), dimension.getFluidHeight(), 0,
engine.getHeight());
boolean caveFluidPolicies = false;
if (settings.underground().cavePools().enabled()) {
requireBiomeFluids(dimension.getReachableBiomes(engine), settings);
caveFluidPolicies = requireCaveFluids(dimension, dimension.getAllRegions(engine), dimension.getReachableCaveBiomes(engine), settings);
}
requireBiomeFluids(dimension.getReachableBiomes(engine), settings);
boolean caveFluidPolicies = requireCaveFluids(dimension, dimension.getAllRegions(engine), dimension.getReachableCaveBiomes(engine), settings)
&& settings.underground().cavePools().enabled();
if (settings.density() == 0D) {
return DISABLED;
}
@@ -22,6 +22,7 @@ import art.arcane.iris.generation.hydrology.config.IrisSeaInlets;
import art.arcane.iris.generation.hydrology.underground.SeaInletPlanner;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import art.arcane.iris.generation.hydrology.water.LakeCandidate;
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
import com.google.gson.Gson;
@@ -47,6 +48,12 @@ public final class HydrologySettings {
private static final int INLET_LAST_STEP = (int) Math.ceil(WindowPlanner.CELL * Math.sqrt(2D));
private static final int INLET_SHELL = SeaInletRasterizer.SHELL;
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 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;
private static final int MIN_WATERFALL_DROP = 2;
private final long seed;
private final int seaLevel;
@@ -88,6 +95,7 @@ public final class HydrologySettings {
this.seams = seams(config.getFluids());
this.prefetchRings = config.getPrefetchRings();
this.persist = config.isPersist();
requireBounds(config);
requireFluidReferences();
this.fingerprint = computeFingerprint();
}
@@ -498,6 +506,77 @@ public final class HydrologySettings {
}
}
private void requireBounds(IrisHydrology config) {
requireWithin(prefetchRings, 0, MAX_PREFETCH_RINGS, "prefetchRings");
requirePositive(config.getDrainage().getFillEpsilon(), "drainage.fillEpsilon");
for (int index = 0; index < config.getTiers().size(); index++) {
requireTierBounds(config.getTiers().get(index), "tiers[" + index + "]");
}
double seeded = config.getPonds().getSeeded().getDensity();
if (!(seeded >= 0D && seeded <= MAX_SEEDED_DENSITY)) {
throw new IllegalArgumentException("Hydrology ponds.seeded.density must stay within 0.." + MAX_SEEDED_DENSITY + ", got " + seeded);
}
requireShoreDepth(ponds.materials(), "ponds.materials");
requireAtLeast(deformation.maxFill(), 0, "deformation.maxFill");
if (lakes.maxArea() > MAX_LAKE_AREA) {
throw new IllegalArgumentException("Hydrology lakes.maxArea must not go above " + MAX_LAKE_AREA + " (" + LakeCandidate.MAX_EXTENT
+ " by " + LakeCandidate.MAX_EXTENT + " blocks, the widest a lake can span), got " + lakes.maxArea());
}
requireAtLeast(underground.seaInlets().spacing(), 1, "underground.seaInlets.spacing");
requireCavePoolBounds(underground.cavePools());
}
private static void requireTierBounds(IrisHydrologyTier config, String field) {
requireNonNegative(config.getWidthFactor(), field + ".widthFactor");
requireNonNegative(config.getDepthRatio(), field + ".depthRatio");
requireAtLeast(config.getWaterfallMinimumDrop(), MIN_WATERFALL_DROP, field + ".waterfallMinimumDrop");
requireShoreDepth(config.getMaterials(), field + ".materials");
}
private static void requireShoreDepth(IrisHydrologyMaterials materials, String field) {
if (materials != null) {
requireAtLeast(materials.getShoreDepth(), 1, field + ".shoreDepth");
}
}
private static void requireCavePoolBounds(CavePools pools) {
if (!pools.enabled()) {
return;
}
if (pools.freeboard().max() >= pools.maxDepth()) {
throw new IllegalArgumentException("Hydrology underground.cavePools.freeboard max " + pools.freeboard().max()
+ " must stay below maxDepth " + pools.maxDepth());
}
if (pools.maxArea() > MAX_CAVE_POOL_AREA) {
throw new IllegalArgumentException("Hydrology underground.cavePools.maxArea must not go above " + MAX_CAVE_POOL_AREA + " ("
+ CAVE_POOL_SPAN + " by " + CAVE_POOL_SPAN + " blocks, the widest a pool can spread), got " + pools.maxArea());
}
}
private static void requireWithin(int value, int min, int max, String field) {
if (value < min || value > max) {
throw new IllegalArgumentException("Hydrology " + field + " must stay within " + min + ".." + max + ", got " + value);
}
}
private static void requireAtLeast(int value, int min, String field) {
if (value < min) {
throw new IllegalArgumentException("Hydrology " + field + " must be at least " + min + ", got " + value);
}
}
private static void requireNonNegative(double value, String field) {
if (!(Double.isFinite(value) && value >= 0D)) {
throw new IllegalArgumentException("Hydrology " + field + " must be a finite value of at least 0, got " + value);
}
}
private static void requirePositive(double value, String field) {
if (!(Double.isFinite(value) && value > 0D)) {
throw new IllegalArgumentException("Hydrology " + field + " must be a finite value above 0, got " + value);
}
}
private void requireFluidReferences() {
for (Map.Entry<String, String> seam : seams.entrySet()) {
requireFluid(seam.getValue(), "the seam of fluid '" + seam.getKey() + "'");
@@ -5,6 +5,7 @@ import art.arcane.iris.generation.decoration.HydrologyVegetation;
import art.arcane.iris.generation.decoration.IrisDecorator;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyWetness;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.terrain.IrisDimension;
@@ -14,6 +15,7 @@ import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.volmlib.util.json.JSONArray;
import art.arcane.volmlib.util.json.JSONObject;
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
import java.io.File;
import java.util.ArrayList;
@@ -39,31 +41,36 @@ final class PackHydrologyValidator {
new RangeField("underground.cavePools.freeboard", Floor.NON_NEGATIVE, true)
);
private static final List<String> FLUID_REFERENCES = List.of("ponds.fluid", "underground.cavePools.fluid");
private static final IrisHydrologyTier DEFAULT_TIER = new IrisHydrologyTier();
private static final String MANTLE_WATER = "the falling water at waterfalls and cascades, sea inlets and cave pools";
private PackHydrologyValidator() {
}
static Validation validate(File packFolder, File[] dimensionFiles) {
List<String> errors = new ArrayList<>();
List<String> warnings = new ArrayList<>();
if (packFolder == null || !packFolder.isDirectory() || dimensionFiles == null) {
return new Validation(errors, List.of());
return new Validation(errors, warnings);
}
List<File> sortedDimensions = new ArrayList<>(List.of(dimensionFiles));
sortedDimensions.sort(Comparator.comparing(File::getPath));
File dimensionsFolder = new File(packFolder, PackValidator.DIMENSIONS_FOLDER);
Findings findings = new Findings(errors, warnings);
IrisData data = null;
try {
for (File dimensionFile : sortedDimensions) {
data = validateDimension(packFolder, dimensionsFolder, dimensionFile, data, errors);
data = validateDimension(packFolder, dimensionsFolder, dimensionFile, data, findings);
}
} finally {
close(packFolder, data, errors);
}
return new Validation(errors, List.of());
return new Validation(errors, warnings);
}
private static IrisData validateDimension(File packFolder, File dimensionsFolder, File dimensionFile, IrisData data,
List<String> errors) {
Findings findings) {
List<String> errors = findings.errors();
JSONObject dimension = PackValidationIo.readJson(dimensionFile);
if (dimension == null || !dimension.has(CONFIG)) {
return data;
@@ -79,6 +86,7 @@ final class PackHydrologyValidator {
}
int reported = errors.size();
validateRanges(path, hydrology, errors);
warnPartialTiers(path, hydrology, findings.warnings());
Set<String> fluids = fluidNames(hydrology);
Set<String> seams = seamNames(hydrology);
validateFluidReferences(path, hydrology, fluids, errors);
@@ -87,6 +95,7 @@ final class PackHydrologyValidator {
if (loadedDimension == null) {
return loaded;
}
warnMantleOff("Dimension '" + dimensionKey + "'", loadedDimension, findings.warnings());
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), errors);
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
@@ -150,6 +159,37 @@ final class PackHydrologyValidator {
}
}
private static void warnPartialTiers(String path, JSONObject hydrology, List<String> warnings) {
JSONArray tiers = hydrology.optJSONArray("tiers");
if (tiers == null) {
return;
}
for (int index = 0; index < tiers.length(); index++) {
JSONObject tier = tiers.optJSONObject(index);
if (tier == null) {
continue;
}
String field = path + ".tiers[" + index + "] ('" + tier.optString("name", DEFAULT_TIER.getName()) + "')";
if (!tier.has("halfWidth")) {
warnings.add(field + " does not set halfWidth, so it takes the default " + DEFAULT_TIER.getHalfWidth() + ".");
}
if (!tier.has("bankBand")) {
warnings.add(field + " does not set bankBand, so it takes the default " + DEFAULT_TIER.getBankBand()
+ " and leaves the ground beside its channels as it is.");
}
}
}
private static void warnMantleOff(String path, IrisDimension dimension, List<String> warnings) {
if (!dimension.isUseMantle()) {
warnings.add(path + " sets useMantle to false while hydrology is enabled, so " + MANTLE_WATER + " are not generated.");
}
if (dimension.getDisabledComponents() != null && dimension.getDisabledComponents().contains(ReservedFlag.RIVER_HYDROLOGY)) {
warnings.add(path + " disables the " + ReservedFlag.RIVER_HYDROLOGY + " component while hydrology is enabled, so " + MANTLE_WATER
+ " are not generated.");
}
}
private static double[] range(String field, Object value, Floor floor, boolean whole, List<String> errors) {
if (!(value instanceof JSONArray pair) || pair.length() != 2 || !(pair.opt(0) instanceof Number first)
|| !(pair.opt(1) instanceof Number second)) {
@@ -320,4 +360,7 @@ final class PackHydrologyValidator {
private record PolicyFluids(Set<String> defined, Set<String> seams) {
}
private record Findings(List<String> errors, List<String> warnings) {
}
}
@@ -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,