Carve dresses caves with the terrain and decorant built-ins' layers, palettes and decorators directly, now that all three ship in the jar: CaveDressing becomes carve's own seam

This commit is contained in:
piexel committed 2026-10-15 07:23:42 +02:00
1 parent 81e8b300ef
commit 3eb987680e
8 files changed
+212 -113

No files matched your search

@@ -1,88 +0,0 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.builtin;
import art.arcane.iris.builtin.decorant.DecorationPart;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.block.BlockState;
import com.volmit.hunk.Hunk;
import com.volmit.resource.ResourceId;
import com.volmit.world.PackWorld;
import java.util.List;
/**
* What a cave's floor, ceiling and walls get from the rest of Iris's terrain and decoration: the blocks of a biome's layers
* and wall, its decorators and the fluid of the dimension's palette. Those features keep their workers per world and are
* ported on their own; until they are modules this narrow interface is the one thing {@code iris:carve} needs from them, in
* IrisApi's types, and Iris's worlds implement it ({@link Source}).
*
* <p>Transitional: when {@code iris:terrain} and {@code iris:decorant} are modules of the same jar, {@code iris:carve} asks
* their classes directly and this interface goes.
*
* <p>The methods that give a block take the {@code chunk} hunk the block is for. A block read from here and written to that
* hunk keeps the identity of a content plugin's custom block, as it did when the layers wrote the platform's states themselves.
*/
public interface CaveDressing {
/** The dressing of {@code world}, which must be a world Iris generates. */
static CaveDressing of(PackWorld world) {
if (world instanceof Source source) {
return source.caveDressing();
}
throw new IllegalArgumentException("Built-in modules generate Iris's own worlds, not " + world);
}
/** Iris's worlds answer for their dressing. */
interface Source {
CaveDressing caveDressing();
}
/** Whether the dimension's fluid palette gives a fluid (water, lava) at the column; false where it gives none. */
boolean fluidPresentAt(int x, int z);
/** The block the dimension's fluid palette gives at the column; null where it gives none. */
BlockState fluidAt(Hunk<BlockState> chunk, int x, int z);
/** The block the biome's wall gives at the position; null where the biome has no wall or the layer gives none. */
BlockState wall(Hunk<BlockState> chunk, ResourceId biome, RNG rng, int x, int y, int z);
/** The blocks the biome's surface layers stack up to at the column, top first, at most {@code depth} of them. */
List<BlockState> floorLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int floorY);
/** The blocks the biome's cave ceiling layers stack up to at the column, nearest the ceiling first, at most {@code depth} of them. */
List<BlockState> ceilingLayers(Hunk<BlockState> chunk, ResourceId biome, int x, int z, RNG rng, int depth, int ceilingY);
/** Whether the biome has a decorator for {@code part}. */
boolean hasDecorators(ResourceId biome, DecorationPart part);
/**
* Decorates a cave's floor in the column at {@code chunk}'s {@code localX}, {@code localZ} (world {@code x}, {@code z}) above
* the block at {@code floorY}, with the biome's decorators for {@link DecorationPart#NONE}, in a space {@code airThickness} high.
*/
void decorateFloor(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int floorY, int airThickness);
/** Decorates a cave's ceiling the same way, from the block at {@code ceilingY} down, with the decorators for {@link DecorationPart#CEILING}. */
void decorateCeiling(Hunk<BlockState> chunk, int localX, int localZ, int x, int z, ResourceId biome, int ceilingY, int airThickness);
/**
* {@code layer}, the block a layer wants in the place of the ore {@code existing}, as the deepslate or the stone variant
* of the ore that fits the rock {@code existing} is; {@code layer} itself where it has no variant.
*/
BlockState deepSlateOre(Hunk<BlockState> chunk, BlockState existing, BlockState layer);
}
@@ -18,7 +18,6 @@
package art.arcane.iris.engine.mantle.components;
import art.arcane.iris.builtin.CaveDressing;
import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.builtin.carve.CaveProfile;
import art.arcane.iris.engine.object.terrain.carving.CarvingResolver;
@@ -63,7 +62,7 @@ public class CaveCarving {
private final CarveWorld world;
private final DeclaredCaveProfiles declaredProfiles;
private final CarvingResolver resolver;
private final CaveDressing dressing;
private final FluidColumns fluidColumns;
private final boolean upperDimensionCarving;
private final Object profileCarverLock = new Object();
private volatile Map<CaveProfile, IrisCaveCarver3D> profileCarvers = new IdentityHashMap<>();
@@ -81,11 +80,17 @@ public class CaveCarving {
}
}
public CaveCarving(PackWorld packWorld, CarveWorld world, boolean upperDimensionCarving) {
/** Whether the dimension's fluid palette gives a column a fluid, which caves near it blend towards. */
@FunctionalInterface
public interface FluidColumns {
boolean hasFluid(int worldX, int worldZ);
}
public CaveCarving(PackWorld packWorld, CarveWorld world, boolean upperDimensionCarving, FluidColumns fluidColumns) {
this.world = world;
this.declaredProfiles = DeclaredCaveProfiles.of(packWorld);
this.resolver = CarvingResolver.of(packWorld);
this.dressing = CaveDressing.of(packWorld);
this.fluidColumns = fluidColumns;
this.upperDimensionCarving = upperDimensionCarving;
}
@@ -430,7 +435,7 @@ public class CaveCarving {
int worldZ = startZ + fieldZ;
int fieldIndex = (fieldX * FIELD_SIZE) + fieldZ;
blendScratch.fieldSurfaceHeights[fieldIndex] = terrain.surfaceY(worldX, worldZ);
blendScratch.fieldHasFluid[fieldIndex] = dressing.fluidPresentAt(worldX, worldZ);
blendScratch.fieldHasFluid[fieldIndex] = fluidColumns.hasFluid(worldX, worldZ);
}
}
}
@@ -0,0 +1,111 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.decorant.DecorantSettings;
import art.arcane.iris.builtin.decorant.DecorationPart;
import art.arcane.iris.builtin.terrain.BiomeLayers;
import art.arcane.iris.builtin.terrain.ColumnSlope;
import art.arcane.iris.builtin.terrain.PaletteExplosion;
import art.arcane.iris.builtin.terrain.TerrainPalettes;
import art.arcane.iris.engine.decorator.BiomeDecorators;
import art.arcane.iris.engine.decorator.DecoratedBiome;
import art.arcane.iris.engine.decorator.DecorationScene;
import art.arcane.iris.engine.decorator.IrisCeilingDecorator;
import art.arcane.iris.engine.decorator.IrisSurfaceDecorator;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.block.BlockRegistry;
import com.volmit.block.BlockState;
import com.volmit.config.FeatureSettings;
import com.volmit.resource.ResourceId;
import com.volmit.stage.ChunkStageContext;
import com.volmit.world.BiomeKind;
import com.volmit.world.TerrainSampler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** A chunk's {@link CaveDressing} from the world's biome layers, terrain palettes and decorators, which carving shares with the terrain and decorant built-ins. */
final class BuiltInCaveDressing implements CaveDressing {
private final BiomeLayers layers;
private final TerrainPalettes palettes;
private final FeatureSettings settings;
private final BlockRegistry blocks;
private final PaletteExplosion explosion;
private final ColumnSlope slope;
private final DecorationScene scene;
private final Map<ResourceId, DecoratedBiome> decoratedBiomes = new HashMap<>();
BuiltInCaveDressing(ChunkStageContext context) {
TerrainSampler terrain = context.terrain();
this.layers = BiomeLayers.of(context.world());
this.palettes = TerrainPalettes.of(context.world());
this.settings = context.settings();
this.blocks = context.resources().blocks();
this.explosion = PaletteExplosion.of(settings, context.originX(), context.originZ());
this.slope = (x, z) -> terrain.column((int) x, (int) z).slope();
this.scene = DecorationScene.of(context);
}
@Override
public BlockState fluidAt(int x, int z) {
return palettes.fluidAt(x, z);
}
@Override
public BlockState wall(ResourceId biome, RNG rng, int x, int y, int z) {
return layers.wall(layers.biome(biome, settings)).get(rng, x, y, z);
}
@Override
public List<BlockState> floorLayers(ResourceId biome, int x, int z, RNG rng, int depth, int floorY) {
return layers.generateLayers(layers.biome(biome, settings), explosion, x, z, rng, depth, floorY, slope);
}
@Override
public List<BlockState> ceilingLayers(ResourceId biome, int x, int z, RNG rng, int depth) {
return layers.generateCeilingLayers(layers.biome(biome, settings), explosion, x, z, rng, depth);
}
@Override
public boolean hasDecorators(ResourceId biome, DecorationPart part) {
return scene.decorators().hasDecorators(decorated(biome), part);
}
@Override
public void decorateFloor(int localX, int localZ, int x, int z, ResourceId biome, int floorY, int airThickness) {
new IrisSurfaceDecorator(scene).decorate(localX, localZ, x, x, x, z, z, z, decorated(biome), floorY, airThickness);
}
@Override
public void decorateCeiling(int localX, int localZ, int x, int z, ResourceId biome, int ceilingY, int airThickness) {
new IrisCeilingDecorator(scene).decorate(localX, localZ, x, x, x, z, z, z, decorated(biome), ceilingY, airThickness);
}
@Override
public BlockState oreFor(BlockState rock, BlockState ore) {
return blocks.oreFor(rock, ore);
}
/** The decorators' view of a cave biome: what it declares, under the key its settings come from, as other decorated biomes are. */
private DecoratedBiome decorated(ResourceId biome) {
return decoratedBiomes.computeIfAbsent(biome, id -> new DecoratedBiome(BiomeDecorators.biomeKey(id),
settings.declaredBy(id, DecorantSettings.class).orElse(null), BiomeKind.CAVE));
}
}
@@ -28,6 +28,7 @@ import art.arcane.iris.builtin.carve.CaveDepthSettings;
import art.arcane.iris.builtin.carve.CaveLavaHeightSettings;
import art.arcane.iris.builtin.carve.CaveProfile;
import art.arcane.iris.builtin.carve.UpperDimensionCarvingSettings;
import art.arcane.iris.builtin.terrain.TerrainPalettes;
import art.arcane.iris.engine.mantle.components.CarveWorld;
import art.arcane.iris.engine.mantle.components.CaveCarving;
import com.volmit.FeatureRegistry;
@@ -38,7 +39,9 @@ import com.volmit.config.FeatureSettings;
import com.volmit.config.FeatureSettings.Entry;
import com.volmit.FeatureAttachment.Target;
import com.volmit.hunk.Hunk;
import com.volmit.block.BlockRegistry;
import com.volmit.block.BlockState;
import com.volmit.block.BlockTrait;
import com.volmit.service.CaveBiomes;
import com.volmit.stage.ChunkStageContext;
import com.volmit.stage.MantleStageContext;
@@ -99,12 +102,12 @@ public final class CarveModule implements IrisModule {
MatterMantle mantle = MatterMantle.of(context.mantle());
Hunk<BlockState> blocks = context.hunk(BlockState.class);
caveApplying(context.world(), context.terrain(), context.settings(), context.originX(), context.originZ())
.apply(mantle, context.terrain(), context.originX() >> CHUNK_SHIFT, context.originZ() >> CHUNK_SHIFT, blocks);
.apply(mantle, context.terrain(), context.originX() >> CHUNK_SHIFT, context.originZ() >> CHUNK_SHIFT, blocks, CaveDressing.of(context));
}
private static CaveCarving caveCarving(PackWorld world, TerrainSampler terrain, FeatureSettings settings, int originX, int originZ) {
return world.state(CaveCarving.class, generating -> new CaveCarving(generating, carveWorld(generating, terrain),
upperDimensionCarving(settings, originX, originZ)));
upperDimensionCarving(settings, originX, originZ), fluidColumns(generating)));
}
private static CaveApplying caveApplying(PackWorld world, TerrainSampler terrain, FeatureSettings settings, int originX, int originZ) {
@@ -112,6 +115,16 @@ public final class CarveModule implements IrisModule {
upperDimensionCarving(settings, originX, originZ)));
}
/** The columns the dimension's fluid palette fills with a fluid. */
private static CaveCarving.FluidColumns fluidColumns(PackWorld world) {
TerrainPalettes palettes = TerrainPalettes.of(world);
BlockRegistry blocks = world.resources().blocks();
return (worldX, worldZ) -> {
BlockState fluid = palettes.fluidAt(worldX, worldZ);
return fluid != null && blocks.hasTrait(fluid, BlockTrait.FLUID);
};
}
/** What the carvers need of the world, from the dimension's settings and the first terrain they see (constant for the world). */
private static CarveWorld carveWorld(PackWorld world, TerrainSampler terrain) {
int lavaHeight = dimensionSetting(world, CaveLavaHeightSettings.class, CaveLavaHeightSettings::height, CaveLavaHeightSettings.DEFAULT_HEIGHT);
@@ -18,7 +18,6 @@
package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.CaveDressing;
import art.arcane.iris.builtin.MatterMantle;
import art.arcane.iris.builtin.decorant.DecorationPart;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
@@ -66,7 +65,6 @@ public class CaveApplying {
private final CarveWorld world;
private final PackResources resources;
private final BlockRegistry blocks;
private final CaveDressing dressing;
private final boolean upperDimensionCarving;
private final RNG rng;
private final BlockState caveAir;
@@ -77,7 +75,6 @@ public class CaveApplying {
this.world = world;
this.resources = packWorld.resources();
this.blocks = resources.blocks();
this.dressing = CaveDressing.of(packWorld);
this.upperDimensionCarving = upperDimensionCarving;
this.rng = new RNG(world.carveSeed());
this.caveAir = blocks.resolve("minecraft:cave_air");
@@ -87,14 +84,15 @@ public class CaveApplying {
/**
* Applies the caves to the chunk at chunk coordinates {@code x}, {@code z}, whose blocks are {@code output}; the caves are in
* {@code mantle}, and {@code terrain} gives the heights and cave biomes around the chunk.
* {@code mantle}, {@code terrain} gives the heights and cave biomes around the chunk and {@code dressing} what its caves' walls,
* floors and ceilings get.
*/
public void apply(MatterMantle mantle, TerrainSampler terrain, int x, int z, Hunk<BlockState> output) {
public void apply(MatterMantle mantle, TerrainSampler terrain, int x, int z, Hunk<BlockState> output, CaveDressing dressing) {
MantleChunk<Matter> mantleChunk = mantle.chunk(x, z);
if (mantleChunk == null) {
return;
}
new Application(mantle, mantleChunk, terrain, x, z, output).run();
new Application(mantle, mantleChunk, terrain, x, z, output, dressing).run();
}
static boolean hasExplicitCarveIntent(MatterCavern cavern) {
@@ -153,17 +151,20 @@ public class CaveApplying {
private final int chunkX;
private final int chunkZ;
private final Hunk<BlockState> output;
private final CaveDressing dressing;
private final CaveBlockClasses classes = new CaveBlockClasses(blocks);
private final CaveBiomeCache caveBiomeCache = new CaveBiomeCache(CAVE_BIOME_CACHE_SIZE);
private final IrisCarveScratch scratch = SCRATCH.get();
Application(MatterMantle mantle, MantleChunk<Matter> mantleChunk, TerrainSampler terrain, int chunkX, int chunkZ, Hunk<BlockState> output) {
Application(MatterMantle mantle, MantleChunk<Matter> mantleChunk, TerrainSampler terrain, int chunkX, int chunkZ, Hunk<BlockState> output,
CaveDressing dressing) {
this.mantle = mantle;
this.mantleChunk = mantleChunk;
this.terrain = terrain;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.output = output;
this.dressing = dressing;
}
void run() {
@@ -226,7 +227,7 @@ public class CaveApplying {
if (explicitCarveIntent) {
// Only a fluid cavern consumes the fluid sample, so never take it per voxel.
BlockState fluid = isFluidIntent(cavern) ? dressing.fluidAt(output, chunkBlockX + rx, chunkBlockZ + rz) : null;
BlockState fluid = isFluidIntent(cavern) ? dressing.fluidAt(chunkBlockX + rx, chunkBlockZ + rz) : null;
BlockState carved = resolveExplicitCarveState(cavern, fluid, lava, caveAir);
output.set(rx, yy, rz, carved == null ? plainAir : carved);
} else if (usesDefaultLava(caveLavaHeight, yy)) {
@@ -251,7 +252,7 @@ public class CaveApplying {
: resolveCustomBiome(customBiomeCache, customBiome);
if (biome != null) {
BlockState data = dressing.wall(output, biome, rng, worldX, yy, worldZ);
BlockState data = dressing.wall(biome, rng, worldX, yy, worldZ);
int columnIndex = PowerOfTwoCoordinates.packLocal16(rx, rz);
if (data != null && classes.isSolid(output.get(rx, yy, rz)) && yy < surfaceHeights[columnIndex]) {
@@ -496,7 +497,7 @@ public class CaveApplying {
/** Replaces the solid blocks under {@code floorY} with the layers of {@code floorBiome}. */
private void paintFloorLayers(ResourceId floorBiome, int rx, int rz, int worldX, int worldZ, int floorY) {
List<BlockState> floorLayers = dressing.floorLayers(output, floorBiome, worldX, worldZ, rng, LAYER_DEPTH, floorY);
List<BlockState> floorLayers = dressing.floorLayers(floorBiome, worldX, worldZ, rng, LAYER_DEPTH, floorY);
for (int i = 0; i < floorY - 1; i++) {
if (i >= floorLayers.size()) {
break;
@@ -507,13 +508,13 @@ public class CaveApplying {
if (layer == null || !classes.isSolid(existing) || !canReplaceCaveFloorLayer(output, rx, y, rz, layer, classes)) {
continue;
}
output.set(rx, y, rz, classes.isOre(existing) ? dressing.deepSlateOre(output, existing, layer) : layer);
output.set(rx, y, rz, classes.isOre(existing) ? dressing.oreFor(existing, layer) : layer);
}
}
/** Replaces the solid blocks over {@code ceilingY} with the cave ceiling layers of {@code ceilingBiome}, below {@code maxY}. */
private void paintCeilingLayers(ResourceId ceilingBiome, int rx, int rz, int worldX, int worldZ, int ceilingY, int maxY) {
List<BlockState> ceilingLayers = dressing.ceilingLayers(output, ceilingBiome, worldX, worldZ, rng, LAYER_DEPTH, ceilingY);
List<BlockState> ceilingLayers = dressing.ceilingLayers(ceilingBiome, worldX, worldZ, rng, LAYER_DEPTH);
for (int i = 0; i < ceilingLayers.size(); i++) {
int y = ceilingY + i + 1;
if (y >= maxY) {
@@ -524,7 +525,7 @@ public class CaveApplying {
if (layer == null || !classes.isSolid(existing)) {
continue;
}
output.set(rx, y, rz, classes.isOre(existing) ? dressing.deepSlateOre(output, existing, layer) : layer);
output.set(rx, y, rz, classes.isOre(existing) ? dressing.oreFor(existing, layer) : layer);
}
}
@@ -578,12 +579,12 @@ public class CaveApplying {
if (floorBiome != null && dressing.hasDecorators(floorBiome, DecorationPart.NONE)
&& hasStableCaveFloorSupport(output, rx, zone.getFloor(), rz, classes)) {
dressing.decorateFloor(output, rx, rz, xx, zz, floorBiome, zone.getFloor() - 1, zone.airThickness());
dressing.decorateFloor(rx, rz, xx, zz, floorBiome, zone.getFloor() - 1, zone.airThickness());
}
if (ceilingBiome != null && dressing.hasDecorators(ceilingBiome, DecorationPart.CEILING) && zone.getCeiling() + 1 < maxY
&& classes.isSolid(output.get(rx, zone.getCeiling() + 1, rz))) {
dressing.decorateCeiling(output, rx, rz, xx, zz, ceilingBiome, zone.getCeiling(), zone.airThickness());
dressing.decorateCeiling(rx, rz, xx, zz, ceilingBiome, zone.getCeiling(), zone.airThickness());
}
}
@@ -0,0 +1,55 @@
/*
* Iris is a World Generator for Minecraft Servers
* Copyright (c) 2026 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package art.arcane.iris.engine.modifier;
import art.arcane.iris.builtin.decorant.DecorationPart;
import art.arcane.volmlib.util.math.RNG;
import com.volmit.block.BlockState;
import com.volmit.resource.ResourceId;
import com.volmit.stage.ChunkStageContext;
import java.util.List;
/**
* What a cave's walls, floor and ceiling get in one chunk: its biome's layers and decorators and the dimension's fluid palette.
* {@link #of} answers with the terrain and decorant built-ins, which ship in the same jar; tests answer with fixed blocks.
*/
public interface CaveDressing {
/** The built-ins' dressing of the chunk {@code context} generates. */
static CaveDressing of(ChunkStageContext context) {
return new BuiltInCaveDressing(context);
}
BlockState fluidAt(int x, int z);
/** The block of the biome's wall at the position; null when the biome declares no wall. */
BlockState wall(ResourceId biome, RNG rng, int x, int y, int z);
List<BlockState> floorLayers(ResourceId biome, int x, int z, RNG rng, int depth, int floorY);
List<BlockState> ceilingLayers(ResourceId biome, int x, int z, RNG rng, int depth);
boolean hasDecorators(ResourceId biome, DecorationPart part);
void decorateFloor(int localX, int localZ, int x, int z, ResourceId biome, int floorY, int airThickness);
void decorateCeiling(int localX, int localZ, int x, int z, ResourceId biome, int ceilingY, int airThickness);
/** The ore that suits the {@code rock} it replaces, as the platform decides. */
BlockState oreFor(BlockState rock, BlockState ore);
}