This commit is contained in:
Brian Neumann-Fopiano committed 2026-07-30 12:31:39 -04:00
1 parent 0afbfcb7a2
commit 324cf9e095
374 files changed
+22703 -25648

No files matched your search

@@ -58,8 +58,8 @@ public class IrisModdedChunkGeneratorSpawnTest {
int spawnEnd = source.indexOf("@Override", spawnStart + 1);
String spawn = source.substring(spawnStart, spawnEnd);
assertTrue(spawn.contains("initializeVanillaSpawnBiomes(registry)"));
assertTrue(spawn.contains("vanillaSpawnBiomes.get(visibleBiome.value())"));
assertTrue(spawn.contains("spawnTables.initializeVanillaSpawnBiomes(registry)"));
assertTrue(spawn.contains("spawnTables.vanillaSpawnBiome(visibleBiome.value())"));
assertTrue(spawn.contains("NaturalSpawner.spawnMobsForChunkGeneration("));
assertTrue(spawn.contains("new LegacyRandomSource(RandomSupport.generateUniqueSeed())"));
assertTrue(spawn.contains("random.setDecorationSeed(region.getSeed()"));
@@ -58,10 +58,10 @@ public class IrisModdedStructureParityTest {
@Test
public void spawnHeightMatchesPaperFixedSpawnClamp() {
assertEquals(96, IrisModdedChunkGenerator.clampSpawnHeight(-64, 384));
assertEquals(96, IrisModdedChunkGenerator.clampSpawnHeight(0, 128));
assertEquals(88, IrisModdedChunkGenerator.clampSpawnHeight(80, 10));
assertEquals(101, IrisModdedChunkGenerator.clampSpawnHeight(100, 20));
assertEquals(96, ModdedDimensionMetadata.clampSpawnHeight(-64, 384));
assertEquals(96, ModdedDimensionMetadata.clampSpawnHeight(0, 128));
assertEquals(88, ModdedDimensionMetadata.clampSpawnHeight(80, 10));
assertEquals(101, ModdedDimensionMetadata.clampSpawnHeight(100, 20));
}
@Test
@@ -109,7 +109,7 @@ public class IrisModdedStructureParityTest {
.setVanillaDerivative("minecraft:plains")
.setInferredType(InferredType.SEA);
Set<String> keys = IrisModdedChunkGenerator.collectConfiguredBiomeKeys(
Set<String> keys = ModdedDimensionMetadata.collectConfiguredBiomeKeys(
List.of(ocean, custom, shore, unsafeSea), "OverWorld");
assertEquals(Set.of("minecraft:deep_ocean", "minecraft:forest", "minecraft:beach",
@@ -150,8 +150,8 @@ public class IrisModdedStructureParityTest {
.setFluidHeight(50);
dimension.setLoadKey("bootstrap_contract");
IrisModdedChunkGenerator.DimensionMetadata metadata =
IrisModdedChunkGenerator.dimensionMetadata(dimension);
ModdedDimensionMetadata.DimensionMetadata metadata =
ModdedDimensionMetadata.dimensionMetadata(dimension);
assertEquals(-256, metadata.minY());
assertEquals(512, metadata.maxY());
@@ -161,8 +161,8 @@ public class IrisModdedStructureParityTest {
@Test
public void structureRingWorkersWaitWithoutBlockingLifecycleBinding() throws Exception {
IrisModdedChunkGenerator.EngineBinding<String> binding =
new IrisModdedChunkGenerator.EngineBinding<>(5L, TimeUnit.SECONDS);
ModdedEngineBinding<String> binding =
new ModdedEngineBinding<>(5L, TimeUnit.SECONDS);
String exactEngine = "exact-engine";
CountDownLatch workerStarted = new CountDownLatch(1);
ExecutorService executor = Executors.newSingleThreadExecutor();
@@ -184,8 +184,8 @@ public class IrisModdedStructureParityTest {
@Test
public void structureRingBindingPropagatesBootstrapFailure() {
IrisModdedChunkGenerator.EngineBinding<String> binding =
new IrisModdedChunkGenerator.EngineBinding<>(1L, TimeUnit.SECONDS);
ModdedEngineBinding<String> binding =
new ModdedEngineBinding<>(1L, TimeUnit.SECONDS);
IllegalArgumentException failure = new IllegalArgumentException("broken pack");
binding.fail(failure);
@@ -200,16 +200,16 @@ public class IrisModdedStructureParityTest {
@Test
public void structureBiomeBootstrapAllowsOnlyPendingBindingsToUseMetadata() {
IrisModdedChunkGenerator.EngineBinding<String> binding =
new IrisModdedChunkGenerator.EngineBinding<>(1L, TimeUnit.SECONDS);
ModdedEngineBinding<String> binding =
new ModdedEngineBinding<>(1L, TimeUnit.SECONDS);
binding.throwIfFailed("overworld:overworld");
}
@Test
public void structureBiomeBootstrapPropagatesBindingFailure() {
IrisModdedChunkGenerator.EngineBinding<String> binding =
new IrisModdedChunkGenerator.EngineBinding<>(1L, TimeUnit.SECONDS);
ModdedEngineBinding<String> binding =
new ModdedEngineBinding<>(1L, TimeUnit.SECONDS);
IllegalArgumentException failure = new IllegalArgumentException("broken pack");
binding.fail(failure);
@@ -152,13 +152,13 @@ public class ModdedDimensionTypeParityTest {
.ceiling(TRUE);
IrisDimension dimension = dimension("runtime_contract", IrisEnvironment.CUSTOM,
-128, 384, 384, options);
ModdedWorldCheck.DimensionContract expected = ModdedWorldCheck.expectedDimensionContract(dimension);
ModdedWorldCheck.DimensionContract fallback = new ModdedWorldCheck.DimensionContract(
WorldCheckDimensionContract.DimensionContract expected = WorldCheckDimensionContract.expectedDimensionContract(dimension);
WorldCheckDimensionContract.DimensionContract fallback = new WorldCheckDimensionContract.DimensionContract(
-256, 768, 512, 1D, 0F, true, false, false, 0);
assertTrue(ModdedWorldCheck.matchesDimensionContract(-128, 512, expected, expected));
assertFalse(ModdedWorldCheck.matchesDimensionContract(-256, 768, expected, fallback));
assertFalse(ModdedWorldCheck.matchesDimensionContract(-128, 512, expected, fallback));
assertTrue(WorldCheckDimensionContract.matchesDimensionContract(-128, 512, expected, expected));
assertFalse(WorldCheckDimensionContract.matchesDimensionContract(-256, 768, expected, fallback));
assertFalse(WorldCheckDimensionContract.matchesDimensionContract(-128, 512, expected, fallback));
}
private static IrisDimension dimension(String key, IrisEnvironment environment, int minY, int maxY,
@@ -28,40 +28,43 @@ public class ModdedWorldCheckTest {
@Test
public void poiAuditRunsInASecondServerTaskAfterVillageGeneration() throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/ModdedWorldCheck.java");
String source = Files.readString(sourcePath);
Path sourceRoot = Path.of(System.getProperty("iris.moddedCommonSources"));
String source = Files.readString(sourceRoot.resolve("art/arcane/iris/modded/ModdedWorldCheck.java"));
String auditSource = Files.readString(
sourceRoot.resolve("art/arcane/iris/modded/WorldCheckStructureAudit.java"));
int preparationSubmit = source.indexOf(
"WorldCheckPreparation preparation = serverRef.submit(() -> run(serverRef)).join();");
int completionSubmit = source.indexOf(
"exitCode = serverRef.submit(() -> runAndRequestStop(", preparationSubmit);
int completionMethod = source.indexOf("private static boolean completeWorldCheck");
int deferredAudit = source.indexOf("PoiAudit poi = auditStructurePois", completionMethod);
int structureMethod = source.indexOf("private static StructureCheckResult checkNativeStructure");
int structureMethodEnd = source.indexOf("private static StructureStart resolveStructureStart",
int deferredAudit = source.indexOf(
"PoiAudit poi = WorldCheckStructureAudit.auditStructurePois", completionMethod);
int structureMethod = auditSource.indexOf("private static StructureCheckResult checkNativeStructure");
int structureMethodEnd = auditSource.indexOf("private static StructureStart resolveStructureStart",
structureMethod);
String structureSource = source.substring(structureMethod, structureMethodEnd);
String structureSource = auditSource.substring(structureMethod, structureMethodEnd);
assertTrue(preparationSubmit >= 0);
assertTrue(completionSubmit > preparationSubmit);
assertTrue(deferredAudit > completionMethod);
assertFalse(structureSource.contains("auditStructurePois"));
assertFalse(source.contains("prepareDeferredAudits"));
assertFalse(auditSource.contains("prepareDeferredAudits"));
}
@Test
public void validStructureStartIsGenerationEvidence() {
assertTrue(ModdedWorldCheck.hasNativeStructureEvidence(true, 0));
assertTrue(WorldCheckPredicates.hasNativeStructureEvidence(true, 0));
}
@Test
public void structureReferenceIsGenerationEvidence() {
assertTrue(ModdedWorldCheck.hasNativeStructureEvidence(false, 1));
assertTrue(WorldCheckPredicates.hasNativeStructureEvidence(false, 1));
}
@Test
public void absentStartAndReferencesFailGenerationEvidence() {
assertFalse(ModdedWorldCheck.hasNativeStructureEvidence(false, 0));
assertFalse(WorldCheckPredicates.hasNativeStructureEvidence(false, 0));
}
@Test
@@ -91,68 +94,68 @@ public class ModdedWorldCheckTest {
@Test
public void materialEvidenceMustExist() {
assertFalse(ModdedWorldCheck.hasCharacteristicMaterialEvidence(0, 0, 1));
assertFalse(ModdedWorldCheck.hasCharacteristicMaterialEvidence(8, 0, 1));
assertFalse(ModdedWorldCheck.hasCharacteristicMaterialEvidence(8, 1, 0));
assertFalse(ModdedWorldCheck.hasCharacteristicMaterialEvidence(8, 2, 1));
assertFalse(WorldCheckPredicates.hasCharacteristicMaterialEvidence(0, 0, 1));
assertFalse(WorldCheckPredicates.hasCharacteristicMaterialEvidence(8, 0, 1));
assertFalse(WorldCheckPredicates.hasCharacteristicMaterialEvidence(8, 1, 0));
assertFalse(WorldCheckPredicates.hasCharacteristicMaterialEvidence(8, 2, 1));
}
@Test
public void singleChunkStructureAcceptsMaterialInItsOnlyChunk() {
assertTrue(ModdedWorldCheck.hasCharacteristicMaterialEvidence(8, 1, 1));
assertTrue(WorldCheckPredicates.hasCharacteristicMaterialEvidence(8, 1, 1));
}
@Test
public void multiChunkStructureRejectsMaterialConfinedToOneChunk() {
assertFalse(ModdedWorldCheck.hasCharacteristicMaterialEvidence(8, 1, 4));
assertTrue(ModdedWorldCheck.hasCharacteristicMaterialEvidence(8, 2, 4));
assertFalse(WorldCheckPredicates.hasCharacteristicMaterialEvidence(8, 1, 4));
assertTrue(WorldCheckPredicates.hasCharacteristicMaterialEvidence(8, 2, 4));
}
@Test
public void configuredVerticalShiftRequiresSafetyClampedGenerationEvidence() {
assertTrue(ModdedWorldCheck.verticalShiftMatches(0, null, -32, 20, -64, 320));
assertFalse(ModdedWorldCheck.verticalShiftMatches(0, null, -112, -80, -64, 320));
assertTrue(ModdedWorldCheck.verticalShiftMatches(0, 0, -32, 20, -64, 320));
assertTrue(ModdedWorldCheck.verticalShiftMatches(0, 48, -64, -32, -64, 320));
assertTrue(ModdedWorldCheck.verticalShiftMatches(-64, -64, -48, 4, -64, 320));
assertTrue(ModdedWorldCheck.verticalShiftMatches(-64, -16, -64, -12, -64, 320));
assertFalse(ModdedWorldCheck.verticalShiftMatches(-64, null, -48, 4, -64, 320));
assertFalse(ModdedWorldCheck.verticalShiftMatches(-64, -15, -63, -11, -64, 320));
assertFalse(ModdedWorldCheck.verticalShiftMatches(0, -1, -33, 19, -64, 320));
assertTrue(WorldCheckPredicates.verticalShiftMatches(0, null, -32, 20, -64, 320));
assertFalse(WorldCheckPredicates.verticalShiftMatches(0, null, -112, -80, -64, 320));
assertTrue(WorldCheckPredicates.verticalShiftMatches(0, 0, -32, 20, -64, 320));
assertTrue(WorldCheckPredicates.verticalShiftMatches(0, 48, -64, -32, -64, 320));
assertTrue(WorldCheckPredicates.verticalShiftMatches(-64, -64, -48, 4, -64, 320));
assertTrue(WorldCheckPredicates.verticalShiftMatches(-64, -16, -64, -12, -64, 320));
assertFalse(WorldCheckPredicates.verticalShiftMatches(-64, null, -48, 4, -64, 320));
assertFalse(WorldCheckPredicates.verticalShiftMatches(-64, -15, -63, -11, -64, 320));
assertFalse(WorldCheckPredicates.verticalShiftMatches(0, -1, -33, 19, -64, 320));
}
@Test
public void mansionVegetationGateRejectsRemainingLeaves() {
assertTrue(ModdedWorldCheck.mansionVegetationPass(0));
assertFalse(ModdedWorldCheck.mansionVegetationPass(1));
assertTrue(WorldCheckPredicates.mansionVegetationPass(0));
assertFalse(WorldCheckPredicates.mansionVegetationPass(1));
}
@Test
public void mansionVegetationAuditIgnoresTemplateBlocksAndRejectsVegetationAbovePieces() {
assertFalse(ModdedWorldCheck.mansionVegetationAbovePiece(true, 80, 80));
assertFalse(ModdedWorldCheck.mansionVegetationAbovePiece(true, 79, 80));
assertTrue(ModdedWorldCheck.mansionVegetationAbovePiece(true, 81, 80));
assertFalse(ModdedWorldCheck.mansionVegetationAbovePiece(false, 81, 80));
assertFalse(WorldCheckPredicates.mansionVegetationAbovePiece(true, 80, 80));
assertFalse(WorldCheckPredicates.mansionVegetationAbovePiece(true, 79, 80));
assertTrue(WorldCheckPredicates.mansionVegetationAbovePiece(true, 81, 80));
assertFalse(WorldCheckPredicates.mansionVegetationAbovePiece(false, 81, 80));
}
@Test
public void villageFoundationGateRejectsUnsupportedColumns() {
assertTrue(ModdedWorldCheck.villageFoundationPass(0));
assertFalse(ModdedWorldCheck.villageFoundationPass(1));
assertTrue(WorldCheckPredicates.villageFoundationPass(0));
assertFalse(WorldCheckPredicates.villageFoundationPass(1));
}
@Test
public void villagePoiGateRequiresInBoundsPoiWithoutOutOfBoundsRecords() {
assertTrue(ModdedWorldCheck.villagePoiPass(1, 0));
assertFalse(ModdedWorldCheck.villagePoiPass(0, 0));
assertFalse(ModdedWorldCheck.villagePoiPass(1, 1));
assertTrue(WorldCheckPredicates.villagePoiPass(1, 0));
assertFalse(WorldCheckPredicates.villagePoiPass(0, 0));
assertFalse(WorldCheckPredicates.villagePoiPass(1, 1));
}
@Test
public void smallStructureFootprintIncludesEveryChunk() {
BoundingBox bounds = new BoundingBox(-16, -20, -16, 31, 120, 31);
List<ChunkPos> chunks = ModdedWorldCheck.boundedFootprintChunks(bounds, ChunkPos.ZERO, 96);
List<ChunkPos> chunks = WorldCheckStructureAudit.boundedFootprintChunks(bounds, ChunkPos.ZERO, 96);
assertEquals(9, chunks.size());
assertTrue(chunks.contains(new ChunkPos(-1, -1)));
@@ -163,7 +166,7 @@ public class ModdedWorldCheckTest {
public void largeStructureFootprintIsBoundedAndSamplesEdges() {
BoundingBox bounds = new BoundingBox(-512, -64, -512, 511, 300, 511);
List<ChunkPos> chunks = ModdedWorldCheck.boundedFootprintChunks(bounds, ChunkPos.ZERO, 20);
List<ChunkPos> chunks = WorldCheckStructureAudit.boundedFootprintChunks(bounds, ChunkPos.ZERO, 20);
assertTrue(chunks.size() <= 20);
assertTrue(chunks.size() >= 16);
@@ -174,7 +177,7 @@ public class ModdedWorldCheckTest {
@Test
public void qaEventsEscapeStructuredValues() {
String event = ModdedWorldCheck.qaEventJson("locate\"", "village\n", false, "x\\y\t");
String event = WorldCheckPredicates.qaEventJson("locate\"", "village\n", false, "x\\y\t");
assertEquals("QA_EVT {\"event\":\"locate\\\"\",\"structure\":\"village\\n\","
+ "\"pass\":false,\"detail\":\"x\\\\y\\t\"}", event);
@@ -292,7 +295,7 @@ public class ModdedWorldCheckTest {
}
private static boolean characteristic(String structureLabel, String structureKey, String blockKey) {
return ModdedWorldCheck.isCharacteristicMaterial(structureLabel,
return WorldCheckMaterials.isCharacteristicMaterial(structureLabel,
Identifier.parse(structureKey), Identifier.parse(blockKey));
}
}
@@ -24,15 +24,14 @@ public class NativeStructureFailureContractTest {
@Test
public void structureLocateDoesNotCatchAndFallThroughToAnotherImplementation() throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedChunkGenerator.java");
String source = Files.readString(sourcePath);
String source = moddedSource("IrisModdedChunkGenerator.java");
int locateStart = source.indexOf("public Pair<BlockPos, Holder<Structure>> findNearestMapStructure");
int locateEnd = source.indexOf("public boolean isNativeStructureReachable", locateStart);
String locate = source.substring(locateStart, locateEnd);
int filterStart = source.indexOf("private HolderSet<Structure> filterReachableNativeStructures");
int filterEnd = source.indexOf("private ServerLevel boundLevel", filterStart);
String filter = source.substring(filterStart, filterEnd);
String stage = moddedSource("ModdedNativeStructureStage.java");
int filterStart = stage.indexOf("HolderSet<Structure> filterReachableNativeStructures");
int filterEnd = stage.indexOf("void adjustGeneratedStructures", filterStart);
String filter = stage.substring(filterStart, filterEnd);
assertTrue(locate.contains("Engine current = engine();"));
assertFalse(locate.contains("catch (Throwable"));
@@ -58,10 +57,8 @@ public class NativeStructureFailureContractTest {
@Test
public void structureTerrainPreparationPrecedesVegetationAndPlacement() throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"),
"art/arcane/iris/modded/IrisModdedChunkGenerator.java");
String source = Files.readString(sourcePath);
int placementStart = source.indexOf("private void placeVanillaStructures");
String source = moddedSource("ModdedNativeStructureStage.java");
int placementStart = source.indexOf("void placeVanillaStructures");
int placementEnd = source.indexOf("private static String nativeStructureBatchContext", placementStart);
String placement = source.substring(placementStart, placementEnd);
@@ -74,6 +71,23 @@ public class NativeStructureFailureContractTest {
< placement.indexOf("for (NativePlacementGroup group"));
}
@Test
public void structurePlacementPrimesNeighbourWorldgenHeightmapsBeforeTerrainPreparation() throws IOException {
String source = moddedSource("ModdedNativeStructureStage.java");
int placementStart = source.indexOf("void placeVanillaStructures");
int placementEnd = source.indexOf("private static String nativeStructureBatchContext", placementStart);
String placement = source.substring(placementStart, placementEnd);
assertTrue(source.contains("import art.arcane.iris.nativegen.WorldgenTerrainHeightmaps;"));
assertTrue(placement.contains("WorldgenTerrainHeightmaps.primeStructurePlacement("));
assertTrue(placement.contains("\"heightmap priming\""));
assertTrue(placement.contains("heightmapStarts.add(start);"));
assertTrue(placement.indexOf("WorldgenTerrainHeightmaps.primeStructurePlacement(")
< placement.indexOf("prepareSurfaceStructures"));
assertTrue(source.contains("generationEngine.getHeight(x, z, false) + runtimeMinY + 1"));
assertTrue(source.contains("generationEngine.getHeight(x, z, true) + runtimeMinY + 1"));
}
@Test
public void structureFailurePreservesPhaseIdentityChunkAndCause() {
IllegalArgumentException cause = new IllegalArgumentException("broken placement");
@@ -86,4 +100,10 @@ public class NativeStructureFailureContractTest {
assertTrue(error.getMessage().contains("12,-8"));
assertTrue(error.getMessage().contains("aborted"));
}
private static String moddedSource(String fileName) throws IOException {
Path sourcePath = Path.of(System.getProperty("iris.moddedCommonSources"),
"art", "arcane", "iris", "modded", fileName);
return Files.readString(sourcePath);
}
}
@@ -12,7 +12,8 @@ import static org.junit.Assert.assertTrue;
public class IrisModdedStructureCommandTest {
@Test
public void gotoStructureSupportsIrisAndNativeRegistryTargets() throws IOException {
String source = source("IrisModdedCommands.java");
String source = source("ModdedLocateCommands.java");
String suggestions = source("ModdedCommandSuggestions.java");
assertTrue(source.contains("IrisStructureLocator.isPlaced(engine, key)"));
assertTrue(source.contains("registry.get(identifier)"));
@@ -22,7 +23,7 @@ public class IrisModdedStructureCommandTest {
assertTrue(source.contains("HolderSet.direct(target.holder())"));
assertFalse(source.contains("NativeStructureLocateCapability"));
assertTrue(source.contains("boolean teleported = player.teleportTo("));
assertTrue(source.contains("combineStructureKeys(irisKeys, nativeKeys)"));
assertTrue(suggestions.contains("combineStructureKeys(irisKeys, nativeKeys)"));
assertTrue(source.contains("irisGenerator.isNativeStructureReachable(holder)"));
assertTrue(source.contains("LocateStatus.SEARCH_LIMIT_REACHED"));
assertTrue(source.contains("IRIS_MODDED_COMMANDS_UNABLE_LOCATE_IRIS_PLACED_STRUCTURE_DENSITY_SEARCH_SAFETY_LIMIT_WAS"));
@@ -35,9 +36,9 @@ public class IrisModdedStructureCommandTest {
@Test
public void generatorLocateUsesEveryIrisPlacedNativeStructure() throws IOException {
String source = moddedSource("IrisModdedChunkGenerator.java");
int methodStart = source.indexOf("private Pair<BlockPos, Holder<Structure>> findNearestIrisStructure(");
int methodEnd = source.indexOf("private HolderSet<Structure> filterReachableNativeStructures(", methodStart);
String source = moddedSource("ModdedNativeStructureStage.java");
int methodStart = source.indexOf("Pair<BlockPos, Holder<Structure>> findNearestIrisStructure(");
int methodEnd = source.indexOf("HolderSet<Structure> filterReachableNativeStructures(", methodStart);
String method = source.substring(methodStart, methodEnd);
int unexploredGuard = method.indexOf("if (findUnexplored)");
int registryLookup = method.indexOf("level.registryAccess().lookupOrThrow(Registries.STRUCTURE)");
@@ -58,8 +59,8 @@ public class IrisModdedStructureCommandTest {
@Test
public void commandResolvesNativePolicyBeforeAnyVanillaAliasLookup() throws IOException {
String source = source("IrisModdedCommands.java");
int methodStart = source.indexOf("private static int gotoStructure(");
String source = source("ModdedLocateCommands.java");
int methodStart = source.indexOf("static int gotoStructure(");
int methodEnd = source.indexOf("private static void locateIrisStructure(", methodStart);
String method = source.substring(methodStart, methodEnd);
int nativeResolution = method.indexOf("resolveNativeStructure(source, level, engine, key)");
@@ -79,7 +80,7 @@ public class IrisModdedStructureCommandTest {
@Test
public void verifyResolvesRegisteredNativeBeforeGenericIrisAliases() throws IOException {
String source = source("IrisModdedCommands.java");
String source = source("ModdedLocateCommands.java");
int methodStart = source.indexOf("private static int verifyStructure(");
int methodEnd = source.indexOf("private static Optional<NativeStructureTarget> resolveNativeStructure(",
methodStart);
@@ -1,69 +0,0 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modded.structure;
import net.minecraft.core.Direction;
import org.junit.Test;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class ModdedJigsawStructureCaptureTest {
@Test
public void namespacedSourcePathsRemainDistinctAndPortable() {
String nested = ModdedJigsawStructureCapture.pieceName("village", "mod:a/b");
String underscored = ModdedJigsawStructureCapture.pieceName("village", "mod_a:b");
assertEquals("village/piece/mod/a/b", nested);
assertEquals("village/piece/mod_a/b", underscored);
assertNotEquals(nested, underscored);
assertEquals("village/pool/mod/a/b", ModdedJigsawStructureCapture.poolName("village", "mod:a/b"));
assertEquals(
"village/piece/generated/legacy/mod/a/b",
ModdedJigsawStructureCapture.legacyPieceName("village", "mod:a/b")
);
}
@Test
public void rootJsonRetainsGraphLimitsAndSourceIdentity() {
Map<String, Object> root = ModdedJigsawStructureCapture.structureJson(
"minecraft:village_plains",
"village/pool/minecraft/village/plains/town_centers",
6,
81
);
assertEquals("minecraft:village_plains", root.get("vanillaSource"));
assertEquals(6, root.get("maxDepth"));
assertEquals(6, root.get("maxSizeChunks"));
assertEquals("STRUCTURE_PIECE", root.get("placeMode"));
}
@Test
public void connectorDirectionsUseIrisAxisNames() {
assertEquals("UP_POSITIVE_Y", ModdedJigsawStructureCapture.directionName(Direction.UP));
assertEquals("DOWN_NEGATIVE_Y", ModdedJigsawStructureCapture.directionName(Direction.DOWN));
assertEquals("NORTH_NEGATIVE_Z", ModdedJigsawStructureCapture.directionName(Direction.NORTH));
assertEquals("SOUTH_POSITIVE_Z", ModdedJigsawStructureCapture.directionName(Direction.SOUTH));
assertEquals("EAST_POSITIVE_X", ModdedJigsawStructureCapture.directionName(Direction.EAST));
assertEquals("WEST_NEGATIVE_X", ModdedJigsawStructureCapture.directionName(Direction.WEST));
}
}
@@ -1,86 +0,0 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modded.structure;
import art.arcane.iris.core.structure.authoring.StructureBackend;
import art.arcane.iris.core.structure.authoring.StructureCapability;
import art.arcane.iris.core.structure.authoring.StructureKey;
import art.arcane.iris.core.structure.authoring.StructureResourceBundle;
import art.arcane.iris.core.structure.authoring.StructureSource;
import art.arcane.iris.core.structure.authoring.StructureWriteMode;
import art.arcane.iris.core.structure.authoring.StructureWriteOptions;
import art.arcane.iris.core.structure.authoring.StructureWriteResult;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.nio.file.Path;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedStructureImportServiceTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void writesThroughOwnedAddOnlyAndOverwriteTransactions() throws Exception {
Path root = temporaryFolder.newFolder("modded-import").toPath();
ModdedStructureImportService service = new ModdedStructureImportService(() -> null);
ModdedStructureImportService.PreparedImport first = prepared(root, "one", StructureWriteMode.ADD_ONLY);
ModdedStructureImportService.ImportResult added = service.write(first);
ModdedStructureImportService.ImportResult conflict = service.write(first);
ModdedStructureImportService.ImportResult overwritten = service.write(
prepared(root, "two", StructureWriteMode.OVERWRITE)
);
assertTrue(added.success());
assertEquals(StructureWriteResult.Status.ADDED, added.writeResult().orElseThrow().status());
assertFalse(conflict.success());
assertEquals(StructureWriteResult.Status.ADD_ONLY_CONFLICT, conflict.writeResult().orElseThrow().status());
assertTrue(overwritten.success());
assertEquals(StructureWriteResult.Status.OVERWRITTEN, overwritten.writeResult().orElseThrow().status());
assertTrue(overwritten.capabilities().contains(StructureCapability.BLOCKS));
}
private static ModdedStructureImportService.PreparedImport prepared(
Path root,
String content,
StructureWriteMode mode
) {
StructureKey key = StructureKey.parse("iris:test_structure");
StructureResourceBundle bundle = StructureResourceBundle.builder(key)
.source(StructureSource.of(StructureSource.Kind.DATAPACK, StructureKey.parse("test:source")))
.backend(StructureBackend.SNAPSHOT)
.capability(StructureCapability.BLOCKS)
.textResource("structures/test_structure.json", content)
.build();
return new ModdedStructureImportService.PreparedImport(
root,
new StructureWriteOptions(mode, false),
ModdedStructureImportService.ImportKind.TEMPLATE,
bundle,
1,
1,
1
);
}
}
@@ -1,184 +0,0 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.modded.structure;
import art.arcane.iris.core.structure.authoring.StructureCapability;
import art.arcane.iris.core.structure.authoring.StructureKey;
import net.minecraft.SharedConstants;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.server.Bootstrap;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class ModdedStructureTemplateCaptureTest {
@BeforeClass
public static void bootstrap() {
SharedConstants.tryDetectVersion();
Bootstrap.bootStrap();
}
@Test
public void capturesBlocksTilesAndExplicitStandaloneLosses() throws Exception {
CompoundTag template = templateTag();
ModdedStructureTemplateCapture.Capture capture = ModdedStructureTemplateCapture.captureTag(
StructureKey.parse("minecraft:test/template"),
template,
BuiltInRegistries.BLOCK,
false
);
assertEquals(4, capture.width());
assertEquals(1, capture.height());
assertEquals(1, capture.depth());
assertEquals(3, capture.blocks());
assertEquals(1, capture.tiles());
assertEquals(1, capture.jigsaws());
assertEquals(1, capture.dataMarkers());
assertEquals(3, capture.object().getBlocks().size());
assertEquals(1, capture.object().getStates().size());
assertTrue(capture.capabilities().contains(StructureCapability.BLOCKS));
assertTrue(capture.capabilities().contains(StructureCapability.BLOCK_ENTITIES));
assertFalse(capture.capabilities().contains(StructureCapability.CONNECTORS));
assertTrue(hasLoss(capture, "connectors_not_imported"));
assertTrue(hasLoss(capture, "data_markers_not_imported"));
assertTrue(hasLoss(capture, "entities_not_imported"));
ByteArrayOutputStream serialized = new ByteArrayOutputStream();
capture.object().write(serialized);
assertTrue(serialized.size() > 0);
}
@Test
public void graphCaptureReportsConnectorCapabilityWithoutStandaloneConnectorLoss() {
ModdedStructureTemplateCapture.Capture capture = ModdedStructureTemplateCapture.captureTag(
StructureKey.parse("minecraft:test/template"),
templateTag(),
BuiltInRegistries.BLOCK,
true
);
assertTrue(capture.capabilities().contains(StructureCapability.CONNECTORS));
assertFalse(hasLoss(capture, "connectors_not_imported"));
}
@Test
public void reportsAdditionalNativePalettes() {
CompoundTag template = templateTag();
ListTag palettes = new ListTag();
ListTag first = template.getListOrEmpty(StructureTemplate.PALETTE_TAG);
palettes.add(first.copy());
palettes.add(first.copy());
template.remove(StructureTemplate.PALETTE_TAG);
template.put(StructureTemplate.PALETTE_LIST_TAG, palettes);
ModdedStructureTemplateCapture.Capture capture = ModdedStructureTemplateCapture.captureTag(
StructureKey.parse("minecraft:test/template"),
template,
BuiltInRegistries.BLOCK,
true
);
assertTrue(hasLoss(capture, "palette_variants_not_imported"));
}
@Test
public void legacyCaptureOmitsAirBlocks() {
CompoundTag template = new CompoundTag();
template.put(StructureTemplate.SIZE_TAG, intList(1, 1, 1));
ListTag palette = new ListTag();
palette.add(NbtUtils.writeBlockState(Blocks.AIR.defaultBlockState()));
template.put(StructureTemplate.PALETTE_TAG, palette);
ListTag blocks = new ListTag();
blocks.add(block(0, 0, 0, 0, null));
template.put(StructureTemplate.BLOCKS_TAG, blocks);
ModdedStructureTemplateCapture.Capture capture = ModdedStructureTemplateCapture.captureTag(
StructureKey.parse("minecraft:test/legacy"),
template,
BuiltInRegistries.BLOCK,
true,
false
);
assertEquals(0, capture.blocks());
assertTrue(capture.object().getBlocks().isEmpty());
}
private static CompoundTag templateTag() {
CompoundTag template = new CompoundTag();
template.put(StructureTemplate.SIZE_TAG, intList(4, 1, 1));
ListTag palette = new ListTag();
palette.add(NbtUtils.writeBlockState(Blocks.STONE.defaultBlockState()));
palette.add(NbtUtils.writeBlockState(Blocks.CHEST.defaultBlockState()));
palette.add(NbtUtils.writeBlockState(Blocks.JIGSAW.defaultBlockState()));
palette.add(NbtUtils.writeBlockState(Blocks.STRUCTURE_BLOCK.defaultBlockState()));
template.put(StructureTemplate.PALETTE_TAG, palette);
ListTag blocks = new ListTag();
blocks.add(block(0, 0, 0, 0, null));
CompoundTag chest = new CompoundTag();
chest.putString("id", "minecraft:chest");
chest.putString("CustomName", "test");
blocks.add(block(1, 0, 0, 1, chest));
CompoundTag jigsaw = new CompoundTag();
jigsaw.putString("final_state", "minecraft:oak_planks");
blocks.add(block(2, 0, 0, 2, jigsaw));
blocks.add(block(3, 0, 0, 3, new CompoundTag()));
template.put(StructureTemplate.BLOCKS_TAG, blocks);
ListTag entities = new ListTag();
entities.add(new CompoundTag());
template.put(StructureTemplate.ENTITIES_TAG, entities);
return template;
}
private static CompoundTag block(int x, int y, int z, int state, CompoundTag nbt) {
CompoundTag block = new CompoundTag();
block.put(StructureTemplate.BLOCK_TAG_POS, intList(x, y, z));
block.putInt(StructureTemplate.BLOCK_TAG_STATE, state);
if (nbt != null) {
block.put(StructureTemplate.BLOCK_TAG_NBT, nbt);
}
return block;
}
private static ListTag intList(int... values) {
ListTag list = new ListTag();
for (int value : values) {
list.add(IntTag.valueOf(value));
}
return list;
}
private static boolean hasLoss(ModdedStructureTemplateCapture.Capture capture, String code) {
return capture.losses().stream().anyMatch(loss -> loss.code().equals(code));
}
}