From bf30f8c75b521e1f308ef569f917a924bb0b2ca2 Mon Sep 17 00:00:00 2001 From: Brian Fopiano Date: Tue, 3 Nov 2026 12:33:53 -0500 Subject: [PATCH] Veto springs near structures - Drop a spring when an imported structure piece lies within 32 blocks, from world minimum to one block above the seep - Pass the seep position to the carved terrain structure check - Clear the block update when a pool wall replaces a spring - Pin the spring guards with behaviour tests across several seeds - Pin startsNear reach and the springs-only component and runtime gates --- .../hydrology/underground/CarvedTerrain.java | 2 +- .../hydrology/underground/CavePoolFiller.java | 7 +- .../underground/CaveSpringPlacer.java | 2 +- .../mantle/MantleCarvedTerrain.java | 20 +- .../engine/HydrologyRuntimeTest.java | 25 +++ .../underground/CavePoolFillerTest.java | 2 +- .../underground/CaveSpringPlacerTest.java | 183 ++++++++++++++++-- .../mantle/MantleCarvedTerrainTest.java | 58 ++++++ .../mantle/MantleHydrologyComponentTest.java | 19 ++ .../stage/IrisCarveModifierHydrologyTest.java | 2 +- ...StructurePlacementScopeStartsNearTest.java | 41 +++- 11 files changed, 335 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CarvedTerrain.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CarvedTerrain.java index 17eac68c8..475eed85b 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CarvedTerrain.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CarvedTerrain.java @@ -7,5 +7,5 @@ public interface CarvedTerrain { String caveFluid(int x, int y, int z); - boolean structureNear(); + boolean structureNear(int x, int y, int z); } diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CavePoolFiller.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CavePoolFiller.java index a58ca2349..23564a6a8 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CavePoolFiller.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CavePoolFiller.java @@ -5,6 +5,7 @@ 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.mantle.MantleWriter; +import art.arcane.volmlib.util.matter.slices.UpdateMatter; import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue; import it.unimi.dsi.fastutil.longs.LongOpenHashSet; @@ -174,9 +175,13 @@ public final class CavePoolFiller { } int y = unpackY(cell); HydrologyCaveCell existing = writer.getDataIfPresent(x, y, z, HydrologyCaveCell.class); - if (existing == null || existing.action() == HydrologyCaveAction.SPRING_SOURCE || replacesSharedWall(existing, value)) { + boolean spring = existing != null && existing.action() == HydrologyCaveAction.SPRING_SOURCE; + if (existing == null || spring || replacesSharedWall(existing, value)) { writer.setData(x, y, z, value); } + if (spring) { + writer.setData(x, y, z, UpdateMatter.OFF); + } } } diff --git a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacer.java b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacer.java index 2ab9fa7a1..7794ffa0a 100644 --- a/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacer.java +++ b/core/src/main/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacer.java @@ -46,7 +46,7 @@ public final class CaveSpringPlacer { int x = (chunkX << 4) + (int) (column & 15); int z = (chunkZ << 4) + (int) ((column >>> 4) & 15); int y = seep(carved, x, z, seed); - if (y >= 0 && contained(carved, x, y, z) && !carved.structureNear()) { + if (y >= 0 && contained(carved, x, y, z) && !carved.structureNear(x, y, z)) { write(chunkX, chunkZ, x, y, z, new HydrologyCaveCell(HydrologyCaveAction.SPRING_SOURCE, fluid(carved, x, y, z)), writer); } } diff --git a/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java b/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java index 61f23cf28..5b8cb8c25 100644 --- a/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java +++ b/core/src/main/java/art/arcane/iris/generation/mantle/MantleCarvedTerrain.java @@ -16,6 +16,7 @@ import art.arcane.iris.generation.terrain.IrisDimension; import art.arcane.iris.generation.terrain.IrisRegion; import art.arcane.iris.generation.terrain.Terrain3DColumn; import art.arcane.iris.structure.placement.StructurePlacementScope; +import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume; import art.arcane.volmlib.util.mantle.flag.MantleFlag; import art.arcane.volmlib.util.mantle.runtime.MantleChunk; import art.arcane.volmlib.util.matter.Matter; @@ -31,6 +32,7 @@ final class MantleCarvedTerrain implements CarvedTerrain { private static final int SPAN = 48; private static final int UNKNOWN = Integer.MIN_VALUE; private static final int STRUCTURE_REACH_CHUNKS = 8; + private static final int IMPORTED_STRUCTURE_REACH = 32; private final MantleWriter writer; private final IrisComplex complex; @@ -123,13 +125,27 @@ final class MantleCarvedTerrain implements CarvedTerrain { } @Override - public boolean structureNear() { + public boolean structureNear(int x, int y, int z) { long revision = ProvisionalSampling.revision(); - boolean near = StructurePlacementScope.startsNear(engine, chunkX, chunkZ, STRUCTURE_REACH_CHUNKS); + boolean near = importedStructureNear(x, y, z) || StructurePlacementScope.startsNear(engine, chunkX, chunkZ, STRUCTURE_REACH_CHUNKS); requireFinal(revision, chunkX << 4, chunkZ << 4); return near; } + private boolean importedStructureNear(int x, int y, int z) { + int minX = x - IMPORTED_STRUCTURE_REACH; + int minZ = z - IMPORTED_STRUCTURE_REACH; + int maxX = x + IMPORTED_STRUCTURE_REACH; + int maxZ = z + IMPORTED_STRUCTURE_REACH; + int maxY = y + minimumY + 1; + for (NativeStructureVolume volume : engine.getNativeStructureVolumes(minX, minZ, maxX, maxZ)) { + if (volume.intersects(minX, minimumY, minZ, maxX, maxY, maxZ)) { + return true; + } + } + return false; + } + private static Collection inlets(HydrologyRuntime runtime, int chunkX, int chunkZ) { Map inlets = new LinkedHashMap<>(); for (int offsetZ = -1; offsetZ <= 1; offsetZ++) { diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java index 93abba8d8..3622ba275 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/engine/HydrologyRuntimeTest.java @@ -950,6 +950,31 @@ public class HydrologyRuntimeTest { assertDisabled(HydrologyRuntime.create(engine, complex)); } + @Test(timeout = 180_000L) + public void policyFluidsReachSpringsWithCavePoolsOff() throws Exception { + try (EngineFixture.Environment ignored = EngineFixture.environment(); + EngineFixture fixture = new EngineFixture(EngineFixture.pack(temporaryFolder.newFolder().toPath(), false))) { + IrisHydrology config = new IrisHydrology().setEnabled(true).setPrefetchRings(0); + config.getUnderground().getCavePools().setEnabled(false); + config.getUnderground().getCaveSprings().setFluid("water"); + fixture.dimension.setHydrology(config); + fixture.dimension.setHydrologyPolicy(new IrisHydrologyPolicy().setFluid("water")); + + assertFalse(caveFluidPolicies(fixture)); + config.getUnderground().getCaveSprings().setEnabled(true); + assertTrue(caveFluidPolicies(fixture)); + } + } + + private static boolean caveFluidPolicies(EngineFixture fixture) { + HydrologyRuntime runtime = HydrologyRuntime.create(fixture.engine, fixture.complex); + try { + return runtime.caveFluidPolicies(); + } finally { + runtime.close(); + } + } + @Test public void zeroDensitySkipsRuntimePlanningAfterValidatingSettings() throws Exception { Engine engine = mock(Engine.class); diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CavePoolFillerTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CavePoolFillerTest.java index 18da5c738..2de2a71e3 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CavePoolFillerTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CavePoolFillerTest.java @@ -516,7 +516,7 @@ public class CavePoolFillerTest { } @Override - public boolean structureNear() { + public boolean structureNear(int x, int y, int z) { return false; } } diff --git a/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacerTest.java b/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacerTest.java index 79b85f1cc..f4f889f33 100644 --- a/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacerTest.java +++ b/core/src/test/java/art/arcane/iris/generation/hydrology/underground/CaveSpringPlacerTest.java @@ -39,6 +39,7 @@ import static org.mockito.Mockito.when; public class CaveSpringPlacerTest { private static final long SEED = 1337L; + private static final long[] SEEDS = {1337L, 42L, 7L, 99L, 2048L, -5L, 31337L, 88L}; private static final int FLOOR = 50; private static final int CEILING = 70; private static final int[][] SIDES = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; @@ -47,8 +48,10 @@ public class CaveSpringPlacerTest { public void placesOneSourceInARockWallAboveAnOpeningAndAsksForAnUpdate() { World world = pillars(); Recorder recorder = new Recorder(); - placer(springs -> { - }).place(0, 0, () -> world, recorder.writer, SEED); + for (long seed : SEEDS) { + placer(springs -> { + }).place(0, 0, () -> world, recorder.writer, seed); + } assertFalse(recorder.cells.isEmpty()); for (Map.Entry entry : recorder.cells.entrySet()) { @@ -122,24 +125,26 @@ public class CaveSpringPlacerTest { World world = pillars(); CaveSpringPlacer placer = placer(springs -> { }); - Recorder forward = new Recorder(); List chunks = new ArrayList<>(); for (int chunkX = -2; chunkX <= 2; chunkX++) { for (int chunkZ = -2; chunkZ <= 2; chunkZ++) { chunks.add(new int[]{chunkX, chunkZ}); } } - for (int[] chunk : chunks) { - placer.place(chunk[0], chunk[1], () -> world, forward.writer, SEED); + for (long seed : SEEDS) { + Recorder forward = new Recorder(); + for (int[] chunk : chunks) { + placer.place(chunk[0], chunk[1], () -> world, forward.writer, seed); + } + Collections.shuffle(chunks, new Random(seed)); + Recorder shuffled = new Recorder(); + for (int[] chunk : chunks) { + placer.place(chunk[0], chunk[1], () -> world, shuffled.writer, seed); + } + assertFalse(forward.cells.isEmpty()); + assertEquals(forward.cells, shuffled.cells); + assertEquals(forward.updates.keySet(), shuffled.updates.keySet()); } - Collections.shuffle(chunks, new Random(SEED)); - Recorder shuffled = new Recorder(); - for (int[] chunk : chunks) { - placer.place(chunk[0], chunk[1], () -> world, shuffled.writer, SEED); - } - assertFalse(forward.cells.isEmpty()); - assertEquals(forward.cells, shuffled.cells); - assertEquals(forward.updates.keySet(), shuffled.updates.keySet()); } @Test @@ -161,6 +166,110 @@ public class CaveSpringPlacerTest { place(sloped, springs -> springs.setMinDepthBelowSurface(16)).isEmpty()); } + @Test + public void theFlowKeepsMinDepthOnGroundThatStaysAboveIt() { + World lowGround = pillars(); + lowGround.surfaceAt = (x, z) -> x >= 8 ? 60 : 200; + assertFalse("the floor at 51 lies 9 under the low ground", + place(lowGround, springs -> springs.setMinDepthBelowSurface(9)).isEmpty()); + assertTrue("the same floor is too shallow for 10", + place(lowGround, springs -> springs.setMinDepthBelowSurface(10)).isEmpty()); + } + + @Test + public void aForeignCellBesideTheSeepDropsItEvenWithAnotherSideOpen() { + World walled = pillars(); + for (int x = -16; x < 32; x++) { + for (int z = -16; z < 32; z++) { + if (Math.floorMod(x + z, 2) == 1 && Math.floorMod(z, 2) == 1) { + for (int y = FLOOR + 2; y <= CEILING; y++) { + walled.foreign(x, y, z); + } + } + } + } + assertTrue(place(walled, springs -> { + }).isEmpty()); + } + + @Test + public void anOpeningWithNoDropHoldsNoSeep() { + World slit = new World(); + World drop = new World(); + for (int x = -16; x < 32; x++) { + for (int z = -16; z < 32; z++) { + if (Math.floorMod(x + z, 2) == 1) { + slit.carve(x, x, z, z, 60, 60); + drop.carve(x, x, z, z, 59, 60); + } + } + } + assertTrue(place(slit, springs -> { + }).isEmpty()); + assertFalse(place(drop, springs -> { + }).isEmpty()); + } + + @Test + public void aSeepNeedsRockDirectlyAboveAndBelow() { + World layered = pillars(); + for (int x = -16; x < 32; x++) { + for (int z = -16; z < 32; z++) { + if (Math.floorMod(x + z, 2) == 0) { + for (int y = FLOOR + 4; y <= CEILING; y += 3) { + layered.carve(x, x, z, z, y, y); + } + } + } + } + assertTrue("every wall block has air directly above or below it", place(layered, springs -> { + }).isEmpty()); + } + + @Test + public void seepsCoverEveryColumnOfTheirChunk() { + World world = pillars(); + CaveSpringPlacer placer = placer(springs -> { + }); + Recorder recorder = new Recorder(); + for (long seed = 0L; seed < 128L; seed++) { + placer.place(0, 0, () -> world, recorder.writer, seed); + } + Set xs = new HashSet<>(); + Set zs = new HashSet<>(); + for (long cell : recorder.cells.keySet()) { + xs.add(x(cell)); + zs.add(z(cell)); + } + Set chunk = new HashSet<>(); + for (int column = 0; column < 16; column++) { + chunk.add(column); + } + assertEquals(chunk, xs); + assertEquals(chunk, zs); + } + + @Test + public void theFlowIsFollowedFifteenBlocksAndNoFurther() { + Consumer one = springs -> springs.setDensity(1D); + int checked = 0; + for (long seed : SEEDS) { + Map clean = placeAt(pillars(), seed, one); + for (long cell : clean.keySet()) { + for (int[] side : SIDES) { + World inside = pillars(); + inside.foreign(x(cell) + side[0] * 15, FLOOR, z(cell) + side[1] * 15); + assertTrue(placeAt(inside, seed, one).isEmpty()); + World outside = pillars(); + outside.foreign(x(cell) + side[0] * 16, FLOOR, z(cell) + side[1] * 16); + assertEquals(clean, placeAt(outside, seed, one)); + checked++; + } + } + } + assertTrue(checked > 0); + } + @Test public void aSeepThatWouldOpenOntoTheSurfaceIsDropped() { World open = pillars(); @@ -194,11 +303,26 @@ public class CaveSpringPlacerTest { @Test public void structuresNearbyDropTheSpring() { World world = pillars(); - world.structures = true; + world.structures = (x, y, z) -> true; assertTrue(place(world, springs -> { }).isEmpty()); } + @Test + public void theStructureCheckIsAskedAboutTheSeepItself() { + Consumer one = springs -> springs.setDensity(1D); + int checked = 0; + for (long seed : SEEDS) { + for (long cell : placeAt(pillars(), seed, one).keySet()) { + World world = pillars(); + world.structures = (x, y, z) -> key(x, y, z) == cell; + assertTrue(placeAt(world, seed, one).isEmpty()); + checked++; + } + } + assertTrue(checked > 0); + } + @Test public void poolWallsWinOverSpringsWhicheverChunkWritesFirst() { World world = new World(); @@ -218,6 +342,7 @@ public class CaveSpringPlacerTest { placer.place(0, 0, () -> world, poolsFirst.writer, SEED); assertEquals(springsFirst.cells, poolsFirst.cells); + assertEquals("a replaced spring asks for no block update", liveUpdates(poolsFirst), liveUpdates(springsFirst)); Set replaced = new HashSet<>(); for (long cell : placed.keySet()) { if (springsFirst.cells.get(cell).action() == HydrologyCaveAction.SEAL_GUARD) { @@ -232,11 +357,29 @@ public class CaveSpringPlacerTest { } private static Map place(World world, Consumer springs) { + Map written = new HashMap<>(); + for (long seed : SEEDS) { + written.putAll(placeAt(world, seed, springs)); + } + return written; + } + + private static Map placeAt(World world, long seed, Consumer springs) { Recorder recorder = new Recorder(); - placer(springs).place(0, 0, () -> world, recorder.writer, SEED); + placer(springs).place(0, 0, () -> world, recorder.writer, seed); return recorder.cells; } + private static Set liveUpdates(Recorder recorder) { + Set live = new HashSet<>(); + for (Map.Entry update : recorder.updates.entrySet()) { + if (update.getValue().isUpdate()) { + live.add(update.getKey()); + } + } + return live; + } + private static IrisHydrology config(Consumer springs) { IrisHydrology config = new IrisHydrology().setEnabled(true); config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava"))); @@ -286,6 +429,10 @@ public class CaveSpringPlacerTest { int at(int x, int z); } + private interface StructureAt { + boolean at(int x, int y, int z); + } + private static final class Recorder { private final Map cells = new HashMap<>(); private final Map updates = new HashMap<>(); @@ -318,7 +465,7 @@ public class CaveSpringPlacerTest { private SurfaceAt surfaceAt; private IntFunction policyFluid = x -> null; private int historicMinX = Integer.MAX_VALUE; - private boolean structures; + private StructureAt structures = (x, y, z) -> false; void carve(int minX, int maxX, int minZ, int maxZ, int minY, int maxY) { for (int x = minX; x <= maxX; x++) { @@ -364,8 +511,8 @@ public class CaveSpringPlacerTest { } @Override - public boolean structureNear() { - return structures; + public boolean structureNear(int x, int y, int z) { + return structures.at(x, y, z); } } } diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java index 51e41998a..ece98c231 100644 --- a/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java +++ b/core/src/test/java/art/arcane/iris/generation/mantle/MantleCarvedTerrainTest.java @@ -15,6 +15,7 @@ import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.EnginePlatformHooks; import art.arcane.iris.generation.runtime.IrisComplex; +import art.arcane.iris.generation.runtime.SeedManager; import art.arcane.iris.generation.stream.ProvisionalSampling; import art.arcane.iris.generation.subterrain.SubterrainCell; import art.arcane.iris.generation.subterrain.SubterrainPlan; @@ -23,10 +24,13 @@ import art.arcane.iris.generation.terrain.IrisDimension; import art.arcane.iris.generation.terrain.IrisMaterialPalette; import art.arcane.iris.generation.terrain.IrisRegion; import art.arcane.iris.generation.terrain.Terrain3DColumn; +import art.arcane.iris.structure.placement.IrisStructurePlacement; +import art.arcane.iris.structure.placement.StructureDistribution; import art.arcane.iris.world.IrisWorld; import art.arcane.iris.world.storage.matter.IrisMatterSupport; import art.arcane.iris.world.storage.matter.PreObjectMatterCell; import art.arcane.iris.world.storage.matter.PreObjectMatterTest; +import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume; import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.mantle.flag.MantleFlag; import art.arcane.volmlib.util.mantle.runtime.Mantle; @@ -268,6 +272,60 @@ public class MantleCarvedTerrainTest { poolFluids(poolRoom(new Underground(volcanic, magma, region("temperate", null), new IrisDimension())).generate(0))); } + @Test + public void importedStructuresWithinTheFlowsReachAndBelowTheSeepTopAreNear() { + assertFalse(nearSeep()); + assertTrue("on the seep", nearSeep(volume(8, -34, 8, 8, -34, 8))); + assertTrue("at the bottom of the world", nearSeep(volume(8, -64, 8, 8, -64, 8))); + assertTrue("one block above the seep", nearSeep(volume(8, -33, 8, 8, -20, 8))); + assertFalse("above that", nearSeep(volume(8, -32, 8, 8, -20, 8))); + assertTrue(nearSeep(volume(40, -60, 8, 50, -50, 8))); + assertFalse(nearSeep(volume(41, -60, 8, 50, -50, 8))); + assertTrue(nearSeep(volume(-30, -60, 8, -24, -50, 8))); + assertFalse(nearSeep(volume(-30, -60, 8, -25, -50, 8))); + assertTrue(nearSeep(volume(8, -60, 40, 8, -50, 50))); + assertFalse(nearSeep(volume(8, -60, 41, 8, -50, 50))); + assertTrue(nearSeep(volume(8, -60, -30, 8, -50, -24))); + assertFalse(nearSeep(volume(8, -60, -30, 8, -50, -25))); + } + + @Test + public void placementsThatCanStartNearbyAreNear() { + Scene scene = structureScene(); + assertFalse(scene.carved().structureNear(8, 30, 8)); + + Scene dense = structureScene(); + dense.engine.getDimension().setStructures(new KList<>(new IrisStructurePlacement().setDistribution(StructureDistribution.DENSITY).setDensity(1D))); + assertTrue(dense.carved().structureNear(8, 30, 8)); + } + + private static boolean nearSeep(NativeStructureVolume... volumes) { + return structureScene(volumes).carved().structureNear(8, 30, 8); + } + + private static NativeStructureVolume volume(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { + return new NativeStructureVolume("minecraft:mineshaft", minX, minY, minZ, maxX, maxY, maxZ, null); + } + + private static Scene structureScene(NativeStructureVolume... volumes) { + Scene scene = new Scene(); + IrisWorld world = mock(IrisWorld.class); + when(world.minHeight()).thenReturn(-64); + when(scene.engine.getWorld()).thenReturn(world); + when(scene.engine.getSeedManager()).thenReturn(new SeedManager(SEED)); + when(scene.engine.getAllBiomes()).thenReturn(new KList<>()); + when(scene.engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenAnswer(invocation -> { + KList matches = new KList<>(); + for (NativeStructureVolume volume : volumes) { + if (volume.intersectsInfluenceRect(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2), invocation.getArgument(3))) { + matches.add(volume); + } + } + return matches; + }); + return scene; + } + private static Scene poolRoom(Underground underground) { Scene scene = new Scene(underground); Matter[] room = scene.chunk(0, 0); diff --git a/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java b/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java index 11c808752..f43d0901c 100644 --- a/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java +++ b/core/src/test/java/art/arcane/iris/generation/mantle/MantleHydrologyComponentTest.java @@ -8,6 +8,7 @@ import art.arcane.iris.generation.hydrology.config.IrisHydrology; 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.underground.CavePoolFiller; import art.arcane.iris.generation.hydrology.underground.SeaInlet; import art.arcane.iris.generation.runtime.Engine; import art.arcane.iris.generation.runtime.IrisComplex; @@ -84,6 +85,24 @@ public class MantleHydrologyComponentTest { assertFalse(MantleHydrologyComponent.isEnabledFor(dimension)); } + @Test + public void springsAloneKeepTheCaveWaterReach() { + IrisDimension dimension = new IrisDimension(); + IrisHydrology hydrology = new IrisHydrology().setEnabled(true); + hydrology.getUnderground().getCavePools().setEnabled(false); + dimension.setHydrology(hydrology); + Engine engine = mock(Engine.class); + when(engine.getDimension()).thenReturn(dimension); + EngineMantle mantle = mock(EngineMantle.class); + when(mantle.getEngine()).thenReturn(engine); + MantleHydrologyComponent component = new MantleHydrologyComponent(mantle); + + assertEquals(0, component.getInputRadius()); + hydrology.getUnderground().getCaveSprings().setEnabled(true); + assertEquals(CavePoolFiller.REACH, component.getInputRadius()); + assertEquals(CavePoolFiller.REACH, component.computeRadius()); + } + @Test public void everyDropBetweenWetColumnsFallsFromTheHigherHead() { MantleHydrologyComponent.Falls falls = MantleHydrologyComponent.plan(0, 0, WORLD_HEIGHT, diff --git a/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierHydrologyTest.java b/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierHydrologyTest.java index a5e7b9b91..42e91b19f 100644 --- a/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierHydrologyTest.java +++ b/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierHydrologyTest.java @@ -446,7 +446,7 @@ public class IrisCarveModifierHydrologyTest { } @Override - public boolean structureNear() { + public boolean structureNear(int x, int y, int z) { return false; } } diff --git a/core/src/test/java/art/arcane/iris/structure/placement/StructurePlacementScopeStartsNearTest.java b/core/src/test/java/art/arcane/iris/structure/placement/StructurePlacementScopeStartsNearTest.java index bbb479765..1de72bfb4 100644 --- a/core/src/test/java/art/arcane/iris/structure/placement/StructurePlacementScopeStartsNearTest.java +++ b/core/src/test/java/art/arcane/iris/structure/placement/StructurePlacementScopeStartsNearTest.java @@ -12,6 +12,8 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class StructurePlacementScopeStartsNearTest { + private static final long MANTLE_SEED = 1337L; + @Test public void reportsAStartWithinTheReachAndNothingOutsideIt() { IrisStructurePlacement dense = new IrisStructurePlacement().setDistribution(StructureDistribution.DENSITY).setDensity(1D); @@ -22,10 +24,47 @@ public class StructurePlacementScopeStartsNearTest { assertFalse(StructurePlacementScope.startsNear(engine(new KList<>()), 3, -2, 8)); } + @Test + public void aStartCountsExactlyUpToTheReachOnEverySide() { + IrisStructurePlacement sparse = new IrisStructurePlacement().setDistribution(StructureDistribution.DENSITY).setDensity(0.0005D); + Engine engine = engine(new KList<>(sparse)); + int[] start = loneStart(sparse); + for (int reach : new int[]{1, 3, 8}) { + for (int[] side : new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}}) { + int chunkX = start[0] + side[0] * reach; + int chunkZ = start[1] + side[1] * reach; + assertTrue(StructurePlacementScope.startsNear(engine, chunkX, chunkZ, reach)); + assertFalse(StructurePlacementScope.startsNear(engine, chunkX, chunkZ, reach - 1)); + } + } + } + + private static int[] loneStart(IrisStructurePlacement placement) { + for (int x = 0; x < 4096; x++) { + for (int z = 0; z < 4096; z++) { + if (StructurePlacementGrid.startsInChunk(placement, x, z, MANTLE_SEED) && alone(placement, x, z)) { + return new int[]{x, z}; + } + } + } + throw new AssertionError("No lone start in the searched chunks"); + } + + private static boolean alone(IrisStructurePlacement placement, int startX, int startZ) { + for (int x = startX - 16; x <= startX + 16; x++) { + for (int z = startZ - 16; z <= startZ + 16; z++) { + if ((x != startX || z != startZ) && StructurePlacementGrid.startsInChunk(placement, x, z, MANTLE_SEED)) { + return false; + } + } + } + return true; + } + private static Engine engine(KList placements) { Engine engine = mock(Engine.class); SeedManager seeds = mock(SeedManager.class); - when(seeds.getMantle()).thenReturn(1337L); + when(seeds.getMantle()).thenReturn(MANTLE_SEED); when(engine.getSeedManager()).thenReturn(seeds); IrisDimension dimension = new IrisDimension(); dimension.setStructures(placements);