Test decorating through the iris:decorant module and make the terrain test order independent

This commit is contained in:
piexel committed 2026-10-08 13:24:21 +02:00
1 parent 4d0ed3a635
commit 0b9b873dfa
2 files changed
+72 -4

No files matched your search

@@ -0,0 +1,64 @@
package art.arcane.iris.engine.actuator;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineMetrics;
import art.arcane.iris.engine.framework.SeedManager;
import art.arcane.iris.engine.object.world.biome.IrisBiome;
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.util.project.context.ChunkContext;
import art.arcane.iris.util.project.context.ChunkedDataCache;
import art.arcane.iris.util.project.hunk.Hunk;
import art.arcane.volmlib.util.collection.KList;
import org.junit.Test;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
/** Decorating reads nothing of the chunk when the dimension does not decorate, and skips biomes without decorators. */
public class DecorantModuleTest {
@Test
public void aDimensionThatDoesNotDecorateIsLeftAlone() {
DecorantModule.Decorating decorating = new DecorantModule.Decorating(engine(false));
ChunkContext context = mock(ChunkContext.class);
decorating.decorate(0, 0, Hunk.newArrayHunk(16, 16, 16), context);
verifyNoInteractions(context);
}
@Test
@SuppressWarnings("unchecked")
public void aBiomeWithoutDecoratorsGetsNothingPlaced() {
DecorantModule.Decorating decorating = new DecorantModule.Decorating(engine(true));
IrisBiome biome = mock(IrisBiome.class);
when(biome.getDecorators()).thenReturn(new KList<>());
ChunkedDataCache<IrisBiome> biomes = mock(ChunkedDataCache.class);
when(biomes.get(anyInt(), anyInt())).thenReturn(biome);
ChunkContext context = mock(ChunkContext.class);
when(context.getBiome()).thenReturn(biomes);
Hunk<PlatformBlockState> output = mock(Hunk.class);
when(output.getWidth()).thenReturn(16);
when(output.getDepth()).thenReturn(16);
decorating.decorate(0, 0, output, context);
verify(output, never()).set(anyInt(), anyInt(), anyInt(), org.mockito.ArgumentMatchers.any());
verify(biomes, org.mockito.Mockito.times(16 * 16)).get(anyInt(), anyInt());
}
private Engine engine(boolean decorate) {
IrisDimension dimension = mock(IrisDimension.class);
when(dimension.isDecorate()).thenReturn(decorate);
SeedManager seeds = mock(SeedManager.class);
Engine engine = mock(Engine.class);
when(engine.getDimension()).thenReturn(dimension);
when(engine.getSeedManager()).thenReturn(seeds);
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
return engine;
}
}
@@ -12,7 +12,6 @@ import art.arcane.iris.spi.IrisPlatform;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBlockState;
import art.arcane.iris.spi.PlatformRegistries;
import art.arcane.iris.util.common.data.B;
import art.arcane.iris.util.project.context.ChunkContext;
import art.arcane.iris.util.project.context.ChunkedDataCache;
import art.arcane.iris.util.project.hunk.Hunk;
@@ -25,6 +24,8 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.ArgumentMatchers.any;
@@ -63,7 +64,9 @@ public class TerrainModuleTest {
shaper.shape(0, 0, blocks, context(biome));
assertSame("bedrock at the bottom", B.getState("BEDROCK"), blocks.get(3, 0, 4));
PlatformBlockState floor = blocks.get(3, 0, 4);
assertNotNull("bedrock at the bottom", floor);
assertNotSame(rock, floor);
assertSame("rock below the layers", rock, blocks.get(3, 5, 4));
assertSame("the second layer", dirt, blocks.get(3, HEIGHT - 1, 4));
assertSame("the first layer is the surface", grass, blocks.get(3, HEIGHT, 4));
@@ -111,7 +114,7 @@ public class TerrainModuleTest {
private void bindPlatform() {
IrisPlatforms.unbind();
PlatformRegistries registries = mock(PlatformRegistries.class);
// B keeps the first registries any test binds, so every answer must be usable by the tests that run after this one.
// B keeps the first registries any test binds, and the shaper reads its bedrock from it once, so every answer must be usable by the tests that run after this one.
Map<String, PlatformBlockState> states = new HashMap<>();
when(registries.block(anyString())).thenAnswer(invocation -> states.computeIfAbsent(
invocation.<String>getArgument(0).toLowerCase(Locale.ROOT), this::usableBlock));
@@ -120,7 +123,8 @@ public class TerrainModuleTest {
IrisPlatforms.bind(platform);
}
private PlatformBlockState usableBlock(String key) {
private PlatformBlockState usableBlock(String name) {
String key = name.contains(":") ? name : "minecraft:" + name;
PlatformBlockState block = mock(PlatformBlockState.class);
when(block.key()).thenReturn(key);
when(block.materialKey()).thenReturn(key.split("\\[", 2)[0]);