Fluid seam fixes

- Fluid seams seal from the 3x3 neighbour rasters in the effective water stage
- Seam bands spread across chunk edges like any other column
- Raw rasters keep their fluid so falls and history capture see the real fluid
- Seams no longer change the hydrology fingerprint
- Seam profiles may hold solid blocks but cannot fill tiers, ponds, cave pools or policies
- A seam profile cannot name a seam of its own
- Pack validation reports a policy fluid that names a seam profile
- Inland water skips columns outside the transition seam weight
- Channel fluid test covers the per-reach rule
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-31 21:42:35 -04:00
1 parent 64dc22025e
commit 52989ce88d
15 files changed
+403 -123

No files matched your search

@@ -19,6 +19,7 @@ public class IrisFluidProfile {
@Required
@Description("Blocks that fill the water feature.")
private IrisMaterialPalette palette = new IrisMaterialPalette().qclear().qadd("minecraft:water");
@Description("Name of another fluid profile that fills this fluid's edge where it touches a different fluid, such as obsidian where lava meets water. Worldgen places fluids without updates, so unset leaves the two fluids side by side.")
@Description("Name of another fluid profile that lines this fluid's edge where it touches a different fluid or the sea, such as obsidian where lava meets water. The seam profile may hold solid blocks and serves only as a seam. Unset leaves the two fluids side by side.")
private String seam = null;
}
@@ -173,10 +173,7 @@ public final class HydrologyRuntime {
if (fluid == null) {
continue;
}
if (!settings.fluids().containsKey(fluid)) {
throw new IllegalArgumentException("Biome '" + biome.getLoadKey() + "' hydrologyPolicy.fluid names '" + fluid
+ "', which is not one of the hydrology fluids " + settings.fluids().keySet());
}
settings.requireFillingFluid(fluid, "biome '" + biome.getLoadKey() + "' hydrologyPolicy.fluid");
named = true;
}
return named;
@@ -208,9 +208,8 @@ public final class IrisHydrologyTerrainSource implements HydrologyTerrainSource,
boolean climateZones = inherited(biome, region, IrisHydrologyPolicy::getClimateZones, Boolean.TRUE);
requireMultiplier("rainfall", rainfall, biome, region);
requireMultiplier("pondDensity", pondDensity, biome, region);
if (fluid != null && !settings.fluids().containsKey(fluid)) {
throw new IllegalArgumentException("Hydrology policy for " + where(biome, region) + " names fluid '" + fluid
+ "', which is not one of the hydrology fluids " + settings.fluids().keySet());
if (fluid != null) {
settings.requireFillingFluid(fluid, "the hydrology policy for " + where(biome, region));
}
return new Policy((float) rainfall, (float) pondDensity, permission(streams, ponds), fluid, climateZones);
}
@@ -169,7 +169,6 @@ public final class HydrologySettings {
return fluids;
}
/** Fluid name -> the fluid profile that fills its edge where it touches a different fluid. */
public Map<String, String> seams() {
return seams;
}
@@ -493,13 +492,25 @@ public final class HydrologySettings {
}
private void requireFluidReferences() {
for (HydrologyTier tier : tiers) {
requireFluid(tier.fluid(), "the fluid of tier '" + tier.name() + "'");
}
requireFluid(ponds.fluid(), "ponds.fluid");
requireFluid(underground.cavePools().fluid(), "underground.cavePools.fluid");
for (Map.Entry<String, String> seam : seams.entrySet()) {
requireFluid(seam.getValue(), "the seam of fluid '" + seam.getKey() + "'");
if (seams.containsKey(seam.getValue())) {
throw new IllegalArgumentException("Hydrology fluid '" + seam.getValue() + "' is the seam of fluid '" + seam.getKey()
+ "' and cannot name a seam of its own");
}
}
for (HydrologyTier tier : tiers) {
requireFillingFluid(tier.fluid(), "the fluid of tier '" + tier.name() + "'");
}
requireFillingFluid(ponds.fluid(), "ponds.fluid");
requireFillingFluid(underground.cavePools().fluid(), "underground.cavePools.fluid");
}
public void requireFillingFluid(String name, String field) {
requireFluid(name, field);
if (seams.containsValue(name)) {
throw new IllegalArgumentException("Hydrology fluid '" + name + "' in " + field
+ " is a seam profile; seams only line the edges of other fluids");
}
}
@@ -578,10 +589,6 @@ public final class HydrologySettings {
for (Map.Entry<String, IrisMaterialPalette> fluid : fluids.entrySet()) {
hash.add(fluid.getKey()).add(fluid.getValue());
}
hash.add(seams.size());
for (Map.Entry<String, String> seam : seams.entrySet()) {
hash.add(seam.getKey()).add(seam.getValue());
}
}
public record FloatRange(float min, float max) {
@@ -0,0 +1,112 @@
package art.arcane.iris.generation.hydrology.raster;
import art.arcane.iris.generation.hydrology.grid.CellHash;
import java.util.Map;
public final class FluidSeams {
private static final int CHUNK = 16;
private static final int RING = 2;
private static final int WINDOW = CHUNK + 2 * RING;
private static final int CELLS = WINDOW * WINDOW;
private static final long SALT_SEAM = 0x5345414d4c4eL;
private static final double SPREAD = 0.6D;
private static final byte UNKNOWN = 0;
private static final byte LAND = 1;
private static final byte SEA = 2;
private FluidSeams() {
}
public static String[] seal(Map<String, String> seams, long seed, int chunkX, int chunkZ, Columns columns) {
if (seams.isEmpty()) {
return null;
}
int originX = chunkX * CHUNK - RING;
int originZ = chunkZ * CHUNK - RING;
String[] fluid = new String[CELLS];
boolean sealable = false;
for (int cell = 0; cell < CELLS; cell++) {
fluid[cell] = columns.fluid(originX + cell % WINDOW, originZ + cell / WINDOW);
sealable |= fluid[cell] != null && seams.containsKey(fluid[cell]);
}
if (!sealable) {
return null;
}
byte[] sea = new byte[CELLS];
boolean[] contact = new boolean[CELLS];
for (int gz = 1; gz < WINDOW - 1; gz++) {
for (int gx = 1; gx < WINDOW - 1; gx++) {
int cell = gz * WINDOW + gx;
contact[cell] = touchesOther(cell, fluid, seams, sea, columns, originX, originZ);
}
}
String[] sealed = null;
for (int lz = 0; lz < CHUNK; lz++) {
for (int lx = 0; lx < CHUNK; lx++) {
int cell = (lz + RING) * WINDOW + lx + RING;
String seam = fluid[cell] == null ? null : seams.get(fluid[cell]);
if (seam == null || !contact[cell] && !spreads(cell, fluid, contact, seed, originX, originZ)) {
continue;
}
if (sealed == null) {
sealed = new String[CHUNK * CHUNK];
}
sealed[lz << 4 | lx] = seam;
}
}
return sealed;
}
private static boolean touchesOther(int cell, String[] fluid, Map<String, String> seams, byte[] sea, Columns columns,
int originX, int originZ) {
String own = fluid[cell];
String seam = own == null ? null : seams.get(own);
if (seam == null) {
return false;
}
for (int dz = -1; dz <= 1; dz++) {
for (int dx = -1; dx <= 1; dx++) {
if (dx == 0 && dz == 0) {
continue;
}
int next = cell + dz * WINDOW + dx;
String other = fluid[next];
if (other == null ? sea(next, sea, columns, originX, originZ) : !other.equals(own) && !other.equals(seam)) {
return true;
}
}
}
return false;
}
private static boolean spreads(int cell, String[] fluid, boolean[] contact, long seed, int originX, int originZ) {
int x = originX + cell % WINDOW;
int z = originZ + cell / WINDOW;
if (CellHash.unit(CellHash.mix(seed, SALT_SEAM, x, z)) >= SPREAD) {
return false;
}
for (int dz = -1; dz <= 1; dz++) {
for (int dx = -1; dx <= 1; dx++) {
int next = cell + dz * WINDOW + dx;
if (next != cell && contact[next] && fluid[cell].equals(fluid[next])) {
return true;
}
}
}
return false;
}
private static boolean sea(int cell, byte[] sea, Columns columns, int originX, int originZ) {
if (sea[cell] == UNKNOWN) {
sea[cell] = columns.sea(originX + cell % WINDOW, originZ + cell / WINDOW) ? SEA : LAND;
}
return sea[cell] == SEA;
}
public interface Columns {
String fluid(int x, int z);
boolean sea(int x, int z);
}
}
@@ -2,7 +2,6 @@ package art.arcane.iris.generation.hydrology.raster;
import art.arcane.iris.generation.hydrology.config.IrisBankStyle;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.hydrology.grid.CellHash;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
@@ -25,8 +24,6 @@ final class RasterComposer {
private static final double ROUNDING = 1e-6D;
private static final int SLOPE_REACH = 2;
private static final int RAY_STEP = 4;
private static final long SALT_SEAM = 0x5345414d4c4eL;
private static final double SEAM_SPREAD = 0.6D;
private final HydrologySettings settings;
private final ChunkFeatures features;
@@ -81,7 +78,6 @@ final class RasterComposer {
bermEdges();
measureLakeShores();
nameShores();
sealSeams();
return pack();
}
@@ -123,76 +119,6 @@ final class RasterComposer {
}
}
/**
* Where a fluid with a seam touches a different fluid (or the sea), fill its edge with the seam, e.g. a cooled-lava
* crust where lava meets water. Every touching cell seals, and about SEAM_SPREAD of the cells next to those, picked
* by a world-position hash, so the crust is a ragged band instead of a one-block line.
*/
private void sealSeams() {
Map<String, String> seams = settings.seams();
if (seams.isEmpty()) {
return;
}
boolean[] contact = new boolean[CELLS];
for (int cell = 0; cell < CELLS; cell++) {
if (!sealable(cell, seams)) {
continue;
}
String seam = seams.get(fluid[cell]);
for (int dz = -1; dz <= 1 && !contact[cell]; dz++) {
for (int dx = -1; dx <= 1 && !contact[cell]; dx++) {
int next = neighbour(cell, dx, dz);
contact[cell] = next >= 0 && meetsOther(cell, next, seam);
}
}
}
boolean[] sealed = contact.clone();
for (int cell = 0; cell < CELLS; cell++) {
if (contact[cell] || !sealable(cell, seams)) {
continue;
}
int x = originX + cell % GRID;
int z = originZ + cell / GRID;
if (CellHash.unit(CellHash.mix(settings.seed(), SALT_SEAM, x, z)) >= SEAM_SPREAD) {
continue;
}
for (int dz = -1; dz <= 1 && !sealed[cell]; dz++) {
for (int dx = -1; dx <= 1 && !sealed[cell]; dx++) {
int next = neighbour(cell, dx, dz);
sealed[cell] = next >= 0 && contact[next];
}
}
}
for (int cell = 0; cell < CELLS; cell++) {
if (sealed[cell]) {
fluid[cell] = seams.get(fluid[cell]);
}
}
}
private boolean sealable(int cell, Map<String, String> seams) {
return !corner(cell) && fluid[cell] != null && role[cell].wet() && seams.containsKey(fluid[cell]);
}
/** Whether the neighbour holds a different fluid: other hydrology water, or the sea (dry here, ground below sea level). */
private boolean meetsOther(int cell, int next, String seam) {
if (corner(next) || next == cell) {
return false;
}
if (role[next].wet()) {
String other = fluid[next];
return other != null && !other.equals(fluid[cell]) && !other.equals(seam);
}
return terrain[next] < settings.seaLevel();
}
/** The grid cell dx,dz away, or -1 outside the grid. */
private static int neighbour(int cell, int dx, int dz) {
int x = cell % GRID + dx;
int z = cell / GRID + dz;
return x < 0 || x >= GRID || z < 0 || z >= GRID ? -1 : z * GRID + x;
}
private void standing(int cell, Pond water, int floor) {
head[cell] = level(water.level());
terrain[cell] = Math.min(floor, head[cell] - 1);
@@ -64,18 +64,20 @@ final class EffectiveWater {
}
static final class Chunk {
static final Chunk EMPTY = new Chunk(null, null, null, null);
static final Chunk EMPTY = new Chunk(null, null, null, null, null);
private final long[] columns;
private final WaterRole[] roles;
private final boolean[] owned;
private final ChunkWaterRaster raster;
private final String[] seams;
Chunk(long[] columns, WaterRole[] roles, boolean[] owned, ChunkWaterRaster raster) {
Chunk(long[] columns, WaterRole[] roles, boolean[] owned, ChunkWaterRaster raster, String[] seams) {
this.columns = columns;
this.roles = roles;
this.owned = owned;
this.raster = raster;
this.seams = seams;
}
long column(int lx, int lz) {
@@ -93,6 +95,11 @@ final class EffectiveWater {
ChunkWaterRaster raster() {
return raster;
}
String fluid(int lx, int lz) {
String seam = seams == null ? null : seams[lz << 4 | lx];
return seam != null ? seam : raster.fluid(lx, lz);
}
}
static final class Chunks {
@@ -50,7 +50,9 @@ import art.arcane.iris.generation.decoration.HydrologyVegetation;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.hydrology.config.IrisHydrologyMaterials;
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.raster.FluidSeams;
import art.arcane.iris.generation.hydrology.raster.WaterRole;
import art.arcane.iris.generation.hydrology.water.HydrologyTier;
import art.arcane.iris.generation.image.IrisImageMapApplication;
@@ -710,7 +712,31 @@ public class IrisComplex implements DataProvider {
roles[index] = effectiveRole(own, x, z, columns[index]);
owned[index] = owns(own, x, z, columns[index]);
}
return new EffectiveWater.Chunk(columns, roles, owned, own);
return new EffectiveWater.Chunk(columns, roles, owned, own, sealedFluids(chunkX, chunkZ, around));
}
private String[] sealedFluids(int chunkX, int chunkZ, ChunkWaterRaster[] around) {
HydrologySettings settings = hydrologyRuntime.settings();
if (settings.seams().isEmpty()) {
return null;
}
return FluidSeams.seal(settings.seams(), settings.seed(), chunkX, chunkZ, new FluidSeams.Columns() {
@Override
public String fluid(int x, int z) {
ChunkWaterRaster raster = around[aroundSlot(chunkX, chunkZ, x, z)];
if (raster.empty() || seamWeight(x, z) == 0D || !raster.role(x & 15, z & 15).wet()) {
return null;
}
return raster.fluid(x & 15, z & 15);
}
@Override
public boolean sea(int x, int z) {
ChunkWaterRaster raster = around[aroundSlot(chunkX, chunkZ, x, z)];
int ground = raster.empty() || seamWeight(x, z) == 0D ? naturalTrueHeight(x, z) : raster.terrainHeight(x & 15, z & 15);
return ground < transitionFluidHeight(x, z, fluidHeight);
}
});
}
private long waterColumn(int blockX, int blockZ) {
@@ -1247,27 +1273,18 @@ public class IrisComplex implements DataProvider {
Map<String, ProceduralStream<NativeBlockState>> streams = new HashMap<>();
int index = 0;
for (Map.Entry<String, IrisMaterialPalette> fluid : fluids.entrySet()) {
// a seam (obsidian where lava meets water) is the solid result of two fluids meeting, not a fluid itself
streams.put(fluid.getKey(), configuredFluidStream(fluid.getValue(), rng.nextParallelRNG(10900 + index),
"hydrology fluid " + fluid.getKey(), !seams.contains(fluid.getKey())));
"hydrology fluid " + fluid.getKey(), seams.contains(fluid.getKey())));
index++;
}
return Map.copyOf(streams);
}
private ProceduralStream<NativeBlockState> configuredFluidStream(
IrisMaterialPalette palette,
RNG fluidRng,
String configurationName
) {
return configuredFluidStream(palette, fluidRng, configurationName, true);
}
private ProceduralStream<NativeBlockState> configuredFluidStream(
IrisMaterialPalette palette,
RNG fluidRng,
String configurationName,
boolean fluidOnly
boolean allowSolids
) {
Objects.requireNonNull(palette, configurationName + " fluidPalette must be configured");
KList<NativeBlockState> blocks = palette.getBlockData(data);
@@ -1276,7 +1293,7 @@ public class IrisComplex implements DataProvider {
configurationName + " fluidPalette must resolve at least one fluid block");
}
for (NativeBlockState block : blocks) {
if (block == null || fluidOnly && !block.isFluid()) {
if (block == null || !allowSolids && !block.isFluid()) {
throw new IllegalArgumentException(
configurationName + " fluidPalette may contain only fluid blocks");
}
@@ -1305,7 +1322,8 @@ public class IrisComplex implements DataProvider {
}
public NativeBlockState resolveWaterFluid(int x, int z) {
String profile = chunkRasterAt(x, z).fluid(x & 15, z & 15);
EffectiveWater.Chunk chunk = effectiveChunk(x >> 4, z >> 4);
String profile = chunk != null && chunk.raster() != null ? chunk.fluid(x & 15, z & 15) : hydrologyRasterAt(x, z).fluid(x & 15, z & 15);
if (profile == null) {
throw new IllegalStateException("Column " + x + "," + z + " has no water fluid in its hydrology raster");
}
@@ -1756,7 +1774,6 @@ public class IrisComplex implements DataProvider {
}
IrisBiome base = baseBiomeStream.get(x, z);
if (base.getInferredType() == InferredType.LAND && inlandWater(x, z)) {
// a pond or stream above sea level keeps the land around it, even where its floor dips below sea level
return base;
}
return fixBiomeType(
@@ -1777,7 +1794,7 @@ public class IrisComplex implements DataProvider {
return false;
}
WaterRole role = raster.role(blockX & 15, blockZ & 15);
return role.wet() && role != WaterRole.MOUTH && role != WaterRole.INLET
return role.wet() && role != WaterRole.MOUTH && role != WaterRole.INLET && seamWeight(blockX, blockZ) != 0D
&& raster.waterHead(blockX & 15, blockZ & 15) > transitionFluidHeight(x, z, fluidHeight);
}
@@ -79,13 +79,14 @@ final class PackHydrologyValidator {
int reported = errors.size();
validateRanges(path, hydrology, errors);
Set<String> fluids = fluidNames(hydrology);
Set<String> seams = seamNames(hydrology);
validateFluidReferences(path, hydrology, fluids, errors);
IrisData loaded = data == null ? IrisData.openDatapackCompiler(packFolder) : data;
IrisDimension loadedDimension = loaded.getDimensionLoader().load(dimensionKey, false);
if (loadedDimension == null) {
return loaded;
}
validatePolicies(path, dimensionKey, loaded, loadedDimension, fluids, errors);
validatePolicies(path, dimensionKey, loaded, loadedDimension, new PolicyFluids(fluids, seams), errors);
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
}
@@ -190,6 +191,22 @@ final class PackHydrologyValidator {
return names;
}
private static Set<String> seamNames(JSONObject hydrology) {
JSONArray profiles = hydrology.optJSONArray("fluids");
if (profiles == null) {
return Set.of();
}
Set<String> seams = new LinkedHashSet<>();
for (int index = 0; index < profiles.length(); index++) {
JSONObject profile = profiles.optJSONObject(index);
String seam = profile == null ? null : profile.optString("seam", null);
if (seam != null && !seam.isBlank()) {
seams.add(seam);
}
}
return seams;
}
private static void validateFluidReferences(String path, JSONObject hydrology, Set<String> fluids, List<String> errors) {
JSONArray tiers = hydrology.optJSONArray("tiers");
if (tiers == null) {
@@ -208,7 +225,7 @@ final class PackHydrologyValidator {
}
}
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, Set<String> fluids,
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, PolicyFluids fluids,
List<String> errors) {
validatePolicy("Dimension '" + dimensionKey + "'." + POLICY, dimension.getHydrologyPolicy(), data, fluids, path, errors);
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
@@ -227,13 +244,17 @@ final class PackHydrologyValidator {
}
}
private static void validatePolicy(String field, IrisHydrologyPolicy policy, IrisData data, Set<String> fluids, String configPath,
private static void validatePolicy(String field, IrisHydrologyPolicy policy, IrisData data, PolicyFluids fluids, String configPath,
List<String> errors) {
if (policy == null) {
return;
}
if (policy.getFluid() != null) {
requireFluid(field + ".fluid", policy.getFluid(), fluids, configPath, errors);
String fluid = policy.getFluid();
if (fluid != null) {
requireFluid(field + ".fluid", fluid, fluids.defined(), configPath, errors);
if (fluids.seams().contains(fluid)) {
errors.add(field + ".fluid names fluid '" + fluid + "', which is a seam profile; seams only line the edges of other fluids.");
}
}
if (policy.getDecorators() != null) {
validateDecorators(field + ".decorators", policy.getDecorators(), data, errors);
@@ -283,4 +304,7 @@ final class PackHydrologyValidator {
warnings = List.copyOf(warnings);
}
}
private record PolicyFluids(Set<String> defined, Set<String> seams) {
}
}