mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 00:34:19 +00:00
Warn on unsealed river fluids
- Warn when a non-water river fluid without a seam can meet the sea or another river fluid - Resolve river fluids from tiers and surface biome, region and dimension policies - Compare fluids by palette blocks and skip fluids already lined by a seam - Give the full hydrology test fixture a lava seam - Cover the warning and its silent cases in validator tests
This commit is contained in:
2 files changed
+223
-1
No files matched your search
@@ -1,14 +1,17 @@
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.decoration.HydrologyVegetation;
|
||||
import art.arcane.iris.generation.decoration.IrisDecorator;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisFluidProfile;
|
||||
import art.arcane.iris.generation.hydrology.config.IrisHydrology;
|
||||
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.terrain.IrisDimension;
|
||||
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;
|
||||
@@ -22,12 +25,15 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
final class PackHydrologyValidator {
|
||||
private static final String CONFIG = "hydrology";
|
||||
@@ -47,6 +53,7 @@ final class PackHydrologyValidator {
|
||||
);
|
||||
private static final List<String> FLUID_REFERENCES = List.of("ponds.fluid", "underground.cavePools.fluid");
|
||||
private static final IrisHydrologyTier DEFAULT_TIER = new IrisHydrologyTier();
|
||||
private static final Set<String> WATER_BLOCKS = Set.of("minecraft:water");
|
||||
private static final String MANTLE_WATER = "the falling water at waterfalls and cascades, sea inlets and cave pools";
|
||||
|
||||
private PackHydrologyValidator() {
|
||||
@@ -105,6 +112,7 @@ final class PackHydrologyValidator {
|
||||
warnShoreBiomesWithoutWidth(dimensionKey, loaded, loadedDimension, findings.warnings());
|
||||
if (errors.size() == reported && validateCompile(path, loadedDimension, errors)) {
|
||||
validateDecoratorBlocks(path, loaded, loadedDimension.getHydrology(), errors);
|
||||
warnFluidsWithoutSeam(dimensionKey, loaded, loadedDimension, findings.warnings());
|
||||
}
|
||||
return loaded;
|
||||
}
|
||||
@@ -354,6 +362,90 @@ final class PackHydrologyValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static void warnFluidsWithoutSeam(String dimensionKey, IrisData data, IrisDimension dimension, List<String> warnings) {
|
||||
String path = "Dimension '" + dimensionKey + "'." + CONFIG;
|
||||
Map<String, IrisFluidProfile> profiles = new HashMap<>();
|
||||
for (IrisFluidProfile profile : dimension.getHydrology().getFluids()) {
|
||||
profiles.put(profile.getName(), profile);
|
||||
}
|
||||
Map<String, Set<String>> rivers = riverFluidSources(dimensionKey, data, dimension);
|
||||
rivers.keySet().retainAll(profiles.keySet());
|
||||
for (Map.Entry<String, Set<String>> river : rivers.entrySet()) {
|
||||
IrisFluidProfile profile = profiles.get(river.getKey());
|
||||
Set<String> blocks = blockIds(profile.getPalette());
|
||||
if (hasSeam(profile) || blocks.equals(WATER_BLOCKS)) {
|
||||
continue;
|
||||
}
|
||||
List<String> met = new ArrayList<>();
|
||||
if (dimension.getFluidHeight() > 0 && !blocks.equals(blockIds(dimension.getFluidPalette()))) {
|
||||
met.add("the sea");
|
||||
}
|
||||
for (String other : rivers.keySet()) {
|
||||
IrisFluidProfile otherProfile = profiles.get(other);
|
||||
if (!hasSeam(otherProfile) && !blocks.equals(blockIds(otherProfile.getPalette()))) {
|
||||
met.add("fluid '" + other + "'");
|
||||
}
|
||||
}
|
||||
if (!met.isEmpty()) {
|
||||
warnings.add(path + ".fluids profile '" + river.getKey() + "' sets no seam, so where its rivers meet " + String.join(" or ", met)
|
||||
+ " the fluids lie side by side. Set seam on the profile to line that edge. Its rivers come from "
|
||||
+ String.join(", ", river.getValue()) + ".");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Set<String>> riverFluidSources(String dimensionKey, IrisData data, IrisDimension dimension) {
|
||||
Map<String, Set<String>> sources = new TreeMap<>();
|
||||
List<IrisRegion> regions = new ArrayList<>(dimension.getAllRegions(() -> data));
|
||||
ShoreBiomeLineages.visit(dimension, regions, () -> data, (lineage, region) -> {
|
||||
String fluid = IrisHydrologyPolicy.inherited(lineage, region, dimension, IrisHydrologyPolicy::getFluid);
|
||||
if (fluid == null) {
|
||||
addTierSources(dimensionKey, dimension, sources);
|
||||
} else {
|
||||
sources.computeIfAbsent(fluid, name -> new TreeSet<>()).add(policyFluidOwner(dimensionKey, lineage, region));
|
||||
}
|
||||
});
|
||||
if (sources.isEmpty()) {
|
||||
addTierSources(dimensionKey, dimension, sources);
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
private static void addTierSources(String dimensionKey, IrisDimension dimension, Map<String, Set<String>> sources) {
|
||||
List<IrisHydrologyTier> tiers = dimension.getHydrology().getTiers();
|
||||
for (int index = 0; index < tiers.size(); index++) {
|
||||
sources.computeIfAbsent(tiers.get(index).getFluid(), name -> new TreeSet<>())
|
||||
.add("Dimension '" + dimensionKey + "'." + CONFIG + ".tiers[" + index + "].fluid");
|
||||
}
|
||||
}
|
||||
|
||||
private static String policyFluidOwner(String dimensionKey, List<IrisBiome> lineage, IrisRegion region) {
|
||||
for (IrisBiome biome : lineage) {
|
||||
if (biome.getHydrologyPolicy() != null && biome.getHydrologyPolicy().getFluid() != null) {
|
||||
return "Biome '" + biome.getLoadKey() + "'." + POLICY + ".fluid";
|
||||
}
|
||||
}
|
||||
if (region != null && region.getHydrologyPolicy() != null && region.getHydrologyPolicy().getFluid() != null) {
|
||||
return "Region '" + region.getLoadKey() + "'." + POLICY + ".fluid";
|
||||
}
|
||||
return "Dimension '" + dimensionKey + "'." + POLICY + ".fluid";
|
||||
}
|
||||
|
||||
private static boolean hasSeam(IrisFluidProfile profile) {
|
||||
return profile.getSeam() != null && !profile.getSeam().isBlank();
|
||||
}
|
||||
|
||||
private static Set<String> blockIds(IrisMaterialPalette palette) {
|
||||
Set<String> blocks = new TreeSet<>();
|
||||
for (IrisBlockData block : palette.getPalette()) {
|
||||
String id = block.getBlock().toLowerCase(Locale.ROOT);
|
||||
int state = id.indexOf('[');
|
||||
String name = state < 0 ? id : id.substring(0, state);
|
||||
blocks.add(name.contains(":") ? name : "minecraft:" + name);
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private static void requireMultiplier(String field, Double value, List<String> errors) {
|
||||
if (value != null && !IrisHydrologyPolicy.validMultiplier(value)) {
|
||||
errors.add(field + " must be a finite value from 0 to " + (int) IrisHydrologyPolicy.MAX_MULTIPLIER + ", got " + value + ".");
|
||||
|
||||
@@ -22,6 +22,10 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PackHydrologyValidatorTest {
|
||||
private static final String WATER = "{\"name\": \"water\", \"palette\": {\"palette\": [{\"block\": \"minecraft:water\"}]}}";
|
||||
private static final String LAVA = "{\"name\": \"lava\", \"palette\": {\"palette\": [{\"block\": \"minecraft:lava\"}]}}";
|
||||
private static final String CRUST = "{\"name\": \"crust\", \"palette\": {\"palette\": [{\"block\": \"minecraft:obsidian\"}]}}";
|
||||
private static final String SEA_IS_LAVA = "\"fluidPalette\": {\"palette\": [{\"block\": \"minecraft:lava\"}]},";
|
||||
private static final String WATER_ONLY = "{\"enabled\": true, \"fluids\": [{\"name\": \"water\"}]}";
|
||||
|
||||
@Rule
|
||||
@@ -46,7 +50,8 @@ public class PackHydrologyValidatorTest {
|
||||
},
|
||||
"fluids": [
|
||||
{"name": "water", "palette": {"palette": [{"block": "minecraft:water"}]}},
|
||||
{"name": "lava", "palette": {"palette": [{"block": "minecraft:lava"}]}}
|
||||
{"name": "lava", "palette": {"palette": [{"block": "minecraft:lava"}]}, "seam": "crust"},
|
||||
{"name": "crust", "palette": {"palette": [{"block": "minecraft:obsidian"}]}}
|
||||
]
|
||||
}
|
||||
""", "\"hydrologyPolicy\": {\"fluid\": \"lava\"},")));
|
||||
@@ -661,6 +666,131 @@ public class PackHydrologyValidatorTest {
|
||||
assertTrue(widened.warnings().toString(), widened.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warnsWhenALavaRiverWithoutASeamCanMeetTheSea() throws Exception {
|
||||
File pack = pack(dimension(hydrology("lava", "lava", LAVA), ""));
|
||||
|
||||
PackHydrologyValidator.Validation validation = validate(pack);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertEquals(List.of("Dimension 'main'.hydrology.fluids profile 'lava' sets no seam, so where its rivers meet the sea"
|
||||
+ " the fluids lie side by side. Set seam on the profile to line that edge. Its rivers come from"
|
||||
+ " Dimension 'main'.hydrology.tiers[0].fluid, Dimension 'main'.hydrology.tiers[1].fluid."), validation.warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warnsAgainstADifferentRiverFluidAndNamesTheBiomeItComesFrom() throws Exception {
|
||||
File pack = pack(dimension(hydrology("water", "water", WATER + ", " + LAVA), SEA_IS_LAVA));
|
||||
write(pack, "biomes/biome.json", """
|
||||
{"name": "Biome", "hydrologyPolicy": {"fluid": "lava"}}
|
||||
""");
|
||||
write(pack, "regions/region.json", """
|
||||
{"landBiomes": ["biome", "plain"]}
|
||||
""");
|
||||
write(pack, "biomes/plain.json", "{\"name\": \"Plain\"}");
|
||||
|
||||
PackHydrologyValidator.Validation validation = validate(pack);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertEquals(List.of("Dimension 'main'.hydrology.fluids profile 'lava' sets no seam, so where its rivers meet fluid 'water'"
|
||||
+ " the fluids lie side by side. Set seam on the profile to line that edge. Its rivers come from"
|
||||
+ " Biome 'biome'.hydrologyPolicy.fluid."), validation.warnings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aSeamOnTheOtherRiverFluidLinesTheEdgeBetweenThem() throws Exception {
|
||||
String fluids = WATER + ", " + LAVA + ", " + """
|
||||
{"name": "tar", "palette": {"palette": [{"block": "mod:tar"}]}, "seam": "crust"}, %s
|
||||
""".formatted(CRUST);
|
||||
File pack = pack(dimension(hydrology("lava", "tar", fluids), SEA_IS_LAVA));
|
||||
|
||||
PackHydrologyValidator.Validation validation = validate(pack);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void silentWhenTheFluidHasASeam() throws Exception {
|
||||
String fluids = """
|
||||
{"name": "lava", "palette": {"palette": [{"block": "minecraft:lava"}]}, "seam": "crust"}, %s, %s
|
||||
""".formatted(CRUST, WATER);
|
||||
PackHydrologyValidator.Validation validation = validate(pack(dimension(hydrology("lava", "water", fluids), "")));
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void silentForWaterRiversWhateverTheProfileIsCalled() throws Exception {
|
||||
String fluids = """
|
||||
{"name": "marsh", "palette": {"palette": [{"block": "water"}]}}, %s
|
||||
""".formatted(WATER);
|
||||
File pack = pack(dimension(hydrology("marsh", "water", fluids), SEA_IS_LAVA));
|
||||
|
||||
PackHydrologyValidator.Validation validation = validate(pack);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void silentWhenTheFluidsAreTheSame() throws Exception {
|
||||
String fluids = LAVA + ", " + """
|
||||
{"name": "magma", "palette": {"palette": [{"block": "lava"}]}}
|
||||
""";
|
||||
PackHydrologyValidator.Validation validation = validate(pack(dimension(hydrology("lava", "magma", fluids), SEA_IS_LAVA)));
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void silentWhenAPolicyFluidReplacesEveryTierFluid() throws Exception {
|
||||
String config = hydrology("water", "water", WATER + ", " + LAVA);
|
||||
PackHydrologyValidator.Validation validation = validate(pack(dimension(config,
|
||||
SEA_IS_LAVA + " \"hydrologyPolicy\": {\"fluid\": \"lava\"},")));
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aCaveBiomePolicyFluidIsNotARiverFluid() throws Exception {
|
||||
File pack = pack(dimension(hydrology("water", "water", WATER + ", " + LAVA), ""));
|
||||
write(pack, "regions/region.json", """
|
||||
{"landBiomes": ["biome"], "caveBiomes": ["hollow"]}
|
||||
""");
|
||||
write(pack, "biomes/hollow.json", """
|
||||
{"name": "Hollow", "hydrologyPolicy": {"fluid": "lava"}}
|
||||
""");
|
||||
|
||||
PackHydrologyValidator.Validation validation = validate(pack);
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void silentAboutTheSeaWhenTheDimensionHasNoFluidHeight() throws Exception {
|
||||
PackHydrologyValidator.Validation validation = validate(pack(dimension(hydrology("lava", "lava", LAVA), "\"fluidHeight\": -64,")));
|
||||
|
||||
assertTrue(validation.errors().toString(), validation.errors().isEmpty());
|
||||
assertTrue(validation.warnings().toString(), validation.warnings().isEmpty());
|
||||
}
|
||||
|
||||
private static String hydrology(String streamFluid, String riverFluid, String fluids) {
|
||||
return """
|
||||
{"enabled": true,
|
||||
"tiers": [
|
||||
{"name": "stream", "minCatchment": 1500, "halfWidth": [0.5, 2], "bankBand": 0, "fluid": "%s"},
|
||||
{"name": "river", "minCatchment": 20000, "halfWidth": [2, 16], "bankBand": 8, "fluid": "%s"}],
|
||||
"ponds": {"fluid": "%s"},
|
||||
"underground": {"cavePools": {"fluid": "%s"}},
|
||||
"fluids": [%s]}
|
||||
""".formatted(streamFluid, riverFluid, streamFluid, streamFluid, fluids);
|
||||
}
|
||||
|
||||
private File shorePack(String dimensionWidth) throws Exception {
|
||||
File pack = pack(dimension(WATER_ONLY, "\"hydrologyPolicy\": {\"shoreBiomes\": [\"beach\"]" + dimensionWidth + "},"));
|
||||
write(pack, "regions/region.json", """
|
||||
|
||||
Reference in new issue
Block a user