This commit is contained in:
Brian Neumann-Fopiano committed 2026-08-12 13:52:16 -04:00
1 parent 12b97b7994
commit 365205ad0a
82 files changed
+7978 -5625

No files matched your search

@@ -43,4 +43,20 @@ public class IrisCarveModifierFluidIntentTest {
assertTrue(IrisCarveModifier.usesDefaultLava(18, 18));
assertFalse(IrisCarveModifier.usesDefaultLava(18, 19));
}
@Test
public void unsupportedSurfaceOreIsRemovedOnlyOverCarvedAir() {
PlatformBlockState ore = mock(PlatformBlockState.class);
PlatformBlockState ordinarySurface = mock(PlatformBlockState.class);
PlatformBlockState air = mock(PlatformBlockState.class);
PlatformBlockState solid = mock(PlatformBlockState.class);
when(ore.isOre()).thenReturn(true);
when(ordinarySurface.isOre()).thenReturn(false);
when(air.isSolid()).thenReturn(false);
when(solid.isSolid()).thenReturn(true);
assertTrue(IrisCarveModifier.isUnsupportedSurfaceOre(ore, air));
assertFalse(IrisCarveModifier.isUnsupportedSurfaceOre(ore, solid));
assertFalse(IrisCarveModifier.isUnsupportedSurfaceOre(ordinarySurface, air));
}
}
@@ -1,10 +1,7 @@
package art.arcane.iris.engine.modifier;
import org.junit.BeforeClass;
import org.junit.Test;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@@ -15,32 +12,14 @@ import java.util.Set;
import static org.junit.Assert.assertEquals;
public class IrisCarveModifierZoneParityTest {
private static Constructor<?> columnMaskConstructor;
private static Method addMethod;
private static Method nextSetBitMethod;
private static Method clearMethod;
@BeforeClass
public static void setup() throws Exception {
Class<?> columnMaskClass = Class.forName("art.arcane.iris.engine.modifier.IrisCarveModifier$ColumnMask");
columnMaskConstructor = columnMaskClass.getDeclaredConstructor();
addMethod = columnMaskClass.getDeclaredMethod("add", int.class);
nextSetBitMethod = columnMaskClass.getDeclaredMethod("nextSetBit", int.class);
clearMethod = columnMaskClass.getDeclaredMethod("clear");
columnMaskConstructor.setAccessible(true);
addMethod.setAccessible(true);
nextSetBitMethod.setAccessible(true);
clearMethod.setAccessible(true);
}
@Test
public void randomColumnZonesMatchLegacySortedResolver() throws Exception {
Object columnMask = columnMaskConstructor.newInstance();
public void randomColumnZonesMatchLegacySortedResolver() {
CarveColumnMask columnMask = new CarveColumnMask();
Random random = new Random(913_447L);
int maxHeight = 320;
for (int scenario = 0; scenario < 400; scenario++) {
clearMethod.invoke(columnMask);
columnMask.clear();
int sampleSize = 1 + random.nextInt(180);
Set<Integer> uniqueHeights = new HashSet<>();
@@ -50,7 +29,7 @@ public class IrisCarveModifierZoneParityTest {
int[] heights = toIntArray(uniqueHeights);
for (int index = 0; index < heights.length; index++) {
addMethod.invoke(columnMask, heights[index]);
columnMask.add(heights[index]);
}
List<String> expectedZones = legacyZones(heights, maxHeight);
@@ -60,8 +39,8 @@ public class IrisCarveModifierZoneParityTest {
}
@Test
public void edgeColumnsMatchLegacySortedResolver() throws Exception {
Object columnMask = columnMaskConstructor.newInstance();
public void edgeColumnsMatchLegacySortedResolver() {
CarveColumnMask columnMask = new CarveColumnMask();
int maxHeight = 320;
int[][] scenarios = new int[][]{
{-10, -1, 0, 1, 2, 5, 6, 9, 10, 11, 12, 200, 201, 205},
@@ -71,10 +50,10 @@ public class IrisCarveModifierZoneParityTest {
};
for (int scenario = 0; scenario < scenarios.length; scenario++) {
clearMethod.invoke(columnMask);
columnMask.clear();
int[] heights = Arrays.copyOf(scenarios[scenario], scenarios[scenario].length);
for (int index = 0; index < heights.length; index++) {
addMethod.invoke(columnMask, heights[index]);
columnMask.add(heights[index]);
}
List<String> expectedZones = legacyZones(heights, maxHeight);
@@ -131,9 +110,9 @@ public class IrisCarveModifierZoneParityTest {
return zones;
}
private List<String> bitsetZones(Object columnMask, int maxHeight) throws Exception {
private List<String> bitsetZones(CarveColumnMask columnMask, int maxHeight) {
List<String> zones = new ArrayList<>();
int firstHeight = nextSetBit(columnMask, 0);
int firstHeight = columnMask.nextSetBit(0);
if (firstHeight < 0) {
return zones;
}
@@ -159,7 +138,7 @@ public class IrisCarveModifierZoneParityTest {
}
}
y = nextSetBit(columnMask, y + 1);
y = columnMask.nextSetBit(y + 1);
}
if (isValidZone(floor, ceiling, maxHeight)) {
@@ -169,10 +148,6 @@ public class IrisCarveModifierZoneParityTest {
return zones;
}
private int nextSetBit(Object columnMask, int fromBit) throws Exception {
return (Integer) nextSetBitMethod.invoke(columnMask, fromBit);
}
private boolean isValidZone(int floor, int ceiling, int maxHeight) {
return floor < ceiling
&& floor >= 0
@@ -0,0 +1,67 @@
package art.arcane.iris.engine.modifier;
import art.arcane.volmlib.util.matter.MatterCavern;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
public class IrisCarveScratchTest {
@Test
public void wallBufferResizesAndReplacesWithoutLosingEntries() {
CarveWallBuffer buffer = new CarveWallBuffer(2);
Map<String, MatterCavern> expected = new HashMap<>();
for (int index = 0; index < 24; index++) {
int x = index & 15;
int y = 20 + index;
int z = (index * 3) & 15;
MatterCavern cavern = new MatterCavern(true, "cave-" + index, (byte) 0);
buffer.put(x, y, z, cavern);
expected.put(key(x, y, z), cavern);
}
MatterCavern replacement = new MatterCavern(true, "replacement", (byte) 0);
buffer.put(5, 25, 15, replacement);
expected.put(key(5, 25, 15), replacement);
Map<String, MatterCavern> actual = new HashMap<>();
buffer.forEach((x, y, z, cavern) -> actual.put(key(x, y, z), cavern));
assertEquals(expected.keySet(), actual.keySet());
for (Map.Entry<String, MatterCavern> entry : expected.entrySet()) {
assertSame(entry.getValue(), actual.get(entry.getKey()));
}
}
@Test
public void resetClearsReusableState() {
IrisCarveScratch scratch = new IrisCarveScratch();
MatterCavern cavern = new MatterCavern(true, "cave", (byte) 0);
scratch.columnMasks[0].add(12);
scratch.boundaryMasks[0].add(13);
scratch.boundaryCaverns[0] = cavern;
scratch.walls.put(1, 12, 2, cavern);
scratch.customBiomeCache.put("cave", null);
scratch.customCaveBiomePresent = true;
scratch.reset();
assertTrue(scratch.columnMasks[0].isEmpty());
assertTrue(scratch.boundaryMasks[0].isEmpty());
assertNull(scratch.boundaryCaverns[0]);
assertTrue(scratch.customBiomeCache.isEmpty());
assertFalse(scratch.customCaveBiomePresent);
int[] wallCount = new int[1];
scratch.walls.forEach((x, y, z, value) -> wallCount[0]++);
assertEquals(0, wallCount[0]);
}
private static String key(int x, int y, int z) {
return x + ":" + y + ":" + z;
}
}