diff --git a/core/src/main/java/art/arcane/iris/core/modules/DeclaredBounds.java b/core/src/main/java/art/arcane/iris/core/modules/DeclaredBounds.java
index 6640918b5..ba4b87108 100644
--- a/core/src/main/java/art/arcane/iris/core/modules/DeclaredBounds.java
+++ b/core/src/main/java/art/arcane/iris/core/modules/DeclaredBounds.java
@@ -25,6 +25,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;
import com.volmit.config.JsonForms;
import com.volmit.config.MaxNumber;
+import com.volmit.config.MinItems;
import com.volmit.config.MinNumber;
import java.lang.reflect.Array;
@@ -35,11 +36,8 @@ import java.util.Collection;
import java.util.List;
/**
- * The bounds IrisApi's {@link MinNumber} and {@link MaxNumber} declare, enforced on decoded settings. Only options the
- * JSON writes are checked: a default is the module's own choice.
- *
- * {@code @MinItems} is not enforced yet: most options carrying {@code @MinItems(1)} default to an empty list, and
- * packs write {@code []} for them (OPEN_QUESTIONS 57).
+ * The bounds IrisApi's {@link MinNumber}, {@link MaxNumber} and {@link MinItems} declare, enforced on decoded settings.
+ * Only options the JSON writes are checked: a default is the module's own choice.
*/
final class DeclaredBounds {
private static final List LIBRARY_PACKAGES = List.of("java.", "javax.", "com.google.gson.");
@@ -86,6 +84,18 @@ final class DeclaredBounds {
if (maximum != null && value instanceof Number number && number.doubleValue() > maximum.value()) {
throw new JsonParseException(path + " is " + number + "; it must be at most " + label(maximum.value()));
}
+ requireMinimumItems(field, value, path);
+ }
+
+ private static void requireMinimumItems(Field field, Object value, String path) {
+ MinItems minimumItems = field.getAnnotation(MinItems.class);
+ if (minimumItems == null || value == null) {
+ return;
+ }
+ int count = itemsOf(value).size();
+ if (count < minimumItems.value()) {
+ throw new JsonParseException(path + " has " + count + " items; it must have at least " + minimumItems.value());
+ }
}
private static void requireNested(Object value, JsonElement written, String path) {
diff --git a/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java b/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java
index d73a70f91..b2b8f3518 100644
--- a/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java
+++ b/core/src/test/java/art/arcane/iris/core/modules/DecorantSettingsDecodingTest.java
@@ -151,6 +151,18 @@ public class DecorantSettingsDecodingTest {
+ " not an object of options", refused.getMessage());
}
+ @Test
+ public void aPaletteNeedsAnEntryButAnEmptyListOfNoneIsFine() {
+ List none = decorators("{\"decorators\": [{\"whitelist\": [], \"blacklist\": [], \"topPalette\": []}]}");
+ assertEquals(List.of(), none.getFirst().blacklist());
+
+ IllegalArgumentException refused = assertThrows(IllegalArgumentException.class,
+ () -> decorators("{\"decorators\": [{\"chance\": 1}, {\"palette\": []}]}"));
+
+ assertEquals("Cannot read settings iris:decorant under \"decorators\" in biome meadow:"
+ + " decorators[1].palette has 0 items; it must have at least 1", refused.getMessage());
+ }
+
private List decorators(String biomeJson) {
return decoder.decode(Level.BIOME, new JSONObject(biomeJson), "biome meadow")
.find(DecorantSettings.class).orElseThrow().decorators();