Estuaries replace deltas

- Replace the tier deltas flag with estuary {length 48, flare 2.5}, validated in HydrologySettings and added to the fingerprint
- Grade ocean-ending reaches to sea level over the estuary while the lower bank lies within maxFill of the sea, stopping at held pond outlet points
- Style estuary points MOUTH and flare their half-width by 1 + (flare - 1) * s^2 toward the mouth, keeping the channel depth
- Fill MOUTH columns with the sea fluid so lava rivers meet the sea through their seam
- Paint MOUTH columns with the sea layers and ice of the sea floor, like INLET slots
- Stop bank levees from raising ground below sea level
- Recapture DEFAULT_FINGERPRINT and EXPECTED_SCHEMA_DIGEST
- Cover the estuary flare, mouth sea fluid, lava mouth seam, frozen mouth ice, the strict no-berm coastal fall and the coastal sea-floor scene
- Pin that tiers written with an unknown key load with the default estuary
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-01 22:23:36 -05:00
1 parent 11ce906e5b
commit aef674f206
25 files changed
+470 -40

No files matched your search

@@ -45,8 +45,7 @@ public class IrisHydrology {
.setHalfWidth(new KList<>(8D, 16D))
.setDepthRatio(0.5D)
.setInset(3)
.setBankBand(48)
.setDeltas(true));
.setBankBand(48));
@Description("Standing water above sea level: natural hollows, seeded cups and dams.")
private IrisHydrologyPonds ponds = new IrisHydrologyPonds();
@@ -0,0 +1,24 @@
package art.arcane.iris.generation.hydrology.config;
import art.arcane.iris.pack.schema.annotation.MaxNumber;
import art.arcane.iris.pack.schema.annotation.MinNumber;
import art.arcane.volmlib.util.documentation.Description;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
@Accessors(chain = true)
@NoArgsConstructor
@Description("Where a channel reaches the sea it widens into an estuary: water at sea level that holds the sea's own fluid, so the sea's surface layers and ice continue across it.")
@Data
public class IrisHydrologyEstuary {
@MinNumber(0)
@MaxNumber(256)
@Description("Most blocks upstream of the mouth the estuary reaches. It stops where the lower bank rises more than deformation.maxFill blocks above sea level. 0 ends the channel in a plain mouth.")
private int length = 48;
@MinNumber(1)
@MaxNumber(4)
@Description("Half-width at the mouth of a full-length estuary as a multiple of the channel's own half-width. The channel widens slowly at first and fastest near the mouth and keeps its own depth; an estuary cut short by higher banks widens less. The half-width never passes 64. 1 keeps the channel's width.")
private double flare = 2.5D;
}
@@ -60,8 +60,8 @@ public class IrisHydrologyTier {
@Description("Shape of the banks inside the bank band.")
private IrisBankStyle bankStyle = IrisBankStyle.SMOOTH;
@Description("Spreads the channel into a delta where it reaches the sea.")
private boolean deltas = false;
@Description("How the channel widens into an estuary where it reaches the sea.")
private IrisHydrologyEstuary estuary = new IrisHydrologyEstuary();
@Description("Blocks painted on the bed, shore and banks of this tier.")
private IrisHydrologyMaterials materials = new IrisHydrologyMaterials();
@@ -9,6 +9,7 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrologyClimate;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyDeformation;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyDrainage;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyEstuary;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyLakes;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPonds;
@@ -36,6 +37,8 @@ import java.util.Objects;
public final class HydrologySettings {
private static final Gson PALETTE_JSON = new Gson();
private static final int MAX_BANK_BAND = 64;
private static final int MAX_ESTUARY_LENGTH = 256;
private static final double MAX_ESTUARY_FLARE = 4D;
public static final float MAX_HALF_WIDTH = 64f;
private static final double MIN_INLET_HALF_WIDTH = 1D;
private static final double MAX_INLET_HALF_WIDTH = 16D;
@@ -238,11 +241,26 @@ public final class HydrologySettings {
}
return new HydrologyTier(config.getName(), (float) config.getMinCatchment(), halfWidth.min(), halfWidth.max(),
(float) config.getWidthFactor(), (float) config.getDepthRatio(), config.getInset(), config.isCascades(),
config.getWaterfallMinimumDrop(), config.getBankBand(), config.getBankStyle(), config.isDeltas(),
materials(config.getMaterials(), field + ".materials"), config.getFluid(),
config.getWaterfallMinimumDrop(), config.getBankBand(), config.getBankStyle(),
estuary(config.getEstuary(), field + ".estuary"), materials(config.getMaterials(), field + ".materials"), config.getFluid(),
decorators(config.getDecorators(), field + ".decorators"));
}
private static HydrologyTier.Estuary estuary(IrisHydrologyEstuary config, String field) {
if (config == null) {
throw new IllegalArgumentException("Hydrology " + field + " must be an object");
}
if (config.getLength() < 0 || config.getLength() > MAX_ESTUARY_LENGTH) {
throw new IllegalArgumentException("Hydrology " + field + ".length must stay within 0.." + MAX_ESTUARY_LENGTH + ", got "
+ config.getLength());
}
if (!(config.getFlare() >= 1D && config.getFlare() <= MAX_ESTUARY_FLARE)) {
throw new IllegalArgumentException("Hydrology " + field + ".flare must stay within 1.." + MAX_ESTUARY_FLARE + ", got "
+ config.getFlare());
}
return new HydrologyTier.Estuary(config.getLength(), (float) config.getFlare());
}
private static Ponds ponds(IrisHydrologyPonds config) {
IrisPondDams dams = config.getDams();
return new Ponds(naturalPonds(config.getNatural()), seededPonds(config.getSeeded()),
@@ -549,7 +567,8 @@ public final class HydrologySettings {
for (HydrologyTier tier : tiers) {
hash.add(tier.name()).add(tier.minCatchment()).add(tier.minHalfWidth()).add(tier.maxHalfWidth())
.add(tier.widthFactor()).add(tier.depthRatio()).add(tier.inset()).add(tier.cascades())
.add(tier.waterfallMinimumDrop()).add(tier.bankBand()).add(tier.bankStyle()).add(tier.deltas())
.add(tier.waterfallMinimumDrop()).add(tier.bankBand()).add(tier.bankStyle())
.add(tier.estuary().length()).add(tier.estuary().flare())
.add(tier.materials()).add(tier.fluid());
}
}
@@ -145,7 +145,7 @@ final class RasterComposer {
role[cell] = role(reach.style()[point]);
feature[cell] = reach.id();
tier[cell] = reach.tier();
fluid[cell] = reachFluid(reach);
fluid[cell] = role[cell] == WaterRole.MOUTH ? HydrologyCaveCell.SEA_FLUID : reachFluid(reach);
}
private String reachFluid(Reach reach) {
@@ -190,7 +190,7 @@ final class RasterComposer {
if (ground >= surface) {
double cone = coneSlope(steepestToWater(x, z, bank, bankEdge)) * u * bankTier.bankBand();
cut = BankProfile.cut(bankTier.bankStyle(), surface, ground, u, cone, noise(x, z));
} else {
} else if (ground >= settings.seaLevel()) {
raise = BankProfile.levee(bankTier.bankStyle(), surface, ground, u, noise(x, z), settings.deformation().maxFill());
}
}
@@ -18,7 +18,7 @@ public record HydrologyTier(
int waterfallMinimumDrop,
int bankBand,
IrisBankStyle bankStyle,
boolean deltas,
Estuary estuary,
IrisHydrologyMaterials materials,
String fluid,
List<IrisDecorator> decorators
@@ -34,4 +34,7 @@ public record HydrologyTier(
public float depth(float halfWidth) {
return Math.max(MINIMUM_DEPTH, depthRatio * halfWidth);
}
public record Estuary(int length, float flare) {
}
}
@@ -50,6 +50,9 @@ final class ReachGrader {
for (int upstream : draft.incoming) {
level = Math.min(level, drafts.get(upstream).last());
}
if (draft.chain.end() == ReachTracer.End.OCEAN) {
estuary(draft, seaLevel + maxFill);
}
int[] grade = profile(drafts, draft);
for (int point = 0; point < grade.length; point++) {
if (draft.held != null && draft.held[point] && !draft.ocean[point]) {
@@ -78,6 +81,21 @@ final class ReachGrader {
return levels;
}
private static void estuary(ReachDraft draft, int highestBank) {
int length = draft.tier.estuary().length();
float along = 0f;
for (int point = draft.xs.length - 1; point >= 0; point--) {
if (point < draft.xs.length - 1) {
along += (float) Math.hypot(draft.xs[point + 1] - draft.xs[point], draft.zs[point + 1] - draft.zs[point]);
}
boolean held = draft.held != null && draft.held[point];
if (along > length || held || !draft.ocean[point] && draft.bank[point] > highestBank) {
return;
}
draft.ocean[point] = true;
}
}
static int[] outletPonds(int[] outletDrafts, int drafts) {
int[] outletPond = new int[drafts];
Arrays.fill(outletPond, -1);
@@ -492,6 +492,7 @@ public final class ReachShaper {
boolean flare = draft.incoming.length > 0 && !draft.outlet;
boolean taper = !flare && !draft.outlet;
float[] distance = distances(draft.xs, draft.zs);
float[] estuary = estuaryFlare(draft, distance);
float running = upstream;
draft.halfWidth = new float[count];
draft.depth = new float[count];
@@ -503,13 +504,42 @@ public final class ReachShaper {
law *= Math.min(1f, distance[point] / TAPER_LENGTH);
}
float lip = draft.held != null && draft.held[point] ? LIP_HALF_WIDTH : 0f;
draft.halfWidth[point] = Math.max(Math.max(law, WAIST * running), lip);
running = Math.max(running, draft.halfWidth[point]);
draft.depth[point] = draft.tier.depth(draft.halfWidth[point]);
float channel = Math.max(Math.max(law, WAIST * running), lip);
draft.halfWidth[point] = Math.min(HydrologySettings.MAX_HALF_WIDTH, channel * estuary[point]);
running = Math.max(running, channel);
draft.depth[point] = draft.tier.depth(channel);
}
draft.maxHalfWidth = running;
}
private static float[] estuaryFlare(ReachDraft draft, float[] distance) {
int count = distance.length;
float[] scale = new float[count];
Arrays.fill(scale, 1f);
if (draft.chain.end() != ReachTracer.End.OCEAN) {
return scale;
}
HydrologyTier.Estuary estuary = draft.tier.estuary();
float mouth = distance[count - 1];
int start = count - 1;
while (start > 0 && draft.ocean[start - 1] && mouth - distance[start - 1] <= estuary.length()) {
start--;
}
if (start == count - 1) {
return scale;
}
float first = towardMouth(mouth - distance[start], estuary.length());
for (int point = start + 1; point < count; point++) {
float toward = towardMouth(mouth - distance[point], estuary.length());
scale[point] = 1f + (estuary.flare() - 1f) * (toward * toward - first * first);
}
return scale;
}
private static float towardMouth(float remaining, int length) {
return Math.clamp(1f - remaining / length, 0f, 1f);
}
public static ReachStyle[] styles(int[] grade, boolean[] ocean, boolean[] outletZone, int waterfallMinimumDrop) {
ReachStyle[] styles = new ReachStyle[grade.length];
for (int point = 0; point < grade.length; point++) {
@@ -228,7 +228,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<NativeBloc
WaterRole role = waterRoleStream.get(realX, realZ);
boolean wet = role.wet();
boolean submerged = wet && he < surfaceFluidHeight;
boolean seaFloor = !wet || role == WaterRole.INLET;
boolean seaFloor = !wet || role == WaterRole.INLET || role == WaterRole.MOUTH;
IrisHydrologyMaterials materials = role == WaterRole.NONE || role == WaterRole.INLET ? null
: complex.resolveWaterMaterials(realX, realZ);
Terrain3DColumn terrainColumn = complex.terrainColumn(realX, realZ);
@@ -18,9 +18,9 @@ public class IrisHydrologyDefaultsTest {
"enabled": false,
"drainage": { "fillEpsilon": 0.001, "breachDepth": 24, "wetnessThinning": true, "minimumHeadKeep": 0.25, "saturationCatchment": 4194304 },
"tiers": [
{ "name": "stream", "minCatchment": 1500, "halfWidth": [0.5, 2], "widthFactor": 1.0, "depthRatio": 0.4, "inset": 1, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 0, "bankStyle": "SMOOTH", "deltas": false, "materials": {}, "fluid": "water" },
{ "name": "river", "minCatchment": 20000, "halfWidth": [2, 8], "widthFactor": 1.0, "depthRatio": 0.45, "inset": 2, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 32, "bankStyle": "SMOOTH", "deltas": false, "materials": {}, "fluid": "water" },
{ "name": "major", "minCatchment": 320000, "halfWidth": [8, 16], "widthFactor": 1.0, "depthRatio": 0.5, "inset": 3, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 48, "bankStyle": "SMOOTH", "deltas": true, "materials": {}, "fluid": "water" }
{ "name": "stream", "minCatchment": 1500, "halfWidth": [0.5, 2], "widthFactor": 1.0, "depthRatio": 0.4, "inset": 1, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 0, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "materials": {}, "fluid": "water" },
{ "name": "river", "minCatchment": 20000, "halfWidth": [2, 8], "widthFactor": 1.0, "depthRatio": 0.45, "inset": 2, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 32, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "materials": {}, "fluid": "water" },
{ "name": "major", "minCatchment": 320000, "halfWidth": [8, 16], "widthFactor": 1.0, "depthRatio": 0.5, "inset": 3, "cascades": true, "waterfallMinimumDrop": 6, "bankBand": 48, "bankStyle": "SMOOTH", "estuary": { "length": 48, "flare": 2.5 }, "materials": {}, "fluid": "water" }
],
"ponds": {
"natural": { "enabled": true, "keep": 1.0, "minArea": 256, "maxArea": 65536, "minDepth": 2 },
@@ -126,8 +126,8 @@ public class HydrologyPlanCodecTest {
HydrologyPlanCodec.decodeWindow(settings, damaged);
}
HydrologyTier foreign = new HydrologyTier("foreign", 0f, 1f, 2f, 1f, 0.4f, 1, true, 6, 0, IrisBankStyle.SMOOTH, false,
new IrisHydrologyMaterials(), "water", List.of());
HydrologyTier foreign = new HydrologyTier("foreign", 0f, 1f, 2f, 1f, 0.4f, 1, true, 6, 0, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
Reach stray = new Reach(6L, foreign, -1L, new float[]{1f, 2f}, new float[]{1f, 2f}, new int[]{1, 1}, new float[]{1f, 1f},
new float[]{1f, 1f}, new ReachStyle[]{ReachStyle.RUN, ReachStyle.RUN}, 1f);
try {
@@ -32,7 +32,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 = 8818472145657699942L;
private static final long DEFAULT_FINGERPRINT = 4889114733390836736L;
@Test
public void densityIsBoundedAndChangesThePlanIdentity() {
@@ -230,6 +230,14 @@ public class HydrologySettingsTest {
gravityBlocks.getTiers().get(0).getMaterials().setAllowGravityBlocks(false);
fingerprints.add(compile(gravityBlocks).fingerprint());
IrisHydrology estuaryLength = new IrisHydrology();
estuaryLength.getTiers().get(2).getEstuary().setLength(64);
fingerprints.add(compile(estuaryLength).fingerprint());
IrisHydrology estuaryFlare = new IrisHydrology();
estuaryFlare.getTiers().get(2).getEstuary().setFlare(3D);
fingerprints.add(compile(estuaryFlare).fingerprint());
fingerprints.add(HydrologySettings.compile(new IrisHydrology(), SEED + 1L, SEA_LEVEL, MIN_Y, MAX_Y).fingerprint());
fingerprints.add(HydrologySettings.compile(new IrisHydrology(), SEED, SEA_LEVEL + 1, MIN_Y, MAX_Y).fingerprint());
@@ -362,6 +370,31 @@ public class HydrologySettingsTest {
assertEquals(64, compile(widest).tiers().get(1).bankBand());
}
@Test
public void compileRejectsAnEstuaryOutsideItsBounds() {
for (int length : new int[]{-1, 257}) {
IrisHydrology config = new IrisHydrology();
config.getTiers().get(1).getEstuary().setLength(length);
assertRejected(config, "tiers[1].estuary.length");
}
for (double flare : new double[]{0.99D, 4.01D, Double.NaN}) {
IrisHydrology config = new IrisHydrology();
config.getTiers().get(2).getEstuary().setFlare(flare);
assertRejected(config, "tiers[2].estuary.flare");
}
IrisHydrology missing = new IrisHydrology();
missing.getTiers().get(0).setEstuary(null);
assertRejected(missing, "tiers[0].estuary");
IrisHydrology widest = new IrisHydrology();
widest.getTiers().get(0).getEstuary().setLength(0).setFlare(1D);
widest.getTiers().get(1).getEstuary().setLength(256).setFlare(4D);
HydrologySettings compiled = compile(widest);
assertEquals(new HydrologyTier.Estuary(0, 1f), compiled.tiers().get(0).estuary());
assertEquals(new HydrologyTier.Estuary(256, 4f), compiled.tiers().get(1).estuary());
assertEquals(new HydrologyTier.Estuary(48, 2.5f), compiled.tiers().get(2).estuary());
}
@Test
public void compileRejectsHalfWidthAbove64() {
IrisHydrology config = new IrisHydrology();
@@ -99,7 +99,7 @@ final class PlannedScene {
new IrisHydrologyTier().setName("river").setMinCatchment(5000D).setHalfWidth(new KList<>(2.5D, 9D)).setWidthFactor(1.2D)
.setDepthRatio(0.45D).setInset(2).setBankBand(32),
new IrisHydrologyTier().setName("major").setMinCatchment(200000D).setHalfWidth(new KList<>(9D, 18D)).setWidthFactor(1.2D)
.setDepthRatio(0.5D).setInset(3).setBankBand(48).setWaterfallMinimumDrop(8).setDeltas(true)));
.setDepthRatio(0.5D).setInset(3).setBankBand(48).setWaterfallMinimumDrop(8)));
config.getPonds().setFreeboard(new KList<>(1, 2));
config.getPonds().setClimateDrawdown(3);
config.getPonds().getSeeded().setDensity(10D).setRadius(new KList<>(6, 22)).setMaxSlope(0.7D).setChannelSpacing(new KList<>(80, 192));
@@ -148,6 +148,10 @@ final class PlannedScene {
return raster.empty() ? (int) Math.round(terrain.natural(x, z)) : raster.terrainHeight(Math.floorMod(x, CHUNK), Math.floorMod(z, CHUNK));
}
int natural(int x, int z) {
return (int) Math.round(terrain.natural(x, z));
}
WaterRole role(int x, int z) {
return at(x, z).role(Math.floorMod(x, CHUNK), Math.floorMod(z, CHUNK));
}
@@ -809,6 +809,51 @@ public class WindowPlannerTest {
assertTrue("inlet columns on the cliff coast " + cliffColumns.inlets(), cliffColumns.inlets() >= 500);
}
@Test
public void coastalBanksNeverRaiseTheSeaFloor() {
PlannedScene scene = PlannedScene.plan(SyntheticTerrain.openFractal(1L).lowered(COAST_DROP), PlannedScene.packSettings(SEED), 2, 2);
int banksInTheSea = 0;
int raised = 0;
int emergent = 0;
int holding = 0;
String first = null;
for (int z = scene.minZ() + WaterInvariants.EDGE_MARGIN; z <= scene.maxZ() - WaterInvariants.EDGE_MARGIN; z++) {
for (int x = scene.minX() + WaterInvariants.EDGE_MARGIN; x <= scene.maxX() - WaterInvariants.EDGE_MARGIN; x++) {
int natural = scene.natural(x, z);
if (natural >= SEA_LEVEL || scene.head(x, z) != Integer.MIN_VALUE) {
continue;
}
banksInTheSea += scene.role(x, z) == WaterRole.BANK ? 1 : 0;
int ground = scene.terrain(x, z);
if (ground <= natural) {
continue;
}
if (holdsWaterAboveTheSea(scene, x, z)) {
holding++;
continue;
}
raised++;
emergent += ground >= SEA_LEVEL ? 1 : 0;
if (first == null) {
first = scene.role(x, z) + " at " + x + "," + z + " raised from " + natural + " to " + ground;
}
}
}
assertTrue("bank columns in the sea " + banksInTheSea, banksInTheSea >= 1000);
assertEquals("sea columns raised " + raised + " (" + emergent + " out of the sea, " + holding + " holding water above the sea), first "
+ first, 0, raised);
}
private static boolean holdsWaterAboveTheSea(PlannedScene scene, int x, int z) {
int[][] sides = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
for (int[] side : sides) {
if (scene.head(x + side[0], z + side[1]) > SEA_LEVEL) {
return true;
}
}
return false;
}
@Test
public void planWithAMouthBelowSeaFailsClosed() {
HydrologySettings settings = settings(new IrisHydrology());
@@ -2,6 +2,7 @@ package art.arcane.iris.generation.hydrology.raster;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
@@ -19,6 +20,7 @@ import art.arcane.iris.generation.hydrology.water.PondKind;
import art.arcane.iris.generation.hydrology.water.PondMask;
import art.arcane.iris.generation.hydrology.water.Reach;
import art.arcane.iris.generation.hydrology.water.ReachStyle;
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
import org.junit.Test;
import java.util.ArrayList;
@@ -903,8 +905,8 @@ public class ChunkWaterRasterTest {
@Test
public void crossWindowJunctionDropsSpreadOnTiersWithoutCascades() {
HydrologyTier gentle = new HydrologyTier("stream", 0f, 2f, 2f, 0f, 0.5f, 1, false, 6, 4, IrisBankStyle.SMOOTH, false,
new IrisHydrologyMaterials(), "water", List.of());
HydrologyTier gentle = new HydrologyTier("stream", 0f, 2f, 2f, 0f, 0.5f, 1, false, 6, 4, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
HydrologyTier wide = tier("river", 3f, 0.5f, 4, IrisBankStyle.SMOOTH);
Reach low = line(262L, wide, 0L, 504f, 200f, 600f, 200f, (x, z) -> 62);
Reach steep = line(261L, gentle, low.id(), 440f, 200f, 504f, 200f, (x, z) -> x >= 496f ? 66 : Math.min(80, 66 + (int) ((496f - x) / 2f)));
@@ -1118,11 +1120,8 @@ public class ChunkWaterRasterTest {
int ground = scene.terrain(x, z);
if (x < 40) {
assertTrue(banks + "dry shore at " + x + "," + z + " is cut to " + ground + ", below the sea surface", ground >= SEA_LEVEL);
} else if (bankBand == 0) {
assertEquals(banks + "no berm is built in the sea at " + x + "," + z, coast.applyAsInt(x, z), ground);
} else {
assertTrue(banks + "the sea floor at " + x + "," + z + " is " + ground + ", cut or raised out of the sea",
ground >= coast.applyAsInt(x, z) && ground < SEA_LEVEL);
assertEquals(banks + "no berm is built in the sea at " + x + "," + z, coast.applyAsInt(x, z), ground);
}
}
}
@@ -1130,6 +1129,109 @@ public class ChunkWaterRasterTest {
assertEquals(banks + "leaks", 0, scene.leaks(-20, minZ, 56, maxZ));
}
@Test
public void mouthColumnsUseTheSeaFluid() {
IntBinaryOperator coast = (x, z) -> x < 40 ? 44 : SEA_LEVEL - 10;
HydrologyTier stream = tier("stream", 1.5f, 0.5f, 8, IrisBankStyle.SMOOTH);
Reach river = mouthed(line(126L, stream, 0L, -20f, 8f, 56f, 8f, (x, z) -> x < 40f ? 42 : SEA_LEVEL), 40f);
Scene scene = new Scene(settings(new IrisHydrology()), coast).reach(river);
int mouths = 0;
int channels = 0;
for (int x = -16; x <= 52; x++) {
for (int z = 0; z <= 16; z++) {
WaterRole role = scene.role(x, z);
if (role == WaterRole.MOUTH) {
mouths++;
assertEquals("mouth at " + x + "," + z, HydrologyCaveCell.SEA_FLUID, scene.fluid(x, z));
} else if (role == WaterRole.CHANNEL) {
channels++;
assertEquals("channel at " + x + "," + z, "water", scene.fluid(x, z));
}
}
}
assertTrue("mouth columns " + mouths + ", channel columns " + channels, mouths > 20 && channels > 20);
}
@Test
public void lavaMouthMeetsTheSeaThroughTheSeam() {
IrisHydrology config = new IrisHydrology();
config.getFluids().add(new IrisFluidProfile().setName("lava").setSeam("crust")
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
config.getFluids().add(new IrisFluidProfile().setName("crust")
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:obsidian")));
HydrologySettings settings = settings(config);
HydrologyTier lava = new HydrologyTier("lava", 0f, 1.5f, 1.5f, 0f, 0.5f, 1, true, 6, 8, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "lava", List.of());
IntBinaryOperator coast = (x, z) -> x < 40 ? 44 : SEA_LEVEL - 3;
Reach river = mouthed(line(131L, lava, 0L, -20f, 8f, 56f, 8f, (x, z) -> x < 40f ? 42 : SEA_LEVEL), 40f);
Scene scene = new Scene(settings, coast).reach(river);
FluidSeams.Columns columns = new FluidSeams.Columns() {
@Override
public String fluid(int x, int z) {
return scene.role(x, z).wet() ? scene.fluid(x, z) : null;
}
@Override
public boolean sea(int x, int z) {
return scene.terrain(x, z) < SEA_LEVEL;
}
};
int mouths = 0;
int lavaColumns = 0;
int sealed = 0;
for (int chunkX = -2; chunkX <= 3; chunkX++) {
for (int chunkZ = -1; chunkZ <= 1; chunkZ++) {
String[] seams = FluidSeams.seal(settings.seams(), SEED, chunkX, chunkZ, columns);
for (int lz = 0; lz < 16; lz++) {
for (int lx = 0; lx < 16; lx++) {
int x = chunkX * 16 + lx;
int z = chunkZ * 16 + lz;
String seam = seams == null ? null : seams[lz << 4 | lx];
WaterRole role = scene.role(x, z);
if (role == WaterRole.MOUTH) {
mouths++;
assertEquals("the estuary holds the sea at " + x + "," + z, HydrologyCaveCell.SEA_FLUID, scene.fluid(x, z));
assertNull("the sea itself is never sealed at " + x + "," + z, seam);
} else if (role.wet()) {
lavaColumns++;
assertEquals("upstream of the estuary the river is lava at " + x + "," + z, "lava", scene.fluid(x, z));
if (touchesTheSea(columns, x, z)) {
sealed++;
assertEquals("lava touching the sea is sealed at " + x + "," + z, "crust", seam);
}
} else if (x >= 40) {
assertEquals("no shore rises out of the sea beside the lava at " + x + "," + z, coast.applyAsInt(x, z),
scene.terrain(x, z));
}
}
}
}
}
assertTrue("mouth columns " + mouths + ", lava columns " + lavaColumns + ", sealed " + sealed,
mouths > 20 && lavaColumns > 20 && sealed > 0);
}
private static boolean touchesTheSea(FluidSeams.Columns columns, int x, int z) {
for (int dz = -1; dz <= 1; dz++) {
for (int dx = -1; dx <= 1; dx++) {
String fluid = columns.fluid(x + dx, z + dz);
if (HydrologyCaveCell.SEA_FLUID.equals(fluid) || fluid == null && columns.sea(x + dx, z + dz)) {
return true;
}
}
}
return false;
}
private static Reach mouthed(Reach drawn, float coastX) {
ReachStyle[] style = drawn.style().clone();
for (int point = 0; point < style.length; point++) {
style[point] = drawn.xs()[point] >= coastX ? ReachStyle.MOUTH : ReachStyle.RUN;
}
return new Reach(drawn.id(), drawn.tier(), drawn.downstreamId(), drawn.xs(), drawn.zs(), drawn.grade(), drawn.halfWidth(), drawn.depth(),
style, drawn.catchment());
}
private static void assertContained(String name, Scene scene, int minX, int minZ, int maxX, int maxZ, boolean bermed) {
int water = 0;
int raised = 0;
@@ -1158,8 +1260,8 @@ public class ChunkWaterRasterTest {
}
private static HydrologyTier tier(String name, float halfWidth, float depthRatio, int bankBand, IrisBankStyle style) {
return new HydrologyTier(name, 0f, halfWidth, halfWidth, 0f, depthRatio, 1, true, 6, bankBand, style, false,
new IrisHydrologyMaterials(), "water", List.of());
return new HydrologyTier(name, 0f, halfWidth, halfWidth, 0f, depthRatio, 1, true, 6, bankBand, style,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
}
private static Reach line(long id, HydrologyTier tier, long downstreamId, float startX, float startZ, float endX, float endZ, Grade grade) {
@@ -121,7 +121,7 @@ public class PondChannelSettlementTest {
private static Reach line(long id, int x0, int z0, int x1, int z1, float width, int first, int last) {
HydrologyTier tier = new HydrologyTier("river", 0f, width, width, 0f, 0.5f, 2, true, 6, 0, IrisBankStyle.SMOOTH,
false, null, "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), null, "water", List.of());
float[] widths = new float[]{width, width};
float[] depth = new float[]{2f, 2f};
ReachStyle[] styles = new ReachStyle[2];
@@ -26,7 +26,7 @@ public class ReachIndexTest {
private static final WindowKey WINDOW = new WindowKey(0, 0);
private static final int BANK_BAND = 4;
private static final HydrologyTier TIER = new HydrologyTier("test", 0f, 1f, 4f, 1f, 0.4f, 1, true, 6, BANK_BAND, IrisBankStyle.SMOOTH,
false, new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
@Test
public void aReachIdTwiceInOnePlanFailsClosedNamingTheWindow() {
@@ -186,7 +186,8 @@ public class ReachIndexTest {
}
private static HydrologyTier tier(String name, int bankBand) {
return new HydrologyTier(name, 0f, 0.5f, 4f, 1f, 0.4f, 1, true, 6, bankBand, IrisBankStyle.SMOOTH, false, new IrisHydrologyMaterials(),
return new HydrologyTier(name, 0f, 0.5f, 4f, 1f, 0.4f, 1, true, 6, bankBand, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(),
"water", List.of());
}
@@ -18,7 +18,7 @@ import static org.junit.Assert.assertTrue;
public class ReachSegmentsTest {
private static final HydrologyTier TIER = new HydrologyTier("test", 0f, 1f, 4f, 1f, 0.4f, 1, true, 6, 4, IrisBankStyle.SMOOTH,
false, new IrisHydrologyMaterials(), "water", List.of());
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
@Test
public void coveredChannelLookupsMatchTheFullScan() {
@@ -904,6 +904,56 @@ public class ReachShaperTest {
assertEquals(1, mouths);
}
@Test
public void oceanReachesFlareOverTheEstuary() {
HydrologySettings settings = settings(config -> {
});
HydrologySettings plain = settings(config -> config.getTiers().forEach(tier -> tier.getEstuary().setFlare(1D)));
HydrologySettings plainMouth = settings(config -> config.getTiers().forEach(tier -> tier.getEstuary().setLength(0)));
Reach estuary = coastalRun(settings, true);
Reach unflared = coastalRun(plain, true);
Reach mouth = coastalRun(plainMouth, true);
HydrologyTier.Estuary shape = estuary.tier().estuary();
assertEquals(48, shape.length());
assertEquals(2.5f, shape.flare(), 0f);
assertTrue("the same channel line", Arrays.equals(estuary.xs(), unflared.xs()) && Arrays.equals(estuary.xs(), mouth.xs()));
int last = estuary.xs().length - 1;
int start = trailingMouth(estuary);
float span = estuary.xs()[last] - estuary.xs()[start];
assertTrue("estuary reaches " + span + " blocks up from the mouth", span >= 40f && span <= 52f);
for (int point = 0; point <= last; point++) {
boolean inside = point >= start;
assertEquals(estuary + " is a mouth at " + point, inside, estuary.style()[point] == ReachStyle.MOUTH);
assertTrue(estuary + " grade at " + point, inside ? estuary.grade()[point] == SEA_LEVEL : estuary.grade()[point] > SEA_LEVEL);
assertEquals("the estuary keeps the channel depth at " + point, unflared.depth()[point], estuary.depth()[point], 0f);
if (point <= start) {
assertEquals("no flare above the estuary at " + point, unflared.halfWidth()[point], estuary.halfWidth()[point], 0f);
} else {
float ratio = estuary.halfWidth()[point] / unflared.halfWidth()[point];
float previous = estuary.halfWidth()[point - 1] / unflared.halfWidth()[point - 1];
assertTrue("flare grows toward the mouth at " + point + ": " + previous + " then " + ratio, ratio >= previous - 1e-6f);
}
}
float mouthFlare = estuary.halfWidth()[last] / unflared.halfWidth()[last];
assertTrue("a full-length estuary opens to about flare times the channel: " + mouthFlare, mouthFlare >= 2.45f && mouthFlare <= 2.5f + 1e-4f);
float half = estuary.xs()[start] + 0.5f * span;
int middle = start;
while (estuary.xs()[middle] < half) {
middle++;
}
assertTrue("flare grows slowly at first", estuary.halfWidth()[middle] / unflared.halfWidth()[middle] < 1.75f);
assertTrue("length 0 ends in a plain mouth", mouth.xs()[last] - mouth.xs()[trailingMouth(mouth)] < 8f);
assertTrue("length 0 keeps the channel width", Arrays.equals(unflared.halfWidth(), mouth.halfWidth()));
Reach inland = coastalRun(settings, false);
Reach inlandPlain = coastalRun(plain, false);
assertEquals(0, inland.downstreamId());
assertNotEquals(ReachStyle.MOUTH, inland.style()[inland.xs().length - 1]);
assertTrue("a channel that does not reach the sea keeps its width", Arrays.equals(inlandPlain.halfWidth(), inland.halfWidth()));
}
@Test
public void groundReadIsSymmetricAroundThePoint() {
HydrologySettings settings = settings(config -> {
@@ -1755,6 +1805,41 @@ public class ReachShaperTest {
return found;
}
private static Reach coastalRun(HydrologySettings settings, boolean ocean) {
int width = 24;
DemGrid surface = new DemGrid(0, 0, CELL, width, 3);
Arrays.fill(surface.values(), 60f);
int[] receivers = new int[width * 3];
Arrays.fill(receivers, -1);
float[] accumulation = new float[width * 3];
BitSet channels = new BitSet(width * 3);
for (int i = 0; i < width; i++) {
int cell = surface.index(i, 1);
receivers[cell] = i + 1 < width ? surface.index(i + 1, 1) : -1;
accumulation[cell] = (i + 1) * 1000f;
if (i + 1 < width) {
channels.set(cell);
}
}
if (ocean) {
surface.set(width - 1, 1, 30f);
}
float mouthX = (width - 1) * CELL;
HeightLattice fine = new HeightLattice(new Terrain((x, z) -> SEA_LEVEL + 1D + 0.08D * Math.max(0D, mouthX - x)), FINE, false, 1 << 16);
ShapedNetwork shaped = new ReachShaper(settings).shape(WINDOW, surface, receivers, accumulation, channels, List.of(), fine, SEED);
assertEquals(1, shaped.reaches().size());
return shaped.reaches().get(0);
}
private static int trailingMouth(Reach reach) {
int start = reach.style().length;
while (start > 0 && reach.style()[start - 1] == ReachStyle.MOUTH) {
start--;
}
assertTrue(reach + " ends in a mouth", start < reach.style().length);
return start;
}
private static int firstBeyond(Reach reach, float distance) {
float travelled = 0f;
for (int index = 1; index < reach.xs().length; index++) {
@@ -351,8 +351,8 @@ public class IrisComplexHeightStreamTest {
IrisHydrologyMaterials ponds = RASTER_SETTINGS.ponds().materials();
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
IrisHydrologyMaterials tierMaterials = new IrisHydrologyMaterials();
HydrologyTier tier = new HydrologyTier("river", 0f, 1f, 2f, 1f, 0.4f, 1, true, 6, 0, IrisBankStyle.SMOOTH, false,
tierMaterials, "water", List.of());
HydrologyTier tier = new HydrologyTier("river", 0f, 1f, 2f, 1f, 0.4f, 1, true, 6, 0, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), tierMaterials, "water", List.of());
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
when(raster.tier(5, 9)).thenReturn(tier);
when(raster.fluid(5, 9)).thenReturn("molten");
@@ -208,7 +208,7 @@ public class IrisTerrainNormalActuatorColumnParityTest {
NativeBlockState bedrockState = B.getState("BEDROCK");
NativeBlockState airState = B.getState("AIR");
boolean wet = role.wet();
boolean seaFloor = !wet || role == WaterRole.INLET;
boolean seaFloor = !wet || role == WaterRole.INLET || role == WaterRole.MOUTH;
IrisHydrologyMaterials materials = role == WaterRole.INLET ? null : this.materials;
int he = Math.min(chunkHeight, this.he);
int surfaceFluidHeight = Math.min(chunkHeight, this.surfaceFluid);
@@ -47,6 +47,7 @@ import static org.mockito.Mockito.when;
public class IrisTerrainNormalActuatorHydrologyTest {
private static final List<WaterRole> WET = List.of(WaterRole.CHANNEL, WaterRole.POND, WaterRole.MOUTH, WaterRole.CASCADE,
WaterRole.WATERFALL);
private static final List<WaterRole> OWN_FLUID = List.of(WaterRole.CHANNEL, WaterRole.POND, WaterRole.CASCADE, WaterRole.WATERFALL);
private static final int GROUND = 60;
private static final int HEAD = 64;
@@ -104,7 +105,7 @@ public class IrisTerrainNormalActuatorHydrologyTest {
@Test
public void wetColumnsFillFromAboveTheGroundToTheHeadWithTheirOwnFluid() {
for (WaterRole role : WET) {
for (WaterRole role : OWN_FLUID) {
Painter painter = new Painter(role, HEAD);
Hunk<NativeBlockState> output = painter.paint();
@@ -160,6 +161,34 @@ public class IrisTerrainNormalActuatorHydrologyTest {
}
}
@Test
public void frozenSeaIceContinuesAcrossMouths() {
Painter mouth = new Painter(WaterRole.MOUTH, HEAD);
when(mouth.complex.resolveWaterFluid(11, -4)).thenReturn(mouth.sea);
when(mouth.complex.naturalTrueHeight(11, -4)).thenReturn(GROUND);
Hunk<NativeBlockState> estuary = mouth.paint();
assertSame("the mouth takes the sea's top layer", mouth.ice, estuary.get(0, HEAD, 0));
for (int y = GROUND + 1; y < HEAD; y++) {
assertSame("the mouth holds the sea fluid at y " + y, mouth.sea, estuary.get(0, y, 0));
}
verify(mouth.biome).generateSeaLayers(anyDouble(), anyDouble(), any(RNG.class), eq(HEAD - GROUND), eq(mouth.data));
Painter frozenMouth = new Painter(WaterRole.MOUTH, HEAD);
when(frozenMouth.complex.resolveWaterFluid(11, -4)).thenReturn(frozenMouth.sea);
when(frozenMouth.complex.naturalTrueHeight(11, -4)).thenReturn(GROUND);
frozenMouth.thickSeaLayers();
Painter frozenSea = new Painter(WaterRole.NONE, HEAD);
frozenSea.thickSeaLayers();
Hunk<NativeBlockState> frozenEstuary = frozenMouth.paint();
Hunk<NativeBlockState> ocean = frozenSea.paint();
for (int y = GROUND + 1; y <= HEAD; y++) {
assertEquals("the mouth freezes like the sea beside it at y " + y, ocean.get(0, y, 0).key(), frozenEstuary.get(0, y, 0).key());
}
assertSame(frozenMouth.ice, frozenEstuary.get(0, HEAD, 0));
}
@Test
public void dryColumnsBelowTheSeaKeepTheSeaFillAndItsLayers() {
for (WaterRole role : List.of(WaterRole.NONE, WaterRole.BANK, WaterRole.SHORE)) {
@@ -1,6 +1,8 @@
package art.arcane.iris.pack;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.testsupport.CompatTestPlatform;
import org.junit.Rule;
@@ -240,6 +242,31 @@ public class PackHydrologyValidatorTest {
}
}
@Test
public void unknownTierKeysAreIgnoredAndTiersKeepTheDefaultEstuary() throws Exception {
String written = """
{"enabled": true, "tiers": [
{"name": "stream", "minCatchment": 900, "halfWidth": [0.5, 2.5], "bankBand": 8%s},
{"name": "major", "minCatchment": 200000, "halfWidth": [9, 18], "bankBand": 48%s}
]}
""";
File stale = pack(dimension(written.formatted(", \"deltas\": false", ", \"deltas\": true"), ""));
File current = pack(dimension(written.formatted("", ""), ""));
PackHydrologyValidator.Validation validation = validate(stale);
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
assertTrue(validation.warnings().isEmpty());
PackValidationResult packaging = PackValidator.validateForPackaging(stale);
assertEquals(PackValidator.validateForPackaging(current).getBlockingErrors(), packaging.getBlockingErrors());
IrisHydrology loaded = loadHydrology(stale);
for (IrisHydrologyTier tier : loaded.getTiers()) {
assertEquals(tier.getName(), 48, tier.getEstuary().getLength());
assertEquals(tier.getName(), 2.5D, tier.getEstuary().getFlare(), 0D);
}
assertEquals(HydrologySettings.compile(loadHydrology(current), 1337L, 62, -64, 320).fingerprint(),
HydrologySettings.compile(loaded, 1337L, 62, -64, 320).fingerprint());
}
@Test
public void aMalformedKnownHydrologyValueFailsTheDimensionLoadEvenWhenDisabled() throws Exception {
File pack = pack(dimension("""
@@ -391,6 +418,17 @@ public class PackHydrologyValidatorTest {
assertContains(result.getBlockingErrors(), "ponds.freeboard has its min above its max.");
}
private static IrisHydrology loadHydrology(File pack) {
IrisData data = IrisData.openDatapackCompiler(pack);
try {
IrisHydrology hydrology = data.getDimensionLoader().load("main").getHydrology();
assertNotNull(hydrology);
return hydrology;
} finally {
data.close();
}
}
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 = "e592219e3205fc63395c5f85f3630a9f018670370a56614e5571252fb21fb9d5";
private static final String EXPECTED_SCHEMA_DIGEST = "fe8d1a02aeff1f03d759d2c9def1807fadeac5e99beed02bf7640bd4cb8f6691";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -81,8 +81,8 @@ public final class WaterScene {
}
public static HydrologyTier tier(String name, float halfWidth, float depthRatio) {
return new HydrologyTier(name, 0f, halfWidth, halfWidth, 0f, depthRatio, 1, true, 6, 0, IrisBankStyle.SMOOTH, false,
new IrisHydrologyMaterials(), "water", List.of());
return new HydrologyTier(name, 0f, halfWidth, halfWidth, 0f, depthRatio, 1, true, 6, 0, IrisBankStyle.SMOOTH,
new HydrologyTier.Estuary(48, 2.5f), new IrisHydrologyMaterials(), "water", List.of());
}
public static Reach line(long id, HydrologyTier tier, int startX, int startZ, int endX, int endZ, IntBinaryOperator grade) {