mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Gate pool and inlet leaks
- Count sea inlet added leaks as leak cells present only with inlets on - Fail the cave pool gate on pool cells that are not still sources of their fluid - Compare pool sources against the fluid each cell resolves to
This commit is contained in:
1 parent
1ae68646b4
commit
75d28d16b2
4 files changed
+90
-25
No files matched your search
@@ -76,7 +76,12 @@ public final class CavePoolProbe {
|
||||
Map<Integer, Integer> chunkSpans, int airLeaks, int openLeaks, int skyLeaks, int foreignFluid, int waterloggableWalls,
|
||||
int unsupportedGravity, int fluidAbove, int gravityCeilings, Map<String, Integer> replaced, List<String> examples) {
|
||||
long failures() {
|
||||
return (long) airLeaks + openLeaks + skyLeaks + foreignFluid + waterloggableWalls + unsupportedGravity + fluidAbove + gravityCeilings;
|
||||
long replacedCells = 0L;
|
||||
for (int cells : replaced.values()) {
|
||||
replacedCells += cells;
|
||||
}
|
||||
return (long) airLeaks + openLeaks + skyLeaks + foreignFluid + waterloggableWalls + unsupportedGravity + fluidAbove + gravityCeilings
|
||||
+ replacedCells;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +257,8 @@ public final class CavePoolProbe {
|
||||
}
|
||||
pool.add(new Cell(pack((chunkX << 4) + x, y, (chunkZ << 4) + z), cell.fluidProfileKey()));
|
||||
NativeBlockState state = blocks.get(x, y, z);
|
||||
if (!source(state, cell.fluidProfileKey())) {
|
||||
NativeBlockState expected = engine.getComplex().resolveCaveCellFluid(cell.fluidProfileKey(), (chunkX << 4) + x, (chunkZ << 4) + z);
|
||||
if (!source(state, expected)) {
|
||||
replaced.merge(cell.fluidProfileKey() + "->" + (state == null ? "null" : state.key()), 1, Integer::sum);
|
||||
}
|
||||
});
|
||||
@@ -262,14 +268,13 @@ public final class CavePoolProbe {
|
||||
return guards[0];
|
||||
}
|
||||
|
||||
private static boolean source(NativeBlockState state, String fluid) {
|
||||
static boolean source(NativeBlockState state, NativeBlockState expected) {
|
||||
if (state == null || !state.isFluid()) {
|
||||
return false;
|
||||
}
|
||||
String level = IrisProceduralBlocks.propertyValue(state, "level");
|
||||
boolean still = level == null || "0".equals(level);
|
||||
boolean matches = "lava".equals(fluid) ? state.key().startsWith("minecraft:lava") : state.isWater();
|
||||
return still && matches;
|
||||
return still && IrisProceduralBlocks.materialKey(state).equals(IrisProceduralBlocks.materialKey(expected));
|
||||
}
|
||||
|
||||
private static ChunkRecord record(Hunk<NativeBlockState> blocks, int height) {
|
||||
|
||||
@@ -265,19 +265,15 @@ public final class SeaInletProbe {
|
||||
}
|
||||
}
|
||||
|
||||
record Gate(Checks checks, int orderMismatches, int inletsWithOtherLevel, int waterLeaksOn, int waterLeaksOff) {
|
||||
long addedLeaks() {
|
||||
return Math.max(0, waterLeaksOn - waterLeaksOff);
|
||||
}
|
||||
|
||||
record Gate(Checks checks, int orderMismatches, int inletsWithOtherLevel, int addedLeaks) {
|
||||
long failures() {
|
||||
return checks.failures() + orderMismatches + inletsWithOtherLevel + addedLeaks();
|
||||
return checks.failures() + orderMismatches + inletsWithOtherLevel + addedLeaks;
|
||||
}
|
||||
|
||||
String line() {
|
||||
return String.format(Locale.ROOT, "SEA_INLET_GATE status=%s failures=%d checkFailures=%d orderMismatches=%d inletsWithOtherLevel=%d"
|
||||
+ " addedLeaks=%d", failures() == 0L ? "PASS" : "FAIL", failures(), checks.failures(), orderMismatches,
|
||||
inletsWithOtherLevel, addedLeaks());
|
||||
inletsWithOtherLevel, addedLeaks);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,8 +395,9 @@ public final class SeaInletProbe {
|
||||
}
|
||||
Scan scan = new Scan(on, sea, clearance, owned);
|
||||
scan.run();
|
||||
int onLeaks = scan.countAllLeaks();
|
||||
int offLeaks = new Scan(off, sea, clearance, owned).countAllLeaks();
|
||||
Set<Long> onLeaks = scan.allLeaks();
|
||||
Set<Long> offLeaks = new Scan(off, sea, clearance, owned).allLeaks();
|
||||
int addedLeaks = addedLeaks(onLeaks, offLeaks);
|
||||
int mismatches = mismatches(on.hashes, reverse.hashes);
|
||||
|
||||
System.out.println("SEA_INLET_INVENTORY owned=" + owned.size() + " touching=" + touching.size());
|
||||
@@ -428,7 +425,8 @@ public final class SeaInletProbe {
|
||||
scan.total.missingWater, scan.total.seaPlants, scan.total.seaLayers, scan.total.decorations, scan.total.nonSource,
|
||||
scan.total.waterAbove, scan.total.wet, scan.total.dry);
|
||||
System.out.printf(Locale.ROOT, "SEA_INLET_LEVEL sea=%d inletsWithOtherLevel=%d%n", sea, offLevel);
|
||||
System.out.printf(Locale.ROOT, "SEA_INLET_ALL_WATER_LEAKS scanChunks=%d inletsOn=%d inletsOff=%d%n", on.bands.size(), onLeaks, offLeaks);
|
||||
System.out.printf(Locale.ROOT, "SEA_INLET_ALL_WATER_LEAKS scanChunks=%d inletsOn=%d inletsOff=%d added=%d%n", on.bands.size(),
|
||||
onLeaks.size(), offLeaks.size(), addedLeaks);
|
||||
System.out.printf(Locale.ROOT, "SEA_INLET_ROOF min=%d violations=%d breaches=%d openRoofViolations=%d coveredColumns=%d openColumns=%d%n",
|
||||
scan.total.roofMin, scan.total.roofViolations, scan.total.roofBreaches, scan.total.openRoofViolations, scan.total.covered,
|
||||
scan.total.open);
|
||||
@@ -438,7 +436,7 @@ public final class SeaInletProbe {
|
||||
scan.shellOpen, scan.shellLoose, maxOpenLandStations(owned), scan.total.looseBeds);
|
||||
System.out.printf(Locale.ROOT, "SEA_INLET_DETERMINISM chunks=%d reverseChunks=%d mismatches=%d crossChunkInlets=%d crossWindowInlets=%d%n",
|
||||
on.hashes.size(), reverse.hashes.size(), mismatches, scan.crossChunk(), scan.crossWindow());
|
||||
Gate gate = new Gate(checks(scan), mismatches, offLevel, onLeaks, offLeaks);
|
||||
Gate gate = new Gate(checks(scan), mismatches, offLevel, addedLeaks);
|
||||
System.out.println(gate.line());
|
||||
return gate;
|
||||
}
|
||||
@@ -513,6 +511,18 @@ public final class SeaInletProbe {
|
||||
return (int) key;
|
||||
}
|
||||
|
||||
static int addedLeaks(Set<Long> on, Set<Long> off) {
|
||||
int added = 0;
|
||||
for (long leak : on) {
|
||||
added += off.contains(leak) ? 0 : 1;
|
||||
}
|
||||
return added;
|
||||
}
|
||||
|
||||
static long cellKey(int x, int y, int z) {
|
||||
return ((long) x & 0x3FFFFFFL) << 38 | ((long) z & 0x3FFFFFFL) << 12 | (y & 0xFFFL);
|
||||
}
|
||||
|
||||
static byte classify(NativeBlockState state, String seaFluid) {
|
||||
if (state == null || state.isAir()) {
|
||||
return AIR;
|
||||
@@ -991,8 +1001,8 @@ public final class SeaInletProbe {
|
||||
return level >= 0 && level < band.levels && seen[((z & 15) << 4 | (x & 15)) * band.levels + level];
|
||||
}
|
||||
|
||||
private int countAllLeaks() {
|
||||
int leaks = 0;
|
||||
private Set<Long> allLeaks() {
|
||||
Set<Long> leaks = new HashSet<>();
|
||||
for (Band band : run.bands.values()) {
|
||||
for (int lz = 0; lz < 16; lz++) {
|
||||
for (int lx = 0; lx < 16; lx++) {
|
||||
@@ -1012,7 +1022,7 @@ public final class SeaInletProbe {
|
||||
byte below = band.at(lx, y - 1, lz);
|
||||
open |= below == AIR || below == OTHER;
|
||||
if (open) {
|
||||
leaks++;
|
||||
leaks.add(cellKey(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package art.arcane.iris.probe;
|
||||
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class CavePoolChecksTest {
|
||||
@Test
|
||||
@@ -28,6 +32,30 @@ public class CavePoolChecksTest {
|
||||
assertTrue(failing.line(), failing.line().startsWith("CAVE_POOL_GATE status=FAIL failures=37 "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolCellsThatDidNotStayStillSourcesOfTheirFluidFail() {
|
||||
CavePoolProbe.Counts replaced = new CavePoolProbe.Counts(1, 1, 1, 1, Map.of(), List.of(), List.of(), Map.of(), 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
Map.of("water->minecraft:stone", 2, "lava->null", 1), List.of());
|
||||
assertEquals(3L, replaced.failures());
|
||||
assertEquals(3L, new CavePoolProbe.Gate(replaced, 0).failures());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void poolSourcesMatchTheFluidTheCellResolvesTo() {
|
||||
NativeBlockState water = fluid("minecraft:water", true);
|
||||
NativeBlockState lava = fluid("minecraft:lava", false);
|
||||
assertTrue(CavePoolProbe.source(fluid("minecraft:water", true), water));
|
||||
assertTrue(CavePoolProbe.source(fluid("minecraft:water[level=0]", true), water));
|
||||
assertFalse("flowing water is not a pool source", CavePoolProbe.source(fluid("minecraft:water[level=1]", true), water));
|
||||
assertFalse("lava is not a water pool source", CavePoolProbe.source(fluid("minecraft:lava", false), water));
|
||||
assertTrue(CavePoolProbe.source(fluid("minecraft:lava[level=0]", false), lava));
|
||||
assertFalse(CavePoolProbe.source(fluid("minecraft:water", true), lava));
|
||||
assertFalse(CavePoolProbe.source(null, water));
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
when(stone.key()).thenReturn("minecraft:stone");
|
||||
assertFalse(CavePoolProbe.source(stone, water));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void orderMismatchesCountChunksWhoseHashesDiffer() {
|
||||
assertEquals(0, CavePoolProbe.compare(Map.of(1L, 10L, 2L, 20L), Map.of(2L, 20L, 1L, 10L)));
|
||||
@@ -40,4 +68,12 @@ public class CavePoolChecksTest {
|
||||
return new CavePoolProbe.Counts(1, 1, 1, 1, Map.of(), List.of(), List.of(), Map.of(), air, open, sky, foreign, waterlogged, gravity,
|
||||
fluidAbove, gravityCeilings, Map.of(), List.of());
|
||||
}
|
||||
|
||||
private static NativeBlockState fluid(String key, boolean water) {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.key()).thenReturn(key);
|
||||
when(state.isFluid()).thenReturn(true);
|
||||
when(state.isWater()).thenReturn(water);
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
@@ -29,19 +30,32 @@ public class SeaInletChecksTest {
|
||||
@Test
|
||||
public void theGateFailsOnEveryCheckIncludingOrderSeaLevelAndAddedLeaks() {
|
||||
SeaInletProbe.Checks clean = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 952L, List.of());
|
||||
SeaInletProbe.Gate passing = new SeaInletProbe.Gate(clean, 0, 0, 7, 7);
|
||||
SeaInletProbe.Gate passing = new SeaInletProbe.Gate(clean, 0, 0, 0);
|
||||
assertEquals(0L, passing.failures());
|
||||
assertTrue(passing.line(), passing.line().startsWith("SEA_INLET_GATE status=PASS failures=0 "));
|
||||
assertEquals("inlets that remove natural leaks do not fail", 0L, new SeaInletProbe.Gate(clean, 0, 0, 5, 7).failures());
|
||||
assertEquals(2L, new SeaInletProbe.Gate(clean, 0, 0, 9, 7).failures());
|
||||
assertEquals(1L, new SeaInletProbe.Gate(clean, 1, 0, 7, 7).failures());
|
||||
assertEquals(1L, new SeaInletProbe.Gate(clean, 0, 1, 7, 7).failures());
|
||||
assertEquals(2L, new SeaInletProbe.Gate(clean, 0, 0, 2).failures());
|
||||
assertEquals(1L, new SeaInletProbe.Gate(clean, 1, 0, 0).failures());
|
||||
assertEquals(1L, new SeaInletProbe.Gate(clean, 0, 1, 0).failures());
|
||||
SeaInletProbe.Checks breached = new SeaInletProbe.Checks(3, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 0L, 0L, List.of());
|
||||
SeaInletProbe.Gate failing = new SeaInletProbe.Gate(breached, 0, 0, 0, 0);
|
||||
SeaInletProbe.Gate failing = new SeaInletProbe.Gate(breached, 0, 0, 0);
|
||||
assertEquals(4L, failing.failures());
|
||||
assertTrue(failing.line(), failing.line().startsWith("SEA_INLET_GATE status=FAIL failures=4 "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addedLeaksAreTheLeaksMissingWithoutInlets() {
|
||||
long kept = SeaInletProbe.cellKey(10, 300, -20);
|
||||
long removed = SeaInletProbe.cellKey(11, 300, -20);
|
||||
long added = SeaInletProbe.cellKey(10, 301, -20);
|
||||
assertEquals(0, SeaInletProbe.addedLeaks(Set.of(kept), Set.of(kept)));
|
||||
assertEquals("inlets that remove natural leaks do not fail", 0, SeaInletProbe.addedLeaks(Set.of(kept), Set.of(kept, removed)));
|
||||
assertEquals("a leak the inlets move counts although the totals match", 1, SeaInletProbe.addedLeaks(Set.of(kept, added),
|
||||
Set.of(kept, removed)));
|
||||
assertEquals(2, SeaInletProbe.addedLeaks(Set.of(added, removed), Set.of()));
|
||||
assertNotEquals(SeaInletProbe.cellKey(-1, 300, 0), SeaInletProbe.cellKey(0, 300, -1));
|
||||
assertNotEquals(SeaInletProbe.cellKey(5, 0, 5), SeaInletProbe.cellKey(5, 4095, 5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inletCellsAreClassifiedAgainstTheDimensionSeaFluid() {
|
||||
assertEquals(SeaInletProbe.classify(state("minecraft:water"), "minecraft:water"), SeaInletProbe.classify(state("minecraft:lava"),
|
||||
|
||||
Reference in new issue
Block a user