Shore lists need a width

- Warn in pack validate when a hydrologyPolicy.shoreBiomes list has no shoreBiomeWidth above 0 applying to it, naming the dimension, region or biome that lists it
- Resolve the shore band through IrisHydrologyPolicy.shoreBand for both runtime placement and reachability
- Walk region biome lineages in ShoreBiomeLineages so reachable biomes include only shore biomes a width places
- Make HydrologyShoreTargets.placesAny use the placed shore biomes, so the locator ignores lists without a width
- Take the dimension in IrisRegion.getAllBiomeIds and getAllBiomes and gate their shore biomes on hydrology
- Drop region biome additions the package compilers already get from the dimension's reachable biomes
- Seed unset region colours from the natural biome ids
- State in the shoreBiomes description that a width is required, and recapture the schema digest
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 03:43:29 -05:00
1 parent 5ef47f016e
commit ca431452fe
18 files changed
+395 -96

No files matched your search

@@ -1,6 +1,7 @@
package art.arcane.iris.generation.locator;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.image.IrisImageMapApplication;
@@ -132,11 +133,15 @@ public class BiomeSearchFilterTest {
@Test
public void hydrologyColumnsAreAdmittedForShoreBiomesThePolicyPlaces() {
stubRegions();
when(complex.getRegionStream()).thenReturn(constantStream(region("host")));
IrisRegion host = region("host");
host.setLandBiomes(keys("land_root"));
stubBiome(biome("land_root"));
stubRegions(host);
when(complex.getRegionStream()).thenReturn(constantStream(host));
HydrologyRuntime hydrology = enabledHydrology();
when(complex.getHydrologyRuntime()).thenReturn(hydrology);
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy().setShoreBiomes(keys("river_root")));
when(dimension.getHydrology()).thenReturn(new IrisHydrology().setEnabled(true));
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy().setShoreBiomes(keys("river_root")).setShoreBiomeWidth(4));
IrisBiome river = biome("river_root");
river.setChildren(keys("target"));
stubBiome(river);
@@ -150,11 +155,15 @@ public class BiomeSearchFilterTest {
@Test
public void hydrologyIsNotConsultedForBiomesNoHydrologyPolicyPlaces() {
stubRegions();
when(complex.getRegionStream()).thenReturn(constantStream(region("host")));
IrisRegion host = region("host");
host.setLandBiomes(keys("land_root"));
stubBiome(biome("land_root"));
stubRegions(host);
when(complex.getRegionStream()).thenReturn(constantStream(host));
HydrologyRuntime hydrology = enabledHydrology();
when(complex.getHydrologyRuntime()).thenReturn(hydrology);
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy().setShoreBiomes(keys("river_root")));
when(dimension.getHydrology()).thenReturn(new IrisHydrology().setEnabled(true));
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy().setShoreBiomes(keys("river_root")).setShoreBiomeWidth(4));
stubBiome(biome("river_root"));
when(engine.answersFromNaturalTerrain(anyInt(), anyInt())).thenReturn(false);
@@ -166,10 +175,14 @@ public class BiomeSearchFilterTest {
@Test
public void disabledHydrologyIsNeverConsultedForPolicyShoreBiomes() {
stubRegions();
when(complex.getRegionStream()).thenReturn(constantStream(region("host")));
IrisRegion host = region("host");
host.setLandBiomes(keys("land_root"));
stubBiome(biome("land_root"));
stubRegions(host);
when(complex.getRegionStream()).thenReturn(constantStream(host));
when(complex.getHydrologyRuntime()).thenReturn(mock(HydrologyRuntime.class));
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy().setShoreBiomes(keys("target")));
when(dimension.getHydrology()).thenReturn(new IrisHydrology().setEnabled(true));
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy().setShoreBiomes(keys("target")).setShoreBiomeWidth(4));
stubBiome(biome("target"));
when(engine.answersFromNaturalTerrain(anyInt(), anyInt())).thenReturn(false);
@@ -16,6 +16,7 @@ import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.structure.object.IrisObjectPlacement;
import art.arcane.iris.generation.terrain.IrisRegion;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
import art.arcane.iris.world.history.GenerationSemanticIndex;
import art.arcane.iris.spi.IrisPlatform;
@@ -283,9 +284,14 @@ public class HintedLocatorTest {
HydrologyShoreTargets placed = new HydrologyShoreTargets(Set.of(riverShore.getLoadKey()));
HydrologyShoreTargets unplaced = new HydrologyShoreTargets(Set.of(riverShore.getLoadKey()));
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy().setShoreBiomes(keys(riverShore.getLoadKey())));
stubRegions();
IrisRegion host = region("host");
host.setLandBiomes(keys(plains.getLoadKey()));
when(dimension.getHydrology()).thenReturn(new IrisHydrology().setEnabled(true));
when(dimension.getHydrologyPolicy()).thenReturn(new IrisHydrologyPolicy()
.setShoreBiomes(keys(riverShore.getLoadKey())).setShoreBiomeWidth(4));
stubRegions(host);
stubBiome(riverShore);
stubBiome(plains);
assertTrue(Locator.chunkContainsSurfaceBiome(engine, new Position2(2, 0), riverShore.getLoadKey(), placed));
assertFalse(Locator.chunkContainsSurfaceBiome(engine, new Position2(8, 0), riverShore.getLoadKey(), placed));
@@ -0,0 +1,62 @@
package art.arcane.iris.generation.locator;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.generation.terrain.IrisRegion;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.pack.loading.ResourceLoader;
import art.arcane.volmlib.util.collection.KList;
import org.junit.Test;
import java.util.Set;
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 HydrologyShoreTargetsTest {
@Test
@SuppressWarnings("unchecked")
public void listsWithoutWidthPlaceNothing() {
IrisDimension dimension = new IrisDimension()
.setRegions(new KList<>("coast"))
.setHydrology(new IrisHydrology().setEnabled(true))
.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("beach")));
IrisRegion coast = new IrisRegion()
.setLandBiomes(new KList<>("plains"))
.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("dune")));
coast.setLoadKey("coast");
IrisData data = mock(IrisData.class);
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
when(data.getRegionLoader()).thenReturn(regionLoader);
when(data.getBiomeLoader()).thenReturn(biomeLoader);
when(regionLoader.load("coast")).thenReturn(coast);
when(biomeLoader.load("plains")).thenReturn(biome("plains"));
when(biomeLoader.load("beach")).thenReturn(biome("beach"));
when(biomeLoader.load("dune")).thenReturn(biome("dune"));
Engine engine = mock(Engine.class);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getData()).thenReturn(data);
assertFalse(HydrologyShoreTargets.placesAny(engine, Set.of("beach")));
assertFalse(HydrologyShoreTargets.placesAny(engine, Set.of("dune")));
dimension.getHydrologyPolicy().setShoreBiomeWidth(3);
assertTrue(HydrologyShoreTargets.placesAny(engine, Set.of("dune")));
assertFalse(HydrologyShoreTargets.placesAny(engine, Set.of("beach")));
coast.getHydrologyPolicy().setShoreBiomeWidth(0);
assertFalse(HydrologyShoreTargets.placesAny(engine, Set.of("dune")));
}
private static IrisBiome biome(String key) {
IrisBiome biome = new IrisBiome();
biome.setLoadKey(key);
return biome;
}
}
@@ -1,6 +1,7 @@
package art.arcane.iris.generation.terrain;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
import art.arcane.iris.pack.loading.IrisData;
@@ -18,6 +19,7 @@ import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -51,11 +53,12 @@ public class IrisDimensionFocusRegionTest {
biome("wilds").setChildren(new KList<>("highlands"));
IrisBiome highlands = biome("highlands").setChildren(new KList<>("wilds"))
.setCarvingBiome("chalk-gardens")
.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("shore")));
.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("shore")).setShoreBiomeWidth(4));
IrisBiome chalk = biome("chalk-gardens").setChildren(new KList<>("chalk-child"));
IrisBiome chalkChild = biome("chalk-child");
IrisBiome shore = biome("shore").setChildren(new KList<>("shore-child"));
IrisBiome shoreChild = biome("shore-child").setCarvingBiome("wilds");
dimension.setHydrology(new IrisHydrology().setEnabled(true));
for (IrisBiome focus : List.of(highlands, chalk, chalkChild, shore, shoreChild)) {
assertSame(tropical, dimension.resolveFocusRegion(focus, () -> data));
@@ -73,16 +76,21 @@ public class IrisDimensionFocusRegionTest {
}
@Test
public void hydrologyPolicyShoreBiomesBelongToTheirRegion() {
IrisRegion tropical = region("tropical").setLandBiomes(new KList<>("wilds"))
public void placedHydrologyShoreBiomesBelongToTheirRegion() {
IrisRegion tropical = region("tropical").setLandBiomes(new KList<>("wilds", "dunes"))
.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("beach")));
biome("wilds").setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("reef")));
biome("dunes");
IrisBiome beach = biome("beach");
IrisBiome reef = biome("reef");
dimension.setHydrology(new IrisHydrology().setEnabled(true));
assertNotSame(tropical, dimension.resolveFocusRegion(beach, () -> data));
assertNotSame(tropical, dimension.resolveFocusRegion(reef, () -> data));
tropical.getHydrologyPolicy().setShoreBiomeWidth(3);
assertSame(tropical, dimension.resolveFocusRegion(beach, () -> data));
assertSame(tropical, dimension.resolveFocusRegion(reef, () -> data));
assertEquals(Set.of("wilds"), tropical.getNaturalBiomes(() -> data).stream()
assertEquals(Set.of("wilds", "dunes"), tropical.getNaturalBiomes(() -> data).stream()
.map(IrisBiome::getLoadKey).collect(Collectors.toSet()));
}
@@ -204,12 +204,12 @@ public class IrisDimensionReachableBiomesTest {
@Test
@SuppressWarnings("unchecked")
public void includesHydrologyPolicyShoreBiomesOnlyWhileHydrologyIsEnabled() {
public void includesHydrologyShoreBiomesOnlyWhereAWidthPlacesThem() {
IrisDimension dimension = new IrisDimension()
.setRegions(new KList<>("reachable"))
.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("dimension-shore")));
IrisRegion reachable = new IrisRegion()
.setLandBiomes(new KList<>("root"))
.setLandBiomes(new KList<>("root", "plain"))
.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("region-shore")));
IrisBiome root = biome("root").setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("biome-shore")));
IrisBiome regionShore = biome("region-shore").setChildren(new KList<>("shore-child"));
@@ -221,16 +221,49 @@ public class IrisDimensionReachableBiomesTest {
when(data.getBiomeLoader()).thenReturn(biomeLoader);
when(regionLoader.load("reachable")).thenReturn(reachable);
when(biomeLoader.load("root")).thenReturn(root);
when(biomeLoader.load("plain")).thenReturn(biome("plain"));
when(biomeLoader.load("dimension-shore")).thenReturn(biome("dimension-shore"));
when(biomeLoader.load("region-shore")).thenReturn(regionShore);
when(biomeLoader.load("shore-child")).thenReturn(biome("shore-child"));
when(biomeLoader.load("biome-shore")).thenReturn(biome("biome-shore"));
assertEquals(Set.of("root"), reachableKeys(dimension, data));
dimension.setHydrology(new IrisHydrology().setEnabled(false));
assertEquals(Set.of("root"), reachableKeys(dimension, data));
assertEquals(Set.of("root", "plain"), reachableKeys(dimension, data));
dimension.setHydrology(new IrisHydrology().setEnabled(true));
assertEquals(Set.of("root", "dimension-shore", "region-shore", "shore-child", "biome-shore"), reachableKeys(dimension, data));
assertEquals(Set.of("root", "plain"), reachableKeys(dimension, data));
dimension.getHydrologyPolicy().setShoreBiomeWidth(3);
assertEquals(Set.of("root", "plain", "region-shore", "shore-child", "biome-shore"), reachableKeys(dimension, data));
dimension.setHydrology(new IrisHydrology().setEnabled(false));
assertEquals(Set.of("root", "plain"), reachableKeys(dimension, data));
dimension.setHydrology(new IrisHydrology().setEnabled(true));
reachable.getHydrologyPolicy().setShoreBiomeWidth(0);
assertEquals(Set.of("root", "plain"), reachableKeys(dimension, data));
root.getHydrologyPolicy().setShoreBiomeWidth(2);
assertEquals(Set.of("root", "plain", "biome-shore"), reachableKeys(dimension, data));
}
@Test
@SuppressWarnings("unchecked")
public void aParentWidthReachesTheShoreListOfItsChildren() {
IrisDimension dimension = new IrisDimension()
.setRegions(new KList<>("reachable"))
.setHydrology(new IrisHydrology().setEnabled(true));
IrisRegion reachable = new IrisRegion().setLandBiomes(new KList<>("parent"));
IrisBiome parent = biome("parent").setChildren(new KList<>("child"));
IrisBiome child = biome("child").setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomes(new KList<>("child-shore")));
IrisData data = mock(IrisData.class);
ResourceLoader<IrisRegion> regionLoader = mock(ResourceLoader.class);
ResourceLoader<IrisBiome> biomeLoader = mock(ResourceLoader.class);
when(data.getRegionLoader()).thenReturn(regionLoader);
when(data.getBiomeLoader()).thenReturn(biomeLoader);
when(regionLoader.load("reachable")).thenReturn(reachable);
when(biomeLoader.load("parent")).thenReturn(parent);
when(biomeLoader.load("child")).thenReturn(child);
when(biomeLoader.load("child-shore")).thenReturn(biome("child-shore"));
assertEquals(Set.of("parent", "child"), reachableKeys(dimension, data));
parent.setHydrologyPolicy(new IrisHydrologyPolicy().setShoreBiomeWidth(5));
assertEquals(Set.of("parent", "child", "child-shore"), reachableKeys(dimension, data));
}
@Test
@@ -606,6 +606,38 @@ public class PackHydrologyValidatorTest {
+ " and cascades, sea inlets and cave pools are not generated."), validation.warnings());
}
@Test
public void shoreBiomesWithoutWidthWarn() throws Exception {
PackHydrologyValidator.Validation unset = validate(shorePack(""));
PackHydrologyValidator.Validation widened = validate(shorePack(", \"shoreBiomeWidth\": 3"));
assertTrue(unset.errors().toString(), unset.errors().isEmpty());
assertEquals(List.of(
"Dimension 'main'.hydrologyPolicy.shoreBiomes lists shore biomes, but no shoreBiomeWidth above 0 applies to them,"
+ " so none are placed.",
"Region 'region'.hydrologyPolicy.shoreBiomes lists shore biomes, but no shoreBiomeWidth above 0 applies to them,"
+ " so none are placed.",
"Biome 'dune'.hydrologyPolicy.shoreBiomes lists shore biomes, but no shoreBiomeWidth above 0 applies to them,"
+ " so none are placed."), unset.warnings());
assertTrue(widened.errors().toString(), widened.errors().isEmpty());
assertTrue(widened.warnings().toString(), widened.warnings().isEmpty());
}
private File shorePack(String dimensionWidth) throws Exception {
File pack = pack(dimension(WATER_ONLY, "\"hydrologyPolicy\": {\"shoreBiomes\": [\"beach\"]" + dimensionWidth + "},"));
write(pack, "regions/region.json", """
{"landBiomes": ["biome", "dune", "bare"], "hydrologyPolicy": {"shoreBiomes": ["beach"]}}
""");
write(pack, "biomes/dune.json", """
{"name": "Dune", "hydrologyPolicy": {"shoreBiomes": ["beach"]}}
""");
write(pack, "biomes/bare.json", """
{"name": "Bare", "hydrologyPolicy": {"shoreBiomes": []}}
""");
write(pack, "biomes/beach.json", "{\"name\": \"Beach\"}");
return pack;
}
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 = "33c7287d91f9b38d96e156aa3eb317331befaa2092cf848d04cdbd0e3e7a3cd6";
private static final String EXPECTED_SCHEMA_DIGEST = "a07a6f50e6df895cf7d11a50245bfb3e987c5be2f527e45da86ade9826cd6f3a";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,