Core reads structure placements from settings; package exports leave structures to their own closure

ModuleResourceClosure.exportingElsewhere(type) names the resources of a kind another exporter writes:
IrisPackageCompiler and the modded studio export take the placed structure keys from it, and StructurePackageClosure
still copies structures with their pools, pieces and loot. SchemaBuilder loses the RegistryListStructure branches and
StructureSchemaKeys. Tests build placements as packs write them (StructurePlacementFixtures); a decoding test pins
the overworld's ancient city placement and an anonymous cave placement to the identities and starts the old classes
gave.
This commit is contained in:
piexel committed 2026-10-12 02:19:49 +02:00
1 parent 7d9fd3faa6
commit 57d5a65c57
26 files changed
+770 -711

No files matched your search

@@ -43,6 +43,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
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
@@ -59,6 +60,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<>();
public ModuleResourceClosure(IrisData data) {
this.data = data;
@@ -67,6 +69,16 @@ 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);
@@ -108,6 +120,9 @@ 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());
}
@@ -175,6 +190,11 @@ public final class ModuleResourceClosure {
if (kind == null || key == null || key.isBlank()) {
return;
}
Set<String> elsewhere = exportedElsewhere.get(type);
if (elsewhere != null) {
elsewhere.add(key);
return;
}
Map<String, Object> ofKind = found.computeIfAbsent(kind, ignored -> new LinkedHashMap<>());
if (ofKind.containsKey(key)) {
return;
@@ -34,7 +34,7 @@ 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.IrisStructurePlacement;
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;
@@ -52,8 +52,7 @@ import org.zeroturnaround.zip.ZipUtil;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.List;
import java.util.UUID;
@SuppressWarnings("ALL")
@@ -105,7 +104,7 @@ public class IrisPackageCompiler {
KSet<IrisRegion> regions = new KSet<>();
KSet<IrisBiome> biomes = new KSet<>();
KSet<IrisGenerator> generators = new KSet<>();
ModuleResourceClosure moduleResources = new ModuleResourceClosure(dm);
ModuleResourceClosure moduleResources = new ModuleResourceClosure(dm).exportingElsewhere(IrisStructure.class);
KSet<IrisBlockData> blocks = new KSet<>();
// KSet is ConcurrentHashMap-backed: both add(null) and remove(null) throw NPE, so a
@@ -125,10 +124,7 @@ public class IrisPackageCompiler {
regions.forEach((r) -> allPlacements.addAll(r.getObjects()));
biomes.forEach((i) -> allPlacements.addAll(i.getObjects()));
moduleResources.follow(allPlacements);
Set<String> structureKeys = new LinkedHashSet<>();
collectStructureKeys(structureKeys, dimension.getStructures());
regions.forEach((region) -> collectStructureKeys(structureKeys, region.getStructures()));
biomes.forEach((biome) -> collectStructureKeys(structureKeys, biome.getStructures()));
List<String> structureKeys = moduleResources.keysOf(IrisStructure.class);
KMap<String, String> renameObjects = new KMap<>();
String a;
StringBuilder b = new StringBuilder();
@@ -265,18 +261,4 @@ public class IrisPackageCompiler {
settings.keySet().forEach(key -> json.put(key, settings.get(key)));
return json;
}
private static void collectStructureKeys(Set<String> keys, KList<IrisStructurePlacement> placements) {
if (placements == null) {
return;
}
for (IrisStructurePlacement placement : placements) {
if (placement == null || placement.getStructures() == null) {
continue;
}
for (String structureKey : placement.getStructures()) {
keys.add(structureKey);
}
}
}
}
@@ -28,14 +28,12 @@ import art.arcane.iris.core.loader.ResourceLoader;
import art.arcane.iris.core.modules.IrisValues;
import art.arcane.iris.core.modules.ModuleResourceFiles;
import art.arcane.iris.core.modules.ModuleTargets;
import art.arcane.iris.engine.framework.structure.StructureResources;
import art.arcane.iris.engine.object.image.IrisImageMap;
import art.arcane.iris.engine.object.noise.NoiseStyle;
import art.arcane.iris.engine.object.noise.expression.IrisExpression;
import art.arcane.iris.engine.object.prefab.IrisObject;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import art.arcane.iris.core.structure.StructureSchemaKeys;
import art.arcane.iris.engine.framework.ListFunction;
import art.arcane.iris.engine.object.annotations.ArrayType;
import art.arcane.iris.engine.object.annotations.Desc;
@@ -51,7 +49,6 @@ import art.arcane.iris.engine.object.annotations.RegistryListItemType;
import art.arcane.iris.engine.object.annotations.RegistryListPotionEffect;
import art.arcane.iris.engine.object.annotations.RegistryListResource;
import art.arcane.iris.engine.object.annotations.RegistryListSpecialEntity;
import art.arcane.iris.engine.object.annotations.RegistryListStructure;
import art.arcane.iris.engine.object.annotations.RegistryListVanillaStructure;
import art.arcane.iris.engine.object.annotations.RegistryMapBlockState;
import art.arcane.iris.engine.object.annotations.Required;
@@ -595,21 +592,6 @@ public class SchemaBuilder {
} else {
IrisLogging.error("Cannot find Registry Loader for type " + rr.value() + " used in " + k.getDeclaringClass().getCanonicalName() + " in field " + k.getName());
}
} else if (k.isAnnotationPresent(RegistryListStructure.class)) {
String key = "enum-iris-structure-placement";
if (!definitions.containsKey(key)) {
JSONObject j = new JSONObject();
j.put("enum", new JSONArray(StructureSchemaKeys.collect(
StructureResources.structureKeys(data),
StructureResources.pieceKeys(data)).toArray(new String[0])));
definitions.put(key, j);
}
fancyType = "Structure";
prop.put("$ref", "#/definitions/" + key);
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla, datapack, or imported Iris structure (use ctrl+space for auto complete!)");
} else if (k.isAnnotationPresent(RegistryListBlockType.class)) {
fancyType = "Block Type";
putRegistryEnumRef(prop, "enum-block-type", this::blockTypes);
@@ -771,22 +753,6 @@ public class SchemaBuilder {
} else {
IrisLogging.error("Cannot find Registry Loader for type (list schema) " + rr.value() + " used in " + k.getDeclaringClass().getCanonicalName() + " in field " + k.getName());
}
} else if (k.isAnnotationPresent(RegistryListStructure.class)) {
fancyType = "List<Structure>";
String key = "enum-iris-structure-placement";
if (!definitions.containsKey(key)) {
JSONObject j = new JSONObject();
j.put("enum", new JSONArray(StructureSchemaKeys.collect(
StructureResources.structureKeys(data),
StructureResources.pieceKeys(data)).toArray(new String[0])));
definitions.put(key, j);
}
JSONObject items = new JSONObject();
items.put("$ref", "#/definitions/" + key);
prop.put("items", items);
description.add(SYMBOL_TYPE__N + " Must be a valid vanilla, datapack, or imported Iris structure (use ctrl+space for auto complete!)");
} else if (k.isAnnotationPresent(RegistryListVanillaStructure.class)) {
fancyType = "List<Vanilla Structure>";
putRegistryEnumItems(prop, "enum-vanilla-structure", this::vanillaStructures);
@@ -1,57 +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.structure;
import art.arcane.volmlib.util.collection.KList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;
public final class StructureSchemaKeys {
private StructureSchemaKeys() {
}
public static KList<String> collect(Collection<String> structureKeys, Collection<String> jigsawPieceKeys) {
Set<String> pieces = new HashSet<>();
if (jigsawPieceKeys != null) {
for (String piece : jigsawPieceKeys) {
if (piece != null && !piece.isBlank()) {
pieces.add(piece);
}
}
}
TreeSet<String> merged = new TreeSet<>();
if (structureKeys != null) {
for (String key : structureKeys) {
if (key == null || key.isBlank()) {
continue;
}
if (pieces.contains(key)) {
continue;
}
merged.add(key);
}
}
return new KList<>(merged);
}
}