mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
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.
This commit is contained in:
1 parent
09d6e4b720
commit
4a499c18c4
4 files changed
+114
-4
No files matched your search
@@ -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;
|
||||
}
|
||||
@@ -58,6 +58,7 @@ public final class HydrologySettings {
|
||||
private final Deformation deformation;
|
||||
private final Underground underground;
|
||||
private final Map<String, IrisMaterialPalette> fluids;
|
||||
private final Map<String, String> 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<String, String> seams() {
|
||||
return seams;
|
||||
}
|
||||
|
||||
public int prefetchRings() {
|
||||
return prefetchRings;
|
||||
}
|
||||
@@ -316,6 +323,16 @@ public final class HydrologySettings {
|
||||
return Collections.unmodifiableMap(compiled);
|
||||
}
|
||||
|
||||
private static Map<String, String> seams(List<IrisFluidProfile> profiles) {
|
||||
Map<String, String> 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<String, String> 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<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) {
|
||||
|
||||
@@ -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<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);
|
||||
|
||||
@@ -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<String, ProceduralStream<NativeBlockState>> createWaterFluidStreams(Map<String, IrisMaterialPalette> fluids) {
|
||||
private Map<String, ProceduralStream<NativeBlockState>> createWaterFluidStreams(Map<String, IrisMaterialPalette> fluids,
|
||||
Collection<String> seams) {
|
||||
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()));
|
||||
"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<NativeBlockState> configuredFluidStream(
|
||||
IrisMaterialPalette palette,
|
||||
RNG fluidRng,
|
||||
String configurationName,
|
||||
boolean fluidOnly
|
||||
) {
|
||||
Objects.requireNonNull(palette, configurationName + " fluidPalette must be configured");
|
||||
KList<NativeBlockState> 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");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user