Enforce @MinItems on the options a pack writes

DeclaredBounds checks it with @MinNumber and @MaxNumber, so pack load,
validation and every resource decode refuse an option written with fewer items
than it declares, naming the option: decorators[1].palette has 0 items; it must
have at least 1. An option the pack does not write is the module's default and
is not checked.
This commit is contained in:
piexel committed 2026-11-06 14:34:31 +01:00
1 parent ce7f782561
commit 67d5128942
2 files changed
+27 -5

No files matched your search

@@ -151,6 +151,18 @@ public class DecorantSettingsDecodingTest {
+ " not an object of options", refused.getMessage());
}
@Test
public void aPaletteNeedsAnEntryButAnEmptyListOfNoneIsFine() {
List<Decorator> 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<Decorator> decorators(String biomeJson) {
return decoder.decode(Level.BIOME, new JSONObject(biomeJson), "biome meadow")
.find(DecorantSettings.class).orElseThrow().decorators();