Export structures and objects through the generic resource closure

The packager no longer runs StructurePackageClosure: ModuleResourceClosure
already follows the structure, pool, piece and loot references the model
annotates, and now also collects the object keys everything it follows names.
Pack validation runs first and reports broken structure graphs.

ExportClosureComparisonTest is the gate. On the overworld pack, following every
structure gives the same 210 pools, 1169 pieces and 1169 objects as before. The
export now also carries 10 objects that floating child biome object overrides
place, which the old export left out.

PackExportClosure had no callers and is removed.
This commit is contained in:
piexel committed 2026-11-06 10:07:32 +01:00
1 parent 4e7a46fb2d
commit 5979e3d49d
5 files changed
+246 -121

No files matched your search

@@ -29,6 +29,7 @@ import art.arcane.volmlib.util.json.JSONObject;
import com.google.gson.Gson;
import com.volmit.config.ResourceRef;
import com.volmit.host.ResourceKindRegistration;
import com.volmit.object.GeneratedObject;
import com.volmit.resource.ResourceKind;
import java.io.File;
@@ -50,8 +51,9 @@ import java.util.TreeSet;
/**
* The resources of the pack's module resource kinds that a pack export has to carry: what the settings of the
* exported dimension, regions and biomes (and anything else handed to {@link #follow}) name by {@link ResourceRef},
* {@link IrisStructureRef} or {@link RegistryListResource}, and what those resources name in turn. Core does not know the kinds: it follows the
* references the modules declare on their classes.
* {@link IrisStructureRef} or {@link RegistryListResource}, and what those resources name in turn, plus the keys of
* the objects all of them name. Core does not know the kinds: it follows the references the modules declare on their
* classes.
*/
public final class ModuleResourceClosure {
private static final String JAVA_PACKAGE_PREFIX = "java.";
@@ -62,7 +64,7 @@ public final class ModuleResourceClosure {
private final Map<Class<?>, ResourceKind<?>> kindsByType = new HashMap<>();
private final Map<ResourceKind<?>, Map<String, Object>> found = new LinkedHashMap<>();
private final Set<Object> visited = java.util.Collections.newSetFromMap(new IdentityHashMap<>());
private final Map<Class<?>, Set<String>> exportedElsewhere = new HashMap<>();
private final Set<String> objectKeys = new TreeSet<>();
public ModuleResourceClosure(IrisData data) {
this.data = data;
@@ -71,16 +73,6 @@ public final class ModuleResourceClosure {
}
}
/**
* Leaves the resources that read into {@code type} to another exporter, such as Iris's structure closure that
* copies structures with their pools, pieces and loot: {@link #keysOf} names the ones referenced, but they are
* not loaded, followed or written. Call before following anything.
*/
public ModuleResourceClosure exportingElsewhere(Class<?> type) {
exportedElsewhere.putIfAbsent(type, new TreeSet<>());
return this;
}
/** Adds the resources that the module settings of {@code owner} reference, and those they reference. */
public void followSettingsOf(IrisRegistrant owner) {
owner.getModuleSettings().values().forEach(this::follow);
@@ -122,13 +114,18 @@ public final class ModuleResourceClosure {
/** The keys of the resources found of the kind that reads into {@code type}, in key order. */
public List<String> keysOf(Class<?> type) {
if (exportedElsewhere.containsKey(type)) {
return new ArrayList<>(exportedElsewhere.get(type));
}
ResourceKind<?> kind = kindsByType.get(type);
return kind == null || !found.containsKey(kind) ? List.of() : new ArrayList<>(new TreeMap<>(found.get(kind)).keySet());
}
/**
* The keys of the pack objects that what was found references, in key order. Objects are Iris's own files, not a
* module kind, so the export copies them itself.
*/
public List<String> objectKeys() {
return List.copyOf(objectKeys);
}
/**
* Writes every resource found as {@code <folder of its kind>/<key>.json} below {@code targetRoot}, kinds in folder
* order and keys in key order.
@@ -191,13 +188,15 @@ public final class ModuleResourceClosure {
}
private void add(Class<?> type, String key) {
ResourceKind<?> kind = kindsByType.get(type);
if (kind == null || key == null || key.isBlank()) {
if (key == null || key.isBlank()) {
return;
}
Set<String> elsewhere = exportedElsewhere.get(type);
if (elsewhere != null) {
elsewhere.add(key);
if (type == GeneratedObject.class) {
objectKeys.add(key);
return;
}
ResourceKind<?> kind = kindsByType.get(type);
if (kind == null) {
return;
}
Map<String, Object> ofKind = found.computeIfAbsent(kind, ignored -> new LinkedHashMap<>());
@@ -1,52 +0,0 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.core.pack;
import art.arcane.iris.builtin.objects.ObjectPlacement;
import art.arcane.volmlib.util.collection.KSet;
/**
* Shared key collection for the pack packagers. Both the Bukkit re-serializing compiler and the
* modded verbatim-copy compiler must export the complete ambient-spawning graph: object placements
* carry markers, markers carry spawners, spawners carry entities, entities carry loot. These
* helpers keep the two packagers walking placements identically.
*/
public final class PackExportClosure {
private PackExportClosure() {
}
public static KSet<String> collectObjectKeys(Iterable<ObjectPlacement> placements) {
KSet<String> objectKeys = new KSet<>();
if (placements == null) {
return objectKeys;
}
for (ObjectPlacement placement : placements) {
if (placement == null) {
continue;
}
for (String key : placement.place()) {
if (key == null || key.isBlank()) {
continue;
}
objectKeys.add(key);
}
}
return objectKeys;
}
}
@@ -29,13 +29,11 @@ import art.arcane.iris.core.pack.ImageMapPackageClosure;
import art.arcane.iris.core.pack.ModuleResourceClosure;
import art.arcane.iris.core.pack.PackValidationResult;
import art.arcane.iris.core.pack.PackValidator;
import art.arcane.iris.core.pack.StructurePackageClosure;
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.terrain.IrisGenerator;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.engine.object.structure.IrisStructure;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.util.common.plugin.VolmitSender;
@@ -101,7 +99,7 @@ public class IrisPackageCompiler {
KSet<IrisRegion> regions = new KSet<>();
KSet<IrisBiome> biomes = new KSet<>();
KSet<IrisGenerator> generators = new KSet<>();
ModuleResourceClosure moduleResources = new ModuleResourceClosure(dm).exportingElsewhere(IrisStructure.class);
ModuleResourceClosure moduleResources = new ModuleResourceClosure(dm);
KSet<IrisBlockData> blocks = new KSet<>();
// KSet is ConcurrentHashMap-backed: both add(null) and remove(null) throw NPE, so a
@@ -121,8 +119,7 @@ public class IrisPackageCompiler {
regions.forEach((r) -> allPlacements.addAll(ObjectPlacements.all(r)));
biomes.forEach((i) -> allPlacements.addAll(ObjectPlacements.all(i)));
moduleResources.follow(allPlacements);
List<String> structureKeys = moduleResources.keysOf(IrisStructure.class);
KList<String> exportedObjectNames = new KList<>();
List<String> exportedObjectNames = moduleResources.objectKeys();
String a;
StringBuilder b = new StringBuilder();
StringBuilder c = new StringBuilder();
@@ -130,16 +127,8 @@ public class IrisPackageCompiler {
for (ObjectPlacement j : allPlacements) {
b.append(Objects.hashCode(j.json()));
for (String k : j.place()) {
if (exportedObjectNames.contains(k)) {
continue;
}
b.append(k);
exportedObjectNames.add(k);
}
}
exportedObjectNames.forEach(b::append);
StringBuilder gb = new StringBuilder();
ChronoLatch cl = new ChronoLatch(1000);
@@ -183,11 +172,6 @@ public class IrisPackageCompiler {
IrisLogging.info("Writing Dimensional Scaffold");
try {
StructurePackageClosure structureClosure = StructurePackageClosure.collect(project.getPath(), structureKeys);
if (!structureClosure.isValid()) {
throw new IOException("Structure package closure is invalid: " + String.join("; ", structureClosure.errors()));
}
b.append(structureClosure.writeTo(folder, minify));
b.append(ImageMapPackageClosure.writeAll(dm, folder, minify));
a = withModuleSettings(dimension, Level.DIMENSION, dm).toString(minify ? 0 : 4);
IO.writeAll(new File(folder, "dimensions/" + dimension.getLoadKey() + ".json"), a);