From 4a499c18c4c6946a44844e281d5f2c2799f31014 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 31 Oct 2026 02:12:22 -0500 Subject: [PATCH] Let a fluid set the block that forms where it meets another fluid World generation places fluids without updates, so where lava meets water or the sea the two sit side by side instead of reacting. A fluid profile can now name a seam: another fluid profile that fills its edge where it touches a different fluid or the sea (a dry column whose ground is below sea level). A profile used as a seam may hold solid blocks, e.g. lava with a seam of obsidian, magma and basalt gets a cooled crust where it meets water. Every touching cell (diagonals included) seals, plus about 60% of the cells next to those, picked by a world-position hash, so the seam is a ragged band rather than a straight line. Without a seam nothing changes. --- .../hydrology/config/IrisFluidProfile.java | 2 + .../hydrology/plan/HydrologySettings.java | 24 ++++++ .../hydrology/raster/RasterComposer.java | 73 +++++++++++++++++++ .../iris/generation/runtime/IrisComplex.java | 19 ++++- 4 files changed, 114 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/config/IrisFluidProfile.java b/core/src/main/java/art/arcane/iris/generation/hydrology/config/IrisFluidProfile.java index 808cc1f39..2b047c188 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/config/IrisFluidProfile.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/config/IrisFluidProfile.java @@ -19,4 +19,6 @@ 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.") + private String seam = null; } diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/plan/HydrologySettings.java b/core/src/main/java/art/arcane/iris/generation/hydrology/plan/HydrologySettings.java index 3f5c9b07f..37d5a67d0 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/plan/HydrologySettings.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/plan/HydrologySettings.java @@ -58,6 +58,7 @@ public final class HydrologySettings { private final Deformation deformation; private final Underground underground; private final Map fluids; + private final Map seams; private final int prefetchRings; private final boolean persist; private final long fingerprint; @@ -79,6 +80,7 @@ public final class HydrologySettings { this.deformation = deformation(config.getDeformation()); this.underground = underground(config.getUnderground()); this.fluids = fluids(config.getFluids()); + this.seams = seams(config.getFluids()); this.prefetchRings = config.getPrefetchRings(); this.persist = config.isPersist(); requireFluidReferences(); @@ -159,6 +161,11 @@ public final class HydrologySettings { return fluids; } + /** Fluid name -> the fluid profile that fills its edge where it touches a different fluid. */ + public Map seams() { + return seams; + } + public int prefetchRings() { return prefetchRings; } @@ -316,6 +323,16 @@ public final class HydrologySettings { return Collections.unmodifiableMap(compiled); } + private static Map seams(List profiles) { + Map seams = new LinkedHashMap<>(); + for (IrisFluidProfile profile : profiles) { + if (profile.getSeam() != null && !profile.getSeam().isBlank()) { + seams.put(profile.getName(), profile.getSeam()); + } + } + return Collections.unmodifiableMap(seams); + } + private static IrisMaterialPalette requirePalette(IrisFluidProfile profile, String field) { IrisMaterialPalette palette = profile.getPalette(); if (palette == null || unwritten(palette)) { @@ -457,6 +474,9 @@ public final class HydrologySettings { } requireFluid(ponds.fluid(), "ponds.fluid"); requireFluid(underground.cavePools().fluid(), "underground.cavePools.fluid"); + for (Map.Entry seam : seams.entrySet()) { + requireFluid(seam.getValue(), "the seam of fluid '" + seam.getKey() + "'"); + } } private void requireFluid(String name, String field) { @@ -527,6 +547,10 @@ public final class HydrologySettings { for (Map.Entry fluid : fluids.entrySet()) { hash.add(fluid.getKey()).add(fluid.getValue()); } + hash.add(seams.size()); + for (Map.Entry seam : seams.entrySet()) { + hash.add(seam.getKey()).add(seam.getValue()); + } } public record FloatRange(float min, float max) { diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java index aa36744d6..192df5051 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/raster/RasterComposer.java @@ -25,6 +25,8 @@ final class RasterComposer { private static final double CONE_EXPONENT = 0.8D; private static final double ROUNDING = 1e-6D; private static final long SALT_BANK = 0x42414e4b4e5aL; + private static final long SALT_SEAM = 0x5345414d4c4eL; + private static final double SEAM_SPREAD = 0.6D; private final HydrologySettings settings; private final ChunkFeatures features; @@ -78,6 +80,7 @@ final class RasterComposer { bermEdges(); measureLakeShores(); nameShores(); + sealSeams(); return pack(); } @@ -119,6 +122,76 @@ 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 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 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); diff --git a/core/src/main/java/art/arcane/iris/generation/runtime/IrisComplex.java b/core/src/main/java/art/arcane/iris/generation/runtime/IrisComplex.java index 72fdc9caa..53cee7383 100644 --- a/core/src/main/java/art/arcane/iris/generation/runtime/IrisComplex.java +++ b/core/src/main/java/art/arcane/iris/generation/runtime/IrisComplex.java @@ -485,7 +485,7 @@ public class IrisComplex implements DataProvider { naturalTrueBiomeStream = new BakedStream<>(bakeCache, BakePlane.NATURAL_TRUE_BIOME, naturalTrueBiomeSource); shoreBiomes = new HydrologyShoreBiomes(engine.getDimension(), data, engine.getSeedManager().getBodies()); hydrologyRuntime = HydrologyRuntime.create(engine, this); - waterFluidStreams = hydrologyRuntime.enabled() ? createWaterFluidStreams(hydrologyRuntime.settings().fluids()) : Map.of(); + waterFluidStreams = hydrologyRuntime.enabled() ? createWaterFluidStreams(hydrologyRuntime.settings().fluids(), hydrologyRuntime.settings().seams().values()) : Map.of(); pondMaterials = hydrologyRuntime.enabled() ? hydrologyRuntime.settings().ponds().materials() : null; waterVegetation = hydrologyRuntime.enabled() ? HydrologyVegetationSource.create(engine.getDimension(), hydrologyRuntime.settings(), data, engine.getDimension().getAllRegions(engine), engine.getDimension().getReachableBiomes(engine)) : HydrologyVegetationSource.NONE; @@ -1224,12 +1224,14 @@ public class IrisComplex implements DataProvider { public record BiomePick(IrisBiome biome, InferredType type) { } - private Map> createWaterFluidStreams(Map fluids) { + private Map> createWaterFluidStreams(Map fluids, + Collection seams) { Map> streams = new HashMap<>(); int index = 0; for (Map.Entry 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())); + "hydrology fluid " + fluid.getKey(), !seams.contains(fluid.getKey()))); index++; } return Map.copyOf(streams); @@ -1239,6 +1241,15 @@ public class IrisComplex implements DataProvider { IrisMaterialPalette palette, RNG fluidRng, String configurationName + ) { + return configuredFluidStream(palette, fluidRng, configurationName, true); + } + + private ProceduralStream configuredFluidStream( + IrisMaterialPalette palette, + RNG fluidRng, + String configurationName, + boolean fluidOnly ) { Objects.requireNonNull(palette, configurationName + " fluidPalette must be configured"); KList blocks = palette.getBlockData(data); @@ -1247,7 +1258,7 @@ public class IrisComplex implements DataProvider { configurationName + " fluidPalette must resolve at least one fluid block"); } for (NativeBlockState block : blocks) { - if (block == null || !block.isFluid()) { + if (block == null || fluidOnly && !block.isFluid()) { throw new IllegalArgumentException( configurationName + " fluidPalette may contain only fluid blocks"); }