Bound policy multipliers

- Reject a policy rainfall or pondDensity outside 0..16 when a column resolves it, naming the biome and region
- Report a policy rainfall or pondDensity outside 0..16 at every scope in pack validation
- Share the 0..16 bound between the schema, the terrain source and the validator through IrisHydrologyPolicy.MAX_MULTIPLIER
- Size the window cup grid from a double product of seeded density and peak pond density
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 02:15:34 -05:00
1 parent 4000dfe659
commit fa43b276f4
6 files changed
+82 -6

No files matched your search

@@ -22,13 +22,15 @@ import java.util.function.Function;
@Description("Hydrology settings for a dimension, region or biome. A value a biome leaves unset is inherited from the biome it grows inside as a child, up through that biome's own parents, then from the region, then from the dimension.")
@Data
public class IrisHydrologyPolicy {
public static final double MAX_MULTIPLIER = 16D;
@MinNumber(0)
@MaxNumber(16)
@MaxNumber(MAX_MULTIPLIER)
@Description("Multiplier on the water that falls in this area. Higher values grow more and larger streams and keep ponds fuller. With no value set anywhere it is 1.")
private Double rainfall = null;
@MinNumber(0)
@MaxNumber(16)
@MaxNumber(MAX_MULTIPLIER)
@Description("Multiplier on how many ponds form in this area. With no value set anywhere it is 1.")
private Double pondDensity = null;
@@ -61,6 +63,10 @@ public class IrisHydrologyPolicy {
@Description("Plants for the rivers, streams, ponds and lakes in this area, replacing the decorators of the tiers and ponds there. Written like the tier and pond decorators: partOf SEA_FLOOR, SEA_SURFACE or SHORE_LINE. An empty list grows no plants here. With no value set anywhere, the tiers and ponds use their own decorators.")
private KList<IrisDecorator> decorators = null;
public static boolean validMultiplier(double value) {
return value >= 0D && value <= MAX_MULTIPLIER;
}
public static <T> T inherited(List<IrisBiome> biomes, IrisRegion region, IrisDimension dimension, Function<IrisHydrologyPolicy, T> field) {
for (int index = 0; index < biomes.size(); index++) {
T value = value(biomes.get(index).getHydrologyPolicy(), field);
@@ -230,9 +230,9 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
}
private static void requireMultiplier(String field, double value, List<IrisBiome> biomes, IrisRegion region) {
if (!Double.isFinite(value) || value < 0D) {
throw new IllegalArgumentException("Hydrology policy " + field + " for " + where(biomes, region) + " must be a finite value of 0 or more, got "
+ value);
if (!IrisHydrologyPolicy.validMultiplier(value)) {
throw new IllegalArgumentException("Hydrology policy " + field + " for " + where(biomes, region) + " must be a finite value from 0 to "
+ (int) IrisHydrologyPolicy.MAX_MULTIPLIER + ", got " + value);
}
}
@@ -54,7 +54,7 @@ final class CupCarver {
private void windowCups(DemGrid raw, int wx, int wz, HydrologySampleBuffer samples, List<CupSet.Cup> out) {
float density = settings.ponds().seeded().density();
double expected = density * peakPondDensity(raw, wx, wz, samples);
double expected = (double) density * peakPondDensity(raw, wx, wz, samples);
if (!(expected > 0D)) {
return;
}
@@ -260,12 +260,20 @@ final class PackHydrologyValidator {
if (policy.getDecorators() != null) {
validateDecorators(field + ".decorators", policy.getDecorators(), data, errors);
}
requireMultiplier(field + ".rainfall", policy.getRainfall(), errors);
requireMultiplier(field + ".pondDensity", policy.getPondDensity(), errors);
IrisHydrologyWetness wetness = policy.getWetness();
if (wetness != null && !(wetness.getMin() >= 0D && wetness.getMin() <= wetness.getMax() && wetness.getMax() <= 1D)) {
errors.add(field + ".wetness must have 0 <= min <= max <= 1, got min " + wetness.getMin() + " and max " + wetness.getMax() + ".");
}
}
private static void requireMultiplier(String field, Double value, List<String> errors) {
if (value != null && !IrisHydrologyPolicy.validMultiplier(value)) {
errors.add(field + " must be a finite value from 0 to " + (int) IrisHydrologyPolicy.MAX_MULTIPLIER + ", got " + value + ".");
}
}
private static void close(File packFolder, IrisData data, List<String> errors) {
if (data == null) {
return;
@@ -224,6 +224,50 @@ public class IrisHydrologyTerrainSourceTest {
}
}
@Test
public void policyMultipliersOutsideZeroToSixteenAreRejected() throws Exception {
Path pack = EngineFixture.pack(temporaryFolder.newFolder().toPath());
int[] xs = new int[COLUMNS];
int[] zs = new int[COLUMNS];
columns(xs, zs);
try (EngineFixture.Environment ignored = EngineFixture.environment(); EngineFixture fixture = new EngineFixture(pack)) {
HydrologySettings settings = settings(fixture);
int[] column = spiresColumn(fixture, xs, zs);
IrisBiome spires = fixture.data.getBiomeLoader().load("spires");
spires.setHydrologyPolicy(new IrisHydrologyPolicy().setPondDensity(17D));
assertPolicyRejected(fixture, settings, column,
"Hydrology policy pondDensity for biome spires in region beta must be a finite value from 0 to 16, got 17.0");
spires.setHydrologyPolicy(new IrisHydrologyPolicy().setRainfall(16.5D).setPondDensity(16D));
assertPolicyRejected(fixture, settings, column,
"Hydrology policy rainfall for biome spires in region beta must be a finite value from 0 to 16, got 16.5");
spires.setHydrologyPolicy(new IrisHydrologyPolicy().setRainfall(16D).setPondDensity(16D));
HydrologySampleBuffer bounds = new HydrologySampleBuffer(1);
new IrisHydrologyTerrainSource(fixture.complex, fixture.dimension, settings, null, 1, HydrologyBinding.UNBOUND)
.sample(new int[]{column[0]}, new int[]{column[1]}, bounds, false);
assertEquals(16f, bounds.rainfall()[0], 0f);
assertEquals(16f, bounds.pondDensity()[0], 0f);
}
}
private static int[] spiresColumn(EngineFixture fixture, int[] xs, int[] zs) {
for (int index = 0; index < xs.length; index++) {
if (fixture.complex.getBaseBiomeStream().get(xs[index], zs[index]).getLoadKey().equals("spires")) {
return new int[]{xs[index], zs[index]};
}
}
throw new AssertionError("No sampled column is spires");
}
private static void assertPolicyRejected(EngineFixture fixture, HydrologySettings settings, int[] column, String message) {
try {
new IrisHydrologyTerrainSource(fixture.complex, fixture.dimension, settings, null, 1, HydrologyBinding.UNBOUND)
.sample(new int[]{column[0]}, new int[]{column[1]}, new HydrologySampleBuffer(1), false);
fail("Expected rejection: " + message);
} catch (IllegalArgumentException expected) {
assertEquals(message, expected.getMessage());
}
}
private static void assertInvertedWetnessRejected(EngineFixture fixture, HydrologySettings settings, int[] xs, int[] zs) {
fixture.data.getBiomeLoader().load("meadow").getHydrologyPolicy().setWetness(new IrisHydrologyWetness().setMin(0.8D).setMax(0.3D));
for (int index = 0; index < xs.length; index++) {
@@ -135,6 +135,24 @@ public class PackHydrologyValidatorTest {
assertEquals(errors.toString(), 2, errors.size());
}
@Test
public void rejectsPolicyMultipliersOutsideZeroToSixteen() throws Exception {
File pack = pack(dimension(WATER_ONLY, "\"hydrologyPolicy\": {\"rainfall\": 16, \"pondDensity\": 0},"));
write(pack, "regions/region.json", """
{"landBiomes": ["biome"], "hydrologyPolicy": {"pondDensity": 17}}
""");
write(pack, "biomes/biome.json", """
{"name": "Biome", "hydrologyPolicy": {"rainfall": -0.5, "pondDensity": 16.5}}
""");
List<String> errors = validate(pack).errors();
assertContains(errors, "Region 'region'.hydrologyPolicy.pondDensity must be a finite value from 0 to 16, got 17.0.");
assertContains(errors, "Biome 'biome'.hydrologyPolicy.rainfall must be a finite value from 0 to 16, got -0.5.");
assertContains(errors, "Biome 'biome'.hydrologyPolicy.pondDensity must be a finite value from 0 to 16, got 16.5.");
assertEquals(errors.toString(), 3, errors.size());
}
@Test
public void rejectsFluidReferencesTheFluidProfilesDoNotDefine() throws Exception {
File pack = pack(dimension("""