Captured cave biomes in content

- decorateNaturalCaves resolves coordinates of its own chunk through the captured column path; other coordinates keep the history dispatch
This commit is contained in:
Brian Neumann-Fopiano
2026-09-28 13:32:53 -04:00
parent 808e133cac
commit e31113aaa2
2 changed files with 51 additions and 5 deletions
@@ -880,7 +880,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
chunk.release();
}
}
CaveInputs resolver = new CaveInputs(getEngine());
CaveInputs resolver = CaveInputs.forContentChunk(getEngine(), blockX >> 4, blockZ >> 4);
Long2ObjectOpenHashMap<IrisBiome> caveBiomes = new Long2ObjectOpenHashMap<>(256);
Map<String, IrisBiome> customBiomes = new HashMap<>();
int width = output.getWidth();
@@ -1163,19 +1163,39 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
private final ProceduralStream<IrisBiome> caveBiomes;
private final ProceduralStream<Double> heights;
private final CaveColumn[] columns;
private final boolean chunkLimited;
private final int chunkX;
private final int chunkZ;
CaveInputs(Engine engine) {
this(engine, false, 0, 0);
}
/**
* Inputs for the content stage of one chunk. A coordinate inside that chunk resolves under the chunk's
* own generation route, exactly the binding the natural terrain stage samples with, so it takes the
* captured column path; any other coordinate keeps the per-coordinate history dispatch.
*/
static CaveInputs forContentChunk(Engine engine, int chunkX, int chunkZ) {
return new CaveInputs(engine, true, chunkX, chunkZ);
}
private CaveInputs(Engine engine, boolean contentChunk, int chunkX, int chunkZ) {
this.engine = engine;
complex = engine.getComplex();
dimension = engine.getDimension();
data = engine.getData();
height = engine.getHeight();
IrisContext context = IrisContext.get();
boolean scoped = engine instanceof IrisEngine irisEngine
boolean generating = engine instanceof IrisEngine irisEngine
&& irisEngine.hasGenerationRuntimeScope() && !engine.getPlatformHooks().isMainThread()
&& context != null && context.getChunkContext() != null
&& context.getChunkContext().getComplex() == complex
&& context.getChunkContext().isNaturalTerrain();
&& context.getChunkContext().getComplex() == complex;
boolean natural = generating && context.getChunkContext().isNaturalTerrain();
boolean scoped = natural || generating && contentChunk;
this.chunkLimited = !natural;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
snapshot = scoped ? IrisDimensionCarvingResolver.snapshot(engine) : null;
minimumY = scoped ? engine.getWorld().minHeight() : 0;
stack = scoped ? engine.getDimensionStackContext() : null;
@@ -1186,7 +1206,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
}
IrisBiome resolve(int x, int y, int z) {
if (snapshot == null) {
if (snapshot == null || chunkLimited && ((x >> 4) != chunkX || (z >> 4) != chunkZ)) {
return engine.getCaveBiome(x, y, z, state);
}
IrisBiome configured = snapshot.resolveBiome(x, y + minimumY, z);
@@ -26,6 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
@@ -122,6 +123,31 @@ public class IrisCarveModifierCaveInputsTest {
}
}
@Test
public void contentChunkCapturesOnlyItsOwnColumnsAndDispatchesTheRestThroughHistory() {
try (Fixture fixture = new Fixture()) {
when(fixture.context.isNaturalTerrain()).thenReturn(false);
IrisBiome historical = biome("historical", 0);
when(fixture.engine.getCaveBiome(anyInt(), anyInt(), anyInt(), any(IrisDimensionCarvingResolver.State.class))).thenReturn(historical);
IrisCarveModifier.CaveInputs inputs = IrisCarveModifier.CaveInputs.forContentChunk(fixture.engine, -2, 1);
IrisDimensionCarvingResolver.State state = new IrisDimensionCarvingResolver.State();
for (int x = -32; x <= -17; x++) {
for (int z = 16; z <= 31; z += 5) {
for (int y : new int[]{0, 30, 33, 34, 39, 40}) {
assertSame(fixture.scalar.getCaveBiome(x, y, z, state), inputs.resolve(x, y, z));
}
}
}
int captured = fixture.samples.get();
assertTrue(captured > 0);
assertSame(historical, inputs.resolve(-33, 20, 16));
assertSame(historical, inputs.resolve(-16, 20, 16));
assertSame(historical, inputs.resolve(-17, 20, 15));
assertSame(historical, inputs.resolve(-17, 20, 32));
assertEquals(captured, fixture.samples.get());
}
}
private static IrisBiome biome(String key, int depth) {
IrisBiome biome = new IrisBiome();
biome.setLoadKey(key);