Full audit fixpass: 93 defect fixes, 14 perf wins, vestigial cleanup

This commit is contained in:
Brian Neumann-Fopiano committed 2026-08-13 01:01:01 -04:00
1 parent 13e02ecd2f
commit 14b6280668
215 files changed
+4604 -2407

No files matched your search

@@ -0,0 +1,31 @@
package art.arcane.iris.modded;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedDownloadBranchParityTest {
private static final List<String> DOWNLOAD_SOURCES = List.of(
"art/arcane/iris/modded/command/ModdedWorldCommands.java",
"art/arcane/iris/modded/command/ModdedStudioCommands.java",
"art/arcane/iris/modded/command/ModdedCommandTree.java");
@Test
public void implicitAndExplicitDownloadsShareTheCoreDefaultBranch() throws Exception {
for (String source : DOWNLOAD_SOURCES) {
Path path = Path.of(System.getProperty("iris.moddedCommonSources"), source);
String text = Files.readString(path);
assertFalse(source + " must not hardcode a \"master\" download branch",
text.contains("\"master\""));
assertFalse(source + " must not hardcode a \"stable\" download branch",
text.contains("\"stable\""));
assertTrue(source + " must use PackDownloader.DEFAULT_BRANCH",
text.contains("PackDownloader.DEFAULT_BRANCH"));
}
}
}
@@ -36,12 +36,12 @@ public class ModdedLootApplierTest {
}
@Test
public void clearRemovesNativeAndIrisSourcesBeforeAdding() {
public void clearRemovesEverythingAndContributesNothing() {
List<String> sources = new ArrayList<>(List.of("placement-native", "dimension-iris"));
LootResolver.injectSources(sources, List.of("biome-iris"), IrisLootMode.CLEAR, false);
assertEquals(List.of("biome-iris"), sources);
assertEquals(List.of(), sources);
}
@Test
@@ -0,0 +1,106 @@
package art.arcane.iris.modded;
import net.minecraft.core.BlockPos;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.block.state.BlockState;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.nio.file.Path;
import static org.junit.Assert.assertEquals;
public class ModdedPlatformPathsTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
private ModdedPlatform platform() {
Path configDir = temporaryFolder.getRoot().toPath();
return new ModdedPlatform(new ModdedLoader() {
@Override
public String platformName() {
return "test";
}
@Override
public String minecraftVersion() {
return "26.2";
}
@Override
public String modVersion() {
return "0.0.0";
}
@Override
public MinecraftServer currentServer() {
return null;
}
@Override
public void invalidateLevelCache(MinecraftServer server) {
}
@Override
public boolean clientEnvironment() {
return false;
}
@Override
public Path configDir() {
return configDir;
}
@Override
public File modJar() {
return null;
}
@Override
public boolean hasTreeFellerPermission(ServerPlayer player) {
return false;
}
@Override
public boolean canTreeFellerBreak(ServerLevel level, ServerPlayer player, BlockPos position, BlockState state) {
return false;
}
});
}
@Test
public void packsResolveUnderIrisworldgen() {
ModdedPlatform platform = platform();
File root = temporaryFolder.getRoot();
File packsRoot = new File(new File(root, "irisworldgen"), "packs");
assertEquals(packsRoot, platform.packsFolder());
assertEquals(packsRoot, platform.dataFolder("packs"));
assertEquals(new File(packsRoot, "overworld"), platform.dataFolderNoCreate("packs", "overworld"));
assertEquals(new File(packsRoot, "overworld" + File.separator + "dimensions" + File.separator + "overworld.json"),
platform.dataFile("packs", "overworld", "dimensions", "overworld.json"));
}
@Test
public void everythingElseStaysUnderIris() {
ModdedPlatform platform = platform();
File iris = new File(temporaryFolder.getRoot(), "iris");
assertEquals(iris, platform.dataFolder());
assertEquals(new File(iris, "settings.json"), platform.dataFile("settings.json"));
assertEquals(new File(iris, "parity"), platform.dataFolder("parity"));
}
@Test
public void packsMatchIsExactSegmentOnly() {
ModdedPlatform platform = platform();
File iris = new File(temporaryFolder.getRoot(), "iris");
assertEquals(new File(iris, "packbenchmarks"), platform.dataFolder("packbenchmarks"));
assertEquals(new File(iris, "packsx"), platform.dataFolderNoCreate("packsx"));
}
}
@@ -0,0 +1,75 @@
package art.arcane.iris.modded;
import art.arcane.iris.engine.object.IRare;
import art.arcane.iris.engine.object.IrisEntitySpawn;
import art.arcane.volmlib.util.collection.KList;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedSpawnerRarityParityTest {
private static IrisEntitySpawn spawn(int rarity) {
IrisEntitySpawn spawn = new IrisEntitySpawn();
spawn.setRarity(rarity);
return spawn;
}
@Test
public void rarityIsAppliedOnceAsPoolWeightOnly() {
IrisEntitySpawn common = spawn(1);
IrisEntitySpawn rare = spawn(4);
KList<IrisEntitySpawn> expanded = IRare.expandWeighted(List.of(common, rare));
// totalRarity 5 -> common appears 5/1 = 5 times, rare 5/4 = 1 time.
assertEquals(6, expanded.size());
assertEquals(5, expanded.stream().filter(entry -> entry == common).count());
assertEquals(1, expanded.stream().filter(entry -> entry == rare).count());
}
@Test
public void rarityZeroAndNegativeAreClampedToOne() {
assertEquals(1, IRare.get(spawn(0)));
assertEquals(1, IRare.get(spawn(-5)));
assertEquals(3, IRare.get(spawn(3)));
}
@Test
public void perPositionSpawnLoopsDoNotRerollEntryRarity() throws Exception {
String source = Files.readString(Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedWorldManager.java"));
for (String method : List.of("private int spawnEntry(", "private int spawnEntryAt(")) {
String body = methodBody(source, method);
assertFalse(method + " must not re-roll rarity per position; rarityPick already weighted the pool",
body.contains("getRarity()"));
assertTrue(method + " must keep the min/max spawn-count roll",
body.contains("LootResolver.inclusive("));
}
}
private static String methodBody(String source, String declaration) {
int start = source.indexOf(declaration);
assertTrue("ModdedWorldManager must declare " + declaration, start >= 0);
int open = source.indexOf('{', start);
int depth = 0;
for (int index = open; index < source.length(); index++) {
char character = source.charAt(index);
if (character == '{') {
depth++;
} else if (character == '}') {
depth--;
if (depth == 0) {
return source.substring(open + 1, index);
}
}
}
throw new AssertionError(declaration + " is not brace balanced");
}
}