Read module settings under the key their feature declares

The decoder reads a setting under its declared key, as the object of its options or,
for a feature with a root option, as exactly that option's value; a wrong shape fails
naming the key and the resource. The studio schema renders the root option's schema as
the key's one shape. Iris passes its own JSON fields per target to the module host so
no key can take one, and the pack validators and messages name the keys packs write
(decorators, importedStructures).
This commit is contained in:
piexel committed 2026-10-09 23:27:24 +02:00
1 parent 081f793696
commit b642b7f04e
15 files changed
+96 -47

No files matched your search

@@ -533,10 +533,10 @@ public final class IrisModdedChunkGenerator extends ChunkGenerator {
}
String remedy = integratedEnvironment()
? "enable 'Generate Structures' for this world; Iris requires it, then deny families through "
+ "iris:structure disabled or complete keys through iris:structure disabledExact"
+ "importedStructures.disabled or complete keys through importedStructures.disabledExact"
: "set generate-structures=true in server.properties, restart the server, "
+ "then deny families through iris:structure disabled or complete keys through "
+ "iris:structure disabledExact";
+ "then deny families through importedStructures.disabled or complete keys through "
+ "importedStructures.disabledExact";
throw new IllegalStateException("Iris generator '" + dimensionKey
+ "' cannot bind while generate-structures=false; " + remedy);
}
@@ -290,8 +290,8 @@ final class ModdedNativeStructureStage {
+ " because generate-structures=false disables them outside the pack. That flag is fixed when "
+ "the world is created (server.properties generate-structures, or the Generate Structures "
+ "toggle in singleplayer), so it cannot be changed for this world: create a new world with "
+ "structures enabled, then deny families through iris:structure disabled or complete keys "
+ "through iris:structure disabledExact");
+ "structures enabled, then deny families through importedStructures.disabled or complete keys "
+ "through importedStructures.disabledExact");
}
ChunkPos chunkPos = chunk.getPos();
SectionPos sectionPos = SectionPos.of(chunkPos, world.getMinSectionY());
@@ -677,7 +677,7 @@ public final class DatapackIngestService {
if (report.changed()) {
message(sender, C.YELLOW + "New datapack structures were installed. A server restart is required for them to register and generate.");
message(sender, C.GRAY + "After the restart they generate natively only in Iris dimensions that declare their source URL - no import needed. To get editable Iris copies (jigsaw pools, pieces & objects written into the pack) run /iris structure import <dimension>, or set general.autoImportDatapackStructures=true to do it on every ingest. Place any registered key directly with a 'structures' placement using nativeStructures.");
message(sender, C.GRAY + "Datapacks replace matching vanilla structure keys by default. Set 'iris:structure datapackOverrides' to false to keep minecraft-namespaced structure definitions untouched; deny non-minecraft datapack and mod structure families with iris:structure disabled or complete keys with iris:structure disabledExact.");
message(sender, C.GRAY + "Datapacks replace matching vanilla structure keys by default. Set 'importedStructures.datapackOverrides' to false to keep minecraft-namespaced structure definitions untouched; deny non-minecraft datapack and mod structure families with importedStructures.disabled or complete keys with importedStructures.disabledExact.");
if (!restart) {
message(sender, C.GRAY + "Run with restart=true to restart now, or restart manually. After restart, run /iris structure list <dimension> to see the new keys.");
}
@@ -19,7 +19,7 @@ public final class JsonSchemaValidator {
/**
* Warns about every top-level key that is neither a field of {@code objectClass} nor one of
* {@code moduleKeys}, the ids the pack's modules read at this resource's target.
* {@code moduleKeys}, the keys the pack's modules read at this resource's target.
*/
public static void validateTopLevelKeys(JSONObject parsed, String rawText, File file, String resourceTypeName, Class<?> objectClass,
Set<String> moduleKeys) {
@@ -437,7 +437,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
}
}
/** The ids and aliases the pack's modules read at {@code target}; none for resources that hold no module settings. */
/** The keys the pack's modules read at {@code target}; none for resources that hold no module settings. */
private Set<String> moduleKeys(Optional<Target> target) {
return target.map(found -> getManager().getModules().settings().keys(found)).orElse(Set.of());
}
@@ -83,6 +83,7 @@ public final class IrisModuleHost {
private static ModuleHost build() {
return ModuleHost.of(builtInModules())
.exposing(BUILT_IN_API_PACKAGE)
.reservingFields(ModuleTargets.reservedFields())
.describingHostTypesIn(HOST_TYPE_PACKAGE)
.reservingFolders(IrisData.ownFolderNames().toArray(String[]::new))
.copyingJarsTo(jarCopyRoot())
@@ -18,6 +18,7 @@
package art.arcane.iris.core.modules;
import art.arcane.volmlib.util.json.JSONArray;
import art.arcane.volmlib.util.json.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -31,6 +32,7 @@ import com.google.gson.stream.JsonWriter;
import com.volmit.FeatureAttachment.Target;
import com.volmit.IrisFeature;
import com.volmit.block.BlockState;
import com.volmit.config.OptionsMetadata;
import com.volmit.config.Snippet;
import com.volmit.host.FeatureCatalog;
import com.volmit.host.FeatureDescriptor;
@@ -41,6 +43,7 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.EnumMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -53,13 +56,14 @@ import java.util.stream.Stream;
/**
* Reads the module settings a dimension, region or biome declares: each settings feature of the pack at
* that target, under its id. Settings are created with their no-argument
* that target, under the key the feature declares. Settings are created with their no-argument
* constructor and the JSON is read into them, so an omitted option keeps its default. A {@link Snippet}
* type may be written as {@code "snippet/<name>"} or, as Iris's own snippets are, {@code "snippet/<snippet folder>/<name>"},
* both read from {@code snippet/<snippet folder>/<name>.json}. IrisApi's value types ({@code BlockSpec},
* {@code NoiseStyle} and the rest) are read like settings, and an {@code Object} as Gson reads any JSON value.
* <p>
* Settings are always written as their object. Iris's own classes that built-in settings hold (see
* Settings are written in the one shape their class declares: an object of the class's options or, when the feature
* names a {@code root} option, exactly that option's value. Iris's own classes that built-in settings hold (see
* {@link IrisModuleHost#isHostType}) are read by Iris's pack Gson, exactly as Iris reads them elsewhere.
*/
public final class ModuleSettingsDecoder {
@@ -89,7 +93,7 @@ public final class ModuleSettingsDecoder {
}
}
/** Every JSON key the pack's modules read at {@code target}: the feature ids, object generators' included. */
/** Every JSON key the pack's modules read at {@code target}: the keys of their features, object generators' included. */
public Set<String> keys(Target target) {
return keys.get(target);
}
@@ -127,8 +131,8 @@ public final class ModuleSettingsDecoder {
private IrisFeature read(FeatureDescriptor<?> feature, Object value, String resource) {
try {
requireObjectOrSnippet(feature, value);
IrisFeature decoded = gson.fromJson(JSONObject.valueToString(value), feature.type());
requireShape(feature, value);
IrisFeature decoded = gson.fromJson(settingsJson(feature, value), feature.type());
if (decoded == null) {
throw new JsonParseException("the value is null");
}
@@ -139,6 +143,21 @@ public final class ModuleSettingsDecoder {
}
}
/** The settings object the value stands for: the value itself, or the root option holding it. */
private static String settingsJson(FeatureDescriptor<?> feature, Object value) {
return feature.root()
.map(root -> new JSONObject().put(root, value).toString())
.orElseGet(() -> JSONObject.valueToString(value));
}
private static void requireShape(FeatureDescriptor<?> feature, Object value) {
if (feature.root().isPresent()) {
requireRootValue(feature, feature.root().get(), value);
return;
}
requireObjectOrSnippet(feature, value);
}
private static void requireObjectOrSnippet(FeatureDescriptor<?> feature, Object value) {
if (value instanceof JSONObject || (value instanceof String && feature.type().isAnnotationPresent(Snippet.class))) {
return;
@@ -146,6 +165,31 @@ public final class ModuleSettingsDecoder {
throw new JsonParseException("write the settings as an object, {\"<option>\": ...}");
}
private static void requireRootValue(FeatureDescriptor<?> feature, String root, Object value) {
if (JSONObject.NULL.equals(value)) {
throw new JsonParseException("the value is null; write " + describeRootShape(feature, root));
}
if (isListOption(feature, root) && !(value instanceof JSONArray)) {
throw new JsonParseException("write " + describeRootShape(feature, root) + ", not an object of options");
}
}
private static boolean isListOption(FeatureDescriptor<?> feature, String root) {
Class<?> type = rootOption(feature, root).field().getType();
return Collection.class.isAssignableFrom(type) || type.isArray();
}
private static String describeRootShape(FeatureDescriptor<?> feature, String root) {
return isListOption(feature, root) ? "a list, [...], of the " + root : "the " + root + " directly";
}
private static OptionsMetadata.Option rootOption(FeatureDescriptor<?> feature, String root) {
return feature.options().options().stream()
.filter(option -> option.name().equals(root))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Root " + root + " is no option of " + feature.type().getName()));
}
private static List<FeatureDescriptor<?>> settingsAt(FeatureCatalog catalog, Target target) {
return catalog.settings().stream()
.filter(feature -> feature.attachment().targets().contains(target))
@@ -18,14 +18,17 @@
package art.arcane.iris.core.modules;
import art.arcane.iris.core.loader.JsonFieldNames;
import art.arcane.iris.engine.object.placement.IrisObjectPlacement;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.engine.object.world.region.IrisRegion;
import com.volmit.FeatureAttachment.Target;
import java.util.EnumMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* Which Iris class holds the JSON of each attachment target that module settings can appear in.
@@ -47,4 +50,11 @@ public final class ModuleTargets {
.map(Map.Entry::getKey)
.findFirst();
}
/** Iris's own JSON fields per target, which no settings key may take. */
static Map<Target, Set<String>> reservedFields() {
Map<Target, Set<String>> fields = new EnumMap<>(Target.class);
HOLDERS.forEach((target, holder) -> fields.put(target, JsonFieldNames.of(holder)));
return fields;
}
}
@@ -35,7 +35,6 @@ import java.util.List;
*/
final class PackBiomeLayerValidator {
private static final int DEFAULT_LAYER_COUNT = 1;
private static final String DECORANT_SETTINGS = "iris:decorant";
private static final String DECORATORS = "decorators";
private PackBiomeLayerValidator() {
@@ -81,18 +80,10 @@ final class PackBiomeLayerValidator {
for (File biomeFile : biomeFiles) {
String biomeKey = PackValidationIo.deriveKey(biomesFolder, biomeFile);
JSONObject biome = PackValidationIo.readJson(biomeFile);
if (biome == null || !biome.has(DECORANT_SETTINGS) || biome.isNull(DECORANT_SETTINGS)) {
if (biome == null || !biome.has(DECORATORS) || biome.isNull(DECORATORS)) {
continue;
}
JSONObject decorant = biome.optJSONObject(DECORANT_SETTINGS);
if (decorant == null) {
blockingErrors.add("Biome '" + biomeKey + "' " + DECORANT_SETTINGS + " must be an object.");
continue;
}
if (!decorant.has(DECORATORS) || decorant.isNull(DECORATORS)) {
continue;
}
JSONArray decorators = decorant.optJSONArray(DECORATORS);
JSONArray decorators = biome.optJSONArray(DECORATORS);
if (decorators == null) {
blockingErrors.add("Biome '" + biomeKey + "' decorators must be an array.");
continue;
@@ -95,8 +95,8 @@ final class PackDimensionValidator {
}
}
/** The dimension's settings of the {@code iris:structure} module, which the platform's own structures follow. */
static final String STRUCTURE_SETTINGS = "iris:structure";
/** The dimension's {@code importedStructures} settings of the iris:structure module, which the platform's own structures follow. */
static final String STRUCTURE_SETTINGS = "importedStructures";
static void validateImportedStructurePolicy(String dimensionKey, JSONObject dimension,
List<String> blockingErrors, List<String> warnings) {
@@ -104,21 +104,21 @@ final class PackDimensionValidator {
return;
}
if (dimension.isNull(STRUCTURE_SETTINGS)) {
blockingErrors.add("Dimension '" + dimensionKey + "' iris:structure must be an object.");
blockingErrors.add("Dimension '" + dimensionKey + "' importedStructures must be an object.");
return;
}
JSONObject policy = dimension.optJSONObject(STRUCTURE_SETTINGS);
if (policy == null) {
blockingErrors.add("Dimension '" + dimensionKey + "' iris:structure must be an object.");
blockingErrors.add("Dimension '" + dimensionKey + "' importedStructures must be an object.");
return;
}
if (policy.has("mode")) {
blockingErrors.add("Dimension '" + dimensionKey
+ "' iris:structure.mode is not supported. Native structures are enabled by default; deny families in iris:structure disabled or complete keys in iris:structure disabledExact.");
+ "' importedStructures.mode is not supported. Native structures are enabled by default; deny families in importedStructures.disabled or complete keys in importedStructures.disabledExact.");
}
if (policy.has("enabled")) {
blockingErrors.add("Dimension '" + dimensionKey
+ "' iris:structure.enabled is not supported. Native structures are enabled by default; deny families in iris:structure disabled or complete keys in iris:structure disabledExact.");
+ "' importedStructures.enabled is not supported. Native structures are enabled by default; deny families in importedStructures.disabled or complete keys in importedStructures.disabledExact.");
}
validateStructureKeyList(dimensionKey, policy, "disabled", blockingErrors);
validateStructureKeyList(dimensionKey, policy, "disabledExact", blockingErrors);
@@ -127,7 +127,7 @@ final class PackDimensionValidator {
if (adjustments == null) {
if (policy.has("adjustments")) {
blockingErrors.add("Dimension '" + dimensionKey
+ "' iris:structure.adjustments must be an array.");
+ "' importedStructures.adjustments must be an array.");
}
return;
}
@@ -135,17 +135,17 @@ final class PackDimensionValidator {
JSONObject adjustment = adjustments.optJSONObject(index);
if (adjustment == null) {
blockingErrors.add("Dimension '" + dimensionKey
+ "' iris:structure.adjustments has a non-object entry at index " + index + ".");
+ "' importedStructures.adjustments has a non-object entry at index " + index + ".");
continue;
}
if (adjustment.has("clearVegetation")) {
warnings.add("Dimension '" + dimensionKey + "' iris:structure.adjustments[" + index
warnings.add("Dimension '" + dimensionKey + "' importedStructures.adjustments[" + index
+ "].clearVegetation was removed and is ignored. Vegetation is always cleared inside structure piece envelopes.");
}
validateStructureKeyList(dimensionKey, adjustment, "match", blockingErrors);
validateAdjustmentYBand(dimensionKey, adjustment, index, blockingErrors);
PackStructurePlacementValidator.validateNativeTerrain("Dimension '" + dimensionKey
+ "' iris:structure.adjustments[" + index + "]", adjustment, blockingErrors);
+ "' importedStructures.adjustments[" + index + "]", adjustment, blockingErrors);
}
}
@@ -157,13 +157,13 @@ final class PackDimensionValidator {
JSONArray overrides = policy.optJSONArray("frequencyOverrides");
if (overrides == null) {
blockingErrors.add("Dimension '" + dimensionKey
+ "' iris:structure.frequencyOverrides must be an array.");
+ "' importedStructures.frequencyOverrides must be an array.");
return;
}
for (int index = 0; index < overrides.length(); index++) {
JSONObject override = overrides.optJSONObject(index);
String path = "Dimension '" + dimensionKey
+ "' iris:structure.frequencyOverrides[" + index + "]";
+ "' importedStructures.frequencyOverrides[" + index + "]";
if (override == null) {
blockingErrors.add(path + " must be an object.");
continue;
@@ -185,7 +185,7 @@ final class PackDimensionValidator {
return;
}
String path = "Dimension '" + dimensionKey
+ "' iris:structure.adjustments[" + index + "].yBand";
+ "' importedStructures.adjustments[" + index + "].yBand";
JSONObject band = adjustment.optJSONObject("yBand");
if (band == null) {
blockingErrors.add(path + " must be an object.");
@@ -511,7 +511,7 @@ final class PackStructurePlacementValidator {
continue;
}
String path = "Dimension '" + dimensionKey
+ "' iris:structure.adjustments[" + adjustmentIndex + "]";
+ "' importedStructures.adjustments[" + adjustmentIndex + "]";
for (String structureKey : orderedStructureKeys) {
if (matchesStructure(matches, structureKey)) {
effective.put(structureKey, new EffectiveTerrainAdjustment(path, adjustment));
@@ -661,7 +661,7 @@ final class PackStructurePlacementValidator {
if ("VACUUM".equals(mode) || "ENCASE".equals(mode)) {
blockingErrors.add(path + ".terrain.mode " + mode
+ " cannot target editable Iris structures; use nativeStructures or "
+ "iris:structure adjustments for native terrain preparation.");
+ "importedStructures.adjustments for native terrain preparation.");
}
}
@@ -38,8 +38,8 @@ import java.util.function.Function;
/**
* Renders the settings a pack's modules add, described by IrisApi as a {@link PackSchema}, into the JSON
* schema studio writes: each feature as a property of its target under its id, each settings class once as a
* definition, references as completion lists (resource references as the keys of the module resource kind they
* schema studio writes: each feature as a property of its target under its key, each settings class once as a
* definition (a feature whose key holds one option's value is that option's schema, not the class's), references as completion lists (resource references as the keys of the module resource kind they
* name). Iris's own classes in built-in settings use Iris's own definitions, and so do IrisApi's value types, which read the same JSON as
* an Iris class ({@code BlockSpec} as Iris's block data), with the snippet references their {@code @Snippet} allows.
*/
@@ -89,7 +89,7 @@ final class ModuleSchemaRenderer {
this.snippetFiles = snippetFiles;
}
/** Adds every feature at {@code target} to {@code properties} under its id. */
/** Adds every feature at {@code target} to {@code properties} under its key. */
void addFeatures(Target target, JSONObject properties) {
for (FeatureSchema feature : schema.fields(target)) {
properties.put(feature.key(), featureProperty(feature));
@@ -107,14 +107,17 @@ final class ModuleSchemaRenderer {
}
private JSONObject featureProperty(FeatureSchema feature) {
JSONObject property = new JSONObject();
property.put("$ref", DEFINITION_REF + definition(feature.settings().name()));
JSONObject property = feature.rootOption().map(this::optionSchema).orElseGet(() -> settingsReference(feature));
String description = feature.name() + " (" + feature.id() + "), from module " + feature.module().name()
+ " (" + feature.module().id() + ")" + (feature.settings().description().isEmpty() ? "" : ". " + feature.settings().description());
property.put("description", description);
return property;
}
private JSONObject settingsReference(FeatureSchema feature) {
return new JSONObject().put("$ref", DEFINITION_REF + definition(feature.settings().name()));
}
/** Whether the pack's modules describe the class {@code typeName}. */
boolean describes(String typeName) {
return schema.types().stream().anyMatch(type -> type.name().equals(typeName));
@@ -293,7 +293,7 @@ public class SchemaBuilder {
/**
* A registry enum that ALSO accepts family/namespace prefixes ("minecraft:village",
* "nova_structures:") — the runtime prefix-matching contract of iris:structure disabled and
* "nova_structures:") — the runtime prefix-matching contract of importedStructures.disabled and
* adjustments[].match ({@code Reference.STRUCTURE_PREFIX}). Emitted as anyOf(enum, pattern) so autocomplete still offers registered
* keys while prefix entries validate instead of being rejected.
*/
@@ -113,7 +113,7 @@ public final class StructureIndexService {
counts.put("irisStructures", iris.size());
Map<String, Object> root = new LinkedHashMap<>();
root.put("note", "Generated index of every structure available at runtime. Toggle vanilla/datapack generation via the dimension's iris:structure settings (by structure key). Place structures via biome/region/dimension structures lists.");
root.put("note", "Generated index of every structure available at runtime. Toggle vanilla/datapack generation via the dimension importedStructures block (by structure key). Place structures via biome/region/dimension structures lists.");
root.put("counts", counts);
root.put("structures", structuresNode);
root.put("structureSets", setsNode);
@@ -73,7 +73,7 @@ public final class NativeStructureGenerationPolicy {
return switch (Objects.requireNonNull(status, "Native structure status must not be null")) {
case GENERATE_NATIVE -> "Native structure " + key + " generates natively.";
case DISABLED_BY_PACK -> "Native structure " + key
+ " is disabled by this dimension's iris:structure settings or a module of the pack.";
+ " is disabled by this dimension's importedStructures settings or a module of the pack.";
case REPLACED_BY_IRIS -> "Native structure " + key
+ " is replaced by an Iris placement in this pack and locates through that explicit replacement.";
case INVALID_REGISTRY_KEY -> "Native structure registry key is invalid: " + key;