Drop dead biome inject writes

- sBiome, floating biomes and publishNaturalMetadata no longer write MatterBiomeInject; nothing reads it
- stack metadata clearing only runs for dimension stacks
This commit is contained in:
Brian Neumann-Fopiano
2026-09-28 11:05:42 -04:00
parent 241260a762
commit 3df1fba518
6 changed files with 91 additions and 162 deletions
@@ -230,6 +230,10 @@ public class ChunkContext {
return region;
}
public boolean hasDimensionStack() {
return dimensionStackContext != null;
}
public DimensionStackLayout getDimensionStackLayout(int localX, int localZ) {
if (dimensionStackContext == null) {
return null;
@@ -23,7 +23,7 @@ import art.arcane.iris.generation.concurrent.MultiBurst;
import art.arcane.iris.generation.context.ChunkContext;
import art.arcane.iris.generation.context.IrisContext;
import art.arcane.iris.generation.mantle.EngineMantle;
import art.arcane.iris.generation.stage.IrisBiomeActuator;
import art.arcane.iris.generation.stage.IrisDimensionStackActuator;
import art.arcane.iris.generation.stage.IrisTransitionGeometryActuator;
import art.arcane.iris.integration.Identifier;
import art.arcane.iris.generation.decoration.tree.TreeBlockMaterial;
@@ -215,7 +215,7 @@ public interface EngineMode extends Staged {
try (IrisContext.Scope chunkScope = IrisContext.open(getEngine(), generationSessionId, ctx)) {
generateTerrain(x, z, blocks, biomes, multicore, ctx);
recordNaturalTerrain(x, z, blocks, biomes, ctx);
IrisBiomeActuator.publishNaturalMetadata(getEngine(), x, z, biomes, ctx);
IrisDimensionStackActuator.clearHostNaturalMetadata(getEngine(), x, z, biomes.getHeight(), ctx);
ctx.beginContent();
List<Matter> continuations = restoreObjectContinuations(x, z);
for (EngineStage i : stages) {
@@ -27,7 +27,6 @@ import art.arcane.iris.world.history.TransitionGenerationPlan;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.iris.generation.biome.IrisBiomeCustom;
import art.arcane.iris.generation.terrain.IrisDimension;
import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.volmlib.nativelib.terrain.NativeBiome;
import art.arcane.iris.generation.context.ChunkContext;
@@ -35,12 +34,7 @@ import art.arcane.iris.generation.context.ChunkedDataCache;
import art.arcane.volmlib.util.hunk.Hunk;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.documentation.BlockCoordinates;
import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterBiomeInject;
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
import java.util.List;
@@ -48,8 +42,8 @@ import java.util.Objects;
public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
private final RNG rng;
private final KMap<String, ResolvedBiome> resolvedBiomes = new KMap<>();
private final KMap<String, ResolvedBiome> resolvedPhysicalBiomes = new KMap<>();
private final KMap<String, NativeBiome> resolvedBiomes = new KMap<>();
private final KMap<String, NativeBiome> resolvedPhysicalBiomes = new KMap<>();
public IrisBiomeActuator(Engine engine) {
super(engine, "Biome");
@@ -64,7 +58,6 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
int depth = h.getDepth();
int height = h.getHeight();
Engine engine = getEngine();
Mantle<Matter> mantle = engine.getMantle().getMantle();
ChunkedDataCache<IrisBiome> biomeCache = context.getBiome();
IrisComplex complex = context.getComplex();
DimensionStackContext dimensionStackContext = engine.getDimensionStackContext();
@@ -74,7 +67,7 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
int worldX = x + xf;
int worldZ = z + zf;
IrisBiome biome = biomeCache.get(xf, zf);
ResolvedBiome resolved = resolve(biomeKey(
NativeBiome platformBiome = resolve(biomeKey(
biome,
getDimension(),
engine,
@@ -82,8 +75,9 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
0,
worldZ
));
NativeBiome platformBiome = resolved.biome();
writeColumn(h, mantle, xf, zf, worldX, worldZ, height, resolved);
if (platformBiome != null) {
h.set(xf, 0, zf, xf, height - 1, zf, platformBiome);
}
if (dimensionStackContext != null) {
NativeBiome bottomBiome = platformBiome == null
@@ -95,48 +89,19 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
worldX,
worldZ,
h,
mantle,
engine,
new ResolvedBiome(bottomBiome, resolved.matter()),
bottomBiome,
context.getDimensionStackLayout(xf, zf)
);
}
writeHistoricalColumn(h, mantle, xf, zf, worldX, worldZ, height, engine, complex);
writeHistoricalColumn(h, xf, zf, worldX, worldZ, height, engine, complex);
}
}
engine.getMetrics().getBiome().put(p.getMilliseconds());
}
public static void publishNaturalMetadata(Engine engine, int x, int z, Hunk<NativeBiome> biomes,
ChunkContext context) {
if (!context.getComplex().allowsMantleChunkWrite(x >> 4, z >> 4)) {
return;
}
Mantle<Matter> mantle = engine.getMantle().getMantle();
MantleChunk<Matter> chunk = mantle.getChunk(x >> 4, z >> 4).use();
try {
synchronized (chunk) {
IrisDimensionStackActuator.clearNaturalMetadata(chunk, context, biomes.getHeight());
chunk.deleteSlices(MatterBiomeInject.class);
for (int localX = 0; localX < biomes.getWidth(); localX += 4) {
for (int localZ = 0; localZ < biomes.getDepth(); localZ += 4) {
for (int y = 0; y < biomes.getHeight(); y += 4) {
NativeBiome biome = biomes.getRaw(localX, y, localZ);
if (biome != null) {
mantle.set(x + localX, y, z + localZ, BiomeInjectMatter.get(biome.key()));
}
}
}
}
}
} finally {
chunk.release();
}
}
private void writeHistoricalColumn(
Hunk<NativeBiome> output,
Mantle<Matter> mantle,
int localX,
int localZ,
int worldX,
@@ -167,12 +132,9 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
applyBiomeRange(
localX,
localZ,
worldX,
worldZ,
rangeStart,
internalY - 1,
output,
mantle,
resolvePhysicalKey(activeKey)
);
}
@@ -181,33 +143,14 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
}
}
private void writeColumn(
Hunk<NativeBiome> output,
Mantle<Matter> mantle,
int localX,
int localZ,
int worldX,
int worldZ,
int height,
ResolvedBiome resolved
) {
if (resolved.biome() != null) {
output.set(localX, 0, localZ, localX, height - 1, localZ, resolved.biome());
}
if (mantle != null) {
mantle.set(worldX, 0, worldZ, resolved.matter());
}
}
private void applyDimensionStackBiomes(
int localX,
int localZ,
int worldX,
int worldZ,
Hunk<NativeBiome> output,
Mantle<Matter> mantle,
Engine engine,
ResolvedBiome bottom,
NativeBiome bottom,
DimensionStackLayout layout
) {
List<DimensionStackLayout.Layer> layers = layout.layersBottomToTop();
@@ -222,18 +165,15 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
applyBiomeRange(
localX,
localZ,
worldX,
worldZ,
gapMinY,
gapMaxY,
output,
mantle,
bottom
);
if (!layer.visible()) {
continue;
}
ResolvedBiome resolved = bottom;
NativeBiome resolved = bottom;
if (layer.biome() != null) {
IrisDimension dimension = layer.terrainContext().getDimension();
resolved = resolve(biomeKey(
@@ -248,12 +188,9 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
applyBiomeRange(
localX,
localZ,
worldX,
worldZ,
layer.renderMinY(),
layer.renderMaxY(),
output,
mantle,
resolved
);
}
@@ -262,46 +199,15 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
private void applyBiomeRange(
int localX,
int localZ,
int worldX,
int worldZ,
int minimumY,
int maximumY,
Hunk<NativeBiome> output,
Mantle<Matter> mantle,
ResolvedBiome resolved
NativeBiome biome
) {
if (minimumY > maximumY) {
if (minimumY > maximumY || biome == null) {
return;
}
if (mantle != null) {
clearBiomeMatterRange(mantle, worldX, worldZ, minimumY, maximumY);
}
if (resolved.biome() != null) {
output.set(
localX,
minimumY,
localZ,
localX,
maximumY,
localZ,
resolved.biome()
);
}
if (mantle != null && resolved.matter() != null) {
mantle.set(worldX, minimumY, worldZ, resolved.matter());
}
}
static void clearBiomeMatterRange(
Mantle<Matter> mantle,
int worldX,
int worldZ,
int minimumY,
int maximumY
) {
for (int y = minimumY; y <= maximumY; y++) {
mantle.remove(worldX, y, worldZ, MatterBiomeInject.class);
}
output.set(localX, minimumY, localZ, localX, maximumY, localZ, biome);
}
private String biomeKey(
@@ -319,37 +225,28 @@ public class IrisBiomeActuator extends EngineAssignedActuator<NativeBiome> {
return biome.getSkyBiomeKey(rng, engine, x, y, z);
}
private ResolvedBiome resolve(String key) {
ResolvedBiome cached = key == null ? null : resolvedBiomes.get(key);
private NativeBiome resolve(String key) {
NativeBiome cached = key == null ? null : resolvedBiomes.get(key);
if (cached != null) {
return cached;
}
IrisPlatform platform = IrisPlatforms.get();
NativeBiome biome = platform.registries().biome(key);
ResolvedBiome resolved = new ResolvedBiome(
biome,
BiomeInjectMatter.get(platform.biomeWriter().biomeIdFor(key))
);
NativeBiome biome = IrisPlatforms.get().registries().biome(key);
if (key != null && biome != null) {
resolvedBiomes.put(key, resolved);
resolvedBiomes.put(key, biome);
}
return resolved;
return biome;
}
private ResolvedBiome resolvePhysicalKey(String key) {
ResolvedBiome cached = resolvedPhysicalBiomes.get(key);
private NativeBiome resolvePhysicalKey(String key) {
NativeBiome cached = resolvedPhysicalBiomes.get(key);
if (cached != null) {
return cached;
}
NativeBiome biome = IrisPlatforms.get().registries().biome(key);
ResolvedBiome resolved = new ResolvedBiome(biome, BiomeInjectMatter.get(key));
if (biome != null) {
resolvedPhysicalBiomes.put(key, resolved);
resolvedPhysicalBiomes.put(key, biome);
}
return resolved;
}
private record ResolvedBiome(NativeBiome biome, MatterBiomeInject matter) {
return biome;
}
}
@@ -106,7 +106,21 @@ public final class IrisDimensionStackActuator extends EngineAssignedActuator<Nat
}
}
public static void clearNaturalMetadata(MantleChunk<Matter> chunk, ChunkContext context, int height) {
public static void clearHostNaturalMetadata(Engine engine, int x, int z, int height, ChunkContext context) {
if (!context.hasDimensionStack() || !context.getComplex().allowsMantleChunkWrite(x >> 4, z >> 4)) {
return;
}
MantleChunk<Matter> chunk = engine.getMantle().getMantle().getChunk(x >> 4, z >> 4).use();
try {
synchronized (chunk) {
clearNaturalMetadata(chunk, context, height);
}
} finally {
chunk.release();
}
}
static void clearNaturalMetadata(MantleChunk<Matter> chunk, ChunkContext context, int height) {
MetadataCleaner metadata = new MetadataCleaner(chunk, height);
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
@@ -44,7 +44,6 @@ import art.arcane.volmlib.util.hunk.Hunk;
import art.arcane.volmlib.util.noise.CNG;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.matter.slices.BiomeInjectMatter;
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
@@ -431,7 +430,6 @@ public class IrisFloatingChildBiomeModifier extends EngineAssignedModifier<Nativ
}
context.setNaturalBiome(wx & 15, y, wz & 15, selected);
context.floatingBiomes(chunkHeight).record(wx & 15, y, wz & 15, matter.identity());
getEngine().getMantle().getMantle().set(wx, y, wz, BiomeInjectMatter.get(selected.key()));
}
} catch (Throwable e) {
IrisLogging.reportError(e);
@@ -20,7 +20,6 @@ import art.arcane.volmlib.util.hunk.Hunk;
import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.math.RNG;
import art.arcane.volmlib.util.matter.Matter;
import art.arcane.volmlib.util.matter.MatterBiomeInject;
import org.junit.After;
import org.junit.ClassRule;
import org.junit.Test;
@@ -34,13 +33,13 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyDouble;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@@ -54,19 +53,58 @@ public class IrisBiomeActuatorCoordinateTest {
}
@Test
@SuppressWarnings("unchecked")
public void historicalChunkDoesNotPublishNewPersistentMetadata() {
public void historicalStackChunkDoesNotClearPersistentMetadata() {
Engine engine = mock(Engine.class);
ChunkContext context = mock(ChunkContext.class);
IrisComplex complex = mock(IrisComplex.class);
when(context.hasDimensionStack()).thenReturn(true);
when(context.getComplex()).thenReturn(complex);
when(complex.allowsMantleChunkWrite(0, 0)).thenReturn(false);
IrisBiomeActuator.publishNaturalMetadata(engine, 0, 0, mock(Hunk.class), context);
IrisDimensionStackActuator.clearHostNaturalMetadata(engine, 0, 0, 16, context);
verifyNoMoreInteractions(engine);
}
@Test
public void unstackedChunkNeverTouchesTheMantle() {
Engine engine = mock(Engine.class);
ChunkContext context = mock(ChunkContext.class);
when(context.hasDimensionStack()).thenReturn(false);
IrisDimensionStackActuator.clearHostNaturalMetadata(engine, 0, 0, 16, context);
verifyNoMoreInteractions(engine);
}
@Test
@SuppressWarnings("unchecked")
public void actuatorWritesColumnBiomesWithoutMantleMetadata() {
bindPlatform();
IrisComplex complex = mock(IrisComplex.class);
Engine engine = engine(complex);
IrisBiomeActuator actuator = new IrisBiomeActuator(engine);
Hunk<NativeBiome> output = mock(Hunk.class);
when(output.getWidth()).thenReturn(2);
when(output.getDepth()).thenReturn(2);
when(output.getHeight()).thenReturn(8);
ChunkedDataCache<IrisBiome> biomeCache = currentBiomeCache(engine);
ChunkContext context = mock(ChunkContext.class);
when(context.getComplex()).thenReturn(complex);
when(context.getBiome()).thenReturn(biomeCache);
actuator.onActuate(100, -200, output, false, context);
NativeBiome plains = IrisPlatforms.get().registries().biome("minecraft:plains");
for (int x = 0; x < 2; x++) {
for (int z = 0; z < 2; z++) {
verify(output).set(x, 0, z, x, 7, z, plains);
}
}
verifyNoInteractions(engine.getMantle().getMantle());
verify(IrisPlatforms.get().biomeWriter(), never()).biomeIdFor(anyString());
}
@Test
@SuppressWarnings("unchecked")
public void derivativeScatterUsesEachWorldColumnCoordinate() {
@@ -101,19 +139,6 @@ public class IrisBiomeActuatorCoordinateTest {
assertEquals(List.of("100,-200", "100,-199", "101,-200", "101,-199"), samples);
}
@Test
@SuppressWarnings("unchecked")
public void stackedBiomeReplacementRemovesEveryExistingMarkerWithItsTypedSlice() {
Mantle<Matter> mantle = mock(Mantle.class);
IrisBiomeActuator.clearBiomeMatterRange(mantle, 100, -200, 4, 6);
verify(mantle).remove(100, 4, -200, MatterBiomeInject.class);
verify(mantle).remove(100, 5, -200, MatterBiomeInject.class);
verify(mantle).remove(100, 6, -200, MatterBiomeInject.class);
verifyNoMoreInteractions(mantle);
}
@Test
@SuppressWarnings("unchecked")
public void transitionColumnOverlaysFrozenPhysicalKeyAfterCurrentBiome() {
@@ -143,11 +168,8 @@ public class IrisBiomeActuatorCoordinateTest {
verify(biomeCache).get(0, 0);
verify(IrisPlatforms.get().registries()).biome("iris:old-physical");
verify(IrisPlatforms.get().biomeWriter(), never()).biomeIdFor("iris:old-physical");
Mantle<Matter> mantle = engine.getMantle().getMantle();
verify(mantle).set(eq(100), eq(0), eq(-200), argThat(value -> {
MatterBiomeInject injection = (MatterBiomeInject) value;
return !injection.isCustom() && "iris:old-physical".equals(injection.getBiomeKey());
}));
verify(output, times(2)).set(0, 0, 0, 0, 0, 0, IrisPlatforms.get().registries().biome("iris:old-physical"));
verifyNoInteractions(engine.getMantle().getMantle());
}
@Test
@@ -184,15 +206,9 @@ public class IrisBiomeActuatorCoordinateTest {
verify(transitionPlan, never()).historicalPhysicalBiomeKeyAt(anyInt(), anyInt(), anyInt());
verify(output).set(eq(0), eq(0), eq(0), eq(0), eq(3), eq(0), any(NativeBiome.class));
verify(output).set(eq(0), eq(4), eq(0), eq(0), eq(7), eq(0), any(NativeBiome.class));
Mantle<Matter> mantle = engine.getMantle().getMantle();
verify(mantle).set(eq(100), eq(0), eq(-200), argThat(value -> {
MatterBiomeInject injection = (MatterBiomeInject) value;
return "iris:old-bottom".equals(injection.getBiomeKey());
}));
verify(mantle).set(eq(100), eq(4), eq(-200), argThat(value -> {
MatterBiomeInject injection = (MatterBiomeInject) value;
return "iris:old-top".equals(injection.getBiomeKey());
}));
verify(IrisPlatforms.get().registries()).biome("iris:old-bottom");
verify(IrisPlatforms.get().registries()).biome("iris:old-top");
verifyNoInteractions(engine.getMantle().getMantle());
}
@SuppressWarnings("unchecked")