mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 16:25:36 +00:00
Give cave ceiling layers their own thickness noise
Ceiling layers borrowed the thickness noise of the surface layer at the same index, so ceiling layers beyond the surface layer count were dropped and the validator rejected such packs. Each ceiling layer now has its own cached noise, seeded as before, every declared layer is generated, and the validator accepts any count.
TerrainLayersPinTest re-baselined (length 143112 -> 147047, hash 149645537 -> 216639495). Only the MEADOW ceiling output changed, in both the plain and the exploded runs; surface, sea and smoothing output of every biome is identical, and the biomes without ceiling layers are untouched:
- MEADOW ceiling, plain: 5724 -> 7400 characters. Its fourth layer (basalt) is now emitted instead of cut off at the three surface layers.
- MEADOW ceiling, exploded: 13788 -> 16047 characters. Same fourth layer, plus the barrier separators around it.
- Layers 0 to 2 of MEADOW's ceiling now take thickness from their own style and zoom instead of the surface layers' (SIMPLEX zoom 0.3 against the default style for layer 0, the default style against CELLULAR zoom 0.25 for layer 1), so their block counts change at most columns, e.g. column -400,-400 went from "clay tuff deepslate calcite" to "clay clay tuff deepslate tuff calcite basalt".
Upstream: 23bad0e1a
This commit is contained in:
1 parent
5a2c5b2592
commit
7b2a232a42
8 files changed
+160
-60
No files matched your search
@@ -22,25 +22,17 @@ import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Validates biome layer stacks. caveCeilingLayers reuses the height generators built from layers,
|
||||
* so a biome with more ceiling entries than surface entries has no generator for the extras; the
|
||||
* engine skips them, and this validator surfaces the mistake to the author at validate time.
|
||||
*/
|
||||
final class PackBiomeLayerValidator {
|
||||
private static final int DEFAULT_LAYER_COUNT = 1;
|
||||
private static final String DECORATORS = "decorators";
|
||||
|
||||
private PackBiomeLayerValidator() {
|
||||
}
|
||||
|
||||
static List<String> validateCeilingLayerCounts(File biomesFolder) {
|
||||
static List<String> validateLayers(File biomesFolder) {
|
||||
List<String> blockingErrors = new ArrayList<>();
|
||||
if (biomesFolder == null || !biomesFolder.isDirectory()) {
|
||||
return blockingErrors;
|
||||
@@ -50,24 +42,13 @@ final class PackBiomeLayerValidator {
|
||||
biomeFiles.sort(Comparator.comparing(File::getPath));
|
||||
for (File biomeFile : biomeFiles) {
|
||||
String biomeKey = PackValidationIo.deriveKey(biomesFolder, biomeFile);
|
||||
JSONObject biome;
|
||||
try {
|
||||
biome = new JSONObject(Files.readString(biomeFile.toPath(), StandardCharsets.UTF_8));
|
||||
} catch (Throwable e) {
|
||||
// Invalid JSON is reported by the graph validators; layer counts have nothing to add.
|
||||
JSONObject biome = PackValidationIo.readJson(biomeFile);
|
||||
if (biome == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Integer layers = arrayLength(biome, "layers", biomeKey, DEFAULT_LAYER_COUNT, blockingErrors);
|
||||
Integer ceiling = arrayLength(biome, "caveCeilingLayers", biomeKey, 0, blockingErrors);
|
||||
if (layers == null || ceiling == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ceiling > layers) {
|
||||
blockingErrors.add("Biome '" + biomeKey + "' declares " + ceiling + " caveCeilingLayers but only "
|
||||
+ layers + " layers. caveCeilingLayers reuses the layers height generators and must not have more entries.");
|
||||
}
|
||||
validateLayerArray(biome, "layers", biomeKey, blockingErrors);
|
||||
validateLayerArray(biome, "caveCeilingLayers", biomeKey, blockingErrors);
|
||||
}
|
||||
return blockingErrors;
|
||||
}
|
||||
@@ -127,17 +108,13 @@ final class PackBiomeLayerValidator {
|
||||
}
|
||||
}
|
||||
|
||||
private static Integer arrayLength(JSONObject biome, String field, String biomeKey, int defaultCount,
|
||||
List<String> blockingErrors) {
|
||||
private static void validateLayerArray(JSONObject biome, String field, String biomeKey, List<String> blockingErrors) {
|
||||
if (!biome.has(field) || biome.isNull(field)) {
|
||||
return defaultCount;
|
||||
return;
|
||||
}
|
||||
|
||||
JSONArray array = biome.optJSONArray(field);
|
||||
if (array == null) {
|
||||
if (biome.optJSONArray(field) == null) {
|
||||
blockingErrors.add("Biome '" + biomeKey + "' " + field + " must be an array.");
|
||||
return null;
|
||||
}
|
||||
return array.length();
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public final class PackValidator {
|
||||
new File(packFolder, "spawners"), new File(packFolder, "entities")));
|
||||
blockingErrors.addAll(PackSpawnValidator.validateCustomBiomeSpawns(
|
||||
new File(packFolder, "biomes"), PackSpawnValidator::resolveEntitySpawnCategory));
|
||||
blockingErrors.addAll(PackBiomeLayerValidator.validateCeilingLayerCounts(new File(packFolder, "biomes")));
|
||||
blockingErrors.addAll(PackBiomeLayerValidator.validateLayers(new File(packFolder, "biomes")));
|
||||
blockingErrors.addAll(PackBiomeLayerValidator.validateDecoratorPalettes(
|
||||
new File(packFolder, "biomes"), new File(packFolder, "snippet/iris/decorant/decorator")));
|
||||
PackStyledRangeDefaultValidator.Validation styledRanges = PackStyledRangeDefaultValidator.validate(packFolder);
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class PackBiomeLayerValidatorTest {
|
||||
@@ -19,25 +18,21 @@ public class PackBiomeLayerValidatorTest {
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void rejectsMoreCeilingLayersThanLayers() throws Exception {
|
||||
public void acceptsMoreCeilingLayersThanSurfaceLayers() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "biomes/nested/cave.json",
|
||||
"{\"layers\":[{}],\"caveCeilingLayers\":[{},{},{}]}");
|
||||
|
||||
assertEquals(List.of(
|
||||
"Biome 'nested/cave' declares 3 caveCeilingLayers but only 1 layers. caveCeilingLayers reuses the layers height generators and must not have more entries."
|
||||
), PackBiomeLayerValidator.validateCeilingLayerCounts(new File(pack, "biomes")));
|
||||
assertTrue(PackBiomeLayerValidator.validateLayers(new File(pack, "biomes")).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void respectsIndependentDefaultsWhenFieldsAreAbsent() throws Exception {
|
||||
public void acceptsCeilingLayersWhenSurfaceLayersAreAbsent() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "biomes/defaulted.json", "{\"name\":\"Defaulted\"}");
|
||||
write(pack, "biomes/implicit.json", "{\"caveCeilingLayers\":[{},{}]}");
|
||||
|
||||
assertEquals(List.of(
|
||||
"Biome 'implicit' declares 2 caveCeilingLayers but only 1 layers. caveCeilingLayers reuses the layers height generators and must not have more entries."
|
||||
), PackBiomeLayerValidator.validateCeilingLayerCounts(new File(pack, "biomes")));
|
||||
assertTrue(PackBiomeLayerValidator.validateLayers(new File(pack, "biomes")).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,7 +40,7 @@ public class PackBiomeLayerValidatorTest {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "biomes/ok.json", "{\"layers\":[{},{},{}],\"caveCeilingLayers\":[{},{}]}");
|
||||
|
||||
assertTrue(PackBiomeLayerValidator.validateCeilingLayerCounts(new File(pack, "biomes")).isEmpty());
|
||||
assertTrue(PackBiomeLayerValidator.validateLayers(new File(pack, "biomes")).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,11 +51,11 @@ public class PackBiomeLayerValidatorTest {
|
||||
assertEquals(List.of(
|
||||
"Biome 'bad' layers must be an array.",
|
||||
"Biome 'bad' caveCeilingLayers must be an array."
|
||||
), PackBiomeLayerValidator.validateCeilingLayerCounts(new File(pack, "biomes")));
|
||||
), PackBiomeLayerValidator.validateLayers(new File(pack, "biomes")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ceilingLayerOverflowBlocksFullPackValidation() throws Exception {
|
||||
public void independentCeilingLayersPassFullPackValidation() throws Exception {
|
||||
File pack = temporaryFolder.newFolder("pack");
|
||||
write(pack, "dimensions/main.json", "{\"regions\":[\"region\"]}");
|
||||
write(pack, "regions/region.json", "{\"landBiomes\":[\"biome\"]}");
|
||||
@@ -68,9 +63,7 @@ public class PackBiomeLayerValidatorTest {
|
||||
|
||||
PackValidationResult result = PackValidator.validate(pack);
|
||||
|
||||
assertFalse(result.isLoadable());
|
||||
assertTrue(result.getBlockingErrors().contains(
|
||||
"Biome 'biome' declares 2 caveCeilingLayers but only 1 layers. caveCeilingLayers reuses the layers height generators and must not have more entries."));
|
||||
assertTrue(result.getBlockingErrors().toString(), result.isLoadable());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,8 +41,8 @@ import static org.mockito.Mockito.when;
|
||||
*/
|
||||
public class TerrainLayersPinTest {
|
||||
private static final long TERRAIN_SEED = 1337L;
|
||||
private static final int TRANSCRIPT_LENGTH = 143112;
|
||||
private static final int TRANSCRIPT_HASH = 149645537;
|
||||
private static final int TRANSCRIPT_LENGTH = 147047;
|
||||
private static final int TRANSCRIPT_HASH = 216639495;
|
||||
private static final int COLUMN_STEP_X = 61;
|
||||
private static final int COLUMN_STEP_Z = 67;
|
||||
private static final int COLUMN_RANGE = 400;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class BiomeLayersCeilingGuardTest {
|
||||
KList<BlockState> result = layersOf(data()).generateCeilingLayers(
|
||||
biome, PaletteExplosion.NONE, 0, 0, new RNG(1), 8);
|
||||
|
||||
assertTrue("extra ceiling layers are skipped, not crashed on", result.isEmpty());
|
||||
assertTrue("zeroed palettes with zero heights produce no blocks", result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package art.arcane.iris.engine.terrain;
|
||||
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.loader.ResourceLoader;
|
||||
import art.arcane.iris.core.modules.IrisPackResources;
|
||||
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||
import art.arcane.iris.engine.object.material.IrisBlockData;
|
||||
import art.arcane.iris.modules.terrain.BiomeLayers;
|
||||
import art.arcane.iris.modules.terrain.LayeredBiome;
|
||||
import art.arcane.iris.modules.terrain.PaletteExplosion;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import com.volmit.block.BlockState;
|
||||
import com.volmit.host.ModuleLogs;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class BiomeLayersCeilingTest {
|
||||
private static final int CEILING_DEPTH = 8;
|
||||
private static final int RNG_SEED = 37;
|
||||
private static final int COLUMN_SPAN = 200;
|
||||
private static final int COLUMN_STEP = 7;
|
||||
private static final String CEILING = """
|
||||
"caveCeilingLayers": [
|
||||
{"minHeight": 2, "maxHeight": 2, "palette": [{"block": "moss_block"}]},
|
||||
{"minHeight": 1, "maxHeight": 1, "palette": [{"block": "calcite"}]},
|
||||
{"minHeight": 2, "maxHeight": 2, "palette": [{"block": "basalt"}]}
|
||||
]""";
|
||||
private static final String VARIABLE_CEILING = """
|
||||
"caveCeilingLayers": [
|
||||
{"minHeight": 0, "maxHeight": 6, "zoom": 0.3, "style": {"style": "SIMPLEX", "zoom": 1}, "palette": [{"block": "moss_block"}]},
|
||||
{"minHeight": 0, "maxHeight": 6, "palette": [{"block": "calcite"}]}
|
||||
]""";
|
||||
|
||||
private IrisData data;
|
||||
|
||||
@Before
|
||||
public void bindPlatform() {
|
||||
UsableBlockPlatform.bind();
|
||||
data = mock(IrisData.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisBlockData> blocks = mock(ResourceLoader.class);
|
||||
when(data.getBlockLoader()).thenReturn(blocks);
|
||||
when(data.getDataFolder()).thenReturn(new File("pack"));
|
||||
IrisPackResources resources = new IrisPackResources(data);
|
||||
when(data.getPackResources()).thenReturn(resources);
|
||||
}
|
||||
|
||||
@After
|
||||
public void unbindPlatform() {
|
||||
UsableBlockPlatform.unbind();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emitsEveryCeilingLayerBeyondTheSurfaceLayers() {
|
||||
LayeredBiome biome = biome("{" + CEILING + "}");
|
||||
|
||||
KList<BlockState> blocks = layers().generateCeilingLayers(biome, PaletteExplosion.NONE, 13, -27, new RNG(RNG_SEED), CEILING_DEPTH);
|
||||
|
||||
assertEquals(List.of("moss_block", "moss_block", "calcite", "basalt", "basalt"), keys(blocks));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ceilingLayerBlockPicksWhatGenerationStacks() {
|
||||
LayeredBiome biome = biome("{" + CEILING + "}");
|
||||
BiomeLayers layers = layers();
|
||||
|
||||
List<String> picked = new ArrayList<>();
|
||||
for (int index = 0; index < 3; index++) {
|
||||
for (int depth = 0; depth < 2; depth++) {
|
||||
BlockState block = layers.ceilingLayerBlock(biome, index, depth, 13, -27, new RNG(RNG_SEED));
|
||||
if (block != null) {
|
||||
picked.add(key(block));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(List.of("moss_block", "moss_block", "calcite", "basalt", "basalt"), picked);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ceilingThicknessDoesNotDependOnSurfaceLayers() {
|
||||
LayeredBiome bare = biome("{" + VARIABLE_CEILING + "}");
|
||||
LayeredBiome layered = biome("""
|
||||
{"layers": [
|
||||
{"minHeight": 1, "maxHeight": 3, "zoom": 5, "style": {"style": "PERLIN", "zoom": 1}, "palette": [{"block": "dirt"}]},
|
||||
{"minHeight": 1, "maxHeight": 3, "zoom": 9, "style": {"style": "CELLULAR", "zoom": 1}, "palette": [{"block": "stone"}]}],
|
||||
%s}""".formatted(VARIABLE_CEILING));
|
||||
BiomeLayers bareLayers = layers();
|
||||
BiomeLayers layeredLayers = layers();
|
||||
|
||||
for (int x = -COLUMN_SPAN; x <= COLUMN_SPAN; x += COLUMN_STEP) {
|
||||
RNG rng = new RNG(RNG_SEED);
|
||||
assertEquals("column " + x,
|
||||
keys(bareLayers.generateCeilingLayers(bare, PaletteExplosion.NONE, x, -x, rng, CEILING_DEPTH)),
|
||||
keys(layeredLayers.generateCeilingLayers(layered, PaletteExplosion.NONE, x, -x, rng, CEILING_DEPTH)));
|
||||
}
|
||||
}
|
||||
|
||||
private LayeredBiome biome(String json) {
|
||||
return TestLayeredBiomes.of(TerrainTestSettings.of(json));
|
||||
}
|
||||
|
||||
private BiomeLayers layers() {
|
||||
return new BiomeLayers(TestLayerBlocks.of(data.getPackResources()), () -> data.getPackResources().noise(), ModuleLogs.discarding());
|
||||
}
|
||||
|
||||
private static List<String> keys(KList<BlockState> blocks) {
|
||||
List<String> keys = new ArrayList<>();
|
||||
for (BlockState block : blocks) {
|
||||
keys.add(key(block));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
private static String key(BlockState block) {
|
||||
return block.key().replace("minecraft:", "");
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,7 @@ public final class BiomeLayers {
|
||||
private final ModuleLog log;
|
||||
private final Map<PaletteLayer, ResolvedLayer> resolved = new ConcurrentHashMap<>();
|
||||
private final Map<LayersSettings, AtomicCache<KList<LayerNoise>>> surfaceHeights = new ConcurrentHashMap<>();
|
||||
private final Map<CaveCeilingLayersSettings, AtomicCache<KList<LayerNoise>>> ceilingHeights = new ConcurrentHashMap<>();
|
||||
private final Map<SeaLayersSettings, AtomicCache<KList<LayerNoise>>> seaHeights = new ConcurrentHashMap<>();
|
||||
private final Map<ResourceId, LayeredBiome> biomes = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -147,10 +148,8 @@ public final class BiomeLayers {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
KList<LayerNoise> heightNoises = surfaceHeightNoises(surfaceSettings(biome), random);
|
||||
// Ceiling layers reuse the surface-layer height noise, so entries beyond the surface layers have none; skip them.
|
||||
int usableLayers = Math.min(ceilingLayers.size(), heightNoises.size());
|
||||
for (int i = 0; i < usableLayers; i++) {
|
||||
KList<LayerNoise> heightNoises = ceilingHeightNoises(biome.ceilingLayers(), random);
|
||||
for (int i = 0; i < ceilingLayers.size(); i++) {
|
||||
ResolvedLayer layer = resolve(ceilingLayers.get(i));
|
||||
double depth = layerThickness(layer, heightNoises.get(i), wx, wz);
|
||||
if (depth <= 0) {
|
||||
@@ -203,10 +202,8 @@ public final class BiomeLayers {
|
||||
return biome.seaLayers() == null ? List.of() : biome.seaLayers().layers();
|
||||
}
|
||||
|
||||
/** The biome's cave ceiling layers that place blocks: those with a surface layer at their place to borrow its thickness from. */
|
||||
public List<PaletteLayer> ceilingLayers(LayeredBiome biome) {
|
||||
List<PaletteLayer> declared = biome.ceilingLayers() == null ? List.of() : biome.ceilingLayers().layers();
|
||||
return declared.subList(0, Math.min(declared.size(), surfaceLayers(biome).size()));
|
||||
return biome.ceilingLayers() == null ? List.of() : biome.ceilingLayers().layers();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -231,7 +228,7 @@ public final class BiomeLayers {
|
||||
/** Cave ceiling layer {@code index}'s block {@code depth} blocks below the ceiling, as {@link #generateCeilingLayers} picks it. */
|
||||
public BlockState ceilingLayerBlock(LayeredBiome biome, int index, int depth, double wx, double wz, RNG random) {
|
||||
ResolvedLayer layer = resolve(ceilingLayers(biome).get(index));
|
||||
double thickness = layerThickness(layer, surfaceHeightNoises(surfaceSettings(biome), random).get(index), wx, wz);
|
||||
double thickness = layerThickness(layer, ceilingHeightNoises(biome.ceilingLayers(), random).get(index), wx, wz);
|
||||
return blockAtDepth(layer, index, depth, thickness, wx, wz, random);
|
||||
}
|
||||
|
||||
@@ -341,6 +338,11 @@ public final class BiomeLayers {
|
||||
return heightNoises(cache, settings.layers(), SURFACE_HEIGHT_SEED, rng);
|
||||
}
|
||||
|
||||
private KList<LayerNoise> ceilingHeightNoises(CaveCeilingLayersSettings settings, RNG rng) {
|
||||
AtomicCache<KList<LayerNoise>> cache = ceilingHeights.computeIfAbsent(settings, declared -> new AtomicCache<>());
|
||||
return heightNoises(cache, settings.layers(), SURFACE_HEIGHT_SEED, rng);
|
||||
}
|
||||
|
||||
private KList<LayerNoise> seaHeightNoises(SeaLayersSettings settings, RNG rng) {
|
||||
AtomicCache<KList<LayerNoise>> cache = seaHeights.computeIfAbsent(settings, declared -> new AtomicCache<>());
|
||||
return heightNoises(cache, settings.layers(), SEA_HEIGHT_SEED, rng);
|
||||
|
||||
@@ -29,10 +29,10 @@ import java.util.List;
|
||||
/**
|
||||
* The layers of material on the ceilings of caves in a biome, written as {@code "caveCeilingLayers": [...]}, the list of layers.
|
||||
*/
|
||||
@Desc("Layers of materials placed on cave ceilings in this biome, indexed upward from the ceiling surface. Must not have more entries than layers, whose height generators it reuses. Omitting this leaves cave ceilings unchanged.")
|
||||
@Desc("Layers of materials placed on cave ceilings in this biome, indexed upward from the ceiling surface. Each layer has its own thickness generator, so there may be more or fewer entries than layers. Omitting this leaves cave ceilings unchanged.")
|
||||
@Feature(id = "iris:terrain/cave-ceiling-layers", name = "Cave ceiling layers", key = "caveCeilingLayers", root = "layers", targets = Level.BIOME)
|
||||
public final class CaveCeilingLayersSettings implements IrisFeature {
|
||||
@Desc("Layers of materials placed on cave ceilings in this biome, indexed upward from the ceiling surface. Must not have more entries than layers, whose height generators it reuses. Omitting this leaves cave ceilings unchanged.")
|
||||
@Desc("Layers of materials placed on cave ceilings in this biome, indexed upward from the ceiling surface. Each layer has its own thickness generator, so there may be more or fewer entries than layers. Omitting this leaves cave ceilings unchanged.")
|
||||
private List<PaletteLayer> layers = List.of();
|
||||
|
||||
public CaveCeilingLayersSettings() {
|
||||
|
||||
Reference in new issue
Block a user