diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedBlockBreakHandler.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedBlockBreakHandler.java index c88c82ae7..d2382d541 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedBlockBreakHandler.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedBlockBreakHandler.java @@ -18,6 +18,7 @@ package art.arcane.iris.modded; +import art.arcane.iris.engine.spawn.SpawnResources; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.framework.LootResolver; @@ -235,7 +236,7 @@ public final class ModdedBlockBreakHandler { if ("cave_floor".equals(tag) || "cave_ceiling".equals(tag)) { return; } - IrisMarker configured = engine.getData().getMarkerLoader().load(tag); + IrisMarker configured = SpawnResources.marker(engine.getData(), tag); if (configured == null || configured.isRemoveOnChange()) { engine.getMantle().getMantle().remove(position.getX(), mantleY, position.getZ(), MatterMarker.class); } diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedDeathLoot.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedDeathLoot.java index 2f4236b74..51a5b493b 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedDeathLoot.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedDeathLoot.java @@ -18,6 +18,7 @@ package art.arcane.iris.modded; +import art.arcane.iris.engine.loot.LootResources; import art.arcane.iris.engine.framework.Engine; import art.arcane.iris.engine.object.loot.InventorySlotType; import art.arcane.iris.engine.object.loot.IrisLootTable; @@ -104,7 +105,7 @@ public final class ModdedDeathLoot { private static KList resolve(Engine engine, ServerLevel level, LootBinding binding) { KList drops = new KList<>(); for (String key : binding.tableKeys()) { - IrisLootTable table = engine.getData().getLootLoader().load(key); + IrisLootTable table = LootResources.table(engine.getData(), key); if (table == null) { if (WARNED_TABLES.add(key)) { IrisLogging.warn("Iris death loot: unknown loot table '" + key + "'"); diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java index ffa64a300..5ea3ab45c 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedLootApplier.java @@ -18,6 +18,7 @@ package art.arcane.iris.modded; +import art.arcane.iris.engine.loot.LootResources; import art.arcane.iris.engine.object.loot.IrisObjectLoot; import art.arcane.iris.engine.object.loot.IrisObjectVanillaLoot; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; @@ -144,7 +145,7 @@ public final class ModdedLootApplier { if (loot == null || loot.getWeight() <= 0) { continue; } - IrisLootTable table = engine.getData().getLootLoader().load(loot.getName()); + IrisLootTable table = LootResources.table(engine.getData(), loot.getName()); if (table == null) { IrisLogging.warn("Couldn't find loot table " + loot.getName()); continue; diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedWorldManager.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedWorldManager.java index 602792f54..9688ed336 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedWorldManager.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedWorldManager.java @@ -18,6 +18,7 @@ package art.arcane.iris.modded; +import art.arcane.iris.engine.spawn.SpawnResources; import art.arcane.iris.core.IrisSettings; import art.arcane.iris.core.gui.PregeneratorJob; import art.arcane.iris.engine.IrisComplex; @@ -396,7 +397,7 @@ public final class ModdedWorldManager implements EngineWorldManager { if (tag.equals("cave_floor") || tag.equals("cave_ceiling")) { return; } - IrisMarker resolved = engine.getData().getMarkerLoader().load(tag); + IrisMarker resolved = SpawnResources.marker(engine.getData(), tag); if (resolved == null) { return; } @@ -429,7 +430,7 @@ public final class ModdedWorldManager implements EngineWorldManager { private KList resolveMarkerSpawners(IrisMarker marker) { KList spawners = new KList<>(); for (String key : marker.getSpawners()) { - IrisSpawner spawner = engine.getData().getSpawnerLoader().load(key); + IrisSpawner spawner = SpawnResources.spawner(engine.getData(), key); if (spawner == null) { IrisLogging.error("Cannot load spawner: " + key + " for marker on " + engine.getName()); continue; @@ -478,9 +479,9 @@ public final class ModdedWorldManager implements EngineWorldManager { int chunkMobs = countChunkLivingEntities(level, chunkX, chunkZ); KList pool = new KList<>(); - collectSpawns(pool, engine.getData().getSpawnerLoader().loadAll(engine.getDimension().getEntitySpawners()), biome, chunkX, chunkZ, chunkMobs, initial); - collectSpawns(pool, engine.getData().getSpawnerLoader().loadAll(region.getEntitySpawners()), null, chunkX, chunkZ, chunkMobs, initial); - collectSpawns(pool, engine.getData().getSpawnerLoader().loadAll(biome.getEntitySpawners()), null, chunkX, chunkZ, chunkMobs, initial); + collectSpawns(pool, SpawnResources.spawners(engine.getData(), engine.getDimension().getEntitySpawners()), biome, chunkX, chunkZ, chunkMobs, initial); + collectSpawns(pool, SpawnResources.spawners(engine.getData(), region.getEntitySpawners()), null, chunkX, chunkZ, chunkMobs, initial); + collectSpawns(pool, SpawnResources.spawners(engine.getData(), biome.getEntitySpawners()), null, chunkX, chunkZ, chunkMobs, initial); if (pool.isEmpty()) { return; } diff --git a/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java b/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java index 5078c11bc..a7de7a58f 100644 --- a/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java +++ b/adapters/modded-common/src/main/java/art/arcane/iris/modded/command/ModdedStudioCommands.java @@ -18,6 +18,9 @@ package art.arcane.iris.modded.command; +import art.arcane.iris.core.loader.IrisRegistrant; +import art.arcane.iris.engine.spawn.SpawnResources; +import art.arcane.iris.engine.loot.LootResources; import art.arcane.iris.modded.ModdedIrisLog; import art.arcane.iris.core.IrisSettings; import art.arcane.iris.core.gui.GuiHost; @@ -935,14 +938,14 @@ public final class ModdedStudioCommands { markerKeys.addAll(PackExportClosure.collectMarkerKeys(biome.getObjects())); } for (String markerKey : markerKeys) { - IrisMarker marker = dm.getMarkerLoader().load(markerKey); + IrisMarker marker = SpawnResources.marker(dm, markerKey); if (marker == null) { continue; } spawnerKeys.addAll(marker.getSpawners()); } for (String spawnerKey : spawnerKeys) { - IrisSpawner spawner = dm.getSpawnerLoader().load(spawnerKey); + IrisSpawner spawner = SpawnResources.spawner(dm, spawnerKey); if (spawner == null) { continue; } @@ -950,7 +953,7 @@ public final class ModdedStudioCommands { spawner.getInitialSpawns().forEach((IrisEntitySpawn spawn) -> entityKeys.add(spawn.getEntity())); } for (String entityKey : entityKeys) { - IrisEntity entity = dm.getEntityLoader().load(entityKey); + IrisEntity entity = SpawnResources.entity(dm, entityKey); if (entity == null) { continue; } @@ -988,16 +991,16 @@ public final class ModdedStudioCommands { hashes.append(copyJson(folder, "biomes", key, dm.getBiomeLoader().findFile(key))); } for (String key : entityKeys) { - hashes.append(copyJson(folder, "entities", key, dm.getEntityLoader().findFile(key))); + hashes.append(copyJson(folder, "entities", key, loadFile(SpawnResources.entity(dm, key)))); } for (String key : lootKeys) { - hashes.append(copyJson(folder, "loot", key, dm.getLootLoader().findFile(key))); + hashes.append(copyJson(folder, "loot", key, loadFile(LootResources.table(dm, key)))); } for (String key : spawnerKeys) { - hashes.append(copyJson(folder, "spawners", key, dm.getSpawnerLoader().findFile(key))); + hashes.append(copyJson(folder, "spawners", key, loadFile(SpawnResources.spawner(dm, key)))); } for (String key : markerKeys) { - hashes.append(copyJson(folder, "markers", key, dm.getMarkerLoader().findFile(key))); + hashes.append(copyJson(folder, "markers", key, loadFile(SpawnResources.marker(dm, key)))); } JSONObject meta = new JSONObject(); @@ -1088,4 +1091,9 @@ public final class ModdedStudioCommands { thread.start(); return 1; } + + /** The file a resource was read from, or null when the pack has no such resource. */ + private static File loadFile(IrisRegistrant resource) { + return resource == null ? null : resource.getLoadFile(); + } } diff --git a/core/src/main/java/art/arcane/iris/core/loader/IrisData.java b/core/src/main/java/art/arcane/iris/core/loader/IrisData.java index 98c269eab..f048c794a 100644 --- a/core/src/main/java/art/arcane/iris/core/loader/IrisData.java +++ b/core/src/main/java/art/arcane/iris/core/loader/IrisData.java @@ -42,17 +42,13 @@ import art.arcane.iris.core.structure.authoring.StructureTransactionWriter; import art.arcane.iris.engine.object.world.biome.IrisBiome; import art.arcane.iris.engine.object.material.IrisBlockData; import art.arcane.iris.engine.object.world.dimension.IrisDimension; -import art.arcane.iris.engine.object.entity.IrisEntity; import art.arcane.iris.engine.object.noise.expression.IrisExpression; import art.arcane.iris.engine.object.terrain.IrisGenerator; import art.arcane.iris.engine.object.image.IrisImage; import art.arcane.iris.engine.object.image.IrisImageMap; -import art.arcane.iris.engine.object.loot.IrisLootTable; -import art.arcane.iris.engine.object.marker.IrisMarker; import art.arcane.iris.engine.object.mod.IrisMod; import art.arcane.iris.engine.object.prefab.IrisObject; import art.arcane.iris.engine.object.world.region.IrisRegion; -import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; import art.arcane.iris.engine.object.annotations.Snippet; import art.arcane.iris.engine.object.prefab.matter.IrisMatterObject; import art.arcane.volmlib.util.collection.KList; @@ -103,9 +99,8 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { private static final Set ENGINE_HOLDERS = Collections.synchronizedSet(Collections.newSetFromMap(new IdentityHashMap<>())); /** Every resource type Iris loads itself for generation, studio and validation; module resource kinds come on top. */ - private static final List> RUNTIME_RESOURCE_TYPES = List.of(IrisLootTable.class, - IrisSpawner.class, IrisEntity.class, IrisRegion.class, IrisBiome.class, IrisMod.class, IrisDimension.class, - IrisGenerator.class, IrisMarker.class, IrisBlockData.class, IrisExpression.class, IrisObject.class, IrisImage.class, + private static final List> RUNTIME_RESOURCE_TYPES = List.of(IrisRegion.class, IrisBiome.class, IrisMod.class, IrisDimension.class, + IrisGenerator.class, IrisBlockData.class, IrisExpression.class, IrisObject.class, IrisImage.class, IrisImageMap.class, IrisMatterObject.class); /** Pack folders Iris reads that hold no resources of its loaders: snippets and module jars. */ private static final List OTHER_OWN_FOLDERS = List.of("snippet", "modules"); @@ -118,13 +113,9 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { @ToString.Exclude private volatile IrisPackResources packResources; private ResourceLoader biomeLoader; - private ResourceLoader lootLoader; private ResourceLoader regionLoader; private ResourceLoader dimensionLoader; private ResourceLoader generatorLoader; - private ResourceLoader entityLoader; - private ResourceLoader markerLoader; - private ResourceLoader spawnerLoader; private ResourceLoader modLoader; private ResourceLoader blockLoader; private ResourceLoader expressionLoader; @@ -254,30 +245,14 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { return loadAny(IrisMod.class, key, nearest); } - public static IrisEntity loadAnyEntity(String key, @Nullable IrisData nearest) { - return loadAny(IrisEntity.class, key, nearest); - } - - public static IrisLootTable loadAnyLootTable(String key, @Nullable IrisData nearest) { - return loadAny(IrisLootTable.class, key, nearest); - } - public static IrisBlockData loadAnyBlock(String key, @Nullable IrisData nearest) { return loadAny(IrisBlockData.class, key, nearest); } - public static IrisSpawner loadAnySpaner(String key, @Nullable IrisData nearest) { - return loadAny(IrisSpawner.class, key, nearest); - } - public static IrisRegion loadAnyRegion(String key, @Nullable IrisData nearest) { return loadAny(IrisRegion.class, key, nearest); } - public static IrisMarker loadAnyMarker(String key, @Nullable IrisData nearest) { - return loadAny(IrisMarker.class, key, nearest); - } - public static IrisImage loadAnyImage(String key, @Nullable IrisData nearest) { return loadAny(IrisImage.class, key, nearest); } @@ -521,15 +496,11 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory { .registerTypeAdapter(MantleFlag.class, new MantleFlagAdapter()) .setPrettyPrinting(); KMap, ResourceLoader> replacement = new KMap<>(); - this.lootLoader = registerLoader(IrisLootTable.class, replacement); - this.spawnerLoader = registerLoader(IrisSpawner.class, replacement); - this.entityLoader = registerLoader(IrisEntity.class, replacement); this.regionLoader = registerLoader(IrisRegion.class, replacement); this.biomeLoader = registerLoader(IrisBiome.class, replacement); this.modLoader = registerLoader(IrisMod.class, replacement); this.dimensionLoader = registerLoader(IrisDimension.class, replacement); this.generatorLoader = registerLoader(IrisGenerator.class, replacement); - this.markerLoader = registerLoader(IrisMarker.class, replacement); this.blockLoader = registerLoader(IrisBlockData.class, replacement); this.expressionLoader = registerLoader(IrisExpression.class, replacement); this.objectLoader = registerLoader(IrisObject.class, replacement); diff --git a/core/src/main/java/art/arcane/iris/core/pack/PackIntegerChecks.java b/core/src/main/java/art/arcane/iris/core/pack/PackIntegerChecks.java new file mode 100644 index 000000000..217a6349f --- /dev/null +++ b/core/src/main/java/art/arcane/iris/core/pack/PackIntegerChecks.java @@ -0,0 +1,68 @@ +/* + * 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 . + */ + +package art.arcane.iris.core.pack; + +import art.arcane.volmlib.util.json.JSONObject; + +import java.util.List; + +/** Checks of integer fields in the JSON of pack files, which add what is wrong to a list of messages. */ +public final class PackIntegerChecks { + private PackIntegerChecks() { + } + + /** The integer in {@code field}, {@code defaultValue} when it is absent, or null (with a message) when it is not an integer. */ + public static Integer integerField(JSONObject object, String field, int defaultValue, + String path, List blockingErrors) { + if (!object.has(field)) { + return defaultValue; + } + Object rawValue = object.opt(field); + if (!(rawValue instanceof Number number) + || !Double.isFinite(number.doubleValue()) + || number.doubleValue() != Math.rint(number.doubleValue()) + || number.longValue() < Integer.MIN_VALUE + || number.longValue() > Integer.MAX_VALUE) { + blockingErrors.add(path + "." + field + " must be an integer."); + return null; + } + return number.intValue(); + } + + public static void requireMinimum(String fieldPath, Integer value, int minimum, + List blockingErrors) { + if (value != null && value < minimum) { + blockingErrors.add(fieldPath + " must be at least " + minimum + "."); + } + } + + public static void requireMaximum(String fieldPath, Integer value, int maximum, + List blockingErrors) { + if (value != null && value > maximum) { + blockingErrors.add(fieldPath + " must be at most " + maximum + "."); + } + } + + public static void requireOrdered(String minimumPath, Integer minimum, String maximumPath, + Integer maximum, List blockingErrors) { + if (minimum != null && maximum != null && minimum > maximum) { + blockingErrors.add(minimumPath + " must not exceed " + maximumPath + "."); + } + } +} diff --git a/core/src/main/java/art/arcane/iris/core/pack/PackJsonFieldChecks.java b/core/src/main/java/art/arcane/iris/core/pack/PackJsonFieldChecks.java index c397a5890..cbbd6e3ed 100644 --- a/core/src/main/java/art/arcane/iris/core/pack/PackJsonFieldChecks.java +++ b/core/src/main/java/art/arcane/iris/core/pack/PackJsonFieldChecks.java @@ -62,9 +62,9 @@ final class PackJsonFieldChecks { if (!object.has(field) || object.opt(field) == JSONObject.NULL) { return; } - Integer value = PackLootValidator.lootInteger(object, field, minimum, path, blockingErrors); - PackLootValidator.requireMinimum(path + "." + field, value, minimum, blockingErrors); - PackLootValidator.requireMaximum(path + "." + field, value, maximum, blockingErrors); + Integer value = PackIntegerChecks.integerField(object, field, minimum, path, blockingErrors); + PackIntegerChecks.requireMinimum(path + "." + field, value, minimum, blockingErrors); + PackIntegerChecks.requireMaximum(path + "." + field, value, maximum, blockingErrors); } static void validateOptionalDoubleRange(String path, JSONObject object, String field, diff --git a/core/src/main/java/art/arcane/iris/core/pack/PackLootValidator.java b/core/src/main/java/art/arcane/iris/core/pack/PackLootValidator.java deleted file mode 100644 index 8e6092ad7..000000000 --- a/core/src/main/java/art/arcane/iris/core/pack/PackLootValidator.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2022 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 . - */ - -package art.arcane.iris.core.pack; - -import art.arcane.iris.engine.object.loot.IrisLoot; -import art.arcane.iris.engine.object.loot.IrisLootReference; -import art.arcane.iris.engine.object.loot.IrisLootTable; -import art.arcane.volmlib.util.json.JSONArray; -import art.arcane.volmlib.util.json.JSONObject; - -import java.io.File; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Set; - -final class PackLootValidator { - private PackLootValidator() { - } - - record LootGraphIssues(List errors, List warnings) { - LootGraphIssues { - errors = List.copyOf(errors); - warnings = List.copyOf(warnings); - } - } - - static LootGraphIssues validateLootGraph(File packFolder) { - List blockingErrors = new ArrayList<>(); - List warnings = new ArrayList<>(); - if (packFolder == null || !packFolder.isDirectory()) { - return new LootGraphIssues(blockingErrors, warnings); - } - - File lootFolder = new File(packFolder, PackValidator.LOOT_FOLDER); - Set lootKeys = ContentKeyValidator.deriveRegistrantKeysExact(lootFolder); - if (lootFolder.isDirectory()) { - List lootFiles = PackValidationIo.listJsonRecursive(lootFolder); - lootFiles.sort(Comparator.comparing(File::getPath)); - for (File lootFile : lootFiles) { - String lootKey = PackValidationIo.deriveKey(lootFolder, lootFile); - JSONObject table = PackStructurePlacementValidator.readGraphJson( - lootFile, "Loot table", lootKey, blockingErrors); - if (table != null) { - validateLootTable(lootKey, table, blockingErrors); - } - } - } - - for (String folderName : PackValidator.STRUCTURE_HOST_FOLDERS) { - File resourceFolder = new File(packFolder, folderName); - if (!resourceFolder.isDirectory()) { - continue; - } - List resourceFiles = PackValidationIo.listJsonRecursive(resourceFolder); - resourceFiles.sort(Comparator.comparing(File::getPath)); - for (File resourceFile : resourceFiles) { - JSONObject resource = PackValidationIo.readJson(resourceFile); - if (resource == null || !resource.has("loot")) { - continue; - } - String resourceType = PackStructurePlacementValidator.structureHostType(folderName); - String resourceKey = PackValidationIo.deriveKey(resourceFolder, resourceFile); - validateLootReference(resourceType, resourceKey, resource.opt("loot"), lootKeys, blockingErrors, warnings); - } - } - return new LootGraphIssues(blockingErrors, warnings); - } - - private static void validateLootTable(String lootKey, JSONObject table, List blockingErrors) { - String path = "Loot table '" + lootKey + "'"; - Integer rarity = lootInteger(table, "rarity", 1, path, blockingErrors); - Integer minimumPicked = lootInteger(table, "minPicked", 1, path, blockingErrors); - Integer maximumPicked = lootInteger(table, "maxPicked", 5, path, blockingErrors); - Integer maximumTries = lootInteger(table, "maxTries", 10, path, blockingErrors); - requireMinimum(path + ".rarity", rarity, 1, blockingErrors); - requireMinimum(path + ".minPicked", minimumPicked, 0, blockingErrors); - requireMinimum(path + ".maxPicked", maximumPicked, 1, blockingErrors); - requireMinimum(path + ".maxTries", maximumTries, 1, blockingErrors); - requireMaximum(path + ".minPicked", minimumPicked, IrisLootTable.MAX_PICKED, blockingErrors); - requireMaximum(path + ".maxPicked", maximumPicked, IrisLootTable.MAX_PICKED, blockingErrors); - requireMaximum(path + ".maxTries", maximumTries, IrisLootTable.MAX_TRIES, blockingErrors); - requireOrdered(path + ".minPicked", minimumPicked, path + ".maxPicked", maximumPicked, blockingErrors); - - JSONArray entries = table.optJSONArray("loot"); - if (entries == null || entries.length() == 0) { - blockingErrors.add(path + ".loot must be a non-empty array."); - return; - } - for (int entryIndex = 0; entryIndex < entries.length(); entryIndex++) { - JSONObject entry = entries.optJSONObject(entryIndex); - String entryPath = path + ".loot[" + entryIndex + "]"; - if (entry == null) { - blockingErrors.add(entryPath + " must be an object."); - continue; - } - String type = entry.optString("type", "").trim(); - if (type.isEmpty()) { - blockingErrors.add(entryPath + ".type must not be blank."); - } - Integer entryRarity = lootInteger(entry, "rarity", 1, entryPath, blockingErrors); - Integer minimumAmount = lootInteger(entry, "minAmount", 1, entryPath, blockingErrors); - Integer maximumAmount = lootInteger(entry, "maxAmount", 1, entryPath, blockingErrors); - requireMinimum(entryPath + ".rarity", entryRarity, 1, blockingErrors); - requireMinimum(entryPath + ".minAmount", minimumAmount, 1, blockingErrors); - requireMinimum(entryPath + ".maxAmount", maximumAmount, 1, blockingErrors); - requireMaximum(entryPath + ".minAmount", minimumAmount, IrisLoot.MAX_AMOUNT, blockingErrors); - requireMaximum(entryPath + ".maxAmount", maximumAmount, IrisLoot.MAX_AMOUNT, blockingErrors); - requireOrdered(entryPath + ".minAmount", minimumAmount, - entryPath + ".maxAmount", maximumAmount, blockingErrors); - validateLootEnchantments(entryPath, entry.opt("enchantments"), blockingErrors); - } - } - - private static void validateLootEnchantments(String entryPath, Object rawEnchantments, - List blockingErrors) { - if (rawEnchantments == null || rawEnchantments == JSONObject.NULL) { - return; - } - if (!(rawEnchantments instanceof JSONArray enchantments)) { - blockingErrors.add(entryPath + ".enchantments must be an array."); - return; - } - for (int enchantmentIndex = 0; enchantmentIndex < enchantments.length(); enchantmentIndex++) { - JSONObject enchantment = enchantments.optJSONObject(enchantmentIndex); - String enchantmentPath = entryPath + ".enchantments[" + enchantmentIndex + "]"; - if (enchantment == null) { - blockingErrors.add(enchantmentPath + " must be an object."); - continue; - } - if (enchantment.optString("enchantment", "").isBlank()) { - blockingErrors.add(enchantmentPath + ".enchantment must not be blank."); - } - Integer minimumLevel = lootInteger(enchantment, "minLevel", 1, enchantmentPath, blockingErrors); - Integer maximumLevel = lootInteger(enchantment, "maxLevel", 1, enchantmentPath, blockingErrors); - requireMinimum(enchantmentPath + ".minLevel", minimumLevel, 1, blockingErrors); - requireMinimum(enchantmentPath + ".maxLevel", maximumLevel, 1, blockingErrors); - requireOrdered(enchantmentPath + ".minLevel", minimumLevel, - enchantmentPath + ".maxLevel", maximumLevel, blockingErrors); - if (enchantment.has("chance")) { - Object rawChance = enchantment.opt("chance"); - if (!(rawChance instanceof Number number) - || !Double.isFinite(number.doubleValue()) - || number.doubleValue() < 0D - || number.doubleValue() > 1D) { - blockingErrors.add(enchantmentPath + ".chance must be a finite number from 0 to 1."); - } - } - } - } - - private static void validateLootReference(String resourceType, String resourceKey, Object rawLoot, - Set lootKeys, List blockingErrors, List warnings) { - String path = resourceType + " '" + resourceKey + "'.loot"; - if (!(rawLoot instanceof JSONObject reference)) { - blockingErrors.add(path + " must be an object."); - return; - } - boolean clearMode = false; - if (reference.has("mode")) { - Object rawMode = reference.opt("mode"); - if (!(rawMode instanceof String mode) - || !Set.of("ADD", "CLEAR", "REPLACE", "FALLBACK").contains(mode)) { - blockingErrors.add(path + ".mode must be ADD, CLEAR, REPLACE, or FALLBACK."); - } else { - clearMode = "CLEAR".equals(mode); - } - } - if (reference.has("multiplier")) { - Object rawMultiplier = reference.opt("multiplier"); - if (!(rawMultiplier instanceof Number multiplier) - || !Double.isFinite(multiplier.doubleValue()) - || multiplier.doubleValue() < 0D - || multiplier.doubleValue() > IrisLootReference.MAX_MULTIPLIER) { - blockingErrors.add(path + ".multiplier must be a finite number from 0 to " - + (int) IrisLootReference.MAX_MULTIPLIER + "."); - } - } - if (!reference.has("tables")) { - return; - } - JSONArray tables = reference.optJSONArray("tables"); - if (tables == null) { - blockingErrors.add(path + ".tables must be an array."); - return; - } - if (clearMode && tables.length() > 0) { - warnings.add(path + " uses mode CLEAR and lists " + tables.length() - + " table(s); CLEAR clears parent tables and contributes no tables of its own, so these entries are dead. Use REPLACE to substitute them."); - } - for (int tableIndex = 0; tableIndex < tables.length(); tableIndex++) { - Object rawTableKey = tables.opt(tableIndex); - if (!(rawTableKey instanceof String tableKey) || tableKey.isBlank()) { - blockingErrors.add(path + ".tables[" + tableIndex + "] must name a loot table."); - } else if (!lootKeys.contains(tableKey)) { - blockingErrors.add(path + ".tables[" + tableIndex - + "] references missing loot table '" + tableKey + "'."); - } - } - } - - static Integer lootInteger(JSONObject object, String field, int defaultValue, - String path, List blockingErrors) { - if (!object.has(field)) { - return defaultValue; - } - Object rawValue = object.opt(field); - if (!(rawValue instanceof Number number) - || !Double.isFinite(number.doubleValue()) - || number.doubleValue() != Math.rint(number.doubleValue()) - || number.longValue() < Integer.MIN_VALUE - || number.longValue() > Integer.MAX_VALUE) { - blockingErrors.add(path + "." + field + " must be an integer."); - return null; - } - return number.intValue(); - } - - static void requireMinimum(String fieldPath, Integer value, int minimum, - List blockingErrors) { - if (value != null && value < minimum) { - blockingErrors.add(fieldPath + " must be at least " + minimum + "."); - } - } - - static void requireMaximum(String fieldPath, Integer value, int maximum, - List blockingErrors) { - if (value != null && value > maximum) { - blockingErrors.add(fieldPath + " must be at most " + maximum + "."); - } - } - - static void requireOrdered(String minimumPath, Integer minimum, String maximumPath, - Integer maximum, List blockingErrors) { - if (minimum != null && maximum != null && minimum > maximum) { - blockingErrors.add(minimumPath + " must not exceed " + maximumPath + "."); - } - } -} diff --git a/core/src/main/java/art/arcane/iris/core/pack/PackStructurePlacementValidator.java b/core/src/main/java/art/arcane/iris/core/pack/PackStructurePlacementValidator.java index 4d95b5e4a..801d17f42 100644 --- a/core/src/main/java/art/arcane/iris/core/pack/PackStructurePlacementValidator.java +++ b/core/src/main/java/art/arcane/iris/core/pack/PackStructurePlacementValidator.java @@ -395,8 +395,8 @@ final class PackStructurePlacementValidator { if (!structureKey.isEmpty() && !sourceKeys.add(structureKey.toLowerCase(Locale.ROOT))) { blockingErrors.add(sourcePath + ".structure duplicates native source '" + structureKey + "'."); } - Integer weight = PackLootValidator.lootInteger(source, "weight", 1, sourcePath, blockingErrors); - PackLootValidator.requireMinimum(sourcePath + ".weight", weight, 1, blockingErrors); + Integer weight = PackIntegerChecks.integerField(source, "weight", 1, sourcePath, blockingErrors); + PackIntegerChecks.requireMinimum(sourcePath + ".weight", weight, 1, blockingErrors); if (weight != null && weight > 0) { totalWeight += weight; } diff --git a/core/src/main/java/art/arcane/iris/core/pack/PackValidator.java b/core/src/main/java/art/arcane/iris/core/pack/PackValidator.java index c6d662bdb..ce9d978a6 100644 --- a/core/src/main/java/art/arcane/iris/core/pack/PackValidator.java +++ b/core/src/main/java/art/arcane/iris/core/pack/PackValidator.java @@ -36,7 +36,6 @@ public final class PackValidator { static final String DATAPACKS_FOLDER = "datapacks"; static final String CACHE_FOLDER = "cache"; static final String OBJECTS_FOLDER = "objects"; - static final String LOOT_FOLDER = "loot"; static final String DIMENSIONS_FOLDER = "dimensions"; static final String STRUCTURES_FOLDER = "structures"; static final String JIGSAW_POOLS_FOLDER = "jigsaw-pools"; @@ -90,9 +89,6 @@ public final class PackValidator { addDistinct(blockingErrors, imageMaps.errors()); addDistinct(warnings, imageMaps.warnings()); blockingErrors.addAll(PackCaveProfileValidator.validateLegacyFields(packFolder)); - PackLootValidator.LootGraphIssues lootIssues = PackLootValidator.validateLootGraph(packFolder); - addDistinct(blockingErrors, lootIssues.errors()); - addDistinct(warnings, lootIssues.warnings()); blockingErrors.addAll(PackObjectSurfaceValidator.validateRemovedWorldgenFields(packFolder)); blockingErrors.addAll(PackObjectSurfaceValidator.validateObjectSurfaceSupport(packFolder)); blockingErrors.addAll(PackObjectSurfaceValidator.validateUnsupportedStructureTransforms(packFolder)); diff --git a/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java b/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java index bfae34b3d..241f811e2 100644 --- a/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java +++ b/core/src/main/java/art/arcane/iris/core/project/IrisPackageCompiler.java @@ -18,6 +18,8 @@ package art.arcane.iris.core.project; +import art.arcane.iris.engine.spawn.SpawnResources; +import art.arcane.iris.engine.loot.LootResources; import art.arcane.iris.engine.object.placement.IrisObjectPlacement; import com.google.gson.Gson; import art.arcane.iris.core.loader.IrisData; @@ -120,29 +122,29 @@ public class IrisPackageCompiler { } dimension.getAllRegions(() -> dm).forEach((region) -> addIfPresent(regions, region)); - dimension.getLoot().getTables().forEach((i) -> addIfPresent(loot, dm.getLootLoader().load(i))); + dimension.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i))); regions.forEach((i) -> biomes.addAll(i.getAllBiomes(() -> dm))); dimension.getReachableBiomes(() -> dm).forEach((biome) -> addIfPresent(biomes, biome)); - regions.forEach((r) -> r.getLoot().getTables().forEach((i) -> addIfPresent(loot, dm.getLootLoader().load(i)))); - regions.forEach((r) -> r.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, dm.getSpawnerLoader().load(sp)))); - dimension.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, dm.getSpawnerLoader().load(sp))); + regions.forEach((r) -> r.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i)))); + regions.forEach((r) -> r.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp)))); + dimension.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp))); biomes.forEach((i) -> i.getGenerators().forEach((j) -> addIfPresent(generators, j.getCachedGenerator(() -> dm)))); - biomes.forEach((r) -> r.getLoot().getTables().forEach((i) -> addIfPresent(loot, dm.getLootLoader().load(i)))); - biomes.forEach((r) -> r.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, dm.getSpawnerLoader().load(sp)))); + biomes.forEach((r) -> r.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i)))); + biomes.forEach((r) -> r.getEntitySpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp)))); KList allPlacements = new KList<>(); regions.forEach((r) -> allPlacements.addAll(r.getObjects())); biomes.forEach((i) -> allPlacements.addAll(i.getObjects())); KSet markers = new KSet<>(); for (String markerKey : PackExportClosure.collectMarkerKeys(allPlacements)) { - IrisMarker marker = dm.getMarkerLoader().load(markerKey); + IrisMarker marker = SpawnResources.marker(dm, markerKey); if (marker == null) { continue; } markers.add(marker); - marker.getSpawners().forEach((sp) -> addIfPresent(spawners, dm.getSpawnerLoader().load(sp))); + marker.getSpawners().forEach((sp) -> addIfPresent(spawners, SpawnResources.spawner(dm, sp))); } - collectSpawnerEntityKeys(spawners).forEach((i) -> addIfPresent(entities, dm.getEntityLoader().load(i))); - entities.forEach((e) -> e.getLoot().getTables().forEach((i) -> addIfPresent(loot, dm.getLootLoader().load(i)))); + collectSpawnerEntityKeys(spawners).forEach((i) -> addIfPresent(entities, SpawnResources.entity(dm, i))); + entities.forEach((e) -> e.getLoot().getTables().forEach((i) -> addIfPresent(loot, LootResources.table(dm, i)))); Set structureKeys = new LinkedHashSet<>(); collectStructureKeys(structureKeys, dimension.getStructures()); regions.forEach((region) -> collectStructureKeys(structureKeys, region.getStructures())); diff --git a/core/src/main/java/art/arcane/iris/util/common/data/registry/Particles.java b/core/src/main/java/art/arcane/iris/util/common/data/registry/Particles.java index be18db1cd..e30c1ba88 100644 --- a/core/src/main/java/art/arcane/iris/util/common/data/registry/Particles.java +++ b/core/src/main/java/art/arcane/iris/util/common/data/registry/Particles.java @@ -1,14 +1,12 @@ package art.arcane.iris.util.common.data.registry; -import art.arcane.iris.engine.object.entity.IrisEntity; import org.bukkit.Particle; import static art.arcane.iris.util.common.data.registry.RegistryUtil.find; /** - * Bukkit particle constants. Statically imported by {@code IrisEntity} (a Gson-registered pack - * type), so this class is reachable from core on the modded loaders. The resolution below is - * therefore guarded against the absent Bukkit class: without the guard the class initializer dies + * Bukkit particle constants, used by the Bukkit entity spawner. Core code can reach this class on the modded + * loaders, so the resolution below is guarded against the absent Bukkit class: without the guard the class initializer dies * with a NoClassDefFoundError and the class stays permanently erroneous for the rest of the JVM's * life. On Bukkit a genuinely missing registry key still throws, exactly as before. */ diff --git a/core/src/main/java/art/arcane/iris/util/common/director/handlers/EntityHandler.java b/core/src/main/java/art/arcane/iris/util/common/director/handlers/EntityHandler.java index df12a7e0b..1844516e5 100644 --- a/core/src/main/java/art/arcane/iris/util/common/director/handlers/EntityHandler.java +++ b/core/src/main/java/art/arcane/iris/util/common/director/handlers/EntityHandler.java @@ -18,7 +18,10 @@ package art.arcane.iris.util.common.director.handlers; +import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.object.entity.IrisEntity; +import art.arcane.iris.engine.spawn.SpawnResources; +import art.arcane.volmlib.util.collection.KList; import art.arcane.iris.util.common.director.specialhandlers.RegistrantHandler; public class EntityHandler extends RegistrantHandler { @@ -27,6 +30,18 @@ public class EntityHandler extends RegistrantHandler { super(IrisEntity.class, false); } + @Override + protected KList loadAll(IrisData data) { + KList entities = new KList<>(); + for (String key : SpawnResources.entityKeys(data)) { + IrisEntity entity = SpawnResources.entity(data, key); + if (entity != null) { + entities.add(entity); + } + } + return entities; + } + @Override public String getRandomDefault() { return "entity"; diff --git a/core/src/main/java/art/arcane/iris/util/common/director/specialhandlers/RegistrantHandler.java b/core/src/main/java/art/arcane/iris/util/common/director/specialhandlers/RegistrantHandler.java index c11a99aff..b9d7ecad4 100644 --- a/core/src/main/java/art/arcane/iris/util/common/director/specialhandlers/RegistrantHandler.java +++ b/core/src/main/java/art/arcane/iris/util/common/director/specialhandlers/RegistrantHandler.java @@ -29,7 +29,7 @@ public abstract class RegistrantHandler implements Dir Set known = new HashSet<>(); IrisData data = data(); if (data != null) { - for (T j : data.getLoader(type).loadAll(data.getLoader(type).getPossibleKeys())) { + for (T j : loadAll(data)) { known.add(j.getLoadKey()); p.add(j); } @@ -38,7 +38,7 @@ public abstract class RegistrantHandler implements Dir for (File i : PackDirectoryResolver.listVisiblePackDirectories( IrisPlatforms.get().packsFolder())) { data = IrisData.get(i); - for (T j : data.getLoader(type).loadAll(data.getLoader(type).getPossibleKeys())) { + for (T j : loadAll(data)) { if (known.add(j.getLoadKey())) p.add(j); } @@ -47,6 +47,11 @@ public abstract class RegistrantHandler implements Dir return p; } + /** Every resource of this handler's type that {@code data}'s pack has. */ + protected KList loadAll(IrisData data) { + return data.getLoader(type).loadAll(data.getLoader(type).getPossibleKeys()); + } + @Override public String toString(T t) { return t != null ? t.getLoadKey() : "null"; diff --git a/core/src/main/java/art/arcane/iris/util/project/matter/slices/RegistryMatter.java b/core/src/main/java/art/arcane/iris/util/project/matter/slices/RegistryMatter.java index 780e55617..229e1f11b 100644 --- a/core/src/main/java/art/arcane/iris/util/project/matter/slices/RegistryMatter.java +++ b/core/src/main/java/art/arcane/iris/util/project/matter/slices/RegistryMatter.java @@ -20,7 +20,6 @@ package art.arcane.iris.util.project.matter.slices; import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.core.loader.IrisRegistrant; -import art.arcane.iris.core.loader.ResourceLoader; import art.arcane.iris.util.project.matter.IrisMatterContext; import art.arcane.volmlib.util.data.palette.Palette; import art.arcane.volmlib.util.matter.slices.RawMatter; @@ -29,7 +28,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -public class RegistryMatter extends RawMatter { +public abstract class RegistryMatter extends RawMatter { public RegistryMatter(int width, int height, int depth, Class c, T e) { super(width, height, depth, c); } @@ -46,12 +45,9 @@ public class RegistryMatter extends RawMatter { @Override public T readNode(DataInputStream din) throws IOException { - String key = din.readUTF(); - IrisData data = IrisMatterContext.require(); - ResourceLoader loader = data.getLoaders().get(getType()); - if (loader == null) { - throw new IOException("No Iris registry loader is available for matter type " + getType().getName() + " while reading key " + key + "."); - } - return (T) loader.load(key); + return load(IrisMatterContext.require(), din.readUTF()); } + + /** The resource of the pack {@code data} named by {@code key}, or null when the pack has none. */ + protected abstract T load(IrisData data, String key); } diff --git a/core/src/main/java/art/arcane/iris/util/project/matter/slices/SpawnerMatter.java b/core/src/main/java/art/arcane/iris/util/project/matter/slices/SpawnerMatter.java index 0c7040ecb..0cd4eb21b 100644 --- a/core/src/main/java/art/arcane/iris/util/project/matter/slices/SpawnerMatter.java +++ b/core/src/main/java/art/arcane/iris/util/project/matter/slices/SpawnerMatter.java @@ -18,7 +18,9 @@ package art.arcane.iris.util.project.matter.slices; +import art.arcane.iris.core.loader.IrisData; import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; +import art.arcane.iris.engine.spawn.SpawnResources; import art.arcane.volmlib.util.matter.Sliced; @Sliced @@ -30,4 +32,9 @@ public class SpawnerMatter extends RegistryMatter { public SpawnerMatter(int width, int height, int depth) { super(width, height, depth, IrisSpawner.class, new IrisSpawner()); } + + @Override + protected IrisSpawner load(IrisData data, String key) { + return SpawnResources.spawner(data, key); + } } diff --git a/core/src/test/java/art/arcane/iris/engine/framework/structure/StructureResourcesTest.java b/core/src/test/java/art/arcane/iris/engine/framework/structure/StructureResourcesTest.java index 2c6a07efb..139a0f3b4 100644 --- a/core/src/test/java/art/arcane/iris/engine/framework/structure/StructureResourcesTest.java +++ b/core/src/test/java/art/arcane/iris/engine/framework/structure/StructureResourcesTest.java @@ -44,10 +44,11 @@ public class StructureResourcesTest { try { var catalog = data.getModules().pack().catalog(); + var kinds = catalog.resourceKinds().stream().map(ResourceKindRegistration::kind) + .filter(kind -> kind.id().toString().startsWith("iris:structure/")).toList(); assertEquals(List.of("iris:structure/piece", "iris:structure/pool", "iris:structure/structure"), - catalog.resourceKinds().stream().map(registration -> registration.kind().id().toString()).toList()); - assertEquals(List.of("jigsaw-pieces", "jigsaw-pools", "structures"), - catalog.resourceKinds().stream().map(ResourceKindRegistration::kind).map(kind -> kind.folder()).toList()); + kinds.stream().map(kind -> kind.id().toString()).toList()); + assertEquals(List.of("jigsaw-pieces", "jigsaw-pools", "structures"), kinds.stream().map(kind -> kind.folder()).toList()); assertTrue(catalog.validators().stream().map(ValidatorRegistration::validator).anyMatch(StructureValidator.class::isInstance)); assertFalse(data.getLoaders().containsKey(IrisStructure.class)); assertFalse(data.getLoaders().containsKey(IrisJigsawPool.class)); @@ -146,7 +147,8 @@ public class StructureResourcesTest { List entries = ModuleResourceSchemas.entries(data, true); assertEquals(List.of("./.iris/schema/jigsaw-pieces-schema.json", "./.iris/schema/jigsaw-pools-schema.json", - "./.iris/schema/structures-schema.json"), entries.stream().map(entry -> entry.getString("url")).toList()); + "./.iris/schema/structures-schema.json"), + entries.stream().map(entry -> entry.getString("url")).filter(url -> url.contains("jigsaw") || url.contains("structures-")).toList()); JSONObject structures = new JSONObject(Files.readString(pack.resolve(".iris/schema/structures-schema.json"))); JSONObject startPool = structures.getJSONObject("properties").getJSONObject("startPool"); assertEquals("#/definitions/erzjigsaw-pools", startPool.getString("$ref")); diff --git a/core/src/test/java/art/arcane/iris/engine/loot/LootResourcesTest.java b/core/src/test/java/art/arcane/iris/engine/loot/LootResourcesTest.java new file mode 100644 index 000000000..a1e0d4029 --- /dev/null +++ b/core/src/test/java/art/arcane/iris/engine/loot/LootResourcesTest.java @@ -0,0 +1,113 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.loot; + +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.core.project.ModuleResourceSchemas; +import art.arcane.iris.core.project.SchemaTestPlatform; +import art.arcane.iris.engine.object.loot.IrisLootTable; +import art.arcane.volmlib.util.json.JSONObject; +import com.volmit.host.ValidatorRegistration; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.nio.charset.StandardCharsets; +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.assertNull; +import static org.junit.Assert.assertTrue; + +/** Loot tables are a resource kind of module {@code iris:loot}, read from the folder packs have always had. */ +public class LootResourcesTest { + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Test + public void theLootModuleOwnsTheKindAndItsValidator() throws Exception { + IrisData data = IrisData.openValidation(lootPack("owned").toFile()); + try { + var catalog = data.getModules().pack().catalog(); + + assertEquals(List.of("iris:loot/table"), catalog.resourceKinds().stream().map(registration -> registration.kind().id().toString()) + .filter(id -> id.startsWith("iris:loot/")).toList()); + assertTrue(catalog.validators().stream().map(ValidatorRegistration::validator).anyMatch(LootValidator.class::isInstance)); + assertFalse(data.getLoaders().containsKey(IrisLootTable.class)); + } finally { + data.close(); + } + } + + @Test + public void tablesAreReadThroughPackResourcesAndReadAgainAfterAReload() throws Exception { + Path pack = lootPack("tables"); + IrisData data = IrisData.openValidation(pack.toFile()); + try { + IrisLootTable table = LootResources.table(data, "dungeon/chest"); + + assertEquals("Chest", table.getName()); + assertEquals("dungeon/chest", table.getLoadKey()); + assertEquals(pack.resolve("loot/dungeon/chest.json").toFile(), table.getLoadFile()); + assertEquals(List.of("dungeon/chest"), LootResources.tableKeys(data)); + assertEquals(List.of(table), LootResources.tables(data, List.of("dungeon/chest", "missing"))); + assertNull(LootResources.table(data, "missing")); + assertNull(LootResources.table(data, " ")); + + write(pack, "loot/dungeon/chest.json", "{\"name\":\"Renamed\"}"); + data.dump(); + assertEquals("Renamed", LootResources.table(data, "dungeon/chest").getName()); + } finally { + data.close(); + } + } + + @Test + public void studioDescribesLootTablesAsIrisDoes() throws Exception { + Path pack = lootPack("studio"); + IrisData data = IrisData.openValidation(pack.toFile()); + try (SchemaTestPlatform ignored = SchemaTestPlatform.bind(temporaryFolder.getRoot())) { + List entries = ModuleResourceSchemas.entries(data, true); + + assertTrue(entries.stream().anyMatch(entry -> entry.getString("url").equals("./.iris/schema/loot-schema.json"))); + assertTrue(Files.exists(pack.resolve(".iris/schema/loot-schema.json"))); + } finally { + data.close(); + } + } + + private Path lootPack(String name) throws Exception { + File pack = temporaryFolder.newFolder(name); + write(pack.toPath(), "dimensions/main.json", "{\"regions\":[\"region\"]}"); + write(pack.toPath(), "regions/region.json", "{\"landBiomes\":[\"biome\"]}"); + write(pack.toPath(), "biomes/biome.json", "{\"name\":\"Biome\"}"); + write(pack.toPath(), "loot/dungeon/chest.json", "{\"name\":\"Chest\",\"loot\":[{\"type\":\"stick\"}]}"); + return pack.toPath(); + } + + private static void write(Path root, String relative, String content) throws Exception { + Path path = root.resolve(relative); + Files.createDirectories(path.getParent()); + Files.writeString(path, content, StandardCharsets.UTF_8); + } +} diff --git a/core/src/test/java/art/arcane/iris/core/pack/PackValidatorLootTest.java b/core/src/test/java/art/arcane/iris/engine/loot/LootValidatorTest.java similarity index 86% rename from core/src/test/java/art/arcane/iris/core/pack/PackValidatorLootTest.java rename to core/src/test/java/art/arcane/iris/engine/loot/LootValidatorTest.java index ac435304e..b27b04f32 100644 --- a/core/src/test/java/art/arcane/iris/core/pack/PackValidatorLootTest.java +++ b/core/src/test/java/art/arcane/iris/engine/loot/LootValidatorTest.java @@ -1,8 +1,10 @@ -package art.arcane.iris.core.pack; +package art.arcane.iris.engine.loot; import art.arcane.iris.engine.object.loot.IrisLoot; import art.arcane.iris.engine.object.loot.IrisLootTable; import art.arcane.iris.engine.object.annotations.MaxNumber; +import com.volmit.validation.Problem; +import com.volmit.validation.Severity; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -16,7 +18,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public class PackValidatorLootTest { +public class LootValidatorTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -28,7 +30,7 @@ public class PackValidatorLootTest { write(pack, "dimensions/main.json", "{\"loot\":{\"mode\":\"FALLBACK\",\"multiplier\":0.5," + "\"tables\":[\"global/clutter\"]}}"); - assertTrue(PackLootValidator.validateLootGraph(pack).errors().isEmpty()); + assertTrue(errors(pack).isEmpty()); } @Test @@ -37,7 +39,7 @@ public class PackValidatorLootTest { write(pack, "dimensions/main.json", "{\"loot\":{\"tables\":[\"missing\"]}}"); assertEquals(List.of("Dimension 'main'.loot.tables[0] references missing loot table 'missing'."), - PackLootValidator.validateLootGraph(pack).errors()); + errors(pack)); } @Test @@ -47,7 +49,7 @@ public class PackValidatorLootTest { + "\"loot\":[{\"type\":\"\",\"rarity\":0,\"minAmount\":3,\"maxAmount\":1," + "\"enchantments\":[{\"enchantment\":\"\",\"minLevel\":4,\"maxLevel\":2,\"chance\":2}]}]}"); - List errors = PackLootValidator.validateLootGraph(pack).errors(); + List errors = errors(pack); assertTrue(errors.stream().anyMatch(error -> error.contains(".rarity must be at least 1"))); assertTrue(errors.stream().anyMatch(error -> error.contains(".minPicked must not exceed"))); @@ -63,7 +65,7 @@ public class PackValidatorLootTest { File pack = temporaryFolder.newFolder("pack"); write(pack, "dimensions/main.json", "{\"loot\":{\"mode\":\"MERGE\",\"multiplier\":-1,\"tables\":[]}}"); - List errors = PackLootValidator.validateLootGraph(pack).errors(); + List errors = errors(pack); assertEquals(2, errors.size()); assertTrue(errors.get(0).contains(".mode must be")); @@ -74,12 +76,12 @@ public class PackValidatorLootTest { public void enforcesPublishedLootMultiplierCap() throws Exception { File acceptedPack = temporaryFolder.newFolder("accepted-pack"); write(acceptedPack, "dimensions/main.json", "{\"loot\":{\"multiplier\":16,\"tables\":[]}}"); - assertTrue(PackLootValidator.validateLootGraph(acceptedPack).errors().isEmpty()); + assertTrue(errors(acceptedPack).isEmpty()); File rejectedPack = temporaryFolder.newFolder("rejected-pack"); write(rejectedPack, "dimensions/main.json", "{\"loot\":{\"multiplier\":16.01,\"tables\":[]}}"); assertEquals(List.of("Dimension 'main'.loot.multiplier must be a finite number from 0 to 16."), - PackLootValidator.validateLootGraph(rejectedPack).errors()); + errors(rejectedPack)); } @Test @@ -88,7 +90,7 @@ public class PackValidatorLootTest { write(pack, "loot/boundary.json", "{\"minPicked\":64,\"maxPicked\":64,\"maxTries\":256," + "\"loot\":[{\"type\":\"stone\",\"minAmount\":64,\"maxAmount\":64}]}"); - assertTrue(PackLootValidator.validateLootGraph(pack).errors().isEmpty()); + assertTrue(errors(pack).isEmpty()); } @Test @@ -97,7 +99,7 @@ public class PackValidatorLootTest { write(pack, "loot/excessive.json", "{\"minPicked\":65,\"maxPicked\":65,\"maxTries\":257," + "\"loot\":[{\"type\":\"stone\",\"minAmount\":65,\"maxAmount\":65}]}"); - List errors = PackLootValidator.validateLootGraph(pack).errors(); + List errors = errors(pack); assertTrue(errors.contains("Loot table 'excessive'.minPicked must be at most 64.")); assertTrue(errors.contains("Loot table 'excessive'.maxPicked must be at most 64.")); @@ -127,12 +129,11 @@ public class PackValidatorLootTest { write(pack, "loot/t.json", "{\"loot\":[{\"type\":\"minecraft:stone\"}]}"); write(pack, "biomes/x.json", "{\"loot\":{\"mode\":\"CLEAR\",\"tables\":[\"t\"]}}"); - PackLootValidator.LootGraphIssues issues = PackLootValidator.validateLootGraph(pack); - - assertTrue(issues.errors().isEmpty()); + + assertTrue(errors(pack).isEmpty()); assertEquals(List.of("Biome 'x'.loot uses mode CLEAR and lists 1 table(s); CLEAR clears parent tables" + " and contributes no tables of its own, so these entries are dead. Use REPLACE to substitute them."), - issues.warnings()); + warnings(pack)); } @Test @@ -140,12 +141,23 @@ public class PackValidatorLootTest { File pack = temporaryFolder.newFolder("clear-dangling"); write(pack, "biomes/x.json", "{\"loot\":{\"mode\":\"CLEAR\",\"tables\":[\"missing\"]}}"); - PackLootValidator.LootGraphIssues issues = PackLootValidator.validateLootGraph(pack); - - assertTrue(issues.errors().contains( + + assertTrue(errors(pack).contains( "Biome 'x'.loot.tables[0] references missing loot table 'missing'.")); } + private static List errors(File pack) { + return messages(pack, Severity.ERROR); + } + + private static List warnings(File pack) { + return messages(pack, Severity.WARNING); + } + + private static List messages(File pack, Severity severity) { + return LootValidator.check(pack).stream().filter(problem -> problem.severity() == severity).map(Problem::message).toList(); + } + private void write(File root, String relative, String content) throws Exception { File file = new File(root, relative); Files.createDirectories(file.toPath().getParent()); diff --git a/core/src/test/java/art/arcane/iris/engine/spawn/EntitySpawningTest.java b/core/src/test/java/art/arcane/iris/engine/spawn/EntitySpawningTest.java index 6f706a5c9..b66829125 100644 --- a/core/src/test/java/art/arcane/iris/engine/spawn/EntitySpawningTest.java +++ b/core/src/test/java/art/arcane/iris/engine/spawn/EntitySpawningTest.java @@ -19,7 +19,6 @@ package art.arcane.iris.engine.spawn; import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.core.loader.ResourceLoader; import art.arcane.iris.core.modules.ModuleResourceFixture; import art.arcane.iris.engine.UsableBlockPlatform; import art.arcane.iris.engine.framework.Engine; @@ -58,9 +57,7 @@ public class EntitySpawningTest { private static final BlockPosition MARKER_BLOCK = new BlockPosition(40, 70, -12); private Engine engine; - private ResourceLoader spawners; - private ResourceLoader markers; - private ResourceLoader entities; + private ModuleResourceFixture fixture; private PackWorld world; @BeforeClass @@ -74,18 +71,11 @@ public class EntitySpawningTest { } @Before - @SuppressWarnings("unchecked") public void buildWorld() { engine = mock(Engine.class); IrisData data = mock(IrisData.class); - spawners = (ResourceLoader) mock(ResourceLoader.class); - markers = (ResourceLoader) mock(ResourceLoader.class); - entities = (ResourceLoader) mock(ResourceLoader.class); when(engine.getData()).thenReturn(data); - when(data.getSpawnerLoader()).thenReturn(spawners); - when(data.getMarkerLoader()).thenReturn(markers); - when(data.getEntityLoader()).thenReturn(entities); - ModuleResourceFixture.serve(data); + fixture = ModuleResourceFixture.serve(data); when(data.getPackResources().items()).thenReturn(mock(ItemRegistry.class)); IrisWorld engineWorld = mock(IrisWorld.class); when(engineWorld.platformWorld()).thenReturn(mock(PlatformWorld.class)); @@ -109,8 +99,8 @@ public class EntitySpawningTest { public void aMarkerMeansItsSpawnersAndWhetherItGoesAwayWhenItsBlockChanges() { IrisMarker marker = new IrisMarker(); marker.setSpawners(new KList<>("zombies", "missing")).setEmptyAbove(true).setRemoveOnChange(false); - when(markers.load("camp")).thenReturn(marker); - when(spawners.load("zombies")).thenReturn(new IrisSpawner()); + fixture.resource(SpawnResources.MARKERS, "camp", marker); + fixture.resource(SpawnResources.SPAWNERS, "zombies", new IrisSpawner()); EntitySpawns.MarkerRule rule = new EntitySpawning().marker(world, "camp").orElseThrow(); @@ -130,13 +120,13 @@ public class EntitySpawningTest { IrisSpawner spawner = new IrisSpawner(); spawner.setLoadKey("camp/zombies"); spawner.getSpawns().add(new IrisEntitySpawn().setEntity("zombie").setMinSpawns(2).setMaxSpawns(2)); - when(spawners.load("camp/zombies")).thenReturn(spawner); + fixture.resource(SpawnResources.SPAWNERS, "camp/zombies", spawner); IrisMarker marker = new IrisMarker(); marker.setExhaustionChance(2); - when(markers.load("camp")).thenReturn(marker); + fixture.resource(SpawnResources.MARKERS, "camp", marker); IrisEntity zombie = new IrisEntity(); zombie.setType("minecraft:zombie"); - when(entities.load("zombie")).thenReturn(zombie); + fixture.resource(SpawnResources.ENTITIES, "zombie", zombie); when(engine.getMinHeight()).thenReturn(-64); EntitySpawns.Plan plan = new EntitySpawning() @@ -156,7 +146,7 @@ public class EntitySpawningTest { @Test public void aSpawnerThatCannotFireOrHasNoEntitiesPlansNothing() { IrisSpawner empty = new IrisSpawner(); - when(spawners.load("empty")).thenReturn(empty); + fixture.resource(SpawnResources.SPAWNERS, "empty", empty); Optional plan = new EntitySpawning().plan(world, new EntitySpawns.Marker(MARKER_BLOCK, "camp", "empty", false)); @@ -167,7 +157,7 @@ public class EntitySpawningTest { public void anEntityOfThePackResolvesToTheSpecTheHostSpawns() { IrisEntity entity = new IrisEntity(); entity.setType("minecraft:cow").setCustomName("&6Bessie").setBaby(true); - when(entities.load("cow")).thenReturn(entity); + fixture.resource(SpawnResources.ENTITIES, "cow", entity); EntitySpec spec = new EntitySpawning().entity(world, "cow").orElseThrow(); diff --git a/core/src/test/java/art/arcane/iris/engine/spawn/SpawnResourcesTest.java b/core/src/test/java/art/arcane/iris/engine/spawn/SpawnResourcesTest.java new file mode 100644 index 000000000..13e7d542e --- /dev/null +++ b/core/src/test/java/art/arcane/iris/engine/spawn/SpawnResourcesTest.java @@ -0,0 +1,104 @@ +/* + * 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 . + */ + +package art.arcane.iris.engine.spawn; + +import art.arcane.iris.core.loader.IrisData; +import art.arcane.iris.engine.object.entity.IrisEntity; +import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; +import art.arcane.iris.engine.object.marker.IrisMarker; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.nio.charset.StandardCharsets; +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.assertNull; + +/** Spawners, entities and markers are resource kinds of module {@code iris:spawn}, read from the folders packs have always had. */ +public class SpawnResourcesTest { + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Test + public void theSpawnModuleOwnsTheKinds() throws Exception { + IrisData data = IrisData.openValidation(spawnPack("owned").toFile()); + try { + var catalog = data.getModules().pack().catalog(); + + var kinds = catalog.resourceKinds().stream().map(registration -> registration.kind()) + .filter(kind -> kind.id().toString().startsWith("iris:spawn/")).toList(); + assertEquals(List.of("iris:spawn/entity", "iris:spawn/marker", "iris:spawn/spawner"), kinds.stream().map(kind -> kind.id().toString()).toList()); + assertEquals(List.of("entities", "markers", "spawners"), kinds.stream().map(kind -> kind.folder()).toList()); + assertFalse(data.getLoaders().containsKey(IrisSpawner.class)); + assertFalse(data.getLoaders().containsKey(IrisEntity.class)); + assertFalse(data.getLoaders().containsKey(IrisMarker.class)); + } finally { + data.close(); + } + } + + @Test + public void spawnersEntitiesAndMarkersAreReadThroughPackResources() throws Exception { + Path pack = spawnPack("spawns"); + IrisData data = IrisData.openValidation(pack.toFile()); + try { + IrisSpawner spawner = SpawnResources.spawner(data, "camp/zombies"); + + assertEquals("camp/zombies", spawner.getLoadKey()); + assertEquals(pack.resolve("spawners/camp/zombies.json").toFile(), spawner.getLoadFile()); + assertEquals("minecraft:zombie", SpawnResources.entity(data, "zombie").getType()); + assertEquals(List.of("camp/zombies"), SpawnResources.marker(data, "camp").getSpawners()); + assertEquals(List.of(spawner), SpawnResources.spawners(data, List.of("camp/zombies", "missing"))); + assertEquals(List.of("zombie"), SpawnResources.entityKeys(data)); + assertEquals(List.of("camp"), SpawnResources.markerKeys(data)); + assertEquals(List.of("camp/zombies"), SpawnResources.spawnerKeys(data)); + assertNull(SpawnResources.spawner(data, "missing")); + assertNull(SpawnResources.entity(data, " ")); + + write(pack, "entities/zombie.json", "{\"type\":\"minecraft:husk\"}"); + data.dump(); + assertEquals("minecraft:husk", SpawnResources.entity(data, "zombie").getType()); + } finally { + data.close(); + } + } + + private Path spawnPack(String name) throws Exception { + File pack = temporaryFolder.newFolder(name); + write(pack.toPath(), "dimensions/main.json", "{\"regions\":[\"region\"]}"); + write(pack.toPath(), "regions/region.json", "{\"landBiomes\":[\"biome\"]}"); + write(pack.toPath(), "biomes/biome.json", "{\"name\":\"Biome\"}"); + write(pack.toPath(), "entities/zombie.json", "{\"type\":\"minecraft:zombie\"}"); + write(pack.toPath(), "spawners/camp/zombies.json", "{\"spawns\":[{\"entity\":\"zombie\"}]}"); + write(pack.toPath(), "markers/camp.json", "{\"spawners\":[\"camp/zombies\"]}"); + return pack.toPath(); + } + + private static void write(Path root, String relative, String content) throws Exception { + Path path = root.resolve(relative); + Files.createDirectories(path.getParent()); + Files.writeString(path, content, StandardCharsets.UTF_8); + } +} diff --git a/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java b/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java index 13dc6934e..fc680340a 100644 --- a/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java +++ b/core/src/test/java/art/arcane/iris/purity/PackTypeBukkitPurityGateTest.java @@ -89,8 +89,7 @@ import static org.junit.Assert.fail; * deleted) and {@code Particles} (Bukkit registry lookups in a static initializer). *

* Deliberately not asserted: method and constructor descriptors. These classes legitimately - * expose a Bukkit-typed edge that only the Bukkit adapter calls - {@code IrisEntity.spawn(Engine, - * Location)}, {@code IrisLoot.get(...) -> ItemStack}, {@code IrisObjectRotation.rotate(BlockData, + * expose a Bukkit-typed edge that only the Bukkit adapter calls - {@code IrisObjectRotation.rotate(BlockData, * ...)}, {@code TileData.toBukkit(Block)} and ~60 more. Method descriptors are resolved at * invocation, never at class load, field walk or equals/hashCode/toString, so they are not a modded * boot hazard. Fields and supertypes are, and both are asserted hard below. @@ -110,15 +109,11 @@ public class PackTypeBukkitPurityGateTest { * #registeredRootListMatchesIrisData()} fails if the source drifts away from it. */ private static final List GSON_REGISTERED_ROOTS = List.of( - "art.arcane.iris.engine.object.loot.IrisLootTable", - "art.arcane.iris.engine.object.entity.spawn.IrisSpawner", - "art.arcane.iris.engine.object.entity.IrisEntity", "art.arcane.iris.engine.object.world.region.IrisRegion", "art.arcane.iris.engine.object.world.biome.IrisBiome", "art.arcane.iris.engine.object.mod.IrisMod", "art.arcane.iris.engine.object.world.dimension.IrisDimension", "art.arcane.iris.engine.object.terrain.IrisGenerator", - "art.arcane.iris.engine.object.marker.IrisMarker", "art.arcane.iris.engine.object.material.IrisBlockData", "art.arcane.iris.engine.object.noise.expression.IrisExpression", "art.arcane.iris.engine.object.prefab.IrisObject", @@ -133,7 +128,11 @@ public class PackTypeBukkitPurityGateTest { private static final List MODULE_RESOURCE_ROOTS = List.of( "art.arcane.iris.engine.object.structure.IrisStructure", "art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPool", - "art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece"); + "art.arcane.iris.engine.object.structure.jigsaw.IrisJigsawPiece", + "art.arcane.iris.engine.object.loot.IrisLootTable", + "art.arcane.iris.engine.object.entity.spawn.IrisSpawner", + "art.arcane.iris.engine.object.entity.IrisEntity", + "art.arcane.iris.engine.object.marker.IrisMarker"); /** * Types reachable from a pack that are not roots and carry no {@code @Snippet}, but are @@ -145,8 +144,9 @@ public class PackTypeBukkitPurityGateTest { "art.arcane.iris.engine.object.loot.IrisVanillaLootTable"); /** - * Bukkit-registry constant holders that a core pack type references, so their class initializer - * runs on the modded loaders too. {@code Particles} is statically imported by {@code IrisEntity}. + * Bukkit-registry constant holders that a core pack type may reference, so their class initializer + * must run on the modded loaders too. {@code Particles} is used by the Bukkit entity spawner now; it stays in the + * gate so that a pack type importing it again keeps working. * ({@code Materials} and {@code Attributes} have the same shape but are only reachable from the * Bukkit adapter, so they stay out of the gate.) */ diff --git a/core/src/test/java/art/arcane/iris/util/project/matter/RegistryMatterContextTest.java b/core/src/test/java/art/arcane/iris/util/project/matter/RegistryMatterContextTest.java index cd32792d9..7e6271aba 100644 --- a/core/src/test/java/art/arcane/iris/util/project/matter/RegistryMatterContextTest.java +++ b/core/src/test/java/art/arcane/iris/util/project/matter/RegistryMatterContextTest.java @@ -1,11 +1,10 @@ package art.arcane.iris.util.project.matter; import art.arcane.iris.core.loader.IrisData; -import art.arcane.iris.core.loader.IrisRegistrant; -import art.arcane.iris.core.loader.ResourceLoader; +import art.arcane.iris.core.modules.ModuleResourceFixture; +import art.arcane.iris.engine.spawn.SpawnResources; import art.arcane.iris.engine.object.entity.spawn.IrisSpawner; import art.arcane.iris.util.project.matter.slices.SpawnerMatter; -import art.arcane.volmlib.util.collection.KMap; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -18,7 +17,6 @@ import java.util.concurrent.Future; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; public class RegistryMatterContextTest { @Test @@ -49,14 +47,9 @@ public class RegistryMatterContextTest { } } - @SuppressWarnings("unchecked") private IrisData dataReturning(IrisSpawner resolved) { - ResourceLoader loader = mock(ResourceLoader.class); - when(loader.load("test-spawner")).thenReturn(resolved); - KMap, ResourceLoader> loaders = new KMap<>(); - loaders.put(IrisSpawner.class, loader); IrisData data = mock(IrisData.class); - when(data.getLoaders()).thenReturn(loaders); + ModuleResourceFixture.serve(data).resource(SpawnResources.SPAWNERS, "test-spawner", resolved); return data; } }