Iris has no loaders for loot tables, spawners, entities and markers any more

Callers read them through LootResources and SpawnResources; the pack's loot check moved to iris:loot. RegistryMatter
asks its subclass how to load a key, the entity command handler lists entities through the module kind.
This commit is contained in:
piexel committed 2026-10-09 22:24:20 +02:00
1 parent 406d3e47d3
commit e120991ad3
24 files changed
+423 -394

No files matched your search

@@ -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<IrisData> 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<Class<? extends IrisRegistrant>> 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<Class<? extends IrisRegistrant>> 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<String> 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<IrisBiome> biomeLoader;
private ResourceLoader<IrisLootTable> lootLoader;
private ResourceLoader<IrisRegion> regionLoader;
private ResourceLoader<IrisDimension> dimensionLoader;
private ResourceLoader<IrisGenerator> generatorLoader;
private ResourceLoader<IrisEntity> entityLoader;
private ResourceLoader<IrisMarker> markerLoader;
private ResourceLoader<IrisSpawner> spawnerLoader;
private ResourceLoader<IrisMod> modLoader;
private ResourceLoader<IrisBlockData> blockLoader;
private ResourceLoader<IrisExpression> 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<Class<? extends IrisRegistrant>, ResourceLoader<? extends IrisRegistrant>> 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);
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<String> 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<String> 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<String> 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<String> blockingErrors) {
if (minimum != null && maximum != null && minimum > maximum) {
blockingErrors.add(minimumPath + " must not exceed " + maximumPath + ".");
}
}
}
@@ -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,
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<String> errors, List<String> warnings) {
LootGraphIssues {
errors = List.copyOf(errors);
warnings = List.copyOf(warnings);
}
}
static LootGraphIssues validateLootGraph(File packFolder) {
List<String> blockingErrors = new ArrayList<>();
List<String> warnings = new ArrayList<>();
if (packFolder == null || !packFolder.isDirectory()) {
return new LootGraphIssues(blockingErrors, warnings);
}
File lootFolder = new File(packFolder, PackValidator.LOOT_FOLDER);
Set<String> lootKeys = ContentKeyValidator.deriveRegistrantKeysExact(lootFolder);
if (lootFolder.isDirectory()) {
List<File> 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<File> 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<String> 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<String> 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<String> lootKeys, List<String> blockingErrors, List<String> 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<String> 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<String> blockingErrors) {
if (value != null && value < minimum) {
blockingErrors.add(fieldPath + " must be at least " + minimum + ".");
}
}
static void requireMaximum(String fieldPath, Integer value, int maximum,
List<String> 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<String> blockingErrors) {
if (minimum != null && maximum != null && minimum > maximum) {
blockingErrors.add(minimumPath + " must not exceed " + maximumPath + ".");
}
}
}
@@ -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;
}
@@ -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));
@@ -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<IrisObjectPlacement> allPlacements = new KList<>();
regions.forEach((r) -> allPlacements.addAll(r.getObjects()));
biomes.forEach((i) -> allPlacements.addAll(i.getObjects()));
KSet<IrisMarker> 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<String> structureKeys = new LinkedHashSet<>();
collectStructureKeys(structureKeys, dimension.getStructures());
regions.forEach((region) -> collectStructureKeys(structureKeys, region.getStructures()));
@@ -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.
*/
@@ -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<IrisEntity> {
@@ -27,6 +30,18 @@ public class EntityHandler extends RegistrantHandler<IrisEntity> {
super(IrisEntity.class, false);
}
@Override
protected KList<IrisEntity> loadAll(IrisData data) {
KList<IrisEntity> 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";
@@ -29,7 +29,7 @@ public abstract class RegistrantHandler<T extends IrisRegistrant> implements Dir
Set<String> 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<T extends IrisRegistrant> 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<T extends IrisRegistrant> implements Dir
return p;
}
/** Every resource of this handler's type that {@code data}'s pack has. */
protected KList<T> loadAll(IrisData data) {
return data.getLoader(type).loadAll(data.getLoader(type).getPossibleKeys());
}
@Override
public String toString(T t) {
return t != null ? t.getLoadKey() : "null";
@@ -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<T extends IrisRegistrant> extends RawMatter<T> {
public abstract class RegistryMatter<T extends IrisRegistrant> extends RawMatter<T> {
public RegistryMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c);
}
@@ -46,12 +45,9 @@ public class RegistryMatter<T extends IrisRegistrant> extends RawMatter<T> {
@Override
public T readNode(DataInputStream din) throws IOException {
String key = din.readUTF();
IrisData data = IrisMatterContext.require();
ResourceLoader<? extends IrisRegistrant> 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);
}
@@ -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<IrisSpawner> {
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);
}
}