Carve and floating islands read a biome's layers once per biome and convert layer blocks once per block instance; the upper dimension's palette explosion is read once per chunk

This commit is contained in:
piexel committed 2026-10-12 02:57:42 +02:00
1 parent 12ec03d61c
commit 36d464d0a3
4 files changed
+67 -28

No files matched your search

@@ -209,7 +209,7 @@ final class TerrainShaper {
BlockState upperMappedSurface = upper.surfaceBlock(realX, realZ).orElse(null);
int upperThickness = chunkHeight - 1 - upperSurfaceY;
LayeredBiome upperBiome = upperBiome(upperSettings, realX, realZ);
KList<BlockState> upperBlocks = layers.generateLayers(upperBiome, PaletteExplosion.of(upperSettings, realX, realZ),
KList<BlockState> upperBlocks = layers.generateLayers(upperBiome, chunk.upperExplosion(upperSettings, realX, realZ),
realX, realZ, rng, upperThickness, upperThickness, chunk.slope);
for (int y = chunkHeight - 1; y >= upperSurfaceY; y--) {
@@ -267,6 +267,7 @@ final class TerrainShaper {
final Optional<UpperDimension> upper;
final ResolvedOres dimensionOres;
private final boolean hideOres;
private PaletteExplosion upperExplosion;
Chunk(ChunkStageContext context) {
this.blocks = context.hunk(BlockState.class);
@@ -286,6 +287,14 @@ final class TerrainShaper {
this.dimensionOres = hideOres ? ResolvedOres.NONE : ores.of(levelValue(settings.at(OreSettings.class, centreX, centreZ), Target.DIMENSION));
}
/** What the upper dimension declares about exploded palettes: a setting of the dimension, so the same for every column of the chunk. */
PaletteExplosion upperExplosion(FeatureSettings upperSettings, int worldX, int worldZ) {
if (upperExplosion == null) {
upperExplosion = PaletteExplosion.of(upperSettings, worldX, worldZ);
}
return upperExplosion;
}
/** The ores of the column's region and biome; none where the levels below the dimension declare none, or the dimension hides ores. */
ColumnOres oresAt(int worldX, int worldZ) {
if (hideOres || !levelsBelowTheDimensionDeclareOres) {
@@ -70,12 +70,14 @@ public class CaveApplying {
private final PlatformBlockState AIR = B.getState("CAVE_AIR");
private final PlatformBlockState LAVA = B.getState("LAVA");
private final BiomeLayers layers;
private final IrisLayers glue;
private final TerrainPalettes palettes;
public CaveApplying(Engine engine, ModuleLog log) {
this.engine = engine;
rng = new RNG(engine.getSeedManager().getCarve());
layers = BiomeLayers.of(engine.getGeneration().world());
glue = new IrisLayers(engine);
palettes = TerrainPalettes.of(engine.getGeneration().world());
}
@@ -153,7 +155,7 @@ public class CaveApplying {
if (explicitCarveIntent) {
// Only a fluid cavern consumes the fluid sample, and on the maintenance path that
// sample is a full procedural stream evaluation, so never take it per voxel.
PlatformBlockState fluid = isFluidIntent(cavern) ? IrisLayers.platform(palettes.fluidAt(chunkBlockX + rx, chunkBlockZ + rz)) : null;
PlatformBlockState fluid = isFluidIntent(cavern) ? glue.platform(palettes.fluidAt(chunkBlockX + rx, chunkBlockZ + rz)) : null;
output.setRaw(rx, yy, rz, resolveExplicitCarveState(cavern, fluid, LAVA, AIR));
} else if (usesDefaultLava(caveLavaHeight, yy)) {
output.setRaw(rx, yy, rz, LAVA);
@@ -180,7 +182,7 @@ public class CaveApplying {
: resolveCustomBiome(customBiomeCache, customBiome);
if (biome != null) {
PlatformBlockState data = IrisLayers.platform(layers.wall(IrisLayers.wallOf(biome)).get(rng, worldX, yy, worldZ));
PlatformBlockState data = glue.platform(layers.wall(IrisLayers.wallOf(biome)).get(rng, worldX, yy, worldZ));
int columnIndex = PowerOfTwoCoordinates.packLocal16(rx, rz);
if (data != null && B.isSolid(output.getRaw(rx, yy, rz)) && yy < surfaceHeights[columnIndex]) {
@@ -515,8 +517,8 @@ public class CaveApplying {
}
if (floorBiome != null) {
KList<PlatformBlockState> floorLayers = IrisLayers.platform(layers.generateLayers(IrisLayers.biome(floorBiome),
IrisLayers.explosion(engine.getDimension()), worldX, worldZ, rng, 3, zoneFloor, IrisLayers.slope(engine)));
KList<PlatformBlockState> floorLayers = glue.platform(layers.generateLayers(glue.biome(floorBiome),
glue.explosion(), worldX, worldZ, rng, 3, zoneFloor, glue.slope()));
for (int i = 0; i < zoneFloor - 1; i++) {
if (!floorLayers.hasIndex(i)) {
break;
@@ -540,8 +542,8 @@ public class CaveApplying {
if (ceilingBiome != null) {
int worldMaxY = engine.getWorld().maxHeight() - engine.getWorld().minHeight();
KList<PlatformBlockState> ceilingLayers = IrisLayers.platform(layers.generateCeilingLayers(IrisLayers.biome(ceilingBiome),
IrisLayers.explosion(engine.getDimension()), worldX, worldZ, rng, 3));
KList<PlatformBlockState> ceilingLayers = glue.platform(layers.generateCeilingLayers(glue.biome(ceilingBiome),
glue.explosion(), worldX, worldZ, rng, 3));
for (int i = 0; i < ceilingLayers.size(); i++) {
int ceilingY = zoneCeiling + i + 1;
if (ceilingY >= worldMaxY) {
@@ -602,7 +604,7 @@ public class CaveApplying {
}
if (floorBiome != null) {
KList<PlatformBlockState> floorBlocks = IrisLayers.platform(layers.generateLayers(IrisLayers.biome(floorBiome), IrisLayers.explosion(engine.getDimension()), xx, zz, rng, 3, zone.floor, IrisLayers.slope(engine)));
KList<PlatformBlockState> floorBlocks = glue.platform(layers.generateLayers(glue.biome(floorBiome), glue.explosion(), xx, zz, rng, 3, zone.floor, glue.slope()));
for (int i = 0; i < zone.floor - 1; i++) {
if (!floorBlocks.hasIndex(i)) {
break;
@@ -622,7 +624,7 @@ public class CaveApplying {
}
if (ceilingBiome != null) {
KList<PlatformBlockState> ceilingBlocks = IrisLayers.platform(layers.generateCeilingLayers(IrisLayers.biome(ceilingBiome), IrisLayers.explosion(engine.getDimension()), xx, zz, rng, 3));
KList<PlatformBlockState> ceilingBlocks = glue.platform(layers.generateCeilingLayers(glue.biome(ceilingBiome), glue.explosion(), xx, zz, rng, 3));
for (int i = 0; i < ceilingBlocks.size(); i++) {
int cy = zone.ceiling + i + 1;
if (cy >= maxY) {
@@ -70,6 +70,7 @@ public class FloatingIslands {
private final Engine engine;
private final RNG rng;
private final BiomeLayers biomeLayers;
private final IrisLayers glue;
private final ModuleLog log;
private KList<PlatformBlockState> generateBottomPaletteLayers(ResolvedFloatingChild entry, IrisDimension dimension, double wx, double wz, RNG random, int paletteDepth, IrisData data, IrisComplex complex) {
@@ -109,7 +110,7 @@ public class FloatingIslands {
}
try {
generated.add(IrisLayers.platform(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.zoom(), j, (wz - j) / layer.zoom())));
generated.add(glue.platform(layer.get(random.nextParallelRNG(i + j), (wx + j) / layer.zoom(), j, (wz - j) / layer.zoom())));
} catch (Throwable e) {
log.error("Failed to pick a block of a floating island's palette", e);
}
@@ -192,9 +193,9 @@ public class FloatingIslands {
IrisBiome target = entry == null ? parent : entry.getRealBiome(parent, data);
int entrySeed = entry == null || entry.settings().biome() == null ? 0 : entry.settings().biome().hashCode();
RNG layerRng = rng.nextParallelRNG((int) (colSeed ^ 0x7A4E ^ entrySeed));
KList<PlatformBlockState> topBlocks = target == null ? null : IrisLayers.platform(biomeLayers.generateLayers(IrisLayers.biome(target), IrisLayers.explosion(dimension), wx, wz, layerRng, paletteDepth, paletteDepth, IrisLayers.slope(engine)));
KList<PlatformBlockState> topBlocks = target == null ? null : glue.platform(biomeLayers.generateLayers(glue.biome(target), IrisLayers.explosionOf(dimension), wx, wz, layerRng, paletteDepth, paletteDepth, glue.slope()));
if (topBlocks == null || topBlocks.isEmpty()) {
topBlocks = IrisLayers.platform(biomeLayers.generateLayers(IrisLayers.biome(parent), IrisLayers.explosion(dimension), wx, wz, layerRng, paletteDepth, paletteDepth, IrisLayers.slope(engine)));
topBlocks = glue.platform(biomeLayers.generateLayers(glue.biome(parent), IrisLayers.explosionOf(dimension), wx, wz, layerRng, paletteDepth, paletteDepth, glue.slope()));
}
KList<PlatformBlockState> bottomBlocks = generateBottomPaletteLayers(entry, dimension, wx, wz, layerRng, paletteDepth, data, complex);
return new PaletteContext(topBlocks, bottomBlocks, B.getState("minecraft:stone"));
@@ -217,6 +218,7 @@ public class FloatingIslands {
this.log = log;
rng = new RNG(engine.getSeedManager().getTerrain() ^ 0x7EB0A73F1DCE514DL);
biomeLayers = BiomeLayers.of(engine.getGeneration().world());
glue = new IrisLayers(engine);
}
/** Fills the islands' solids into the chunk whose first block is {@code x}, {@code z}. */
@@ -36,20 +36,35 @@ import art.arcane.iris.util.common.data.B;
import art.arcane.volmlib.util.collection.KList;
import com.volmit.block.BlockState;
/** What Iris's carving and floating islands, which hold Iris's own types, hand the terrain's layers and palettes, and take back as the platform's blocks. */
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.Map;
/**
* What Iris's carving and floating islands, which hold Iris's own types, hand the terrain's layers and palettes, and take back as the
* platform's blocks. One per engine: what a biome declares about its layers is read once for each biome.
*/
final class IrisLayers {
private IrisLayers() {
private final Engine engine;
private final Map<IrisBiome, LayeredBiome> biomes = Collections.synchronizedMap(new IdentityHashMap<>());
private final Map<BlockState, PlatformBlockState> platformStates = Collections.synchronizedMap(new IdentityHashMap<>());
private final ColumnSlope slope;
private volatile PaletteExplosion explosion;
IrisLayers(Engine engine) {
this.engine = engine;
this.slope = (x, z) -> engine.getComplex().getSlopeStream().get(x, z);
}
/** What the biome declares about its layers. */
static LayeredBiome biome(IrisBiome biome) {
return new LayeredBiome(
biome.getModuleSettings().find(LayersSettings.class).orElse(null),
biome.getModuleSettings().find(SeaLayersSettings.class).orElse(null),
biome.getModuleSettings().find(CaveCeilingLayersSettings.class).orElse(null),
biome.getModuleSettings().find(LockLayersSettings.class).orElse(null),
biome.getModuleSettings().find(LockLayersMaxSettings.class).orElse(null),
biome.getModuleSettings().find(WallSettings.class).orElse(null));
LayeredBiome biome(IrisBiome biome) {
return biomes.computeIfAbsent(biome, declared -> new LayeredBiome(
declared.getModuleSettings().find(LayersSettings.class).orElse(null),
declared.getModuleSettings().find(SeaLayersSettings.class).orElse(null),
declared.getModuleSettings().find(CaveCeilingLayersSettings.class).orElse(null),
declared.getModuleSettings().find(LockLayersSettings.class).orElse(null),
declared.getModuleSettings().find(LockLayersMaxSettings.class).orElse(null),
declared.getModuleSettings().find(WallSettings.class).orElse(null)));
}
/** The biome with only its wall, for a caller that asks for nothing else. */
@@ -57,7 +72,17 @@ final class IrisLayers {
return new LayeredBiome(null, null, null, null, null, biome.getModuleSettings().find(WallSettings.class).orElse(null));
}
static PaletteExplosion explosion(IrisDimension dimension) {
/** What the engine's dimension declares about separating layers with barriers. */
PaletteExplosion explosion() {
PaletteExplosion known = explosion;
if (known == null) {
known = explosionOf(engine.getDimension());
explosion = known;
}
return known;
}
static PaletteExplosion explosionOf(IrisDimension dimension) {
if (dimension == null) {
return PaletteExplosion.NONE;
}
@@ -67,15 +92,16 @@ final class IrisLayers {
.orElse(ExplodeBiomePaletteSizeSettings.DEFAULT_SIZE));
}
static ColumnSlope slope(Engine engine) {
return (x, z) -> engine.getComplex().getSlopeStream().get(x, z);
ColumnSlope slope() {
return slope;
}
static PlatformBlockState platform(BlockState block) {
return block == null ? null : B.getState(block.key());
/** The platform's block for {@code block}, worked out once for each block instance, since a world's layers hold few. */
PlatformBlockState platform(BlockState block) {
return block == null ? null : platformStates.computeIfAbsent(block, known -> B.getState(known.key()));
}
static KList<PlatformBlockState> platform(KList<BlockState> blocks) {
KList<PlatformBlockState> platform(KList<BlockState> blocks) {
KList<PlatformBlockState> converted = new KList<>(blocks.size());
for (BlockState block : blocks) {
converted.add(platform(block));