mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Merged fluid seam fixes
This commit is contained in:
commit
f686ec84f8
15 files changed
+403
-123
No files matched your search
+2
-1
@@ -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;
|
||||
}
|
||||
+1
-4
@@ -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;
|
||||
|
||||
+2
-3
@@ -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);
|
||||
}
|
||||
|
||||
+17
-10
@@ -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) {
|
||||
}
|
||||
}
|
||||
+38
@@ -3,6 +3,7 @@ package art.arcane.iris.generation.hydrology.plan;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorationPart;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
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.water.HydrologyTier;
|
||||
@@ -17,6 +18,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -250,6 +252,33 @@ public class HydrologySettingsTest {
|
||||
assertRejected(config, "lava");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seamsLeaveTheFingerprintAlone() {
|
||||
assertEquals(compile(lavaAndCrust(null)).fingerprint(), compile(lavaAndCrust("crust")).fingerprint());
|
||||
assertEquals(Map.of("lava", "crust"), compile(lavaAndCrust("crust")).seams());
|
||||
assertTrue(compile(lavaAndCrust(null)).seams().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileRejectsAnUnknownSeam() {
|
||||
assertRejected(lavaAndCrust("ash"), "ash");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileRejectsASeamThatAlsoFillsWater() {
|
||||
IrisHydrology tier = lavaAndCrust("crust");
|
||||
tier.getTiers().get(2).setFluid("crust");
|
||||
assertRejected(tier, "crust");
|
||||
|
||||
IrisHydrology ponds = lavaAndCrust("crust");
|
||||
ponds.getPonds().setFluid("crust");
|
||||
assertRejected(ponds, "crust");
|
||||
|
||||
IrisHydrology chained = lavaAndCrust("crust");
|
||||
chained.getFluids().get(2).setSeam("lava");
|
||||
assertRejected(chained, "crust");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compileRejectsMalformedRange() {
|
||||
IrisHydrology inverted = new IrisHydrology();
|
||||
@@ -554,6 +583,15 @@ public class HydrologySettingsTest {
|
||||
assertTrue(failure.getMessage(), failure.getMessage().contains("\"palette\" list is missing, misspelt or empty"));
|
||||
}
|
||||
|
||||
private static IrisHydrology lavaAndCrust(String seam) {
|
||||
IrisHydrology config = new IrisHydrology();
|
||||
config.getFluids().add(new IrisFluidProfile().setName("lava").setSeam(seam)
|
||||
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
|
||||
config.getFluids().add(new IrisFluidProfile().setName("crust")
|
||||
.setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:obsidian")));
|
||||
return config;
|
||||
}
|
||||
|
||||
private static HydrologySettings compile(IrisHydrology config) {
|
||||
return HydrologySettings.compile(config, SEED, SEA_LEVEL, MIN_Y, MAX_Y);
|
||||
}
|
||||
|
||||
+9
-6
@@ -465,11 +465,14 @@ public class ChunkWaterRasterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void channelTakesTheAreaFluidWhereOneIsSet() {
|
||||
public void reachKeepsThePolicyFluidOfItsUpstreamEnd() {
|
||||
HydrologySettings settings = settings(new IrisHydrology());
|
||||
Reach reach = line(61L, tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH), 0L, 400f, 400f, 480f, 400f, (x, z) -> 69);
|
||||
HydrologyTier stream = tier("stream", 1.5f, 0.5f, 0, IrisBankStyle.SMOOTH);
|
||||
Reach outflow = line(61L, stream, 0L, 400f, 403f, 480f, 403f, (x, z) -> 69);
|
||||
Reach inflow = line(62L, stream, 0L, 480f, 412f, 400f, 412f, (x, z) -> 69);
|
||||
WindowKey key = new WindowKey(0, 0);
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(reach), List.of(), List.of()), ReachIndex.build(List.of(reach), List.of()));
|
||||
IndexedWindow own = new IndexedWindow(new WindowPlan(key, List.of(outflow, inflow), List.of(), List.of()),
|
||||
ReachIndex.build(List.of(outflow, inflow), List.of()));
|
||||
ChannelFluids volcanic = (x, z) -> x < 440 ? "lava" : null;
|
||||
ChunkWaterRaster raster = new ChunkRasterizer(settings, volcanic).rasterize(27, 25, (x, z) -> 70, List.of(own), regions(27, 25, List.of()));
|
||||
int lava = 0;
|
||||
@@ -479,9 +482,9 @@ public class ChunkWaterRasterTest {
|
||||
if (!isChannel(raster.role(lx, lz))) {
|
||||
continue;
|
||||
}
|
||||
boolean inside = 27 * 16 + lx < 440;
|
||||
assertEquals("column " + lx + "," + lz, inside ? "lava" : "water", raster.fluid(lx, lz));
|
||||
if (inside) {
|
||||
boolean startsVolcanic = raster.featureId(lx, lz) == 61L;
|
||||
assertEquals("column " + lx + "," + lz, startsVolcanic ? "lava" : "water", raster.fluid(lx, lz));
|
||||
if (startsVolcanic) {
|
||||
lava++;
|
||||
} else {
|
||||
water++;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package art.arcane.iris.generation.hydrology.raster;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FluidSeamsTest {
|
||||
private static final long SEED = 4242L;
|
||||
private static final Map<String, String> LAVA_CRUST = Map.of("lava", "crust");
|
||||
|
||||
@Test
|
||||
public void lavaSealsEveryColumnTouchingWater() {
|
||||
FluidSeams.Columns columns = columns(x -> x < 100 ? "lava" : "water", x -> false);
|
||||
String[] sealed = FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns);
|
||||
int spread = 0;
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
int x = 96 + lx;
|
||||
String seam = sealed[lz << 4 | lx];
|
||||
if (x == 99) {
|
||||
assertEquals("touching column " + x + "," + lz, "crust", seam);
|
||||
} else if (x == 98) {
|
||||
spread += seam == null ? 0 : 1;
|
||||
} else {
|
||||
assertNull("column " + x + "," + lz, seam);
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue("spread columns " + spread, spread > 0 && spread < 16);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spreadReachesAcrossTheChunkEdge() {
|
||||
FluidSeams.Columns columns = columns(x -> x < 97 ? "lava" : "water", x -> false);
|
||||
int spread = 0;
|
||||
int rows = 0;
|
||||
for (int chunkZ = 0; chunkZ < 8; chunkZ++) {
|
||||
String[] west = FluidSeams.seal(LAVA_CRUST, SEED, 5, chunkZ, columns);
|
||||
String[] east = FluidSeams.seal(LAVA_CRUST, SEED, 6, chunkZ, columns);
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
rows++;
|
||||
assertEquals("crust", east[lz << 4]);
|
||||
assertNull(west[lz << 4 | 14]);
|
||||
spread += west[lz << 4 | 15] == null ? 0 : 1;
|
||||
}
|
||||
}
|
||||
double fraction = spread / (double) rows;
|
||||
assertTrue("spread fraction at the chunk edge " + fraction, fraction > 0.45D && fraction < 0.75D);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dryGroundBelowSeaLevelCountsAsTheSea() {
|
||||
String[] sea = FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : null, x -> x >= 100));
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
assertEquals("crust", sea[lz << 4 | 3]);
|
||||
}
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : null, x -> false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingSealsWithoutASeamOrAnotherFluid() {
|
||||
assertNull(FluidSeams.seal(Map.of(), SEED, 6, 0, columns(x -> x < 100 ? "lava" : "water", x -> false)));
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> "water", x -> true)));
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> "lava", x -> false)));
|
||||
assertNull(FluidSeams.seal(LAVA_CRUST, SEED, 6, 0, columns(x -> x < 100 ? "lava" : "crust", x -> false)));
|
||||
}
|
||||
|
||||
private static FluidSeams.Columns columns(IntFunction<String> fluid, IntPredicate sea) {
|
||||
return new FluidSeams.Columns() {
|
||||
@Override
|
||||
public String fluid(int x, int z) {
|
||||
return fluid.apply(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sea(int x, int z) {
|
||||
return sea.test(x);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.context.ChunkContext;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.hydrology.water.Pond;
|
||||
import art.arcane.iris.generation.hydrology.water.Reach;
|
||||
@@ -159,11 +160,25 @@ public class EffectiveWaterTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sealedColumnsTakeTheirSeamAndTheRestKeepTheRasterFluid() {
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(raster.fluid(anyInt(), anyInt())).thenReturn("lava");
|
||||
String[] seams = new String[256];
|
||||
seams[3 << 4 | 2] = "crust";
|
||||
EffectiveWater.Chunk sealed = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], raster, seams);
|
||||
EffectiveWater.Chunk open = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], raster, null);
|
||||
|
||||
assertEquals("crust", sealed.fluid(2, 3));
|
||||
assertEquals("lava", sealed.fluid(3, 2));
|
||||
assertEquals("lava", open.fluid(2, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chunksSharingACacheSlotNeverAnswerForEachOther() {
|
||||
EffectiveWater.Chunks chunks = new EffectiveWater.Chunks();
|
||||
EffectiveWater.Chunk first = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null);
|
||||
EffectiveWater.Chunk second = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null);
|
||||
EffectiveWater.Chunk first = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null, null);
|
||||
EffectiveWater.Chunk second = new EffectiveWater.Chunk(new long[256], new WaterRole[256], new boolean[256], null, null);
|
||||
|
||||
chunks.put(0, 0, first);
|
||||
assertSame(first, chunks.get(0, 0));
|
||||
|
||||
+22
@@ -24,6 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -39,6 +40,8 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisComplexSurfaceBiomeTest {
|
||||
private static final int INLAND_SEA_LEVEL = 85;
|
||||
|
||||
@ClassRule
|
||||
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
|
||||
@Rule
|
||||
@@ -208,6 +211,25 @@ public class IrisComplexSurfaceBiomeTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 120_000L)
|
||||
public void pondAboveSeaLevelKeepsTheLandBiomeOverAFloorBelowIt() throws Exception {
|
||||
Path pack = HydrologyFixture.pack(temporaryFolder.newFolder().toPath(), null, null);
|
||||
Files.writeString(pack.resolve("dimensions/main.json"), """
|
||||
{"regions":["plain"],"landChance":1,"fluidHeight":%d,"carvingEnabled":false}
|
||||
""".formatted(INLAND_SEA_LEVEL));
|
||||
Files.writeString(pack.resolve("regions/plain.json"), "{\"landBiomes\":[\"plain\"],\"seaBiomes\":[\"ocean\"]}");
|
||||
Files.writeString(pack.resolve("biomes/ocean.json"), "{\"generators\":[{\"generator\":\"flat\",\"min\":10,\"max\":10}]}");
|
||||
try (HydrologyFixture fixture = new HydrologyFixture(pack)) {
|
||||
ChunkWaterRaster raster = fixture.hydrology.runtime.raster(0, 0);
|
||||
int sea = fixture.engine.getDimension().getFluidHeight();
|
||||
assertEquals(WaterRole.POND, raster.role(8, 8));
|
||||
assertTrue("the pond floor sits below sea level", raster.terrainHeight(8, 8) < sea);
|
||||
assertTrue("the pond surface sits above sea level", raster.waterHead(8, 8) > sea);
|
||||
assertTrue("the land around the pond sits above sea level", HydrologyFixture.NATURAL > sea);
|
||||
assertEquals("plain", fixture.complex.getTrueBiomeStream().get(8, 8).getLoadKey());
|
||||
}
|
||||
}
|
||||
|
||||
private static int shoreColumn(HydrologyFixture fixture, int distance) {
|
||||
for (int x = 0; x < 64; x++) {
|
||||
ChunkWaterRaster raster = fixture.hydrology.runtime.raster(x >> 4, 0);
|
||||
|
||||
@@ -93,6 +93,31 @@ public class PackHydrologyValidatorTest {
|
||||
assertEquals(validation.errors().toString(), 6, validation.errors().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsPoliciesThatFillWaterWithASeamProfile() throws Exception {
|
||||
File pack = pack(dimension("""
|
||||
{
|
||||
"enabled": true,
|
||||
"fluids": [
|
||||
{"name": "water"},
|
||||
{"name": "lava", "palette": {"palette": [{"block": "minecraft:lava"}]}, "seam": "crust"},
|
||||
{"name": "crust", "palette": {"palette": [{"block": "minecraft:obsidian"}]}}
|
||||
]
|
||||
}
|
||||
""", ""));
|
||||
write(pack, "regions/region.json", """
|
||||
{"landBiomes": ["biome"], "hydrologyPolicy": {"fluid": "lava"}}
|
||||
""");
|
||||
write(pack, "biomes/biome.json", """
|
||||
{"name": "Biome", "hydrologyPolicy": {"fluid": "crust"}}
|
||||
""");
|
||||
|
||||
List<String> errors = validate(pack).errors();
|
||||
|
||||
assertContains(errors, "Biome 'biome'.hydrologyPolicy.fluid names fluid 'crust', which is a seam profile");
|
||||
assertEquals(errors.toString(), 1, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsFluidReferencesTheFluidProfilesDoNotDefine() throws Exception {
|
||||
File pack = pack(dimension("""
|
||||
|
||||
Reference in new issue
Block a user