mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
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:
1 parent
64dc22025e
commit
52989ce88d
15 files changed
+403
-123
No files matched your search
+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