Seat cave objects on ground

- Add IObjectPlacer.caveCell, answered from the carve by CaveObjectPlacementTransaction
- Move ORGANIC_STILT and CEILING_HANG cave objects until they touch the floor or roof
- Seat flora on its stem or trunk and ignore buried cap rims
- Drop cave placements with no floor or roof in reach or only fluid beneath
- Close gaps up to 8 blocks with rock and give longer drops a short ragged root
- Never repeat ore or flora; ore in a rock bottom uses the layer's rock
- Key cave jitter and scratch on CellHash
- Add CaveStiltProbe for vertical runs, seating, ore lines and column digests
- Recapture the schema digest for the new mode descriptions
This commit is contained in:
Brian Fopiano committed 2026-11-04 02:16:16 -05:00
1 parent 343da05e3d
commit 6043c4fcaf
14 files changed
+1497 -9

No files matched your search

@@ -45,15 +45,15 @@ public class IrisStiltSettings {
private KList<String> exclude = new KList<>();
@MinNumber(1)
@MaxNumber(256)
@Description("For ORGANIC_STILT / CEILING_HANG: the maximum number of blocks to scan toward the cave floor (or ceiling) looking for solid ground before giving up.")
@Description("For ORGANIC_STILT / CEILING_HANG: how far to look for solid ground. In caves the object may still move up to 16 blocks to seat, and rock filler never goes beyond this value or 8 blocks.")
private int organicMaxScan = 48;
@MinNumber(0)
@MaxNumber(32)
@Description("For ORGANIC_STILT / CEILING_HANG: the maximum number of blocks each column's stilt is randomly shortened by, giving the underside a ragged organic edge instead of a flat disc.")
@Description("For ORGANIC_STILT / CEILING_HANG: the maximum number of blocks a column that cannot reach ground is randomly shortened by, giving the underside a ragged organic edge instead of a flat disc.")
private int organicJitter = 3;
@MinNumber(0)
@MaxNumber(1)
@Description("For ORGANIC_STILT / CEILING_HANG: in the deepest fraction of each stilt column, blocks are randomly skipped to break the tip up. Higher = more broken and scratchy. 0 disables.")
@Description("For ORGANIC_STILT / CEILING_HANG: in the deepest fraction of a column that cannot reach ground, the column randomly ends early to break the tip up. Higher = shorter and rougher. 0 disables.")
private double organicScratch = 0.55;
public Set<String> excludedMaterials() {
@@ -29,6 +29,7 @@ import art.arcane.iris.generation.block.TileData;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import art.arcane.volmlib.util.math.BlockPosition;
import art.arcane.volmlib.util.matter.MatterCavern;
import art.arcane.iris.generation.block.B;
import it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@@ -268,6 +269,34 @@ final class CaveObjectPlacementTransaction implements IObjectPlacer {
return buffered == null ? delegate.isSolid(x, y, z) : B.isSolid(buffered);
}
@Override
public CaveCell caveCell(int x, int y, int z) {
if (engine == null) {
return null;
}
if (y < 0 || y >= worldHeight) {
return CaveCell.GROUND;
}
if (y > getSurfaceHeight(x, z)) {
return CaveCell.OPEN;
}
if (!delegate.isCarved(x, y, z)) {
return CaveCell.GROUND;
}
HydrologyCaveCell hydrology = delegate.getData(x, y, z, HydrologyCaveCell.class);
MatterCavern cavern = hydrology == null ? delegate.getData(x, y, z, MatterCavern.class) : hydrology.asCavern();
if (cavern == null) {
return CaveCell.OPEN;
}
if (cavern.getLiquid() == MantleObjectComponent.LIQUID_FORCED_AIR) {
return CaveCell.OPEN;
}
if (!cavern.isAir()) {
return CaveCell.FLUID;
}
return engine.getDimension() != null && y <= engine.getDimension().getCaveLavaHeight() ? CaveCell.FLUID : CaveCell.OPEN;
}
@Override
public boolean isUnderwater(int x, int z) {
return delegate.isUnderwater(x, z);
@@ -84,7 +84,7 @@ import java.util.function.BiConsumer;
public class MantleObjectComponent extends IrisMantleComponent {
private static final long CAVE_REJECT_LOG_THROTTLE_MS = 5000L;
private static final int BEDROCK_CLEARANCE = 6;
private static final byte LIQUID_FORCED_AIR = 3;
static final byte LIQUID_FORCED_AIR = 3;
private static final Map<String, CaveRejectLogState> CAVE_REJECT_LOG_STATE = new ConcurrentHashMap<>();
private static final Set<String> MISSING_LOAD_KEY_WARNED = ConcurrentHashMap.newKeySet();
private static final long SOURCE_PLAN_STATS_INTERVAL_MS = 30_000L;
@@ -58,6 +58,16 @@ public interface IObjectPlacer {
boolean isSolid(int x, int y, int z);
default @Nullable CaveCell caveCell(int x, int y, int z) {
return null;
}
enum CaveCell {
OPEN,
GROUND,
FLUID
}
boolean isUnderwater(int x, int z);
int getFluidHeight();
@@ -316,6 +316,27 @@ final class IrisObjectShaping {
&& !excludedMaterials.contains(materialKey(state));
}
static boolean isTrunk(NativeBlockState state) {
String material = materialKey(state);
return material.endsWith("_stem") || material.endsWith("_log") || material.endsWith("_wood") || material.endsWith("_hyphae");
}
static boolean isStiltFiller(NativeBlockState state) {
String material = materialKey(state);
String plain = material.substring(material.indexOf(':') + 1);
if (plain.endsWith("_bricks") || plain.endsWith("_terracotta") || plain.endsWith("sandstone") || plain.endsWith("_tiles")) {
return true;
}
return switch (plain) {
case "stone", "cobblestone", "mossy_cobblestone", "deepslate", "cobbled_deepslate", "andesite", "diorite", "granite",
"tuff", "calcite", "dripstone_block", "basalt", "smooth_basalt", "blackstone", "netherrack", "end_stone",
"obsidian", "crying_obsidian", "terracotta", "clay", "dirt", "coarse_dirt", "rooted_dirt", "mud", "packed_mud",
"gravel", "sand", "red_sand", "suspicious_sand", "moss_block", "snow_block", "ice", "packed_ice", "blue_ice",
"magma_block", "sculk", "soul_sand", "soul_soil", "amethyst_block", "bedrock" -> true;
default -> false;
};
}
static String materialKey(NativeBlockState state) {
return IrisProceduralBlocks.materialKey(state);
}
@@ -68,11 +68,11 @@ public enum ObjectPlaceMode {
ERODE_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.ERODE, false)),
@Description("Organic stilting scans straight down from the bottom of the object to the first solid block (the cave floor, or terrain) and fills the gap with the object's own bottom block. Each column stops at a slightly different, noise-varied depth and the lower portion is randomly broken up, so the underside reads as rough organic roots rather than a flat disc. Designed for objects placed inside caves so they connect to the floor instead of floating. Tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).")
@Description("In caves, moves the object down until it rests on the carved floor at its authored size, seating on the stem or trunk when the bottom layer has one. Gaps of up to 8 blocks under rock and soil bottoms are closed with rock, longer drops get a short ragged root, and ore, mushroom, log and leaf blocks are never repeated. A placement with no floor in reach is dropped. Outside caves it extends the bottom block toward solid ground. Tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).")
ORGANIC_STILT(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.ORGANIC, false)),
@Description("Hangs the object upside-down from a cave ceiling. The object is flipped vertically (its tip points down like a stalactite) and its top is anchored to the ceiling, while an organic, noise-varied stilt grows up into the ceiling so it never floats below the roof. Use inside caves; tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).")
@Description("Hangs the object upside-down from a cave ceiling. The object is flipped vertically (its tip points down like a stalactite) and moved up until it touches the carved roof. Gaps follow the same rock rules as ORGANIC_STILT, and a placement with no roof in reach is dropped. Use inside caves; tune with stilt-settings (organicMaxScan, organicJitter, organicScratch).")
CEILING_HANG(() -> new PlacementModuleStilt(PlacementModuleStilt.Mode.CEILING, false)),
@@ -16,7 +16,10 @@ final class PlacementModuleBlocks implements PlacementModule {
}, PlacementModuleBore.BORE);
}
private static void bake(PlacementContext context, PlacementState state) {
static void bake(PlacementContext context, PlacementState state) {
if (state.bake != null) {
return;
}
state.bake = ObjectPlacementBake.of(context.self, state.spin, state.ceilingHang, state.translateOffset);
IrisStiltSettings stiltSettings = state.config.getStiltSettings();
Set<String> excludedStiltMaterials = stiltSettings == null ? Set.of() : stiltSettings.excludedMaterials();
@@ -2,6 +2,8 @@ package art.arcane.iris.structure.object;
import art.arcane.iris.generation.block.BlockDataMergeSupport;
import art.arcane.iris.generation.decoration.IrisStiltSettings;
import art.arcane.iris.generation.hydrology.grid.CellHash;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
@@ -9,9 +11,19 @@ import art.arcane.iris.generation.block.B;
import art.arcane.volmlib.util.noise.CNG;
import art.arcane.volmlib.util.math.RNG;
/** Repeats the object's stilt layer down to the ground, or up into the ceiling, after the block pass. */
import java.util.LinkedHashMap;
import java.util.Map;
/** Repeats the object's stilt layer down to the ground or up into the ceiling; cave placements seat on the carve and fill with rock. */
public final class PlacementModuleStilt implements PlacementModule {
static final PlacementLifecycleDependency FILL = new PlacementLifecycleDependency("stilt.fill");
static final PlacementLifecycleDependency SEAT = new PlacementLifecycleDependency("stilt.cave-seat");
private static final int CAVE_SEAT_REACH = 16;
private static final int CAVE_FILL_REACH = 8;
private static final int NO_GROUND = -1;
private static final long CAVE_JITTER_SALT = 0x5ca1ab1e0c5a7e01L;
private static final long CAVE_SCRATCH_SALT = 0x5ca1ab1e0c5a7e02L;
private final boolean fast;
private final Mode mode;
@@ -39,6 +51,9 @@ public final class PlacementModuleStilt implements PlacementModule {
case DEFAULT, ERODE -> new PlacementModuleHeight(PlacementModuleHeight.Mode.MAX, fast);
};
height.install(lifecycle);
if (mode == Mode.ORGANIC || mode == Mode.CEILING) {
lifecycle.add(SEAT, PlacementStage.BEFORE_BLOCKS, this::seat, PlacementModuleAnchor.FINAL_HEIGHT);
}
lifecycle.add(FILL, PlacementStage.AFTER_BLOCKS, this::fill, PlacementModuleAnchor.HEIGHT,
PlacementModuleBlocks.COMPLETE, PlacementModuleTreeGrounding.ROOTS);
}
@@ -56,7 +71,158 @@ public final class PlacementModuleStilt implements PlacementModule {
return new StiltLayers(lowest, highest);
}
private void seat(PlacementContext context, PlacementState state, Void ignored) {
if (state.grounding != null || state.placer.caveCell(context.x, state.y, context.z) == null) {
return;
}
PlacementModuleBlocks.bake(context, state);
ObjectPlacementBake bake = state.bake;
PlacementPalette palette = state.palette;
StiltLayers layers = stiltLayers(bake, palette);
if (layers.isEmpty()) {
return;
}
boolean up = mode == Mode.CEILING;
int targetLayer = up ? layers.highest() : layers.lowest();
IrisStiltSettings settings = state.config.getStiltSettings();
int reach = Math.max(CAVE_SEAT_REACH, settings != null ? settings.getOrganicMaxScan() : 0);
boolean underwater = state.config.isUnderwater();
boolean rock = dominantRock(bake, palette, targetLayer) != null;
boolean trunk = false;
for (int index = 0; !rock && !trunk && index < bake.count(); index++) {
int entry = bake.paletteIndex(index);
trunk = bake.layerY(index) == targetLayer && palette.shouldStilt(entry) && IrisObjectShaping.isTrunk(palette.stiltDefault(entry));
}
int closest = NO_GROUND;
boolean candidates = false;
boolean buried = false;
boolean exposed = false;
for (int index = 0; index < bake.count() && closest != 0; index++) {
if (bake.layerY(index) != targetLayer || !palette.shouldStilt(bake.paletteIndex(index))) {
continue;
}
candidates = true;
if (trunk && !IrisObjectShaping.isTrunk(palette.stiltDefault(bake.paletteIndex(index)))) {
continue;
}
int cellX = context.x + bake.offsetX(index);
int cellZ = context.z + bake.offsetZ(index);
int startY = targetLayer + state.y;
if (!rock && state.placer.caveCell(cellX, startY, cellZ) == IObjectPlacer.CaveCell.GROUND) {
buried = true;
continue;
}
exposed = true;
int gap = caveGap(state.placer, cellX, startY, cellZ, up, reach, underwater);
if (gap != NO_GROUND && (closest == NO_GROUND || gap < closest)) {
closest = gap;
}
}
if (buried && !exposed) {
return;
}
if (!candidates) {
return;
}
if (closest == NO_GROUND) {
state.caveUnseated = true;
return;
}
state.y += up ? closest : -closest;
}
private static int caveGap(IObjectPlacer placer, int x, int startY, int z, boolean up, int reach, boolean underwater) {
if (placer.caveCell(x, startY, z) == IObjectPlacer.CaveCell.GROUND) {
return 0;
}
int direction = up ? 1 : -1;
for (int step = 1; step <= reach; step++) {
IObjectPlacer.CaveCell cell = placer.caveCell(x, startY + direction * step, z);
if (cell == IObjectPlacer.CaveCell.GROUND) {
return step - 1;
}
if (cell == IObjectPlacer.CaveCell.FLUID && !underwater) {
return NO_GROUND;
}
}
return NO_GROUND;
}
private static NativeBlockState dominantRock(ObjectPlacementBake bake, PlacementPalette palette, int targetLayer) {
Map<NativeBlockState, Integer> counts = new LinkedHashMap<>();
for (int index = 0; index < bake.count(); index++) {
int entry = bake.paletteIndex(index);
if (bake.layerY(index) == targetLayer && palette.shouldStilt(entry)) {
NativeBlockState state = palette.stiltDefault(entry);
if (IrisObjectShaping.isStiltFiller(state)) {
counts.merge(state, 1, Integer::sum);
}
}
}
NativeBlockState best = null;
int bestCount = 0;
for (Map.Entry<NativeBlockState, Integer> count : counts.entrySet()) {
if (count.getValue() > bestCount) {
best = count.getKey();
bestCount = count.getValue();
}
}
return best;
}
private void fillCaveColumn(PlacementState state, NativeBlockState own, NativeBlockState rock, int x, int startY, int z, long seed, boolean up, boolean waterlogCandidate) {
NativeBlockState filler = IrisObjectShaping.isStiltFiller(own) ? own : rock;
if (filler == null) {
return;
}
IObjectPlacer placer = state.placer;
IrisStiltSettings settings = state.config.getStiltSettings();
int maxScan = settings != null ? Math.max(1, settings.getOrganicMaxScan()) : 48;
if (placer.caveCell(x, startY, z) == IObjectPlacer.CaveCell.GROUND) {
return;
}
boolean underwater = state.config.isUnderwater();
int limit = Math.min(maxScan, CAVE_FILL_REACH);
int direction = up ? 1 : -1;
int open = 0;
boolean grounded = false;
for (int step = 1; step <= limit; step++) {
IObjectPlacer.CaveCell cell = placer.caveCell(x, startY + direction * step, z);
if (cell == IObjectPlacer.CaveCell.GROUND) {
grounded = true;
break;
}
if (cell == IObjectPlacer.CaveCell.FLUID && !underwater) {
break;
}
open = step;
}
int depth = open;
double scratch = 0;
if (!grounded) {
int jitterMax = settings != null ? Math.max(0, settings.getOrganicJitter()) : 3;
scratch = settings != null ? Math.max(0, Math.min(1, settings.getOrganicScratch())) : 0.55;
depth -= jitterMax > 0 ? Math.floorMod(CellHash.mix(seed, CAVE_JITTER_SALT, x, z), jitterMax + 1) : 0;
}
long scratchHash = CellHash.mix(seed, CAVE_SCRATCH_SALT, x, z);
for (int step = 1; step <= depth; step++) {
double ratio = (double) step / depth;
if (scratch > 0 && ratio > 1.0 - scratch) {
double skipChance = (ratio - (1.0 - scratch)) / scratch;
if (CellHash.unit(CellHash.mix(scratchHash, step, x, z)) < skipChance * 0.7) {
break;
}
}
int y = startY + direction * step;
placer.set(x, y, z, ObjectBlockPass.normalizePlacedWaterlogging(filler, placer, x, y, z, waterlogCandidate));
}
}
private void fill(PlacementContext context, PlacementState state, Void ignored) {
if (state.caveUnseated) {
state.reject("cave-no-ground");
return;
}
if (state.grounding != null) {
return;
}
@@ -118,6 +284,10 @@ public final class PlacementModuleStilt implements PlacementModule {
}
int targetLayer = ceilingHang ? topLayer : lowest;
boolean cave = organic && placer.caveCell(x, y, z) != null;
NativeBlockState caveRock = cave ? dominantRock(bake, palette, targetLayer) : null;
Engine engine = placer.getEngine();
long caveSeed = cave && engine != null && engine.getSeedManager() != null ? engine.getSeedManager().getComplex() : 0L;
for (int index = 0; index < count; index++) {
int entry = bake.paletteIndex(index);
if (!palette.shouldStilt(entry)) {
@@ -173,6 +343,11 @@ public final class PlacementModuleStilt implements PlacementModule {
zz += surfaceWarp.fitDouble(-warpHalf, warpHalf, exactZ + z, exactY + y, exactX + x);
}
if (cave) {
fillCaveColumn(state, d, caveRock, xx, targetLayer + y, zz, caveSeed, ceilingHang, waterlogCandidate);
continue;
}
if (organic) {
int startY = targetLayer + y;
int maxScan = settings != null ? Math.max(1, settings.getOrganicMaxScan()) : 48;
@@ -23,6 +23,7 @@ public final class PlacementState {
int spinY;
int spinZ;
boolean ceilingHang;
boolean caveUnseated;
IrisBlockVector translateOffset;
int rty;
int ty;
@@ -23,6 +23,7 @@ import art.arcane.iris.generation.subterrain.SubterrainCell;
import art.arcane.iris.generation.subterrain.SubterrainRoom;
import art.arcane.iris.generation.subterrain.IrisSubterrainFamily;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.volmlib.util.matter.MatterCavern;
import art.arcane.iris.structure.object.IObjectPlacer;
import art.arcane.iris.generation.block.TileData;
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveAction;
@@ -88,6 +89,27 @@ public class CaveObjectPlacementTransactionTest {
order.verify(delegate).setData(4, 30, 7, "object@1");
}
@Test
public void caveCellsComeFromTheCarveAndTheSurfaceNotFromMantleBlocks() {
Engine engine = mock(Engine.class);
when(engine.getHeight()).thenReturn(128);
when(engine.getHeight(eq(4), anyInt(), eq(true))).thenReturn(80);
IObjectPlacer delegate = mock(IObjectPlacer.class);
when(delegate.getEngine()).thenReturn(engine);
when(delegate.isSolid(anyInt(), anyInt(), anyInt())).thenReturn(false);
when(delegate.isCarved(4, 30, 7)).thenReturn(true);
when(delegate.isCarved(4, 29, 7)).thenReturn(false);
when(delegate.isCarved(4, 31, 7)).thenReturn(true);
MatterCavern water = new MatterCavern(true, "", (byte) 1);
when(delegate.getData(4, 31, 7, MatterCavern.class)).thenReturn(water);
CaveObjectPlacementTransaction transaction = new CaveObjectPlacementTransaction(delegate, 30, 10);
assertEquals(IObjectPlacer.CaveCell.OPEN, transaction.caveCell(4, 30, 7));
assertEquals(IObjectPlacer.CaveCell.GROUND, transaction.caveCell(4, 29, 7));
assertEquals(IObjectPlacer.CaveCell.FLUID, transaction.caveCell(4, 31, 7));
assertEquals(IObjectPlacer.CaveCell.OPEN, transaction.caveCell(4, 90, 7));
}
@Test
public void oneInvalidMetadataWriteRejectsTheWholePlacement() {
Engine engine = mock(Engine.class);
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "9bb901e1c56c0a3996b956b0aeb0f1aa1060489181164790c554f8a89da16794";
private static final String EXPECTED_SCHEMA_DIGEST = "86ef7692e01b99a240bb4a4d86186eab1aaec81b98e7e87859fd61f8ced972a8";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -0,0 +1,390 @@
package art.arcane.iris.structure.object;
import art.arcane.iris.generation.block.TileData;
import art.arcane.iris.generation.cave.CarvingMode;
import art.arcane.iris.generation.decoration.IrisStiltSettings;
import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.pack.loading.IrisData;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformRegistries;
import art.arcane.iris.testsupport.PlatformLeakGuard;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
import art.arcane.volmlib.util.math.RNG;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class CaveObjectSeatingTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final int FLOOR = 40;
private static final int CEILING = 80;
private IrisData data;
private NativeBlockState stem;
private NativeBlockState cap;
private NativeBlockState ore;
private NativeBlockState stone;
@Before
public void bindPlatform() {
IrisPlatforms.unbind();
PlatformRegistries registries = mock(PlatformRegistries.class);
Map<String, NativeBlockState> registryStates = new HashMap<>();
when(registries.block(anyString())).thenAnswer(invocation -> {
String key = invocation.getArgument(0);
return registryStates.computeIfAbsent(key, value -> state(value.toLowerCase(), !value.toLowerCase().contains("air")));
});
IrisPlatform platform = mock(IrisPlatform.class);
when(platform.registries()).thenReturn(registries);
IrisPlatforms.bind(platform);
data = mock(IrisData.class);
stem = state("minecraft:mushroom_stem", true);
cap = state("minecraft:red_mushroom_block", true);
ore = state("minecraft:coal_ore", true);
stone = state("minecraft:stone", true);
}
@After
public void unbindPlatform() {
IrisPlatforms.unbind();
}
@Test
public void floatingFloraDropsOntoTheFloorAtItsIntendedSize() {
IrisObject mushroom = mushroom();
CavePlacer placer = new CavePlacer();
int result = mushroom.place(0, FLOOR + 12, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertTrue(result >= 0);
assertEquals(1, placer.writesOf(stem).size());
assertEquals(1, placer.writesOf(cap).size());
assertEquals(FLOOR + 1, placer.writesOf(stem).getFirst().y());
}
@Test
public void seatedFloraNeverRepeatsOverALowerStep() {
IrisObject wide = new IrisObject(3, 1, 1);
wide.setUnsigned(0, 0, 0, cap);
wide.setUnsigned(1, 0, 0, stem);
wide.setUnsigned(2, 0, 0, cap);
CavePlacer placer = new CavePlacer();
placer.floor(-1, 0, FLOOR - 5);
int result = wide.place(0, FLOOR + 1, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertTrue(result >= 0);
assertEquals(2, placer.writesOf(cap).size());
assertEquals(1, placer.writesOf(stem).size());
}
@Test
public void floraWithACapRimInTheWallStillDropsToTheFloor() {
IrisObject wide = new IrisObject(3, 1, 1);
wide.setUnsigned(0, 0, 0, cap);
wide.setUnsigned(1, 0, 0, stem);
wide.setUnsigned(2, 0, 0, cap);
CavePlacer placer = new CavePlacer();
placer.floor(1, 0, FLOOR + 20);
int result = wide.place(0, FLOOR + 6, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertTrue(result >= 0);
assertEquals(FLOOR + 1, placer.writesOf(stem).getFirst().y());
}
@Test
public void aCapRimOnALedgeDoesNotHoldTheStemUp() {
IrisObject wide = new IrisObject(3, 1, 1);
wide.setUnsigned(0, 0, 0, cap);
wide.setUnsigned(1, 0, 0, stem);
wide.setUnsigned(2, 0, 0, cap);
CavePlacer placer = new CavePlacer();
placer.floor(1, 0, FLOOR + 5);
int result = wide.place(0, FLOOR + 6, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertTrue(result >= 0);
assertEquals(FLOOR + 1, placer.writesOf(stem).getFirst().y());
}
@Test
public void floraBuriedInEveryColumnStaysWhereItIs() {
IrisObject wide = new IrisObject(2, 1, 1);
wide.setUnsigned(0, 0, 0, stem);
wide.setUnsigned(1, 0, 0, cap);
CavePlacer placer = new CavePlacer();
IrisObjectPlacement placement = organic(ObjectPlaceMode.ORGANIC_STILT);
placement.setForcePlace(true);
int result = wide.place(0, FLOOR - 3, 0, placer, placement, new RNG(2L), data);
assertTrue(result >= 0);
assertEquals(FLOOR - 3, placer.writesOf(stem).getFirst().y());
}
@Test
public void oreInARockBottomIsNeverRepeatedAndTheFillerIsTheRock() {
IrisObject rock = new IrisObject(4, 1, 1);
rock.setUnsigned(0, 0, 0, stone);
rock.setUnsigned(1, 0, 0, stone);
rock.setUnsigned(2, 0, 0, ore);
rock.setUnsigned(3, 0, 0, stone);
CavePlacer placer = new CavePlacer();
placer.floor(0, 0, FLOOR - 3);
int result = rock.place(0, FLOOR + 1, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertTrue(result >= 0);
assertEquals(1, placer.writesOf(ore).size());
assertTrue(placer.writesOf(stone).size() > 3);
assertSame(stone, placer.get(0, FLOOR - 2, 0));
}
@Test
public void rockFillerClosesAReachableGapCompletelyEvenWithRaggedSettings() {
IrisObject rock = new IrisObject(2, 1, 1);
rock.setUnsigned(0, 0, 0, stone);
rock.setUnsigned(1, 0, 0, stone);
CavePlacer placer = new CavePlacer();
placer.floor(0, 0, FLOOR - 6);
IrisObjectPlacement placement = organic(ObjectPlaceMode.ORGANIC_STILT);
placement.setStiltSettings(new IrisStiltSettings().setOrganicJitter(3).setOrganicScratch(0.9));
rock.place(0, FLOOR + 1, 0, placer, placement, new RNG(2L), data);
for (int y = FLOOR - 5; y <= FLOOR + 1; y++) {
assertSame(stone, placer.get(0, y, 0));
}
}
@Test
public void aDeepDropGetsAShortRaggedRootWithNoDetachedCells() {
IrisObject rock = new IrisObject(2, 1, 1);
rock.setUnsigned(0, 0, 0, stone);
rock.setUnsigned(1, 0, 0, stone);
for (int x = -40; x < 40; x++) {
CavePlacer placer = new CavePlacer();
placer.floor(x - 1, 0, FLOOR);
placer.floor(x, 0, FLOOR - 30);
IrisObjectPlacement placement = organic(ObjectPlaceMode.ORGANIC_STILT);
placement.setStiltSettings(new IrisStiltSettings().setOrganicJitter(3).setOrganicScratch(0.9));
rock.place(x, FLOOR + 1, 0, placer, placement, new RNG(2L), data);
int finalX = x;
List<BlockWrite> column = placer.writesOf(stone).stream().filter(write -> write.x() == finalX).toList();
int lowest = column.stream().mapToInt(BlockWrite::y).min().orElseThrow();
assertTrue(lowest >= FLOOR + 1 - 8);
assertEquals(FLOOR + 1 - lowest + 1, column.size());
}
}
@Test
public void rootsStopAtStandingWater() {
IrisObject rock = new IrisObject(2, 1, 1);
rock.setUnsigned(0, 0, 0, stone);
rock.setUnsigned(1, 0, 0, stone);
CavePlacer placer = new CavePlacer();
placer.floor(0, 0, FLOOR - 30);
placer.fluidBelow = FLOOR - 2;
rock.place(0, FLOOR + 1, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertTrue(placer.writesOf(stone).stream().allMatch(write -> write.y() > FLOOR - 2));
}
@Test
public void anObjectWithNoFloorInReachIsRejectedInsteadOfFloating() {
IrisObject mushroom = mushroom();
CavePlacer placer = new CavePlacer();
placer.floor(0, 0, 0);
int result = mushroom.place(0, CEILING - 2, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertEquals(-1, result);
}
@Test
public void standingWaterIsNotAFloorForADryObject() {
IrisObject mushroom = mushroom();
CavePlacer placer = new CavePlacer();
placer.fluidBelow = FLOOR + 5;
int result = mushroom.place(0, FLOOR + 12, 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertEquals(-1, result);
}
@Test
public void ceilingObjectsRiseToTheRoofAndNeverRepeat() {
IrisObject hanging = new IrisObject(1, 2, 1);
hanging.setUnsigned(0, 0, 0, stem);
hanging.setUnsigned(0, 1, 0, cap);
CavePlacer placer = new CavePlacer();
int result = hanging.place(0, CEILING - 8, 0, placer, organic(ObjectPlaceMode.CEILING_HANG), new RNG(2L), data);
assertTrue(result >= 0);
assertEquals(1, placer.writesOf(stem).size());
assertEquals(1, placer.writesOf(cap).size());
int top = placer.writes.stream().mapToInt(BlockWrite::y).max().orElseThrow();
assertEquals(CEILING - 1, top);
}
@Test
public void anObjectAlreadyOnTheFloorStaysPut() {
IrisObject mushroom = mushroom();
CavePlacer placer = new CavePlacer();
mushroom.place(0, FLOOR + 1 + mushroom.getCenter().getBlockY(), 0, placer, organic(ObjectPlaceMode.ORGANIC_STILT), new RNG(2L), data);
assertEquals(FLOOR + 1, placer.writesOf(stem).getFirst().y());
}
@Test
public void placersWithoutACaveAnswerKeepTheirStilt() {
IObjectPlacer plain = mock(IObjectPlacer.class, CALLS_REAL_METHODS);
assertNull(plain.caveCell(0, FLOOR, 0));
}
private IrisObject mushroom() {
IrisObject mushroom = new IrisObject(1, 2, 1);
mushroom.setUnsigned(0, 0, 0, stem);
mushroom.setUnsigned(0, 1, 0, cap);
return mushroom;
}
private static IrisObjectPlacement organic(ObjectPlaceMode mode) {
IrisObjectPlacement placement = new IrisObjectPlacement();
placement.setMode(mode);
placement.setRequireSurfaceSupport(false);
placement.setCarvingSupport(CarvingMode.CARVING_ONLY);
placement.setRotation(IrisObjectRotation.of(0, 0, 0));
placement.setStiltSettings(new IrisStiltSettings().setOrganicJitter(0).setOrganicScratch(0));
return placement;
}
private static NativeBlockState state(String key, boolean solid) {
NativeBlockState state = mock(NativeBlockState.class);
when(state.key()).thenReturn(key);
when(state.materialKey()).thenReturn(key);
when(state.isSolid()).thenReturn(solid);
when(state.isOccluding()).thenReturn(solid);
return state;
}
private record BlockWrite(int x, int y, int z, NativeBlockState state) {
}
private static final class CavePlacer implements IObjectPlacer {
final List<BlockWrite> writes = new ArrayList<>();
final Map<String, NativeBlockState> world = new HashMap<>();
final Map<String, Integer> floors = new HashMap<>();
int fluidBelow = Integer.MIN_VALUE;
void floor(int x, int z, int y) {
floors.put(x + ":" + z, y);
}
List<BlockWrite> writesOf(NativeBlockState state) {
return writes.stream().filter(write -> write.state() == state).toList();
}
@Override
public CaveCell caveCell(int x, int y, int z) {
if (y <= floors.getOrDefault(x + ":" + z, FLOOR) || y >= CEILING) {
return CaveCell.GROUND;
}
return y <= fluidBelow ? CaveCell.FLUID : CaveCell.OPEN;
}
@Override
public int getHighest(int x, int z, IrisData data) {
return 120;
}
@Override
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
return 120;
}
@Override
public void set(int x, int y, int z, NativeBlockState state) {
writes.add(new BlockWrite(x, y, z, state));
world.put(x + ":" + y + ":" + z, state);
}
@Override
public NativeBlockState get(int x, int y, int z) {
return world.get(x + ":" + y + ":" + z);
}
@Override
public boolean isPreventingDecay() {
return false;
}
@Override
public boolean isCarved(int x, int y, int z) {
return caveCell(x, y, z) != CaveCell.GROUND;
}
@Override
public boolean isSolid(int x, int y, int z) {
return false;
}
@Override
public boolean isUnderwater(int x, int z) {
return false;
}
@Override
public int getFluidHeight() {
return 0;
}
@Override
public boolean isDebugSmartBore() {
return false;
}
@Override
public void setTile(int x, int y, int z, TileData tile) {
}
@Override
public <T> void setData(int x, int y, int z, T data) {
}
@Override
public <T> T getData(int x, int y, int z, Class<T> type) {
return null;
}
@Override
public Engine getEngine() {
return null;
}
}
}