From d6228c3074df6224a374424995317144ff0ba57e Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 9 Oct 2026 20:21:14 +0200 Subject: [PATCH] Settings are keyed by feature id and always an object: drop aliases and the one-option bare value The settings decoder, the studio schema renderer and the schema builder no longer know aliases. Tests and fixtures use the iris:deposit object form. --- .../iris/core/modules/IrisModuleHost.java | 1 - .../core/modules/ModuleSettingsDecoder.java | 56 ++++++------------- .../iris/core/modules/ModuleTargets.java | 10 ---- .../core/project/ModuleSchemaRenderer.java | 37 +++--------- .../iris/core/project/SchemaBuilder.java | 6 +- .../modules/BuiltInGenerationGraphTest.java | 9 ++- .../modules/DepositSettingsDecodingTest.java | 24 ++++++-- .../modules/ModuleChunkGenerationTest.java | 2 +- .../modules/ModuleSettingsDecoderTest.java | 55 +++++++++--------- .../core/project/SchemaBuilderParityTest.java | 13 ++--- 10 files changed, 84 insertions(+), 129 deletions(-) diff --git a/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java b/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java index 48cb8ca51..54eebface 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java +++ b/core/src/main/java/art/arcane/iris/core/modules/IrisModuleHost.java @@ -81,7 +81,6 @@ 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()) diff --git a/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java b/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java index c862c95e2..fd3792a3e 100644 --- a/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java +++ b/core/src/main/java/art/arcane/iris/core/modules/ModuleSettingsDecoder.java @@ -31,7 +31,6 @@ 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; @@ -46,7 +45,6 @@ import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Set; import java.util.TreeSet; import java.util.function.Function; @@ -55,14 +53,13 @@ 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 or, for built-ins, its alias. Settings are created with their no-argument + * that target, under its id. 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/"} or, as Iris's own snippets are, {@code "snippet//"}, * both read from {@code snippet//.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. *

- * Settings with exactly one option may be written as that option's value: {@code "snow": 0.5} reads as - * {@code "snow": {"amount": 0.5}}. Iris's own classes that built-in settings hold (see + * Settings are always written as their object. 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 { @@ -92,7 +89,7 @@ public final class ModuleSettingsDecoder { } } - /** Every JSON key the pack's modules read at {@code target}: feature ids and built-in aliases, object generators' included. */ + /** Every JSON key the pack's modules read at {@code target}: the feature ids, object generators' included. */ public Set keys(Target target) { return keys.get(target); } @@ -101,13 +98,14 @@ public final class ModuleSettingsDecoder { * Decodes the settings {@code json} declares for {@code target}. * * @param resource names the file in errors, such as {@code biome desert/dunes} - * @throws IllegalArgumentException when the JSON holds both a feature's alias and its id, or a value - * that does not decode into the settings type + * @throws IllegalArgumentException when a value does not decode into its settings type */ public ModuleSettings decode(Target target, JSONObject json, String resource) { Map, IrisFeature> values = new LinkedHashMap<>(); for (FeatureDescriptor feature : settings.get(target)) { - presentKey(feature, json, resource).ifPresent(key -> values.put(feature.type(), read(feature, json.get(key), key, resource))); + if (json.has(feature.key())) { + values.put(feature.type(), read(feature, json.get(feature.key()), resource)); + } } return ModuleSettings.of(values); } @@ -127,44 +125,25 @@ public final class ModuleSettingsDecoder { return decoded; } - private static Optional presentKey(FeatureDescriptor feature, JSONObject json, String resource) { - boolean hasKey = json.has(feature.key()); - Optional alias = feature.alias().filter(json::has); - if (hasKey && alias.isPresent()) { - throw new IllegalArgumentException(resource + " sets both \"" + alias.get() + "\" and \"" + feature.key() - + "\", the alias and the id of settings " + feature.id() + "; keep one"); - } - return hasKey ? Optional.of(feature.key()) : alias; - } - - private IrisFeature read(FeatureDescriptor feature, Object value, String key, String resource) { + private IrisFeature read(FeatureDescriptor feature, Object value, String resource) { try { - IrisFeature decoded = gson.fromJson(JSONObject.valueToString(asObject(feature, value)), feature.type()); + requireObjectOrSnippet(feature, value); + IrisFeature decoded = gson.fromJson(JSONObject.valueToString(value), feature.type()); if (decoded == null) { throw new JsonParseException("the value is null"); } return decoded; } catch (RuntimeException failure) { - throw new IllegalArgumentException("Cannot read settings " + feature.id() + " under \"" + key + "\" in " + throw new IllegalArgumentException("Cannot read settings " + feature.id() + " under \"" + feature.key() + "\" in " + resource + ": " + failure.getMessage(), failure); } } - /** A bare value of settings with exactly one option, as the object holding it; anything else unchanged. */ - private static Object asObject(FeatureDescriptor feature, Object value) { - if (value instanceof JSONObject || isSnippetReference(feature, value)) { - return value; + private static void requireObjectOrSnippet(FeatureDescriptor feature, Object value) { + if (value instanceof JSONObject || (value instanceof String && feature.type().isAnnotationPresent(Snippet.class))) { + return; } - List options = feature.options().options(); - if (options.size() != 1) { - throw new JsonParseException("write an object; only settings with exactly one option may be written as that" - + " option's value, and these have " + options.size()); - } - return new JSONObject().put(options.getFirst().name(), value); - } - - private static boolean isSnippetReference(FeatureDescriptor feature, Object value) { - return feature.type().isAnnotationPresent(Snippet.class) && value instanceof String text && text.startsWith(SNIPPET_PREFIX); + throw new JsonParseException("write the settings as an object, {\"