Remove inlet passage

- Delete SeaInlet, its rasterizer, space and footprint, and the old inlet probe
- Keep the mantle cells, old chunk seal and cave headroom behind SealedPassage
- Keep their tests on a test passage so grottos can build on them
- Report tidal arm counts from the plan in the hydrology probe
This commit is contained in:
Brian Fopiano committed 2026-11-03 15:42:18 -05:00
1 parent 848226c6f3
commit 4132db5f8b
21 files changed
+315 -1681

No files matched your search

@@ -3,6 +3,7 @@ package art.arcane.iris.generation.hydrology.underground;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.iris.generation.mantle.MantleWriter;
import art.arcane.iris.testsupport.TestPassage;
import org.junit.Test;
import java.util.ArrayList;
@@ -23,14 +24,14 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class SeaInletRasterizerTest {
public class PassageRasterizerTest {
private static final int SEA = 40;
private static final String FLUID = HydrologyCaveCell.SEA_FLUID;
private static final int CAVE_CLEARANCE = 2;
@Test
public void waterLevelIsSeaLevelEverywhere() {
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet(1L, 15f)), order(false));
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(passage(1L, 15f)), order(false));
int wetColumns = 0;
Map<Long, Integer> tops = new TreeMap<>();
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
@@ -53,8 +54,8 @@ public class SeaInletRasterizerTest {
@Test
public void everyWaterCellIsHeldBySealedOrWetNeighbours() {
List<SeaInlet> inlets = List.of(inlet(1L, 15f), inlet(2L, 30f));
Map<Long, HydrologyCaveCell> cells = rasterize(inlets, order(false));
List<TestPassage> passages = List.of(passage(1L, 15f), passage(2L, 30f));
Map<Long, HydrologyCaveCell> cells = rasterize(passages, order(false));
int checked = 0;
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) {
@@ -64,9 +65,6 @@ public class SeaInletRasterizerTest {
int y = y(entry.getKey());
int z = z(entry.getKey());
for (int[] side : new int[][]{{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, -1, 0}}) {
if (paintedSlot(inlets, x + side[0], y + side[1], z + side[2])) {
continue;
}
HydrologyCaveCell neighbour = cells.get(key(x + side[0], y + side[1], z + side[2]));
assertNotNull("water at " + x + "," + y + "," + z + " has an open side " + side[0] + "," + side[1] + "," + side[2], neighbour);
assertTrue(neighbour.action() == HydrologyCaveAction.WET_SOURCE || neighbour.action() == HydrologyCaveAction.SEAL_GUARD);
@@ -78,8 +76,8 @@ public class SeaInletRasterizerTest {
@Test
public void sealKeepsCavesTwoBlocksFromTheWater() {
List<SeaInlet> inlets = List.of(inlet(1L, 15f));
Map<Long, HydrologyCaveCell> cells = rasterize(inlets, order(false));
List<TestPassage> passages = List.of(passage(1L, 15f));
Map<Long, HydrologyCaveCell> cells = rasterize(passages, order(false));
int checked = 0;
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
if (entry.getValue().action() != HydrologyCaveAction.WET_SOURCE) {
@@ -91,9 +89,6 @@ public class SeaInletRasterizerTest {
for (int below = 0; below <= CAVE_CLEARANCE; below++) {
for (int dz = -CAVE_CLEARANCE; dz <= CAVE_CLEARANCE; dz++) {
for (int dx = -CAVE_CLEARANCE; dx <= CAVE_CLEARANCE; dx++) {
if (paintedSlot(inlets, x + dx, y - below, z + dz)) {
continue;
}
HydrologyCaveCell held = cells.get(key(x + dx, y - below, z + dz));
assertNotNull("no seal at " + (x + dx) + "," + (y - below) + "," + (z + dz) + " near water at " + x + "," + y + "," + z,
held);
@@ -113,67 +108,15 @@ public class SeaInletRasterizerTest {
}
@Test
public void openSlotColumnsLeaveTheirWaterToThePainter() {
SeaInlet inlet = inlet(1L, 15f);
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), order(false));
int[] column = new int[2];
int sealed = 0;
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
int x = x(entry.getKey());
int z = z(entry.getKey());
if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] != SeaInlet.OPEN) {
continue;
}
assertEquals("open slot column " + x + "," + z + " holds only its seal", HydrologyCaveAction.SEAL_GUARD, entry.getValue().action());
assertTrue(y(entry.getKey()) <= column[0]);
sealed++;
}
assertTrue("open slot seal cells " + sealed, sealed > 100);
assertTrue(cells.values().stream().anyMatch(cell -> cell.action() == HydrologyCaveAction.DRY_AIR));
assertTrue(cells.values().stream().anyMatch(cell -> cell.action() == HydrologyCaveAction.WET_SOURCE));
}
@Test
public void openSlotBedsKeepTheirSeaFloorOnTwoSealedBlocks() {
SeaInlet inlet = inlet(1L, 15f);
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), order(false));
int[] column = new int[2];
int beds = 0;
int covered = 0;
for (int z = -16; z <= 63; z++) {
for (int x = -32; x <= 79; x++) {
if (!SeaInletRasterizer.column(inlet, x, z, column)) {
continue;
}
int floor = column[0];
if (column[1] == SeaInlet.OPEN) {
assertNull("the open slot bed at " + x + "," + floor + "," + z + " keeps the painted sea floor", cells.get(key(x, floor, z)));
for (int under = 1; under <= SeaInletRasterizer.SHELL; under++) {
HydrologyCaveCell sealed = cells.get(key(x, floor - under, z));
assertNotNull("rock under the open slot bed at " + x + "," + (floor - under) + "," + z, sealed);
assertEquals(HydrologyCaveAction.SEAL_GUARD, sealed.action());
}
beds++;
} else {
assertEquals("covered bed at " + x + "," + floor + "," + z, HydrologyCaveAction.SEAL_GUARD, cells.get(key(x, floor, z)).action());
covered++;
}
}
}
assertTrue("open slot beds " + beds, beds > 20);
assertTrue("covered beds " + covered, covered > 100);
}
@Test
public void subterrainFluidWithinTwoBlocksOfInletAirAboveSeaLevelIsSealed() {
SeaInlet inlet = inlet(1L, 15f);
SeaInletRasterizer.SubterrainFluid flooded = (x, y, z) -> Math.floorMod(x + 2 * z + y, 5) != 0;
Map<Long, HydrologyCaveCell> plain = rasterize(List.of(inlet), order(false));
public void subterrainFluidWithinTwoBlocksOfPassageAirAboveSeaLevelIsSealed() {
TestPassage passage = passage(1L, 15f);
PassageRasterizer.SubterrainFluid flooded = (x, y, z) -> Math.floorMod(x + 2 * z + y, 5) != 0;
Map<Long, HydrologyCaveCell> plain = rasterize(List.of(passage), order(false));
for (Map.Entry<Long, HydrologyCaveCell> entry : plain.entrySet()) {
assertTrue("without subterrain fluid nothing above sea level is sealed",
y(entry.getKey()) <= SEA || entry.getValue().action() == HydrologyCaveAction.DRY_AIR);
}
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), order(false), flooded);
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(passage), order(false), flooded);
int checked = 0;
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
if (entry.getValue().action() != HydrologyCaveAction.DRY_AIR) {
@@ -189,7 +132,7 @@ public class SeaInletRasterizerTest {
continue;
}
HydrologyCaveCell held = cells.get(key(x + dx, y + dy, z + dz));
assertNotNull("subterrain fluid at " + (x + dx) + "," + (y + dy) + "," + (z + dz) + " beside inlet air at " + x + "," + y
assertNotNull("subterrain fluid at " + (x + dx) + "," + (y + dy) + "," + (z + dz) + " beside passage air at " + x + "," + y
+ "," + z, held);
assertTrue(held.action() == HydrologyCaveAction.DRY_AIR || held.action() == HydrologyCaveAction.SEAL_GUARD);
checked++;
@@ -206,12 +149,12 @@ public class SeaInletRasterizerTest {
continue;
}
assertTrue("only subterrain fluid is sealed above sea level, not " + x + "," + y + "," + z, flooded.at(x, y, z));
assertTrue("the seal at " + x + "," + y + "," + z + " lies within two blocks of inlet air", nearAir(cells, x, y, z));
assertTrue("the seal at " + x + "," + y + "," + z + " lies within two blocks of passage air", nearAir(cells, x, y, z));
sealed++;
}
assertTrue("checked " + checked, checked > 1000);
assertTrue("sealed " + sealed, sealed > 200);
assertEquals(cells, rasterize(List.of(inlet), order(true), flooded));
assertEquals(cells, rasterize(List.of(passage), order(true), flooded));
}
private static boolean nearAir(Map<Long, HydrologyCaveCell> cells, int x, int y, int z) {
@@ -228,16 +171,6 @@ public class SeaInletRasterizerTest {
return false;
}
private static boolean paintedSlot(List<SeaInlet> inlets, int x, int y, int z) {
int[] column = new int[2];
for (SeaInlet inlet : inlets) {
if (SeaInletRasterizer.column(inlet, x, z, column) && column[1] == SeaInlet.OPEN && y >= column[0] && y <= inlet.waterLevel()) {
return true;
}
}
return false;
}
@Test(timeout = 20_000L)
public void thinDiagonalPassagesSealTheirBedWithoutRunningAway() {
float[] xs = {0f, 8f, 16f, 24f, 32f};
@@ -245,7 +178,7 @@ public class SeaInletRasterizerTest {
float[] halfWidth = {0.6f, 0.6f, 0.6f, 0.6f, 0.6f};
int[] floor = {SEA - 3, SEA - 3, SEA - 3, SEA - 3, SEA - 3};
int[] ceiling = {SEA + 4, SEA + 4, SEA + 4, SEA + 4, SEA + 4};
SeaInlet thin = new SeaInlet(9L, xs, zs, halfWidth, SEA, floor, ceiling, 32, 32, 2);
TestPassage thin = new TestPassage(9L, xs, zs, halfWidth, SEA, floor, ceiling, 32, 32, 2);
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(thin), order(false));
int wet = 0;
for (Map.Entry<Long, HydrologyCaveCell> entry : cells.entrySet()) {
@@ -260,11 +193,11 @@ public class SeaInletRasterizerTest {
@Test
public void passageEndingAtAnOldChunkIsSealed() {
SeaInlet inlet = inlet(1L, 15f);
SeaInletRasterizer.HistoricalChunks old = (chunkX, chunkZ) -> chunkX == 2;
Map<Long, HydrologyCaveCell> open = rasterize(List.of(inlet), order(false), SeaInletRasterizer.SubterrainFluid.NOWHERE,
SeaInletRasterizer.HistoricalChunks.NONE);
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(inlet), newChunks(order(false), old), SeaInletRasterizer.SubterrainFluid.NOWHERE,
TestPassage passage = passage(1L, 15f);
PassageRasterizer.HistoricalChunks old = (chunkX, chunkZ) -> chunkX == 2;
Map<Long, HydrologyCaveCell> open = rasterize(List.of(passage), order(false), PassageRasterizer.SubterrainFluid.NOWHERE,
PassageRasterizer.HistoricalChunks.NONE);
Map<Long, HydrologyCaveCell> cells = rasterize(List.of(passage), newChunks(order(false), old), PassageRasterizer.SubterrainFluid.NOWHERE,
old);
int[] column = new int[2];
int seamColumns = 0;
@@ -273,12 +206,12 @@ public class SeaInletRasterizerTest {
if (old.at(x >> 4, z >> 4) || !nearOldChunk(old, x, z)) {
continue;
}
if (!SeaInletRasterizer.column(inlet, x, z, column) || column[1] == SeaInlet.OPEN) {
if (!passage.column(x, z, column)) {
continue;
}
assertEquals("without old chunks the seam column " + x + "," + z + " holds water", HydrologyCaveAction.WET_SOURCE,
open.get(key(x, inlet.waterLevel(), z)).action());
for (int y = column[0] - SeaInletRasterizer.SHELL; y <= column[1]; y++) {
open.get(key(x, passage.waterLevel(), z)).action());
for (int y = column[0] - PassageRasterizer.SHELL; y <= column[1]; y++) {
HydrologyCaveCell sealed = cells.get(key(x, y, z));
assertNotNull("no seal at " + x + "," + y + "," + z + " beside the old chunk", sealed);
assertEquals("seal at " + x + "," + y + "," + z + " beside the old chunk", HydrologyCaveAction.SEAL_GUARD, sealed.action());
@@ -301,9 +234,6 @@ public class SeaInletRasterizerTest {
continue;
}
for (int[] side : new int[][]{{1, 0, 0}, {-1, 0, 0}, {0, 0, 1}, {0, 0, -1}, {0, -1, 0}}) {
if (paintedSlot(List.of(inlet), x + side[0], y + side[1], z + side[2])) {
continue;
}
HydrologyCaveCell neighbour = cells.get(key(x + side[0], y + side[1], z + side[2]));
assertNotNull("water at " + x + "," + y + "," + z + " has an open side " + side[0] + "," + side[1] + "," + side[2], neighbour);
assertTrue(neighbour.action() == HydrologyCaveAction.WET_SOURCE || neighbour.action() == HydrologyCaveAction.SEAL_GUARD);
@@ -312,12 +242,12 @@ public class SeaInletRasterizerTest {
}
assertTrue("covered seam columns " + seamColumns, seamColumns > 10);
assertTrue("water cells away from the old chunks " + wet, wet > 300);
assertEquals(cells, rasterize(List.of(inlet), newChunks(order(true), old), SeaInletRasterizer.SubterrainFluid.NOWHERE, old));
assertEquals(cells, rasterize(List.of(passage), newChunks(order(true), old), PassageRasterizer.SubterrainFluid.NOWHERE, old));
}
private static boolean nearOldChunk(SeaInletRasterizer.HistoricalChunks old, int x, int z) {
for (int dz = -SeaInletRasterizer.SHELL; dz <= SeaInletRasterizer.SHELL; dz++) {
for (int dx = -SeaInletRasterizer.SHELL; dx <= SeaInletRasterizer.SHELL; dx++) {
private static boolean nearOldChunk(PassageRasterizer.HistoricalChunks old, int x, int z) {
for (int dz = -PassageRasterizer.SHELL; dz <= PassageRasterizer.SHELL; dz++) {
for (int dx = -PassageRasterizer.SHELL; dx <= PassageRasterizer.SHELL; dx++) {
if (old.at((x + dx) >> 4, (z + dz) >> 4)) {
return true;
}
@@ -326,7 +256,7 @@ public class SeaInletRasterizerTest {
return false;
}
private static List<int[]> newChunks(List<int[]> chunks, SeaInletRasterizer.HistoricalChunks old) {
private static List<int[]> newChunks(List<int[]> chunks, PassageRasterizer.HistoricalChunks old) {
List<int[]> fresh = new ArrayList<>();
for (int[] chunk : chunks) {
if (!old.at(chunk[0], chunk[1])) {
@@ -337,34 +267,34 @@ public class SeaInletRasterizerTest {
}
@Test
public void chunkOrderAndInletOrderDoNotChangeTheCells() {
List<SeaInlet> inlets = List.of(inlet(1L, 15f), inlet(2L, 22f));
Map<Long, HydrologyCaveCell> forward = rasterize(inlets, order(false));
Map<Long, HydrologyCaveCell> reverse = rasterize(List.of(inlets.get(1), inlets.get(0)), order(true));
public void chunkOrderAndPassageOrderDoNotChangeTheCells() {
List<TestPassage> passages = List.of(passage(1L, 15f), passage(2L, 22f));
Map<Long, HydrologyCaveCell> forward = rasterize(passages, order(false));
Map<Long, HydrologyCaveCell> reverse = rasterize(List.of(passages.get(1), passages.get(0)), order(true));
assertEquals(forward, reverse);
assertFalse(forward.isEmpty());
}
@Test
public void chunksWriteOnlyTheirOwnColumns() {
SeaInlet inlet = inlet(1L, 15f);
TestPassage passage = passage(1L, 15f);
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
MantleWriter writer = writer(cells, 1, 0);
new SeaInletRasterizer().write(inlet, 1, 0, writer, FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
SeaInletRasterizer.HistoricalChunks.NONE);
new PassageRasterizer().write(passage, 1, 0, writer, FLUID, PassageRasterizer.SubterrainFluid.NOWHERE,
PassageRasterizer.HistoricalChunks.NONE);
assertFalse(cells.isEmpty());
for (long key : cells.keySet()) {
assertEquals(1, x(key) >> 4);
assertEquals(0, z(key) >> 4);
}
Map<Long, HydrologyCaveCell> far = new TreeMap<>();
new SeaInletRasterizer().write(inlet, 20, 20, writer(far, 20, 20), FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
SeaInletRasterizer.HistoricalChunks.NONE);
new PassageRasterizer().write(passage, 20, 20, writer(far, 20, 20), FLUID, PassageRasterizer.SubterrainFluid.NOWHERE,
PassageRasterizer.HistoricalChunks.NONE);
assertTrue(far.isEmpty());
assertFalse(SeaInletRasterizer.touches(inlet, 20, 20));
assertFalse(PassageRasterizer.touches(passage, 20, 20));
}
private static SeaInlet inlet(long id, float z) {
private static TestPassage passage(long id, float z) {
float[] xs = {-8f, 0f, 8f, 16f, 24f, 32f, 40f, 48f};
float[] zs = new float[xs.length];
float[] halfWidth = new float[xs.length];
@@ -374,9 +304,9 @@ public class SeaInletRasterizerTest {
zs[station] = z + (station % 2 == 0 ? 0f : 3f);
halfWidth[station] = 5f - station * 0.4f;
floor[station] = SEA - 2 - station % 3;
ceiling[station] = station < 2 ? SeaInlet.OPEN : SEA + 4 + station % 4;
ceiling[station] = SEA + 4 + station % 4;
}
return new SeaInlet(id, xs, zs, halfWidth, SEA, floor, ceiling, 48, (int) z, 7);
return new TestPassage(id, xs, zs, halfWidth, SEA, floor, ceiling, 48, (int) z, 7);
}
private static List<int[]> order(boolean reverse) {
@@ -392,22 +322,22 @@ public class SeaInletRasterizerTest {
return chunks;
}
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks) {
return rasterize(inlets, chunks, SeaInletRasterizer.SubterrainFluid.NOWHERE);
private static Map<Long, HydrologyCaveCell> rasterize(List<TestPassage> passages, List<int[]> chunks) {
return rasterize(passages, chunks, PassageRasterizer.SubterrainFluid.NOWHERE);
}
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks, SeaInletRasterizer.SubterrainFluid subterrain) {
return rasterize(inlets, chunks, subterrain, SeaInletRasterizer.HistoricalChunks.NONE);
private static Map<Long, HydrologyCaveCell> rasterize(List<TestPassage> passages, List<int[]> chunks, PassageRasterizer.SubterrainFluid subterrain) {
return rasterize(passages, chunks, subterrain, PassageRasterizer.HistoricalChunks.NONE);
}
private static Map<Long, HydrologyCaveCell> rasterize(List<SeaInlet> inlets, List<int[]> chunks, SeaInletRasterizer.SubterrainFluid subterrain,
SeaInletRasterizer.HistoricalChunks old) {
private static Map<Long, HydrologyCaveCell> rasterize(List<TestPassage> passages, List<int[]> chunks, PassageRasterizer.SubterrainFluid subterrain,
PassageRasterizer.HistoricalChunks old) {
Map<Long, HydrologyCaveCell> cells = new TreeMap<>();
SeaInletRasterizer rasterizer = new SeaInletRasterizer();
PassageRasterizer rasterizer = new PassageRasterizer();
for (int[] chunk : chunks) {
MantleWriter writer = writer(cells, chunk[0], chunk[1]);
for (SeaInlet inlet : inlets) {
rasterizer.write(inlet, chunk[0], chunk[1], writer, FLUID, subterrain, old);
for (TestPassage passage : passages) {
rasterizer.write(passage, chunk[0], chunk[1], writer, FLUID, subterrain, old);
}
}
return cells;
@@ -2,8 +2,8 @@ package art.arcane.iris.generation.mantle;
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.testsupport.TestPassage;
import art.arcane.iris.generation.hydrology.underground.PassageRasterizer;
import art.arcane.iris.testsupport.WaterScene;
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
import org.junit.Test;
@@ -102,16 +102,16 @@ public class CaveCeilingMaskTest {
}
@Test
public void cavesStayOutOfInletHeadroom() {
SeaInlet inlet = inlet();
int[] bounds = SeaInletRasterizer.bounds(inlet);
public void cavesStayOutOfPassageHeadroom() {
TestPassage passage = passage();
int[] bounds = passage.bounds();
long[] bands = new long[256];
int[] column = new int[2];
int covered = 0;
int around = 0;
for (int chunkZ = (bounds[1] >> 4) - 1; chunkZ <= (bounds[3] >> 4) + 1; chunkZ++) {
for (int chunkX = (bounds[0] >> 4) - 1; chunkX <= (bounds[2] >> 4) + 1; chunkX++) {
boolean masked = CaveCeilingMask.fillHeadroom(chunkX, chunkZ, List.of(inlet), ROOF_CLEARANCE, bands);
boolean masked = CaveCeilingMask.fillHeadroom(chunkX, chunkZ, List.of(passage), bands);
long[] headroom = masked ? bands : null;
boolean expectedMasked = false;
for (int lz = 0; lz < 16; lz++) {
@@ -119,24 +119,24 @@ public class CaveCeilingMaskTest {
int x = (chunkX << 4) + lx;
int z = (chunkZ << 4) + lz;
int index = PowerOfTwoCoordinates.packLocal16(lx, lz);
int top = highestRoofWithinTwo(inlet, x, z);
int top = highestRoofWithinTwo(passage, x, z);
if (top == NO_ROOF) {
for (int y = 0; y <= SEA + 64; y++) {
assertFalse("caves stay possible at " + x + "," + y + "," + z + " away from the inlet",
assertFalse("caves stay possible at " + x + "," + y + "," + z + " away from the passage",
CaveCeilingMask.masked(null, headroom, index, y));
}
continue;
}
expectedMasked = true;
for (int y = inlet.waterLevel() + 1; y <= top; y++) {
assertTrue("caves stay out of the inlet headroom and roof at " + x + "," + y + "," + z,
for (int y = passage.waterLevel() + 1; y <= top; y++) {
assertTrue("caves stay out of the passage headroom and roof at " + x + "," + y + "," + z,
CaveCeilingMask.masked(null, headroom, index, y));
}
assertFalse("the seal holds caves at the water level " + x + "," + z,
CaveCeilingMask.masked(null, headroom, index, inlet.waterLevel()));
assertFalse("caves stay possible above the inlet roof at " + x + "," + z,
CaveCeilingMask.masked(null, headroom, index, passage.waterLevel()));
assertFalse("caves stay possible above the passage roof at " + x + "," + z,
CaveCeilingMask.masked(null, headroom, index, top + 1));
if (SeaInletRasterizer.column(inlet, x, z, column) && column[1] != SeaInlet.OPEN) {
if (passage.column(x, z, column)) {
covered++;
} else {
around++;
@@ -148,7 +148,7 @@ public class CaveCeilingMaskTest {
}
assertTrue("covered columns " + covered, covered > 300);
assertTrue("columns around the passage " + around, around > 100);
assertFalse(CaveCeilingMask.fillHeadroom(0, 0, List.of(), ROOF_CLEARANCE, bands));
assertFalse(CaveCeilingMask.fillHeadroom(0, 0, List.of(), bands));
}
@Test
@@ -157,7 +157,7 @@ public class CaveCeilingMaskTest {
Arrays.fill(ceilings, UNMASKED);
ceilings[3] = 40;
long[] bands = new long[256];
assertTrue(CaveCeilingMask.fillHeadroom(0, 0, List.of(inlet()), ROOF_CLEARANCE, bands));
assertTrue(CaveCeilingMask.fillHeadroom(0, 0, List.of(passage()), bands));
int index = PowerOfTwoCoordinates.packLocal16(12, 6);
assertTrue(CaveCeilingMask.masked(ceilings, null, 3, 41));
assertFalse(CaveCeilingMask.masked(ceilings, null, 3, 40));
@@ -166,7 +166,7 @@ public class CaveCeilingMaskTest {
assertFalse(CaveCeilingMask.masked(null, null, index, SEA + 1));
}
private static SeaInlet inlet() {
private static TestPassage passage() {
float[] xs = {-8f, 0f, 8f, 16f, 24f, 32f, 40f, 48f};
float[] zs = new float[xs.length];
float[] halfWidth = new float[xs.length];
@@ -176,17 +176,17 @@ public class CaveCeilingMaskTest {
zs[station] = 6f + (station % 2 == 0 ? 0f : 3f);
halfWidth[station] = 5f - station * 0.4f;
floor[station] = SEA - 2 - station % 3;
ceiling[station] = station < 2 ? SeaInlet.OPEN : SEA + 4 + station % 4;
ceiling[station] = SEA + 4 + station % 4;
}
return new SeaInlet(1L, xs, zs, halfWidth, SEA, floor, ceiling, 48, 6, 7);
return new TestPassage(1L, xs, zs, halfWidth, SEA, floor, ceiling, 48, 6, 7);
}
private static int highestRoofWithinTwo(SeaInlet inlet, int x, int z) {
private static int highestRoofWithinTwo(TestPassage passage, int x, int z) {
int top = NO_ROOF;
int[] column = new int[2];
for (int dz = -CaveCeilingMask.CONTAINMENT; dz <= CaveCeilingMask.CONTAINMENT; dz++) {
for (int dx = -CaveCeilingMask.CONTAINMENT; dx <= CaveCeilingMask.CONTAINMENT; dx++) {
if (SeaInletRasterizer.column(inlet, x + dx, z + dz, column) && column[1] != SeaInlet.OPEN) {
if (passage.column(x + dx, z + dz, column)) {
top = Math.max(top, column[1] + ROOF_CLEARANCE);
}
}
@@ -11,8 +11,9 @@ import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
import art.arcane.iris.generation.hydrology.underground.CavePoolFiller;
import art.arcane.iris.generation.hydrology.underground.CaveVoxel;
import art.arcane.iris.generation.hydrology.underground.SeaInlet;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.testsupport.TestPassage;
import art.arcane.iris.generation.hydrology.underground.PassageRasterizer;
import art.arcane.iris.generation.hydrology.underground.SealedPassage;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.EnginePlatformHooks;
import art.arcane.iris.generation.runtime.IrisComplex;
@@ -189,8 +190,8 @@ public class MantleCarvedTerrainTest {
}
@Test
public void inletSpaceFromEveryNeighbourChunkReadsAsForeignAndPoolsBesideItStayOutInEitherChunkOrder() {
Scene probe = inletScene();
public void passageSpaceFromEveryNeighbourChunkReadsAsForeignAndPoolsBesideItStayOutInEitherChunkOrder() {
Scene probe = passageScene();
MantleCarvedTerrain carved = probe.carved();
assertEquals("passage water", CaveVoxel.FOREIGN, carved.voxel(7, 28, 21));
assertEquals("passage air", CaveVoxel.FOREIGN, carved.voxel(10, 33, 21));
@@ -201,8 +202,8 @@ public class MantleCarvedTerrainTest {
assertEquals(CaveVoxel.SOLID, carved.voxel(10, 34, 21));
assertEquals(CaveVoxel.SOLID, carved.voxel(10, 25, 26));
Map<Long, HydrologyCaveCell> forward = inletScene().generate(0, 1);
Map<Long, HydrologyCaveCell> reverse = inletScene().generate(1, 0);
Map<Long, HydrologyCaveCell> forward = passageScene().generate(0, 1);
Map<Long, HydrologyCaveCell> reverse = passageScene().generate(1, 0);
assertEquals(forward, reverse);
int top = Integer.MIN_VALUE;
@@ -214,19 +215,19 @@ public class MantleCarvedTerrainTest {
top = Math.max(top, cellY(cell));
for (int[] face : FACES) {
HydrologyCaveCell neighbour = forward.get(cell(cellX(cell) + face[0], cellY(cell) + face[1], cellZ(cell) + face[2]));
assertFalse("pool water at " + cellX(cell) + "," + cellY(cell) + "," + cellZ(cell) + " touches the inlet",
assertFalse("pool water at " + cellX(cell) + "," + cellY(cell) + "," + cellZ(cell) + " touches the passage",
neighbour != null && HydrologyCaveCell.SEA_FLUID.equals(neighbour.fluidProfileKey()));
}
}
assertEquals("the pool stops one level below the inlet seal its next level would reach", 24, top);
assertEquals("the pool stops one level below the passage seal its next level would reach", 24, top);
for (int y = 24; y <= 30; y++) {
assertInlet(forward, 7, y, 19, HydrologyCaveAction.SEAL_GUARD);
assertPassage(forward, 7, y, 19, HydrologyCaveAction.SEAL_GUARD);
}
for (int y = 27; y <= 30; y++) {
assertInlet(forward, 7, y, 21, HydrologyCaveAction.WET_SOURCE);
assertPassage(forward, 7, y, 21, HydrologyCaveAction.WET_SOURCE);
}
for (int y = 31; y <= 33; y++) {
assertInlet(forward, 7, y, 21, HydrologyCaveAction.DRY_AIR);
assertPassage(forward, 7, y, 21, HydrologyCaveAction.DRY_AIR);
}
}
@@ -378,7 +379,7 @@ public class MantleCarvedTerrainTest {
return region;
}
private static Scene inletScene() {
private static Scene passageScene() {
Scene scene = new Scene();
Matter[] room = scene.chunk(0, 0);
for (int x = 2; x <= 13; x++) {
@@ -396,14 +397,14 @@ public class MantleCarvedTerrainTest {
}
}
}
scene.inlets.add(new SeaInlet(77L, new float[]{40f, -8f}, new float[]{22f, 22f}, new float[]{2f, 2f}, 30, new int[]{26, 26},
scene.passages.add(new TestPassage(77L, new float[]{40f, -8f}, new float[]{22f, 22f}, new float[]{2f, 2f}, 30, new int[]{26, 26},
new int[]{33, 33}, -8, 22, 2));
return scene;
}
private static void assertInlet(Map<Long, HydrologyCaveCell> written, int x, int y, int z, HydrologyCaveAction action) {
private static void assertPassage(Map<Long, HydrologyCaveCell> written, int x, int y, int z, HydrologyCaveAction action) {
HydrologyCaveCell cell = written.get(cell(x, y, z));
assertTrue("inlet " + action + " at " + x + "," + y + "," + z + " but found " + cell,
assertTrue("passage " + action + " at " + x + "," + y + "," + z + " but found " + cell,
cell != null && cell.action() == action && HydrologyCaveCell.SEA_FLUID.equals(cell.fluidProfileKey()));
}
@@ -450,7 +451,7 @@ public class MantleCarvedTerrainTest {
private final MantleWriter writer = mock(MantleWriter.class);
private final IrisComplex complex = mock(IrisComplex.class);
private final Engine engine;
private final List<SeaInlet> inlets = new ArrayList<>();
private final List<TestPassage> passages = new ArrayList<>();
private final Map<Long, HydrologyCaveCell> cells = new HashMap<>();
private Scene() {
@@ -486,7 +487,7 @@ public class MantleCarvedTerrainTest {
when(complex.allowsMantleChunkWrite(anyInt(), anyInt())).thenReturn(true);
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
when(runtime.caveFluidPolicies()).thenReturn(true);
when(runtime.inlets(anyInt(), anyInt())).thenAnswer(invocation -> touching(invocation.getArgument(0), invocation.getArgument(1)));
when(runtime.passages(anyInt(), anyInt())).thenAnswer(invocation -> touching(invocation.getArgument(0), invocation.getArgument(1)));
doAnswer(invocation -> {
cells.put(cell(invocation.getArgument(0), invocation.getArgument(1), invocation.getArgument(2)), invocation.getArgument(3));
return null;
@@ -504,11 +505,11 @@ public class MantleCarvedTerrainTest {
return new MantleCarvedTerrain(writer, complex, engine, 0, 0);
}
private List<SeaInlet> touching(int chunkX, int chunkZ) {
List<SeaInlet> touching = new ArrayList<>();
for (SeaInlet inlet : inlets) {
if (SeaInletRasterizer.touches(inlet, chunkX, chunkZ)) {
touching.add(inlet);
private List<SealedPassage> touching(int chunkX, int chunkZ) {
List<SealedPassage> touching = new ArrayList<>();
for (TestPassage passage : passages) {
if (PassageRasterizer.touches(passage, chunkX, chunkZ)) {
touching.add(passage);
}
}
return touching;
@@ -519,11 +520,11 @@ public class MantleCarvedTerrainTest {
config.getFluids().add(new IrisFluidProfile().setName("lava").setPalette(new IrisMaterialPalette().qclear().qadd("minecraft:lava")));
config.getUnderground().getCavePools().setDensity(8D).setFreeboard(new KList<>(0, 0));
HydrologySettings settings = HydrologySettings.compile(config, SEED, 63, 0, 384);
SeaInletRasterizer rasterizer = new SeaInletRasterizer();
PassageRasterizer rasterizer = new PassageRasterizer();
for (int chunkZ : chunkZs) {
for (SeaInlet inlet : complex.getHydrologyRuntime().inlets(0, chunkZ)) {
rasterizer.write(inlet, 0, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, SeaInletRasterizer.SubterrainFluid.NOWHERE,
SeaInletRasterizer.HistoricalChunks.NONE);
for (SealedPassage passage : complex.getHydrologyRuntime().passages(0, chunkZ)) {
rasterizer.write(passage, 0, chunkZ, writer, HydrologyCaveCell.SEA_FLUID, PassageRasterizer.SubterrainFluid.NOWHERE,
PassageRasterizer.HistoricalChunks.NONE);
}
new CavePoolFiller(settings, 0).fill(0, chunkZ, () -> new MantleCarvedTerrain(writer, complex, engine, 0, chunkZ), writer, SEED);
}
@@ -8,8 +8,8 @@ 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.SeaInlet;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.testsupport.TestPassage;
import art.arcane.iris.generation.hydrology.underground.PassageRasterizer;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.EngineMetrics;
import art.arcane.iris.generation.runtime.IrisComplex;
@@ -149,9 +149,9 @@ public class MantleCarvingComponentWaterMaskTest {
}
@Test
public void inletHeadroomJoinsTheProfilePassProtection() throws Exception {
SeaInlet inlet = coveredInlet(32, 40, 40);
installInlet(inlet);
public void passageHeadroomJoinsTheProfilePassProtection() throws Exception {
TestPassage passage = coveredPassage(32, 40, 40);
installPassage(passage);
IrisCaveCarver3D carver = installProfile();
List<long[]> boundaries = new ArrayList<>();
doAnswer(call -> {
@@ -167,14 +167,14 @@ public class MantleCarvingComponentWaterMaskTest {
for (int lz = 0; lz < 16; lz++) {
for (int lx = 0; lx < 16; lx++) {
int index = PowerOfTwoCoordinates.packLocal16(lx, lz);
if (!SeaInletRasterizer.column(inlet, 32 + lx, 32 + lz, column)) {
if (!passage.column(32 + lx, 32 + lz, column)) {
continue;
}
for (int y = inlet.waterLevel() + 1; y <= column[1] + ROOF_CLEARANCE; y++) {
assertTrue("the carver keeps out of the inlet headroom at " + (32 + lx) + "," + y + "," + (32 + lz),
for (int y = passage.waterLevel() + 1; y <= column[1] + ROOF_CLEARANCE; y++) {
assertTrue("the carver keeps out of the passage headroom at " + (32 + lx) + "," + y + "," + (32 + lz),
SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, y));
}
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, inlet.waterLevel()));
assertFalse(SurfaceFluidBoundaryPlan.protects(boundaries.getFirst(), index, passage.waterLevel()));
covered++;
}
}
@@ -182,7 +182,7 @@ public class MantleCarvingComponentWaterMaskTest {
}
@Test
public void subterrainFeaturesStayOutOfInletHeadroom() {
public void subterrainFeaturesStayOutOfPassageHeadroom() {
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
.setWorldYRange(new IrisRange(-48, 60));
@@ -196,40 +196,40 @@ public class MantleCarvingComponentWaterMaskTest {
List<int[]> open = openedCells(chunkX, chunkZ);
int[] heights = open.stream().mapToInt(cell -> cell[1]).sorted().toArray();
int water = heights[heights.length / 4];
SeaInlet inlet = coveredInlet(chunkX << 4, (chunkZ << 4) + 8, water);
TestPassage passage = coveredPassage(chunkX << 4, (chunkZ << 4) + 8, water);
int[] column = new int[2];
int inside = 0;
for (int[] cell : open) {
if (SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > water && cell[1] <= column[1] + ROOF_CLEARANCE) {
if (passage.column(cell[0], cell[2], column) && cell[1] > water && cell[1] <= column[1] + ROOF_CLEARANCE) {
inside++;
}
}
assertTrue("subterrain cells in the headroom before the inlet " + inside, inside > 20);
assertTrue("subterrain cells in the headroom before the passage " + inside, inside > 20);
installInlet(inlet);
installPassage(passage);
List<int[]> sealed = openedCells(chunkX, chunkZ);
assertTrue(sealed.size() > 0);
for (int[] cell : sealed) {
boolean headroom = SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > water
boolean headroom = passage.column(cell[0], cell[2], column) && cell[1] > water
&& cell[1] <= column[1] + ROOF_CLEARANCE;
assertFalse("subterrain opened " + cell[0] + "," + cell[1] + "," + cell[2] + " in the inlet headroom", headroom);
assertFalse("subterrain opened " + cell[0] + "," + cell[1] + "," + cell[2] + " in the passage headroom", headroom);
}
}
}
private void installInlet(SeaInlet inlet) {
when(hydrology.inlets(anyInt(), anyInt())).thenAnswer(call -> SeaInletRasterizer.touches(inlet, call.getArgument(0), call.getArgument(1))
? List.of(inlet) : List.of());
private void installPassage(TestPassage passage) {
when(hydrology.passages(anyInt(), anyInt())).thenAnswer(call -> PassageRasterizer.touches(passage, call.getArgument(0), call.getArgument(1))
? List.of(passage) : List.of());
when(hydrology.settings()).thenReturn(HydrologySettings.compile(new IrisHydrology().setEnabled(true), 1L, 63, 0, 128));
}
private static SeaInlet coveredInlet(int startX, int z, int water) {
private static TestPassage coveredPassage(int startX, int z, int water) {
float[] xs = {startX - 4f, startX + 4f, startX + 12f, startX + 20f};
float[] zs = {z, z, z, z};
float[] halfWidth = {4f, 4f, 3.5f, 3f};
int[] floor = {water - 3, water - 3, water - 3, water - 3};
int[] ceiling = {water + 5, water + 5, water + 4, water + 4};
return new SeaInlet(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
return new TestPassage(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
}
private List<int[]> openedCells(int chunkX, int chunkZ) {
@@ -9,7 +9,7 @@ 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.testsupport.TestPassage;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.IrisComplex;
import art.arcane.iris.generation.subterrain.SubterrainCell;
@@ -263,11 +263,11 @@ public class MantleHydrologyComponentTest {
}
@Test
public void seaInletsAreWrittenEvenWhereNoSurfaceWaterFlows() {
public void passagesAreWrittenEvenWhereNoSurfaceWaterFlows() {
Fixture dry = new Fixture(ChunkWaterRaster.EMPTY, (x, z) -> 99);
SeaInlet inlet = new SeaInlet(5L, new float[]{-8f, 8f, 24f}, new float[]{8f, 8f, 8f}, new float[]{4f, 4f, 3f}, 63,
TestPassage passage = new TestPassage(5L, new float[]{-8f, 8f, 24f}, new float[]{8f, 8f, 8f}, new float[]{4f, 4f, 3f}, 63,
new int[]{60, 60, 59}, new int[]{90, 68, 67}, 24, 8, 6);
when(dry.runtime.inlets(0, 0)).thenReturn(List.of(inlet));
when(dry.runtime.passages(0, 0)).thenReturn(List.of(passage));
List<HydrologyCaveCell> written = new ArrayList<>();
List<Integer> heights = new ArrayList<>();
doAnswer(call -> {
@@ -286,15 +286,15 @@ public class MantleHydrologyComponentTest {
assertTrue(heights.get(index) <= 63);
}
}
assertTrue("wet inlet cells " + wet, wet > 100);
assertTrue("wet passage cells " + wet, wet > 100);
}
@Test
public void subterrainFluidBesideSeaInletAirIsSealedAboveSeaLevel() {
public void subterrainFluidBesidePassageAirIsSealedAboveSeaLevel() {
Fixture dry = new Fixture(ChunkWaterRaster.EMPTY, (x, z) -> 99);
SeaInlet inlet = new SeaInlet(5L, new float[]{-8f, 8f, 24f}, new float[]{8f, 8f, 8f}, new float[]{4f, 4f, 3f}, 63,
TestPassage passage = new TestPassage(5L, new float[]{-8f, 8f, 24f}, new float[]{8f, 8f, 8f}, new float[]{4f, 4f, 3f}, 63,
new int[]{60, 60, 59}, new int[]{90, 68, 67}, 24, 8, 6);
when(dry.runtime.inlets(0, 0)).thenReturn(List.of(inlet));
when(dry.runtime.passages(0, 0)).thenReturn(List.of(passage));
SubterrainPlanner planner = mock(SubterrainPlanner.class);
List<SubterrainPlan> plans = List.of(mock(SubterrainPlan.class));
SubterrainCell water = new SubterrainCell(SubterrainCell.Kind.WATER, "", null);
@@ -318,7 +318,7 @@ public class MantleHydrologyComponentTest {
dry.generate();
assertEquals("inlet air keeps its cell", HydrologyCaveAction.DRY_AIR, cells.get(cell(4, 69, 8)).action());
assertEquals("passage air keeps its cell", HydrologyCaveAction.DRY_AIR, cells.get(cell(4, 69, 8)).action());
assertEquals("subterrain water beside the passage", HydrologyCaveAction.SEAL_GUARD, cells.get(cell(8, 69, 13)).action());
assertEquals("subterrain water over the passage roof", HydrologyCaveAction.SEAL_GUARD, cells.get(cell(12, 69, 8)).action());
assertNull("subterrain water three blocks from the passage", cells.get(cell(8, 69, 15)));
@@ -7,8 +7,8 @@ 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.SeaInlet;
import art.arcane.iris.generation.hydrology.underground.SeaInletRasterizer;
import art.arcane.iris.testsupport.TestPassage;
import art.arcane.iris.generation.hydrology.underground.PassageRasterizer;
import art.arcane.iris.generation.mantle.EngineMantle;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.generation.runtime.IrisComplex;
@@ -87,7 +87,7 @@ public class IrisCarveModifierSubterrainMaskTest {
}
@Test
public void preservedSubterrainStaysOutOfInletHeadroom() {
public void preservedSubterrainStaysOutOfPassageHeadroom() {
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
.setWorldYRange(new IrisRange(-48, 60));
@@ -103,23 +103,23 @@ public class IrisCarveModifierSubterrainMaskTest {
List<int[]> open = reopenedCells(modifier, planner, blockX, blockZ);
int[] heights = open.stream().mapToInt(cell -> cell[1]).sorted().toArray();
int water = heights[heights.length / 4];
SeaInlet inlet = coveredInlet(blockX, blockZ + 8, water);
assertTrue("subterrain cells in the headroom before the inlet " + inHeadroom(inlet, open).size(), inHeadroom(inlet, open).size() > 20);
TestPassage passage = coveredPassage(blockX, blockZ + 8, water);
assertTrue("subterrain cells in the headroom before the passage " + inHeadroom(passage, open).size(), inHeadroom(passage, open).size() > 20);
when(hydrology.inlets(anyInt(), anyInt())).thenAnswer(call -> SeaInletRasterizer.touches(inlet, call.getArgument(0),
call.getArgument(1)) ? List.of(inlet) : List.of());
when(hydrology.passages(anyInt(), anyInt())).thenAnswer(call -> PassageRasterizer.touches(passage, call.getArgument(0),
call.getArgument(1)) ? List.of(passage) : List.of());
when(hydrology.settings()).thenReturn(HydrologySettings.compile(new IrisHydrology().setEnabled(true), 1L, 63, 0, 128));
List<int[]> sealed = reopenedCells(modifier, planner, blockX, blockZ);
assertTrue(sealed.size() > 0);
assertEquals("subterrain reopened cells in the inlet headroom", List.of(), inHeadroom(inlet, sealed));
assertEquals("subterrain reopened cells in the passage headroom", List.of(), inHeadroom(passage, sealed));
}
}
private static List<String> inHeadroom(SeaInlet inlet, List<int[]> cells) {
private static List<String> inHeadroom(TestPassage passage, List<int[]> cells) {
List<String> inside = new ArrayList<>();
int[] column = new int[2];
for (int[] cell : cells) {
if (SeaInletRasterizer.column(inlet, cell[0], cell[2], column) && cell[1] > inlet.waterLevel()
if (passage.column(cell[0], cell[2], column) && cell[1] > passage.waterLevel()
&& cell[1] <= column[1] + ROOF_CLEARANCE) {
inside.add(cell[0] + "," + cell[1] + "," + cell[2]);
}
@@ -127,13 +127,13 @@ public class IrisCarveModifierSubterrainMaskTest {
return inside;
}
private static SeaInlet coveredInlet(int startX, int z, int water) {
private static TestPassage coveredPassage(int startX, int z, int water) {
float[] xs = {startX - 4f, startX + 4f, startX + 12f, startX + 20f};
float[] zs = {z, z, z, z};
float[] halfWidth = {4f, 4f, 3.5f, 3f};
int[] floor = {water - 3, water - 3, water - 3, water - 3};
int[] ceiling = {water + 5, water + 5, water + 4, water + 4};
return new SeaInlet(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
return new TestPassage(5L, xs, zs, halfWidth, water, floor, ceiling, startX + 20, z, 3);
}
@SuppressWarnings("unchecked")
@@ -155,7 +155,7 @@ public class IrisCarveModifierSubterrainMaskTest {
}
@Test
public void preservedSubterrainLeavesEveryInletCellAlone() {
public void preservedSubterrainLeavesEveryPassageCellAlone() {
IrisSubterrainFeature feature = new IrisSubterrainFeature().setId("room").setFamily(IrisSubterrainFamily.CENOTE)
.setProbability(1).setLength(64).setRadius(12).setHeight(24).setPillarSpacing(0).setFormationFraction(0)
.setWorldYRange(new IrisRange(-48, 60));
@@ -165,8 +165,8 @@ public class IrisCarveModifierSubterrainMaskTest {
int blockZ = plan.centerZ() >> 4 << 4;
HydrologyRuntime hydrology = mock(HydrologyRuntime.class);
when(hydrology.raster(anyInt(), anyInt())).thenReturn(ChunkWaterRaster.EMPTY);
Map<Long, HydrologyCaveCell> inlet = new HashMap<>();
IrisCarveModifier modifier = modifier(planner, hydrology, inlet);
Map<Long, HydrologyCaveCell> passage = new HashMap<>();
IrisCarveModifier modifier = modifier(planner, hydrology, passage);
try (MockedStatic<B> blocks = mockStatic(B.class)) {
blocks.when(() -> B.getState(anyString())).thenReturn(mock(NativeBlockState.class));
Set<Long> room = written(modifier, blockX, blockZ);
@@ -178,14 +178,14 @@ public class IrisCarveModifierSubterrainMaskTest {
if (y <= water + 2 && y >= water - 3) {
HydrologyCaveAction action = y > water ? HydrologyCaveAction.DRY_AIR
: y == water - 3 ? HydrologyCaveAction.SEAL_GUARD : HydrologyCaveAction.WET_SOURCE;
inlet.put(cell, new HydrologyCaveCell(action, HydrologyCaveCell.SEA_FLUID));
passage.put(cell, new HydrologyCaveCell(action, HydrologyCaveCell.SEA_FLUID));
}
}
assertTrue("inlet cells crossing the room " + inlet.size(), inlet.size() > 20);
assertTrue("passage cells crossing the room " + passage.size(), passage.size() > 20);
Set<Long> crossed = written(modifier, blockX, blockZ);
assertTrue("the room still opens away from the inlet", crossed.size() > 0);
for (long cell : inlet.keySet()) {
assertFalse("the room reopened inlet cell at y " + SubterrainMaskKeys.y(cell), crossed.contains(cell));
assertTrue("the room still opens away from the passage", crossed.size() > 0);
for (long cell : passage.keySet()) {
assertFalse("the room reopened passage cell at y " + SubterrainMaskKeys.y(cell), crossed.contains(cell));
}
}
}
@@ -195,7 +195,7 @@ public class IrisCarveModifierSubterrainMaskTest {
}
@SuppressWarnings("unchecked")
private static IrisCarveModifier modifier(SubterrainPlanner planner, HydrologyRuntime hydrology, Map<Long, HydrologyCaveCell> inlet) {
private static IrisCarveModifier modifier(SubterrainPlanner planner, HydrologyRuntime hydrology, Map<Long, HydrologyCaveCell> passage) {
Engine engine = mock(Engine.class);
EngineMantle engineMantle = mock(EngineMantle.class);
Mantle<Matter> mantle = mock(Mantle.class);
@@ -204,7 +204,7 @@ public class IrisCarveModifierSubterrainMaskTest {
when(engineMantle.getMantle()).thenReturn(mantle);
when(mantle.useChunk(anyInt(), anyInt())).thenReturn(chunk);
when(chunk.exists(anyInt())).thenReturn(true);
when(chunk.get(anyInt())).thenAnswer(call -> section(call.getArgument(0), inlet));
when(chunk.get(anyInt())).thenAnswer(call -> section(call.getArgument(0), passage));
IrisComplex complex = mock(IrisComplex.class);
when(engine.getWorld()).thenReturn(IrisWorld.builder().minHeight(MINIMUM_Y).maxHeight(64).build());
when(engine.getComplex()).thenReturn(complex);
@@ -218,12 +218,12 @@ public class IrisCarveModifierSubterrainMaskTest {
}
@SuppressWarnings("unchecked")
private static Matter section(int section, Map<Long, HydrologyCaveCell> inlet) {
private static Matter section(int section, Map<Long, HydrologyCaveCell> passage) {
Matter matter = mock(Matter.class);
MatterSlice<HydrologyCaveCell> slice = mock(MatterSlice.class);
when(matter.hasSlice(HydrologyCaveCell.class)).thenReturn(true);
when(matter.getSlice(HydrologyCaveCell.class)).thenReturn(slice);
when(slice.get(anyInt(), anyInt(), anyInt())).thenAnswer(call -> inlet.get(SubterrainMaskKeys.key(call.getArgument(0),
when(slice.get(anyInt(), anyInt(), anyInt())).thenAnswer(call -> passage.get(SubterrainMaskKeys.key(call.getArgument(0),
section * 16 + (int) call.getArgument(1), call.getArgument(2))));
return matter;
}
@@ -0,0 +1,70 @@
package art.arcane.iris.testsupport;
import art.arcane.iris.generation.hydrology.underground.SealedPassage;
public record TestPassage(long id, float[] xs, float[] zs, float[] halfWidth, int waterLevel, int[] floor, int[] ceiling, int chamberX,
int chamberZ, int chamberRadius) implements SealedPassage {
public static final int ROOF_CLEARANCE = 6;
public int stations() {
return xs.length;
}
@Override
public int roofClearance() {
return ROOF_CLEARANCE;
}
@Override
public int[] bounds() {
float minX = chamberX - chamberRadius;
float minZ = chamberZ - chamberRadius;
float maxX = chamberX + chamberRadius + 1;
float maxZ = chamberZ + chamberRadius + 1;
for (int station = 0; station < stations(); station++) {
float reach = halfWidth[station] + 1f;
minX = Math.min(minX, xs[station] - reach);
minZ = Math.min(minZ, zs[station] - reach);
maxX = Math.max(maxX, xs[station] + reach);
maxZ = Math.max(maxZ, zs[station] + reach);
}
return new int[]{(int) Math.floor(minX), (int) Math.floor(minZ), (int) Math.ceil(maxX), (int) Math.ceil(maxZ)};
}
@Override
public boolean column(int x, int z, int[] out) {
double px = x + 0.5D;
double pz = z + 0.5D;
int lowest = Integer.MAX_VALUE;
int highest = Integer.MIN_VALUE;
for (int station = 0; station + 1 < xs.length; station++) {
double ax = xs[station];
double az = zs[station];
double dx = xs[station + 1] - ax;
double dz = zs[station + 1] - az;
double span = dx * dx + dz * dz;
double t = span <= 0D ? 0D : Math.clamp(((px - ax) * dx + (pz - az) * dz) / span, 0D, 1D);
double distance = Math.hypot(px - (ax + t * dx), pz - (az + t * dz));
double half = halfWidth[station] + t * (halfWidth[station + 1] - halfWidth[station]);
if (distance > half) {
continue;
}
lowest = Math.min(lowest, (int) Math.round(floor[station] + t * (floor[station + 1] - floor[station])));
highest = Math.max(highest, (int) Math.round(ceiling[station] + t * (ceiling[station + 1] - ceiling[station])));
}
double radius = chamberRadius;
double fromCentre = Math.hypot(px - chamberX, pz - chamberZ);
if (fromCentre <= radius) {
int last = xs.length - 1;
double dome = Math.sqrt(1D - (fromCentre / radius) * (fromCentre / radius));
lowest = Math.min(lowest, waterLevel - (int) Math.max(1L, Math.round((waterLevel - floor[last]) * dome)));
highest = Math.max(highest, waterLevel + (int) Math.round((ceiling[last] - waterLevel) * dome));
}
if (highest == Integer.MIN_VALUE) {
return false;
}
out[0] = lowest;
out[1] = highest;
return true;
}
}