mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 17:23:59 +00:00
Reject unknown hydrology keys
- Report keys under hydrology and hydrologyPolicy that the config classes do not declare, with the full JSON path, as blocking errors - Derive known keys by reflection over the fields Gson reads, and treat map keys as data while checking the objects inside - Check a disabled hydrology block too, so a misspelt enabled flag is caught - Follow snippet references from hydrology into their files - Replace the tests that pinned unknown keys as ignored - Pin the no-sea warning on both sides of its boundary, fluidHeight -64 and -63
This commit is contained in:
2 files changed
+317
-30
No files matched your search
@@ -15,17 +15,27 @@ import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.generation.terrain.IrisRegion;
|
||||
import art.arcane.iris.generation.terrain.ShoreBiomeLineages;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.IrisRegistrant;
|
||||
import art.arcane.iris.pack.schema.annotation.Snippet;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import art.arcane.volmlib.util.mantle.flag.ReservedFlag;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
@@ -39,6 +49,7 @@ final class PackHydrologyValidator {
|
||||
private static final String CONFIG = "hydrology";
|
||||
private static final String POLICY = "hydrologyPolicy";
|
||||
private static final String DEFAULT_FLUID = "water";
|
||||
private static final String SNIPPET_ROOT = "snippet/";
|
||||
private static final List<RangeField> RANGES = List.of(
|
||||
new RangeField("ponds.freeboard", Floor.NON_NEGATIVE, true),
|
||||
new RangeField("ponds.seeded.radius", Floor.POSITIVE, true),
|
||||
@@ -93,6 +104,7 @@ final class PackHydrologyValidator {
|
||||
errors.add(path + " must be an object.");
|
||||
return data;
|
||||
}
|
||||
rejectUnknownKeys(path, hydrology, IrisHydrology.class, packFolder, errors);
|
||||
if (!hydrology.optBoolean("enabled", false)) {
|
||||
return data;
|
||||
}
|
||||
@@ -117,6 +129,96 @@ final class PackHydrologyValidator {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
static void rejectUnknownKeys(String field, Object value, Type type, File packFolder, List<String> errors) {
|
||||
rejectUnknownKeys(field, value, type, new KeyScan(packFolder, errors, new HashSet<>()));
|
||||
}
|
||||
|
||||
private static void rejectUnknownKeys(String field, Object value, Type type, KeyScan scan) {
|
||||
Class<?> raw = TypeToken.get(type).getRawType();
|
||||
if (value instanceof JSONArray array) {
|
||||
Type element = elementType(type, raw);
|
||||
for (int index = 0; index < array.length(); index++) {
|
||||
rejectUnknownKeys(field + "[" + index + "]", array.opt(index), element, scan);
|
||||
}
|
||||
} else if (value instanceof JSONObject object) {
|
||||
if (Map.class.isAssignableFrom(raw)) {
|
||||
Type entry = typeArgument(type, 1);
|
||||
for (String key : new TreeSet<>(object.keySet())) {
|
||||
rejectUnknownKeys(field + "." + key, object.opt(key), entry, scan);
|
||||
}
|
||||
} else if (hasDeclaredKeys(raw)) {
|
||||
rejectUnknownFields(field, object, raw, scan);
|
||||
}
|
||||
} else if (value instanceof String reference && reference.startsWith(SNIPPET_ROOT) && raw.isAnnotationPresent(Snippet.class)) {
|
||||
rejectUnknownSnippetKeys(field, reference, raw, scan);
|
||||
}
|
||||
}
|
||||
|
||||
private static void rejectUnknownFields(String field, JSONObject object, Class<?> type, KeyScan scan) {
|
||||
Map<String, Type> declared = declaredKeys(type);
|
||||
for (String key : new TreeSet<>(object.keySet())) {
|
||||
String child = field + "." + key;
|
||||
Type declaredType = declared.get(key);
|
||||
if (declaredType == null) {
|
||||
scan.errors().add(child + " is not a known key, so its value would be ignored. Known keys there: " + declared.keySet() + ".");
|
||||
} else {
|
||||
rejectUnknownKeys(child, object.opt(key), declaredType, scan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void rejectUnknownSnippetKeys(String field, String reference, Class<?> type, KeyScan scan) {
|
||||
String base = SNIPPET_ROOT + type.getDeclaredAnnotation(Snippet.class).value() + "/";
|
||||
String snippet = reference.startsWith(base) ? reference : base + reference.substring(SNIPPET_ROOT.length());
|
||||
if (!scan.activeSnippets().add(snippet)) {
|
||||
return;
|
||||
}
|
||||
File file = new File(scan.packFolder(), snippet + ".json");
|
||||
JSONObject object = file.isFile() ? PackValidationIo.readJson(file) : null;
|
||||
if (object != null) {
|
||||
rejectUnknownFields(field + " (" + snippet + ")", object, type, scan);
|
||||
}
|
||||
scan.activeSnippets().remove(snippet);
|
||||
}
|
||||
|
||||
private static Type elementType(Type type, Class<?> raw) {
|
||||
if (raw.isArray()) {
|
||||
return raw.getComponentType();
|
||||
}
|
||||
return Collection.class.isAssignableFrom(raw) ? typeArgument(type, 0) : Object.class;
|
||||
}
|
||||
|
||||
private static Type typeArgument(Type type, int index) {
|
||||
if (type instanceof ParameterizedType parameterized && index < parameterized.getActualTypeArguments().length) {
|
||||
return parameterized.getActualTypeArguments()[index];
|
||||
}
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
private static boolean hasDeclaredKeys(Class<?> type) {
|
||||
return !type.isPrimitive() && !type.isEnum() && !type.isArray() && !type.getPackageName().startsWith("java.");
|
||||
}
|
||||
|
||||
private static Map<String, Type> declaredKeys(Class<?> type) {
|
||||
Map<String, Type> keys = new TreeMap<>();
|
||||
for (Class<?> current = type; current != null && current != Object.class; current = current.getSuperclass()) {
|
||||
for (Field field : current.getDeclaredFields()) {
|
||||
int modifiers = field.getModifiers();
|
||||
if (Modifier.isStatic(modifiers) || Modifier.isTransient(modifiers) || field.isSynthetic()) {
|
||||
continue;
|
||||
}
|
||||
SerializedName serialized = field.getAnnotation(SerializedName.class);
|
||||
keys.putIfAbsent(serialized == null ? field.getName() : serialized.value(), field.getGenericType());
|
||||
if (serialized != null) {
|
||||
for (String alternate : serialized.alternate()) {
|
||||
keys.putIfAbsent(alternate, field.getGenericType());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static boolean validateCompile(String path, IrisDimension dimension, List<String> errors) {
|
||||
try {
|
||||
HydrologySettings.compile(dimension.getHydrology(), 0L, dimension.getFluidHeight(), 0,
|
||||
@@ -282,11 +384,13 @@ final class PackHydrologyValidator {
|
||||
|
||||
private static void validatePolicies(String path, String dimensionKey, IrisData data, IrisDimension dimension, PolicyFluids fluids,
|
||||
List<String> errors) {
|
||||
rejectUnknownPolicyKeys("Dimension '" + dimensionKey + "'." + POLICY, dimension, data, errors);
|
||||
validatePolicy("Dimension '" + dimensionKey + "'." + POLICY, dimension.getHydrologyPolicy(), data, fluids, path, errors);
|
||||
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
|
||||
regions.sort(Comparator.comparing(IrisRegion::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
for (IrisRegion region : regions) {
|
||||
if (region != null) {
|
||||
rejectUnknownPolicyKeys("Region '" + region.getLoadKey() + "'." + POLICY, region, data, errors);
|
||||
validatePolicy("Region '" + region.getLoadKey() + "'." + POLICY, region.getHydrologyPolicy(), data, fluids, path, errors);
|
||||
}
|
||||
}
|
||||
@@ -294,11 +398,20 @@ final class PackHydrologyValidator {
|
||||
biomes.sort(Comparator.comparing(IrisBiome::getLoadKey, Comparator.nullsFirst(Comparator.naturalOrder())));
|
||||
for (IrisBiome biome : biomes) {
|
||||
if (biome != null) {
|
||||
rejectUnknownPolicyKeys("Biome '" + biome.getLoadKey() + "'." + POLICY, biome, data, errors);
|
||||
validatePolicy("Biome '" + biome.getLoadKey() + "'." + POLICY, biome.getHydrologyPolicy(), data, fluids, path, errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void rejectUnknownPolicyKeys(String field, IrisRegistrant owner, IrisData data, List<String> errors) {
|
||||
File file = owner.getLoadFile();
|
||||
JSONObject json = file == null ? null : PackValidationIo.readJson(file);
|
||||
if (json != null) {
|
||||
rejectUnknownKeys(field, json.opt(POLICY), IrisHydrologyPolicy.class, data.getDataFolder(), errors);
|
||||
}
|
||||
}
|
||||
|
||||
private static void validatePolicy(String field, IrisHydrologyPolicy policy, IrisData data, PolicyFluids fluids, String configPath,
|
||||
List<String> errors) {
|
||||
if (policy == null) {
|
||||
@@ -501,4 +614,7 @@ final class PackHydrologyValidator {
|
||||
|
||||
private record Findings(List<String> errors, List<String> warnings) {
|
||||
}
|
||||
|
||||
private record KeyScan(File packFolder, List<String> errors, Set<String> activeSnippets) {
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPermission;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyPolicy;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyTier;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrologyWetness;
|
||||
import art.arcane.iris.generation.hydrology.plan.HydrologySettings;
|
||||
import art.arcane.iris.generation.noise.IrisGeneratorStyle;
|
||||
import art.arcane.iris.generation.terrain.IrisMaterialPalette;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.testsupport.CompatTestPlatform;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -13,7 +22,9 @@ import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -266,45 +277,192 @@ public class PackHydrologyValidatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownHydrologyKeysAreIgnoredAndAMissingEnabledFlagLoadsAsOff() throws Exception {
|
||||
public void rejectsAnUnknownKeyAtTheTopOfHydrology() throws Exception {
|
||||
List<String> errors = validate(pack(dimension("{\"enabled\": true, \"unknownSection\": {\"enabled\": true, \"tiers\": 4}}", ""))).errors();
|
||||
|
||||
assertContains(errors, "Dimension 'main'.hydrology.unknownSection is not a known key, so its value would be ignored.");
|
||||
assertContains(errors, "prefetchRings");
|
||||
assertEquals(errors.toString(), 1, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsAMisspeltEnabledFlagThoughTheBlockLoadsAsOff() throws Exception {
|
||||
File pack = pack(dimension("{\"enable\": true, \"ponds\": {\"dryDrawdon\": 3}}", ""));
|
||||
|
||||
List<String> errors = validate(pack).errors();
|
||||
|
||||
assertContains(errors, "Dimension 'main'.hydrology.enable is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.ponds.dryDrawdon is not a known key");
|
||||
assertEquals(errors.toString(), 2, errors.size());
|
||||
assertFalse(loadHydrology(pack).isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsUnknownKeysInNestedObjects() throws Exception {
|
||||
List<String> errors = validate(pack(dimension("""
|
||||
{
|
||||
"enabled": true,
|
||||
"ponds": {"seeded": {"radiusRange": [4, 12]}},
|
||||
"underground": {"cavePools": {"surface": 3}, "seaInlets": {"length": [24, 96], "chamber": {"radius": 4}}}
|
||||
}
|
||||
""", ""))).errors();
|
||||
|
||||
assertContains(errors, "Dimension 'main'.hydrology.ponds.seeded.radiusRange is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.underground.cavePools.surface is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.underground.seaInlets.chamber is not a known key");
|
||||
assertEquals(errors.toString(), 3, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsUnknownKeysInsideTierArrayElements() throws Exception {
|
||||
File pack = pack(dimension("""
|
||||
{"unknownSection": {"enabled": true, "tiers": 4}, "unknownList": [{"enabled": true}]}
|
||||
{"enabled": true, "fluids": [{"name": "water", "palette": {"palette": [{"block": "minecraft:water", "bloc": 1}]}, "sealed": true}],
|
||||
"tiers": [
|
||||
{"name": "stream", "minCatchment": 900, "halfWidth": [0.5, 2.5], "bankBand": 8},
|
||||
{"name": "major", "minCatchment": 200000, "halfWidth": [9, 18], "bankBand": 48, "notATierField": {"depth": 3},
|
||||
"estuary": {"flair": 2},
|
||||
"decorators": [{"partOf": "SEA_FLOOR", "palette": [{"block": "minecraft:kelp"}], "stacks": 1}]}
|
||||
]}
|
||||
""", ""));
|
||||
|
||||
assertTrue(validate(pack).errors().isEmpty());
|
||||
IrisData data = IrisData.openDatapackCompiler(pack);
|
||||
try {
|
||||
IrisHydrology hydrology = data.getDimensionLoader().load("main").getHydrology();
|
||||
assertNotNull(hydrology);
|
||||
assertFalse(hydrology.isEnabled());
|
||||
} finally {
|
||||
data.close();
|
||||
List<String> errors = validate(pack).errors();
|
||||
|
||||
assertContains(errors, "Dimension 'main'.hydrology.tiers[1].notATierField is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.tiers[1].estuary.flair is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.tiers[1].decorators[0].stacks is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.fluids[0].sealed is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.fluids[0].palette.palette[0].bloc is not a known key");
|
||||
assertEquals(errors.toString(), 5, errors.size());
|
||||
for (IrisHydrologyTier tier : loadHydrology(pack).getTiers()) {
|
||||
assertEquals(tier.getName(), 48, tier.getEstuary().getLength());
|
||||
assertEquals(tier.getName(), 2.5D, tier.getEstuary().getFlare(), 0D);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownTierKeysAreIgnoredAndTiersKeepTheDefaultEstuary() throws Exception {
|
||||
String written = """
|
||||
{"enabled": true, "tiers": [
|
||||
{"name": "stream", "minCatchment": 900, "halfWidth": [0.5, 2.5], "bankBand": 8%s},
|
||||
{"name": "major", "minCatchment": 200000, "halfWidth": [9, 18], "bankBand": 48%s}
|
||||
]}
|
||||
""";
|
||||
File extra = pack(dimension(written.formatted(", \"notATierField\": false", ", \"notATierField\": {\"depth\": 3}"), ""));
|
||||
File current = pack(dimension(written.formatted("", ""), ""));
|
||||
public void treatsMapKeysAsDataAndChecksTheObjectsInside() throws Exception {
|
||||
List<String> errors = new ArrayList<>();
|
||||
JSONObject written = new JSONObject("""
|
||||
{"zones": {"swamp": {"min": 0.7, "max": 1}, "desert": {"minimum": 0.1}}}
|
||||
""");
|
||||
|
||||
PackHydrologyValidator.rejectUnknownKeys("root", written, NamedZones.class, temporaryFolder.getRoot(), errors);
|
||||
|
||||
assertContains(errors, "root.zones.desert.minimum is not a known key");
|
||||
assertEquals(errors.toString(), 1, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsAnyKeyInsideABlockDataMap() throws Exception {
|
||||
PackHydrologyValidator.Validation validation = validate(pack(dimension("""
|
||||
{"enabled": true, "fluids": [{"name": "water", "palette": {"palette": [
|
||||
{"block": "minecraft:water", "data": {"level": 0, "anything": {"at": "all"}}, "tileData": {"SpawnData": {"entity": {}}}}
|
||||
]}}]}
|
||||
""", "")));
|
||||
|
||||
PackHydrologyValidator.Validation validation = validate(extra);
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().isEmpty());
|
||||
PackValidationResult packaging = PackValidator.validateForPackaging(extra);
|
||||
assertEquals(PackValidator.validateForPackaging(current).getBlockingErrors(), packaging.getBlockingErrors());
|
||||
IrisHydrology loaded = loadHydrology(extra);
|
||||
for (IrisHydrologyTier tier : loaded.getTiers()) {
|
||||
assertEquals(tier.getName(), 48, tier.getEstuary().getLength());
|
||||
assertEquals(tier.getName(), 2.5D, tier.getEstuary().getFlare(), 0D);
|
||||
}
|
||||
assertEquals(HydrologySettings.compile(loadHydrology(current), 1337L, 62, -64, 320).fingerprint(),
|
||||
HydrologySettings.compile(loaded, 1337L, 62, -64, 320).fingerprint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void acceptsEveryKeyGsonWritesForTheConfigClasses() throws Exception {
|
||||
Gson gson = new Gson();
|
||||
PackHydrologyValidator.Validation defaults = validate(pack(dimension(gson.toJson(new IrisHydrology().setEnabled(true)), "")));
|
||||
assertTrue(defaults.errors().toString(), defaults.errors().isEmpty());
|
||||
|
||||
IrisHydrology hydrology = new IrisHydrology().setEnabled(true);
|
||||
hydrology.getTiers().get(0).getMaterials().setBed(new IrisMaterialPalette()).setShore(new IrisMaterialPalette()).setBank(new IrisMaterialPalette());
|
||||
IrisDecorator decorator = new IrisDecorator().setForceBlock(new IrisBlockData("minecraft:stone"));
|
||||
decorator.getStyle().setFracture(new IrisGeneratorStyle());
|
||||
hydrology.getTiers().get(0).getDecorators().add(decorator);
|
||||
IrisHydrologyPolicy policy = new IrisHydrologyPolicy().setRainfall(1D).setWetness(new IrisHydrologyWetness()).setStreams(IrisHydrologyPermission.ALLOW);
|
||||
|
||||
List<String> errors = validate(pack(dimension(gson.toJson(hydrology), "\"hydrologyPolicy\": " + gson.toJson(policy) + ","))).errors();
|
||||
|
||||
assertEquals(List.of(), errors.stream().filter(error -> error.contains("not a known key")).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsEachRenamedKeyByItsOldName() throws Exception {
|
||||
List<String> errors = validate(pack(dimension("""
|
||||
{
|
||||
"enabled": true,
|
||||
"drainage": {"minimumHeadKeep": 0.6},
|
||||
"tiers": [
|
||||
{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0, "waterfallMinimumDrop": 6},
|
||||
{"name": "river", "minCatchment": 20000, "halfWidth": [2, 8], "bankBand": 32, "waterfallMinimumDrop": 8}
|
||||
],
|
||||
"ponds": {"climateDrawdown": 3},
|
||||
"underground": {"seaInlets": {"minimumCliffHeight": 8}}
|
||||
}
|
||||
""", ""))).errors();
|
||||
|
||||
assertContains(errors, "Dimension 'main'.hydrology.drainage.minimumHeadKeep is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.tiers[0].waterfallMinimumDrop is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.tiers[1].waterfallMinimumDrop is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.ponds.climateDrawdown is not a known key");
|
||||
assertContains(errors, "Dimension 'main'.hydrology.underground.seaInlets.minimumCliffHeight is not a known key");
|
||||
assertEquals(errors.toString(), 5, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectsUnknownKeysInHydrologyPoliciesAtEveryScope() throws Exception {
|
||||
File pack = pack(dimension(WATER_ONLY, "\"hydrologyPolicy\": {\"rainFall\": 1},"));
|
||||
write(pack, "regions/region.json", """
|
||||
{"landBiomes": ["biome"], "hydrologyPolicy": {"streamz": "BLOCK"}}
|
||||
""");
|
||||
write(pack, "biomes/biome.json", """
|
||||
{"name": "Biome", "hydrologyPolicy": {"wetness": {"middle": 0.5},
|
||||
"decorators": [{"partOf": "SHORE_LINE", "palette": [{"block": "minecraft:fern"}], "odds": 2}]}}
|
||||
""");
|
||||
|
||||
List<String> errors = validate(pack).errors();
|
||||
|
||||
assertContains(errors, "Dimension 'main'.hydrologyPolicy.rainFall is not a known key");
|
||||
assertContains(errors, "Region 'region'.hydrologyPolicy.streamz is not a known key");
|
||||
assertContains(errors, "Biome 'biome'.hydrologyPolicy.wetness.middle is not a known key");
|
||||
assertContains(errors, "Biome 'biome'.hydrologyPolicy.decorators[0].odds is not a known key");
|
||||
assertEquals(errors.toString(), 4, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void followsSnippetsAndNamesThemInThePath() throws Exception {
|
||||
File pack = pack(dimension("""
|
||||
{"enabled": true, "tiers": [{"name": "stream", "halfWidth": [0.5, 2], "bankBand": 0,
|
||||
"decorators": ["snippet/reeds", "snippet/decorator/fern", "snippet/decorator/missing"]}]}
|
||||
""", ""));
|
||||
write(pack, "snippet/decorator/reeds.json", """
|
||||
{"partOf": "SHORE_LINE", "palette": [{"block": "minecraft:sugar_cane"}], "odds": 2}
|
||||
""");
|
||||
write(pack, "snippet/decorator/fern.json", """
|
||||
{"partOf": "SHORE_LINE", "palette": [{"block": "minecraft:fern"}]}
|
||||
""");
|
||||
|
||||
List<String> errors = validate(pack).errors().stream().filter(error -> error.contains("not a known key")).toList();
|
||||
|
||||
assertContains(errors, "Dimension 'main'.hydrology.tiers[0].decorators[0] (snippet/decorator/reeds).odds is not a known key");
|
||||
assertEquals(errors.toString(), 1, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSnippetThatRefersToItselfEnds() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("cycle");
|
||||
write(pack, "snippet/style/loop.json", """
|
||||
{"fracture": "snippet/style/loop", "fractures": 1}
|
||||
""");
|
||||
List<String> errors = new ArrayList<>();
|
||||
|
||||
PackHydrologyValidator.rejectUnknownKeys("style", "snippet/style/loop", IrisGeneratorStyle.class, pack, errors);
|
||||
|
||||
assertContains(errors, "style (snippet/style/loop).fractures is not a known key");
|
||||
assertEquals(errors.toString(), 1, errors.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void leavesKeysOutsideTheHydrologyBlockAlone() throws Exception {
|
||||
File pack = pack("{\"regions\": [\"region\"], \"notADimensionKey\": 1, \"hydrology\": " + WATER_ONLY + "}");
|
||||
write(pack, "biomes/biome.json", "{\"name\": \"Biome\", \"notABiomeKey\": {\"a\": 1}}");
|
||||
|
||||
assertTrue(validate(pack).errors().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -779,6 +937,15 @@ public class PackHydrologyValidatorTest {
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warnsAboutTheSeaOneBlockAboveTheDimensionFloor() throws Exception {
|
||||
String noInlets = hydrology("lava", "lava", LAVA).replace("\"underground\": {", "\"underground\": {\"seaInlets\": {\"enabled\": false}, ");
|
||||
PackHydrologyValidator.Validation validation = validate(pack(dimension(noInlets, "\"fluidHeight\": -63,")));
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertContains(validation.warnings(), "where its rivers meet the sea");
|
||||
}
|
||||
|
||||
private static String hydrology(String streamFluid, String riverFluid, String fluids) {
|
||||
return """
|
||||
{"enabled": true,
|
||||
@@ -806,6 +973,10 @@ public class PackHydrologyValidatorTest {
|
||||
return pack;
|
||||
}
|
||||
|
||||
private static final class NamedZones {
|
||||
private Map<String, IrisHydrologyWetness> zones;
|
||||
}
|
||||
|
||||
private PackHydrologyValidator.Validation validate(File pack) {
|
||||
File[] dimensions = new File(pack, "dimensions").listFiles(
|
||||
file -> file.isFile() && file.getName().endsWith(".json"));
|
||||
|
||||
Reference in new issue
Block a user