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
This commit is contained in:
piexel committed 2026-11-27 00:48:50 +01:00
1 parent 188994e97b
commit 417e82d570
21 files changed
+203 -54

No files matched your search

@@ -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<KList<CNG>> layerHeights;
private final SeedTable<KList<CNG>> seaLayerHeights;
private final SeedTable<KList<CNG>> ceilingLayerHeights;
private final LinkedLayers surfaceLayers;
private final LinkedLayers seaLayers;
private final LinkedLayers ceilingLayers;
private final AtomicReferenceArray<LinkedDecorators> 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<CNG> 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<KList<IrisBiomePaletteLayer>> layers;
private volatile PaletteLayerRuntime[] linked;
private LinkedLayers(Supplier<KList<IrisBiomePaletteLayer>> 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<IrisBiomePaletteLayer> source) {
PaletteLayerRuntime[] result = new PaletteLayerRuntime[source.size()];
for (int index = 0; index < result.length; index++) {
result[index] = runtime.paletteLayer(source.get(index));
}
return result;
}
}
}
@@ -74,7 +74,8 @@ final class IrisBiomeLayerGenerator {
return data;
}
KList<CNG> heightGenerators = getLayerHeightGenerators(biome, random, runtime);
BiomeRuntime biomeRuntime = runtime.biome(biome);
KList<CNG> 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<CNG> heightGenerators = getCaveCeilingLayerHeightGenerators(biome, random, runtime);
BiomeRuntime biomeRuntime = runtime.biome(biome);
KList<CNG> 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<CNG> heightGenerators = getLayerHeightGenerators(biome, random, runtime);
BiomeRuntime biomeRuntime = runtime.biome(biome);
KList<CNG> 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<CNG> heightGenerators = getLayerSeaHeightGenerators(biome, random, runtime);
BiomeRuntime biomeRuntime = runtime.biome(biome);
KList<CNG> 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<NativeBlockState> 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");
}
@@ -95,20 +95,26 @@ public class IrisBiomePaletteLayer {
*/
public NativeBlockState get(RNG parent, int signature, double x, double y, double z, PackRuntime runtime) {
KList<NativeBlockState> 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<NativeBlockState> 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<NativeBlockState> 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);
}
@@ -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<CNG> layerGenerators;
private final SeedTable<CNG> 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);
}
@@ -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;
@@ -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<CNG> heightGenerators;
private final SeedTable<CNG> layerGenerators;
private final SeedTable<CNG> 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);
}
@@ -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) {
@@ -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<NativeBlockState>
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<NativeBlockState> output, CaveTerrainSnapshot terrain, CaveInputs inputs,
Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache, Map<String, IrisBiome> customBiomeCache,
@@ -621,6 +625,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
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<NativeBlockState>
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) {
@@ -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;
}
@@ -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<NativeBlockState> 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<NativeBlockState> hostLayers = biome.generateLayers(
rockFallbackDimension(), 12D, -8D, rng, 1, 32, data.standalonePackRuntime(), hostComplex);
@@ -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());
}
@@ -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));
}
@@ -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();
@@ -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);
@@ -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)) {
@@ -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);
@@ -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);
@@ -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);
@@ -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.<PackRuntime>getArgument(4).data());
assertSame(expectedData, call.<PaletteLayerRuntime>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();
@@ -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;
}
@@ -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;