From 417e82d570c6425fa8f960858baefdae0e5f4be9 Mon Sep 17 00:00:00 2001 From: piexel Date: Fri, 27 Nov 2026 00:48:50 +0100 Subject: [PATCH] Link layer and decorator runtimes through the biome runtime - Link surface, sea and ceiling palette layer runtimes by layer index in BiomeRuntime - Link each decoration part's decorator runtimes in bucket order in BiomeRuntime - Resolve the biome runtime once per layer pass and hand layers their runtime directly - Remember the last wall layer runtime while painting carved walls - Let palette layers and decorator chance gates take an already resolved runtime --- .../iris/generation/biome/BiomeRuntime.java | 76 ++++++++++++++++++- .../biome/IrisBiomeLayerGenerator.java | 28 ++++--- .../biome/IrisBiomePaletteLayer.java | 30 +++++--- .../generation/biome/PaletteLayerRuntime.java | 7 ++ .../generation/decoration/DecoratorCore.java | 6 +- .../decoration/DecoratorRuntime.java | 7 ++ .../generation/decoration/IrisDecorator.java | 9 ++- .../generation/stage/IrisCarveModifier.java | 16 +++- .../biome/FloatingIslandLockedLayersTest.java | 2 +- .../biome/IrisBiomeLayerSlopeSourceTest.java | 6 +- .../biome/IrisBiomeLockedLayerTest.java | 9 ++- .../biome/IrisSurfaceLayerFallbackTest.java | 5 +- .../DecorationFailureContainmentTest.java | 6 +- .../decoration/DecoratorCoreTest.java | 6 +- .../IrisDecoratorCaveContextTest.java | 11 +-- .../IrisSeaDecoratorBoundsTest.java | 7 +- .../IrisShoreLineDecoratorTest.java | 4 +- .../DimensionTerrain3DCompositionTest.java | 3 +- .../IrisCarveWallPaletteScopeTest.java | 5 +- .../stage/IrisCarveModifierLayerMemoTest.java | 2 +- .../arcane/iris/testsupport/MockPackData.java | 12 +++ 21 files changed, 203 insertions(+), 54 deletions(-) diff --git a/core/src/main/java/art/arcane/iris/generation/biome/BiomeRuntime.java b/core/src/main/java/art/arcane/iris/generation/biome/BiomeRuntime.java index 877342744..a02fcc65c 100644 --- a/core/src/main/java/art/arcane/iris/generation/biome/BiomeRuntime.java +++ b/core/src/main/java/art/arcane/iris/generation/biome/BiomeRuntime.java @@ -23,11 +23,18 @@ import art.arcane.iris.generation.runtime.SeedTable; import art.arcane.volmlib.util.collection.KList; import art.arcane.volmlib.util.noise.CNG; +import art.arcane.iris.generation.decoration.DecoratorRuntime; +import art.arcane.iris.generation.decoration.IrisDecorationPart; +import art.arcane.iris.generation.decoration.IrisDecorator; + import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicReferenceArray; +import java.util.function.Supplier; /** * What one engine derives from an {@link IrisBiome}: its scatter generators, the children generators per shrink - * scale, and the height generators of its layer palettes. + * scale, the height generators of its layer palettes and the runtimes of those palettes, linked by layer index so + * painting a column reads them without looking each layer up. */ public final class BiomeRuntime { private static final int BIOME_SEED_CAPACITY = 8; @@ -44,6 +51,11 @@ public final class BiomeRuntime { private final SeedTable> layerHeights; private final SeedTable> seaLayerHeights; private final SeedTable> ceilingLayerHeights; + private final LinkedLayers surfaceLayers; + private final LinkedLayers seaLayers; + private final LinkedLayers ceilingLayers; + private final AtomicReferenceArray decoratorBuckets = + new AtomicReferenceArray<>(IrisDecorationPart.values().length); public BiomeRuntime(IrisBiome biome, PackRuntime runtime) { this.biome = biome; @@ -55,6 +67,9 @@ public final class BiomeRuntime { IrisBiomeLayerGenerator.createHeightGenerators(biome.getSeaLayers(), SEA_LAYER_SEED_OFFSET, seed, runtime)); this.ceilingLayerHeights = new SeedTable<>(LAYER_HEIGHT_SEED_CAPACITY, seed -> IrisBiomeLayerGenerator.createHeightGenerators(biome.getCaveCeilingLayers(), CEILING_LAYER_SEED_OFFSET, seed, runtime)); + this.surfaceLayers = new LinkedLayers(biome::getLayers); + this.seaLayers = new LinkedLayers(biome::getSeaLayers); + this.ceilingLayers = new LinkedLayers(biome::getCaveCeilingLayers); } public CNG biomeGenerator(long seed) { @@ -78,4 +93,63 @@ public final class BiomeRuntime { public KList ceilingLayerHeights(long seed) { return ceilingLayerHeights.get(seed); } + + /** The runtime of the surface layer at this index of {@link IrisBiome#getLayers()}. */ + public PaletteLayerRuntime surfaceLayer(int index) { + return surfaceLayers.get(index); + } + + /** The runtime of the sea layer at this index of {@link IrisBiome#getSeaLayers()}. */ + public PaletteLayerRuntime seaLayer(int index) { + return seaLayers.get(index); + } + + /** The runtime of the cave ceiling layer at this index of {@link IrisBiome#getCaveCeilingLayers()}. */ + public PaletteLayerRuntime ceilingLayer(int index) { + return ceilingLayers.get(index); + } + + /** The runtimes of this part's {@link IrisBiome#getDecoratorBucket} decorators, in bucket order. */ + public DecoratorRuntime[] decorators(IrisDecorationPart part) { + IrisDecorator[] bucket = biome.getDecoratorBucket(part); + LinkedDecorators linked = decoratorBuckets.getAcquire(part.ordinal()); + if (linked != null && linked.bucket() == bucket) { + return linked.runtimes(); + } + DecoratorRuntime[] runtimes = new DecoratorRuntime[bucket.length]; + for (int index = 0; index < bucket.length; index++) { + runtimes[index] = runtime.decorator(bucket[index]); + } + decoratorBuckets.setRelease(part.ordinal(), new LinkedDecorators(bucket, runtimes)); + return runtimes; + } + + private record LinkedDecorators(IrisDecorator[] bucket, DecoratorRuntime[] runtimes) { + } + + private final class LinkedLayers { + private final Supplier> layers; + private volatile PaletteLayerRuntime[] linked; + + private LinkedLayers(Supplier> layers) { + this.layers = layers; + } + + private PaletteLayerRuntime get(int index) { + PaletteLayerRuntime[] current = linked; + if (current == null) { + current = link(layers.get()); + linked = current; + } + return current[index]; + } + + private PaletteLayerRuntime[] link(KList source) { + PaletteLayerRuntime[] result = new PaletteLayerRuntime[source.size()]; + for (int index = 0; index < result.length; index++) { + result[index] = runtime.paletteLayer(source.get(index)); + } + return result; + } + } } diff --git a/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomeLayerGenerator.java b/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomeLayerGenerator.java index c4b023541..03484f70c 100644 --- a/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomeLayerGenerator.java +++ b/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomeLayerGenerator.java @@ -74,7 +74,8 @@ final class IrisBiomeLayerGenerator { return data; } - KList heightGenerators = getLayerHeightGenerators(biome, random, runtime); + BiomeRuntime biomeRuntime = runtime.biome(biome); + KList heightGenerators = biomeRuntime.layerHeights(random.getSeed()); double surfaceSlope = 0D; boolean sampledSlope = false; @@ -99,7 +100,7 @@ final class IrisBiomeLayerGenerator { continue; } - appendLayer(data, layer, i, d, wx, wz, random, maxDepth, runtime); + appendLayer(data, layer, biomeRuntime.surfaceLayer(i), i, d, wx, wz, random, maxDepth); if (data.size() >= maxDepth) { break; @@ -130,7 +131,7 @@ final class IrisBiomeLayerGenerator { fallback = dim.getSurfaceLayerFallback(); } if (fallback == IrisSurfaceLayerFallback.TOP_LAYER) { - appendLayer(data, biome.getLayers().get(0), 0, 1, wx, wz, random, maxDepth, runtime); + appendLayer(data, biome.getLayers().get(0), runtime.biome(biome).surfaceLayer(0), 0, 1, wx, wz, random, maxDepth); } } @@ -148,7 +149,8 @@ final class IrisBiomeLayerGenerator { return data; } - KList heightGenerators = getCaveCeilingLayerHeightGenerators(biome, random, runtime); + BiomeRuntime biomeRuntime = runtime.biome(biome); + KList heightGenerators = biomeRuntime.ceilingLayerHeights(random.getSeed()); for (int i = 0; i < layerCount; i++) { IrisBiomePaletteLayer layer = ceilingLayers.get(i); @@ -160,7 +162,7 @@ final class IrisBiomeLayerGenerator { continue; } - appendLayer(data, layer, i, d, wx, wz, random, maxDepth, runtime); + appendLayer(data, layer, biomeRuntime.ceilingLayer(i), i, d, wx, wz, random, maxDepth); if (data.size() >= maxDepth) { break; @@ -193,7 +195,8 @@ final class IrisBiomeLayerGenerator { return data; } - KList heightGenerators = getLayerHeightGenerators(biome, random, runtime); + BiomeRuntime biomeRuntime = runtime.biome(biome); + KList heightGenerators = biomeRuntime.layerHeights(random.getSeed()); int[] boundaries = new int[layerCount + 1]; double surfaceSlope = 0D; boolean sampledSlope = false; @@ -231,7 +234,7 @@ final class IrisBiomeLayerGenerator { double zoom = layer.getZoom(); try { data.add(layer.get(random, layerIndex + offset, - (wx + offset) / zoom, offset, (wz - offset) / zoom, runtime)); + (wx + offset) / zoom, offset, (wz - offset) / zoom, biomeRuntime.surfaceLayer(layerIndex))); } catch (Throwable error) { GenerationFailures.skipPlacement(error, "surface layer", "block", (int) wx, height - depth, (int) wz, biome.getLoadKey()); } @@ -285,7 +288,8 @@ final class IrisBiomeLayerGenerator { return data; } - KList heightGenerators = getLayerSeaHeightGenerators(biome, random, runtime); + BiomeRuntime biomeRuntime = runtime.biome(biome); + KList heightGenerators = biomeRuntime.seaLayerHeights(random.getSeed()); for (int i = 0; i < layerCount; i++) { IrisBiomePaletteLayer layer = seaLayers.get(i); @@ -297,7 +301,7 @@ final class IrisBiomeLayerGenerator { continue; } - appendLayer(data, layer, i, d, wx, wz, random, maxDepth, runtime); + appendLayer(data, layer, biomeRuntime.seaLayer(i), i, d, wx, wz, random, maxDepth); if (data.size() >= maxDepth) { break; @@ -331,13 +335,13 @@ final class IrisBiomeLayerGenerator { } private static void appendLayer(KList blocks, IrisBiomePaletteLayer layer, - int layerIndex, int thickness, double x, double z, - RNG random, int maxDepth, PackRuntime runtime) { + PaletteLayerRuntime layerRuntime, int layerIndex, int thickness, double x, double z, + RNG random, int maxDepth) { double zoom = layer.getZoom(); for (int offset = 0; offset < thickness && blocks.size() < maxDepth; offset++) { try { blocks.add(layer.get(random, layerIndex + offset, - (x + offset) / zoom, offset, (z - offset) / zoom, runtime)); + (x + offset) / zoom, offset, (z - offset) / zoom, layerRuntime)); } catch (Throwable error) { GenerationFailures.skipPlacement(error, "surface layer", "block", (int) x, -1, (int) z, "none"); } diff --git a/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomePaletteLayer.java b/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomePaletteLayer.java index 22063b6df..f4192a042 100644 --- a/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomePaletteLayer.java +++ b/core/src/main/java/art/arcane/iris/generation/biome/IrisBiomePaletteLayer.java @@ -95,20 +95,26 @@ public class IrisBiomePaletteLayer { */ public NativeBlockState get(RNG parent, int signature, double x, double y, double z, PackRuntime runtime) { KList localBlockData = getBlockData(runtime.data()); - - if (localBlockData.isEmpty()) { - return null; + if (localBlockData.size() <= 1) { + return localBlockData.isEmpty() ? null : localBlockData.get(0); } + return fit(localBlockData, runtime.paletteLayer(this), parent, signature, x, y, z); + } - if (localBlockData.size() == 1) { - return localBlockData.get(0); + /** {@link #get(RNG, int, double, double, double, PackRuntime)} for a caller that already holds this layer's runtime. */ + public NativeBlockState get(RNG parent, int signature, double x, double y, double z, PaletteLayerRuntime layerRuntime) { + KList localBlockData = getBlockData(layerRuntime.packRuntime().data()); + if (localBlockData.size() <= 1) { + return localBlockData.isEmpty() ? null : localBlockData.get(0); } + return fit(localBlockData, layerRuntime, parent, signature, x, y, z); + } + private NativeBlockState fit(KList localBlockData, PaletteLayerRuntime layerRuntime, + RNG parent, int signature, double x, double y, double z) { double localZoom = zoom; - double scaledX = x / localZoom; - double scaledY = y / localZoom; - double scaledZ = z / localZoom; - return getLayerGenerator(parent, signature, runtime).fit(localBlockData, scaledX, scaledY, scaledZ); + CNG generator = layerRuntime.layerGenerator(layerGeneratorSeed(parent, signature, localBlockData.size())); + return generator.fit(localBlockData, x / localZoom, y / localZoom, z / localZoom); } public CNG getLayerGenerator(RNG rng, PackRuntime runtime) { @@ -116,10 +122,14 @@ public class IrisBiomePaletteLayer { } public CNG getLayerGenerator(RNG parent, int signature, PackRuntime runtime) { - long generatorSeed = parent.getSeed() + signature + minHeight + maxHeight + getBlockData(runtime.data()).size(); + long generatorSeed = layerGeneratorSeed(parent, signature, getBlockData(runtime.data()).size()); return runtime.paletteLayer(this).layerGenerator(generatorSeed); } + private long layerGeneratorSeed(RNG parent, int signature, int blockCount) { + return parent.getSeed() + signature + minHeight + maxHeight + blockCount; + } + CNG createLayerGenerator(long generatorSeed, PackRuntime runtime) { return style.createNoCache(new RNG(generatorSeed), runtime); } diff --git a/core/src/main/java/art/arcane/iris/generation/biome/PaletteLayerRuntime.java b/core/src/main/java/art/arcane/iris/generation/biome/PaletteLayerRuntime.java index 4b7f970f7..2f9383f04 100644 --- a/core/src/main/java/art/arcane/iris/generation/biome/PaletteLayerRuntime.java +++ b/core/src/main/java/art/arcane/iris/generation/biome/PaletteLayerRuntime.java @@ -31,15 +31,22 @@ public final class PaletteLayerRuntime { private static final int LAYER_RECENT_SLOTS = 32; private static final int HEIGHT_SEED_CAPACITY = 32; + private final PackRuntime runtime; private final SeedTable layerGenerators; private final SeedTable heightGenerators; public PaletteLayerRuntime(IrisBiomePaletteLayer layer, PackRuntime runtime) { + this.runtime = runtime; this.layerGenerators = new SeedTable<>(LAYER_SEED_CAPACITY, LAYER_RECENT_SLOTS, seed -> layer.createLayerGenerator(seed, runtime)); this.heightGenerators = new SeedTable<>(HEIGHT_SEED_CAPACITY, IrisBiomePaletteLayer::createHeightGenerator); } + /** The scope this runtime was built in, whose pack data resolves the layer's palette. */ + public PackRuntime packRuntime() { + return runtime; + } + public CNG layerGenerator(long seed) { return layerGenerators.get(seed); } diff --git a/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorCore.java b/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorCore.java index 2942dac3f..6864ca242 100644 --- a/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorCore.java +++ b/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorCore.java @@ -100,12 +100,14 @@ final class DecoratorCore { return null; } + DecoratorRuntime[] decoratorRuntimes = runtime.biome(biome).decorators(part); IrisDecorator picked = null; int count = 0; - for (IrisDecorator d : bucket) { + for (int index = 0; index < bucket.length; index++) { + IrisDecorator d = bucket[index]; try { - if (d.passesChanceGate(gRNG, realX, realZ, runtime)) { + if (d.passesChanceGate(gRNG, realX, realZ, decoratorRuntimes[index])) { count++; if (count == 1 || colRng.nextInt(count) == 0) { picked = d; diff --git a/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorRuntime.java b/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorRuntime.java index e2f8413a5..87af5b68f 100644 --- a/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorRuntime.java +++ b/core/src/main/java/art/arcane/iris/generation/decoration/DecoratorRuntime.java @@ -26,16 +26,23 @@ import art.arcane.volmlib.util.noise.CNG; public final class DecoratorRuntime { private static final int SEED_CAPACITY = 32; + private final PackRuntime runtime; private final SeedTable heightGenerators; private final SeedTable layerGenerators; private final SeedTable varianceGenerators; public DecoratorRuntime(IrisDecorator decorator, PackRuntime runtime) { + this.runtime = runtime; this.heightGenerators = new SeedTable<>(SEED_CAPACITY, seed -> decorator.createHeightGenerator(seed, runtime)); this.layerGenerators = new SeedTable<>(SEED_CAPACITY, seed -> decorator.createLayerGenerator(seed, runtime)); this.varianceGenerators = new SeedTable<>(SEED_CAPACITY, seed -> decorator.createVarianceGenerator(seed, runtime)); } + /** The scope this runtime was built in, whose pack data resolves the decorator's palettes. */ + public PackRuntime packRuntime() { + return runtime; + } + public CNG heightGenerator(long seed) { return heightGenerators.get(seed); } diff --git a/core/src/main/java/art/arcane/iris/generation/decoration/IrisDecorator.java b/core/src/main/java/art/arcane/iris/generation/decoration/IrisDecorator.java index a4b865ee4..70574f844 100644 --- a/core/src/main/java/art/arcane/iris/generation/decoration/IrisDecorator.java +++ b/core/src/main/java/art/arcane/iris/generation/decoration/IrisDecorator.java @@ -161,12 +161,17 @@ public class IrisDecorator { } public boolean passesChanceGate(RNG rng, double x, double z, PackRuntime runtime) { - if (getBlockData(runtime.data()).isEmpty()) { + return passesChanceGate(rng, x, z, runtime.decorator(this)); + } + + /** {@link #passesChanceGate(RNG, double, double, PackRuntime)} for a caller that already holds this decorator's runtime. */ + public boolean passesChanceGate(RNG rng, double x, double z, DecoratorRuntime decoratorRuntime) { + if (getBlockData(decoratorRuntime.packRuntime().data()).isEmpty()) { return false; } double xx = x / style.getZoom(); double zz = z / style.getZoom(); - return getGenerator(rng, runtime).fitDouble(0D, 1D, xx, zz) <= chance; + return decoratorRuntime.layerGenerator(rng.getSeed()).fitDouble(0D, 1D, xx, zz) <= chance; } public NativeBlockState getBlockData(IrisBiome b, RNG rng, double x, double z, PackRuntime runtime) { diff --git a/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java b/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java index 6d2f35d1d..342316aad 100644 --- a/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java +++ b/core/src/main/java/art/arcane/iris/generation/stage/IrisCarveModifier.java @@ -43,6 +43,7 @@ import art.arcane.iris.generation.mantle.TerrainMatterView; import art.arcane.iris.generation.terrain.InferredType; import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.iris.generation.biome.IrisBiomePaletteLayer; +import art.arcane.iris.generation.biome.PaletteLayerRuntime; import art.arcane.iris.generation.decoration.IrisDecorationPart; import art.arcane.iris.generation.decoration.IrisDecorator; import art.arcane.iris.generation.terrain.IrisDimensionCarvingResolver; @@ -608,6 +609,9 @@ public class IrisCarveModifier extends EngineAssignedModifier private final IrisData data; private final int chunkBlockX; private final int chunkBlockZ; + private final PackRuntime wallRuntime; + private IrisBiomePaletteLayer lastWall; + private PaletteLayerRuntime lastWallRuntime; private WallPainter(Hunk output, CaveTerrainSnapshot terrain, CaveInputs inputs, Long2ObjectOpenHashMap caveBiomeCache, Map customBiomeCache, @@ -621,6 +625,7 @@ public class IrisCarveModifier extends EngineAssignedModifier this.data = data; this.chunkBlockX = chunkBlockX; this.chunkBlockZ = chunkBlockZ; + this.wallRuntime = inputs.runtime.scopeFor(data); } @Override @@ -639,11 +644,20 @@ public class IrisCarveModifier extends EngineAssignedModifier if (biome == null) { return; } - NativeBlockState wall = biome.getWall().get(rng, worldX, yy, worldZ, inputs.runtime.scopeFor(data)); + IrisBiomePaletteLayer wallLayer = biome.getWall(); + NativeBlockState wall = wallLayer.get(rng, 0, worldX, yy, worldZ, wallLayerRuntime(wallLayer)); if (wall != null) { output.setRaw(rx, yy, rz, wall); } } + + private PaletteLayerRuntime wallLayerRuntime(IrisBiomePaletteLayer wallLayer) { + if (wallLayer != lastWall) { + lastWall = wallLayer; + lastWallRuntime = wallRuntime.paletteLayer(wallLayer); + } + return lastWallRuntime; + } } private void addInternalWallsFromMantle(CaveTerrainSnapshot terrain, CarveWallBuffer walls, CarveColumnMask[] columnMasks) { diff --git a/core/src/test/java/art/arcane/iris/generation/biome/FloatingIslandLockedLayersTest.java b/core/src/test/java/art/arcane/iris/generation/biome/FloatingIslandLockedLayersTest.java index 982353beb..edcf5bfd3 100644 --- a/core/src/test/java/art/arcane/iris/generation/biome/FloatingIslandLockedLayersTest.java +++ b/core/src/test/java/art/arcane/iris/generation/biome/FloatingIslandLockedLayersTest.java @@ -125,7 +125,7 @@ public class FloatingIslandLockedLayersTest { when(layer.getSlopeCondition()).thenReturn(new IrisSlopeClip()); when(layer.getHeightGenerator(any(), any())).thenReturn(height); when(height.fit(anyInt(), anyInt(), anyDouble(), anyDouble())).thenReturn(1); - when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(block); + when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any(PaletteLayerRuntime.class))).thenReturn(block); when(layer.get(any(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(block); return layer; } diff --git a/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLayerSlopeSourceTest.java b/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLayerSlopeSourceTest.java index c4c843be7..9335920c3 100644 --- a/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLayerSlopeSourceTest.java +++ b/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLayerSlopeSourceTest.java @@ -70,7 +70,8 @@ public final class IrisBiomeLayerSlopeSourceTest { when(grass.getSlopeCondition()).thenReturn(new IrisSlopeClip(0D, 2.6D)); when(grass.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(heightGenerator); when(heightGenerator.fit(1, 1, 12D, -8D)).thenReturn(1); - when(grass.get(rng, 0, 12D, 0D, -8D, data.standalonePackRuntime())).thenReturn(block); + PaletteLayerRuntime grassRuntime = data.standalonePackRuntime().paletteLayer(grass); + when(grass.get(rng, 0, 12D, 0D, -8D, grassRuntime)).thenReturn(block); KList ledge = biome.generateLayers( rockFallbackDimension(), 12D, -8D, rng, 1, 32, data.standalonePackRuntime(), complex); @@ -110,7 +111,8 @@ public final class IrisBiomeLayerSlopeSourceTest { when(paletteLayer.getSlopeCondition()).thenReturn(new IrisSlopeClip(5D, 5D)); when(paletteLayer.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(heightGenerator); when(heightGenerator.fit(1, 1, 12D, -8D)).thenReturn(1); - when(paletteLayer.get(rng, 0, 12D, 0D, -8D, data.standalonePackRuntime())).thenReturn(surfaceBlock); + PaletteLayerRuntime paletteLayerRuntime = data.standalonePackRuntime().paletteLayer(paletteLayer); + when(paletteLayer.get(rng, 0, 12D, 0D, -8D, paletteLayerRuntime)).thenReturn(surfaceBlock); KList hostLayers = biome.generateLayers( rockFallbackDimension(), 12D, -8D, rng, 1, 32, data.standalonePackRuntime(), hostComplex); diff --git a/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLockedLayerTest.java b/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLockedLayerTest.java index 75f39bbb5..696578058 100644 --- a/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLockedLayerTest.java +++ b/core/src/test/java/art/arcane/iris/generation/biome/IrisBiomeLockedLayerTest.java @@ -123,7 +123,8 @@ public class IrisBiomeLockedLayerTest { IrisBiome biome = new IrisBiome().setLockLayers(true).setLayers(new KList<>(layer)); RNG rng = new RNG(37L); assertEquals(7, biome.generateLockedLayers(13D, -27D, rng, 7, 64, RUNTIME, null).size()); - verify(layer, times(7)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(RUNTIME)); + PaletteLayerRuntime layerRuntime = RUNTIME.paletteLayer(layer); + verify(layer, times(7)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(layerRuntime)); } @Test @@ -133,7 +134,8 @@ public class IrisBiomeLockedLayerTest { IrisBiome biome = new IrisBiome().setLockLayers(true).setLockLayersMax(100).setLayers(new KList<>(layer)); RNG rng = new RNG(37L); assertEquals(100, biome.generateLockedLayers(13D, -27D, rng, 100, 64, RUNTIME, null).size()); - verify(layer, times(3)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(RUNTIME)); + PaletteLayerRuntime layerRuntime = RUNTIME.paletteLayer(layer); + verify(layer, times(3)).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(layerRuntime)); } @Test @@ -157,7 +159,8 @@ public class IrisBiomeLockedLayerTest { IrisBiome biome = new IrisBiome().setLockLayers(true).setLayers(new KList<>(layer)); RNG rng = new RNG(37L); IllegalStateException failure = new IllegalStateException("Palette unavailable"); - doThrow(failure).when(layer).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(RUNTIME)); + PaletteLayerRuntime layerRuntime = RUNTIME.paletteLayer(layer); + doThrow(failure).when(layer).get(same(rng), anyInt(), anyDouble(), anyDouble(), anyDouble(), same(layerRuntime)); assertTrue(biome.generateLockedLayers(0D, 0D, rng, 7, 64, RUNTIME, null).isEmpty()); } diff --git a/core/src/test/java/art/arcane/iris/generation/biome/IrisSurfaceLayerFallbackTest.java b/core/src/test/java/art/arcane/iris/generation/biome/IrisSurfaceLayerFallbackTest.java index 9f567727c..c6f7c8102 100644 --- a/core/src/test/java/art/arcane/iris/generation/biome/IrisSurfaceLayerFallbackTest.java +++ b/core/src/test/java/art/arcane/iris/generation/biome/IrisSurfaceLayerFallbackTest.java @@ -38,8 +38,9 @@ public final class IrisSurfaceLayerFallbackTest { when(layer.getMaxHeight()).thenReturn(2); when(layer.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(heightGenerator); when(heightGenerator.fit(1, 2, 12D, -8D)).thenReturn(2); - when(layer.get(rng, 0, 12D, 0D, -8D, data.standalonePackRuntime())).thenReturn(surfaceBlock); - when(layer.get(rng, 1, 13D, 1D, -9D, data.standalonePackRuntime())).thenReturn(secondBlock); + PaletteLayerRuntime layerRuntime = data.standalonePackRuntime().paletteLayer(layer); + when(layer.get(rng, 0, 12D, 0D, -8D, layerRuntime)).thenReturn(surfaceBlock); + when(layer.get(rng, 1, 13D, 1D, -9D, layerRuntime)).thenReturn(secondBlock); when(slopeStream.getDouble(12D, -8D)).thenReturn(9D); return new IrisBiome().setLayers(new KList<>(layer)); } diff --git a/core/src/test/java/art/arcane/iris/generation/decoration/DecorationFailureContainmentTest.java b/core/src/test/java/art/arcane/iris/generation/decoration/DecorationFailureContainmentTest.java index 6b93c0ff4..96d589b9e 100644 --- a/core/src/test/java/art/arcane/iris/generation/decoration/DecorationFailureContainmentTest.java +++ b/core/src/test/java/art/arcane/iris/generation/decoration/DecorationFailureContainmentTest.java @@ -8,7 +8,7 @@ import art.arcane.iris.generation.runtime.IrisComplex; import art.arcane.iris.generation.runtime.SeedManager; import art.arcane.iris.generation.terrain.InferredType; import art.arcane.iris.generation.terrain.IrisDimension; -import art.arcane.iris.pack.loading.IrisData; +import art.arcane.iris.testsupport.MockPackData; import art.arcane.iris.spi.IrisPlatform; import art.arcane.iris.spi.IrisPlatforms; import art.arcane.iris.spi.PlatformRegistries; @@ -89,7 +89,7 @@ public class DecorationFailureContainmentTest { doReturn("minecraft:vine").when(vine).materialKey(); IrisDecorator decorator = mock(IrisDecorator.class); - doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any()); + doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class)); doReturn(true).when(decorator).isForcePlace(); doReturn(vine).when(decorator).pickBlockData(any(), any(), anyDouble(), anyDouble()); doReturn(new NativeBlockState[]{vine}).when(decorator).getBlockDataArray(any()); @@ -121,7 +121,7 @@ public class DecorationFailureContainmentTest { private static Engine engine() { Engine engine = mock(Engine.class); doReturn(mock(SeedManager.class)).when(engine).getSeedManager(); - doReturn(mock(IrisData.class)).when(engine).getData(); + doReturn(MockPackData.create()).when(engine).getData(); IrisDimension dimension = mock(IrisDimension.class); doReturn(63).when(dimension).getFluidHeight(); doReturn(dimension).when(engine).getDimension(); diff --git a/core/src/test/java/art/arcane/iris/generation/decoration/DecoratorCoreTest.java b/core/src/test/java/art/arcane/iris/generation/decoration/DecoratorCoreTest.java index c25ee931e..cf4a68eb0 100644 --- a/core/src/test/java/art/arcane/iris/generation/decoration/DecoratorCoreTest.java +++ b/core/src/test/java/art/arcane/iris/generation/decoration/DecoratorCoreTest.java @@ -103,7 +103,7 @@ public class DecoratorCoreTest { IrisData data = MockPackData.create(); PackRuntime runtime = data.standalonePackRuntime(); IrisDecorator d = mock(IrisDecorator.class); - when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(PackRuntime.class))).thenReturn(false); + when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(false); when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(new IrisDecorator[]{d}); IrisDecorator result = DecoratorCore.pickDecorator( @@ -117,7 +117,7 @@ public class DecoratorCoreTest { IrisData data = MockPackData.create(); PackRuntime runtime = data.standalonePackRuntime(); IrisDecorator d = mock(IrisDecorator.class); - when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(PackRuntime.class))).thenReturn(true); + when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(true); when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(new IrisDecorator[]{d}); RNG gRNG = new RNG(42L); @@ -138,7 +138,7 @@ public class DecoratorCoreTest { IrisDecorator[] decorators = new IrisDecorator[n]; for (int i = 0; i < n; i++) { IrisDecorator d = mock(IrisDecorator.class); - when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(PackRuntime.class))).thenReturn(true); + when(d.passesChanceGate(any(RNG.class), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(true); decorators[i] = d; } when(biome.getDecoratorBucket(IrisDecorationPart.NONE)).thenReturn(decorators); diff --git a/core/src/test/java/art/arcane/iris/generation/decoration/IrisDecoratorCaveContextTest.java b/core/src/test/java/art/arcane/iris/generation/decoration/IrisDecoratorCaveContextTest.java index 77f6b7858..67c3865ac 100644 --- a/core/src/test/java/art/arcane/iris/generation/decoration/IrisDecoratorCaveContextTest.java +++ b/core/src/test/java/art/arcane/iris/generation/decoration/IrisDecoratorCaveContextTest.java @@ -1,6 +1,7 @@ package art.arcane.iris.generation.decoration; import art.arcane.iris.pack.loading.IrisData; +import art.arcane.iris.testsupport.MockPackData; import art.arcane.iris.generation.runtime.IrisComplex; import art.arcane.iris.generation.mantle.EngineMantle; import art.arcane.iris.generation.runtime.Engine; @@ -63,7 +64,7 @@ public class IrisDecoratorCaveContextTest { Engine engine = mock(Engine.class); SeedManager seedManager = mock(SeedManager.class); doReturn(seedManager).when(engine).getSeedManager(); - doReturn(mock(IrisData.class)).when(engine).getData(); + doReturn(MockPackData.create()).when(engine).getData(); IrisDimension dimension = mock(IrisDimension.class); doReturn(63).when(dimension).getFluidHeight(); doReturn(dimension).when(engine).getDimension(); @@ -74,7 +75,7 @@ public class IrisDecoratorCaveContextTest { doReturn(63).when(mantle).getFluidHeight(anyInt(), anyInt()); IrisDecorator decorator = mock(IrisDecorator.class); - doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any()); + doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class)); doReturn(true).when(decorator).isStacking(); doReturn(true).when(decorator).isForcePlace(); doReturn(1).when(decorator).getHeight(any(), anyDouble(), anyDouble(), any()); @@ -113,7 +114,7 @@ public class IrisDecoratorCaveContextTest { public void dryBlendedSurfaceRunsBiomeDecoratorDespiteHigherModeledWater() { Engine engine = mock(Engine.class); doReturn(mock(SeedManager.class)).when(engine).getSeedManager(); - doReturn(mock(IrisData.class)).when(engine).getData(); + doReturn(MockPackData.create()).when(engine).getData(); doReturn(7L).when(engine).getGenerationSessionId(); IrisDimension dimension = mock(IrisDimension.class); doReturn(dimension).when(engine).getDimension(); @@ -122,7 +123,7 @@ public class IrisDecoratorCaveContextTest { doReturn(63).when(mantle).getFluidHeight(anyInt(), anyInt()); IrisDecorator decorator = mock(IrisDecorator.class); - doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any()); + doReturn(true).when(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class)); doReturn(true).when(decorator).isStacking(); doReturn(true).when(decorator).isForcePlace(); doReturn(1).when(decorator).getHeight(any(), anyDouble(), anyDouble(), any()); @@ -143,7 +144,7 @@ public class IrisDecoratorCaveContextTest { assertEquals(63, surface.surfaceFluidHeight(16, 0)); } - verify(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any()); + verify(decorator).passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class)); assertFalse(DecoratorCore.SCRATCH_OPTS.get().underwater); assertEquals(63, surface.surfaceFluidHeight(0, 0)); try (IrisContext.Scope scope = IrisContext.open(engine, 8L, chunk)) { diff --git a/core/src/test/java/art/arcane/iris/generation/decoration/IrisSeaDecoratorBoundsTest.java b/core/src/test/java/art/arcane/iris/generation/decoration/IrisSeaDecoratorBoundsTest.java index 5959fbe71..dd29bfbf5 100644 --- a/core/src/test/java/art/arcane/iris/generation/decoration/IrisSeaDecoratorBoundsTest.java +++ b/core/src/test/java/art/arcane/iris/generation/decoration/IrisSeaDecoratorBoundsTest.java @@ -1,6 +1,8 @@ package art.arcane.iris.generation.decoration; import art.arcane.iris.generation.runtime.Engine; +import art.arcane.iris.pack.loading.IrisData; +import art.arcane.iris.testsupport.MockPackData; import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.volmlib.nativelib.terrain.NativeBlockState; import art.arcane.volmlib.util.hunk.Hunk; @@ -121,10 +123,13 @@ public class IrisSeaDecoratorBoundsTest { private Fixture(int height, boolean surface) { when(engine.getHeight()).thenReturn(height); + IrisData data = MockPackData.create(); + when(engine.getPackRuntime()).thenReturn(null); + when(engine.getData()).thenReturn(data); output = Hunk.newArrayHunk(1, height, 1); IrisDecorationPart part = surface ? IrisDecorationPart.SEA_SURFACE : IrisDecorationPart.SEA_FLOOR; when(biome.getDecoratorBucket(part)).thenReturn(new IrisDecorator[]{decorator}); - when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), any())).thenReturn(true); + when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), any(DecoratorRuntime.class))).thenReturn(true); when(decorator.getBlockData100(any(), any(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(body); when(decorator.getBlockDataForTop(any(), any(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(top); when(decorator.getTopThreshold()).thenReturn(1D); diff --git a/core/src/test/java/art/arcane/iris/generation/decoration/IrisShoreLineDecoratorTest.java b/core/src/test/java/art/arcane/iris/generation/decoration/IrisShoreLineDecoratorTest.java index 051a16218..378346ffc 100644 --- a/core/src/test/java/art/arcane/iris/generation/decoration/IrisShoreLineDecoratorTest.java +++ b/core/src/test/java/art/arcane/iris/generation/decoration/IrisShoreLineDecoratorTest.java @@ -71,7 +71,7 @@ public class IrisShoreLineDecoratorTest { output, fixture.biome, FLUID_HEIGHT, output.getHeight()); assertSame(targetAir, output.get(0, FLUID_HEIGHT + 1, 0)); - verify(fixture.decorator).passesChanceGate(any(), anyDouble(), anyDouble(), MockPackData.runtimeOf(fixture.data)); + verify(fixture.decorator).passesChanceGate(any(), anyDouble(), anyDouble(), MockPackData.decoratorRuntimeOf(fixture.data)); verify(fixture.decorator, never()).getBlockData100( eq(fixture.biome), any(), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(fixture.data)); } @@ -264,7 +264,7 @@ public class IrisShoreLineDecoratorTest { when(engine.getData()).thenReturn(data); when(biome.getDecoratorBucket(IrisDecorationPart.SHORE_LINE)) .thenReturn(new IrisDecorator[]{decorator}); - when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), MockPackData.runtimeOf(data))).thenReturn(true); + when(decorator.passesChanceGate(any(), anyDouble(), anyDouble(), MockPackData.decoratorRuntimeOf(data))).thenReturn(true); when(decorator.isForcePlace()).thenReturn(forcePlace); when(decorator.getSlopeCondition()).thenReturn(slope); when(slope.isDefault()).thenReturn(true); diff --git a/core/src/test/java/art/arcane/iris/generation/runtime/DimensionTerrain3DCompositionTest.java b/core/src/test/java/art/arcane/iris/generation/runtime/DimensionTerrain3DCompositionTest.java index 939236c19..1a8c98931 100644 --- a/core/src/test/java/art/arcane/iris/generation/runtime/DimensionTerrain3DCompositionTest.java +++ b/core/src/test/java/art/arcane/iris/generation/runtime/DimensionTerrain3DCompositionTest.java @@ -10,6 +10,7 @@ import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.iris.generation.terrain.IrisDimension; import art.arcane.iris.generation.terrain.IrisRegion; import art.arcane.iris.generation.biome.IrisBiomePaletteLayer; +import art.arcane.iris.generation.biome.PaletteLayerRuntime; import art.arcane.iris.generation.terrain.IrisSlopeClip; import art.arcane.iris.generation.image.IrisImageMapRuntime; import art.arcane.iris.generation.terrain.Terrain3DColumn; @@ -425,7 +426,7 @@ public class DimensionTerrain3DCompositionTest { when(layer.getSlopeCondition()).thenReturn(slope); when(layer.getHeightGenerator(any(), any())).thenReturn(height); when(height.fit(anyInt(), anyInt(), anyDouble(), anyDouble())).thenReturn(1); - when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any())).thenReturn(block); + when(layer.get(any(), anyInt(), anyDouble(), anyDouble(), anyDouble(), any(PaletteLayerRuntime.class))).thenReturn(block); layers.add(layer); } return new IrisBiome().setLockLayers(locked).setLayers(layers); diff --git a/core/src/test/java/art/arcane/iris/generation/runtime/IrisCarveWallPaletteScopeTest.java b/core/src/test/java/art/arcane/iris/generation/runtime/IrisCarveWallPaletteScopeTest.java index d95669b20..d3c8b1daf 100644 --- a/core/src/test/java/art/arcane/iris/generation/runtime/IrisCarveWallPaletteScopeTest.java +++ b/core/src/test/java/art/arcane/iris/generation/runtime/IrisCarveWallPaletteScopeTest.java @@ -6,6 +6,7 @@ import art.arcane.iris.generation.mantle.EngineMantle; import art.arcane.iris.generation.stage.IrisCarveModifier; import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.iris.generation.biome.IrisBiomePaletteLayer; +import art.arcane.iris.generation.biome.PaletteLayerRuntime; import art.arcane.iris.generation.terrain.IrisDimension; import art.arcane.iris.generation.terrain.IrisDimensionCarvingResolver; import art.arcane.iris.world.IrisWorld; @@ -227,10 +228,10 @@ public class IrisCarveWallPaletteScopeTest { IrisBiomePaletteLayer palette = mock(IrisBiomePaletteLayer.class); doReturn(palette).when(biome).getWall(); doAnswer(call -> { - assertSame(expectedData, call.getArgument(4).data()); + assertSame(expectedData, call.getArgument(5).packRuntime().data()); paletteCalls.incrementAndGet(); return wall; - }).when(palette).get(any(RNG.class), anyDouble(), anyDouble(), anyDouble(), any(PackRuntime.class)); + }).when(palette).get(any(RNG.class), anyInt(), anyDouble(), anyDouble(), anyDouble(), any(PaletteLayerRuntime.class)); for (IrisComplex complex : new IrisComplex[]{activeComplex, detachedComplex, assemblyComplex}) { doReturn(ProceduralStream.of((x, z) -> biome, Interpolated.of(value -> 0D, value -> null))) .when(complex).getTrueBiomeStream(); diff --git a/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierLayerMemoTest.java b/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierLayerMemoTest.java index d36d0fe0e..043b6c86c 100644 --- a/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierLayerMemoTest.java +++ b/core/src/test/java/art/arcane/iris/generation/stage/IrisCarveModifierLayerMemoTest.java @@ -86,7 +86,7 @@ public class IrisCarveModifierLayerMemoTest { when(layer.getSlopeCondition()).thenReturn(slope); when(layer.getHeightGenerator(any(RNG.class), MockPackData.runtimeOf(data))).thenReturn(height); when(height.fit(anyInt(), anyInt(), anyDouble(), anyDouble())).thenReturn(thickness); - when(layer.get(any(RNG.class), anyInt(), anyDouble(), anyDouble(), anyDouble(), MockPackData.runtimeOf(data))) + when(layer.get(any(RNG.class), anyInt(), anyDouble(), anyDouble(), anyDouble(), MockPackData.paletteLayerRuntimeOf(data))) .thenAnswer(call -> block((int) call.getArgument(1))); return layer; } diff --git a/core/src/test/java/art/arcane/iris/testsupport/MockPackData.java b/core/src/test/java/art/arcane/iris/testsupport/MockPackData.java index 5227997c6..b062c5b6e 100644 --- a/core/src/test/java/art/arcane/iris/testsupport/MockPackData.java +++ b/core/src/test/java/art/arcane/iris/testsupport/MockPackData.java @@ -1,5 +1,7 @@ package art.arcane.iris.testsupport; +import art.arcane.iris.generation.biome.PaletteLayerRuntime; +import art.arcane.iris.generation.decoration.DecoratorRuntime; import art.arcane.iris.generation.runtime.PackRuntime; import art.arcane.iris.pack.loading.IrisData; @@ -28,6 +30,16 @@ public final class MockPackData { return argThat(runtime -> runtime != null && runtime.data() == data); } + /** Matches a palette layer runtime built in a runtime scope of this pack data. */ + public static PaletteLayerRuntime paletteLayerRuntimeOf(IrisData data) { + return argThat(runtime -> runtime != null && runtime.packRuntime().data() == data); + } + + /** Matches a decorator runtime built in a runtime scope of this pack data. */ + public static DecoratorRuntime decoratorRuntimeOf(IrisData data) { + return argThat(runtime -> runtime != null && runtime.packRuntime().data() == data); + } + private static IrisData withStandaloneRuntime(IrisData data) { doReturn(PackRuntime.standalone(data)).when(data).standalonePackRuntime(); return data;