mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 18:24:06 +00:00
Remove insertMatter from EngineMantle, test matter insertion, share one block platform between the stage tests
This commit is contained in:
1 parent
f4953497a9
commit
a319b36f2d
6 files changed
+217
-104
No files matched your search
@@ -175,45 +175,6 @@ public interface EngineMantle extends MatterGenerator {
|
|||||||
return getEngine().burst();
|
return getEngine().burst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ChunkCoordinates
|
|
||||||
default void insertMatter(int x, int z, Hunk<PlatformBlockState> blocks, boolean multicore) {
|
|
||||||
if (!getEngine().getDimension().isUseMantle()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UpperDimensionContext upperCtx = getEngine().getUpperContext();
|
|
||||||
boolean protectUpper = upperCtx != null;
|
|
||||||
|
|
||||||
MantleChunk<Matter> chunk = getMantle().getChunk(x, z).use();
|
|
||||||
try {
|
|
||||||
if (protectUpper) {
|
|
||||||
int chunkBlockX = x << 4;
|
|
||||||
int chunkBlockZ = z << 4;
|
|
||||||
int gap = getEngine().getDimension().getUpperDimensionGap();
|
|
||||||
int[] upperYs = new int[256];
|
|
||||||
for (int i = 0; i < 256; i++) {
|
|
||||||
int lx = i >> 4;
|
|
||||||
int lz = i & 15;
|
|
||||||
int worldX = chunkBlockX + lx;
|
|
||||||
int worldZ = chunkBlockZ + lz;
|
|
||||||
int he = (int) Math.round(getEngine().getComplex().getHeightStream().get((double) worldX, (double) worldZ));
|
|
||||||
int rawUpper = upperCtx.getUpperSurfaceY(worldX, worldZ);
|
|
||||||
upperYs[i] = Math.max(rawUpper, he + gap);
|
|
||||||
}
|
|
||||||
chunk.iterate(PlatformBlockState.class, (lx, y, lz, value) -> {
|
|
||||||
int colIdx = (lx << 4) | (lz & 15);
|
|
||||||
if (y < upperYs[colIdx]) {
|
|
||||||
blocks.set(lx, y, lz, value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
chunk.iterate(PlatformBlockState.class, (lx, y, lz, value) -> blocks.set(lx, y, lz, value));
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
chunk.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@BlockCoordinates
|
@BlockCoordinates
|
||||||
default void updateBlock(int x, int y, int z) {
|
default void updateBlock(int x, int y, int z) {
|
||||||
getMantle().set(x, y, z, UpdateMatter.ON);
|
getMantle().set(x, y, z, UpdateMatter.ON);
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package art.arcane.iris.engine;
|
||||||
|
|
||||||
|
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 java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds a platform whose registries answer every block name with a usable, namespaced block. {@code B} keeps the
|
||||||
|
* registries it first sees, so binding and unbinding here also clear that cache: what a test binds is what it
|
||||||
|
* reads, and nothing it binds is left behind for the tests that run after it.
|
||||||
|
*/
|
||||||
|
public final class UsableBlockPlatform {
|
||||||
|
private UsableBlockPlatform() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void bind() {
|
||||||
|
IrisPlatforms.unbind();
|
||||||
|
forgetCachedRegistries();
|
||||||
|
PlatformRegistries registries = mock(PlatformRegistries.class);
|
||||||
|
Map<String, PlatformBlockState> states = new HashMap<>();
|
||||||
|
when(registries.block(anyString())).thenAnswer(invocation -> states.computeIfAbsent(
|
||||||
|
invocation.<String>getArgument(0).toLowerCase(Locale.ROOT), UsableBlockPlatform::block));
|
||||||
|
IrisPlatform platform = mock(IrisPlatform.class);
|
||||||
|
when(platform.registries()).thenReturn(registries);
|
||||||
|
IrisPlatforms.bind(platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void unbind() {
|
||||||
|
IrisPlatforms.unbind();
|
||||||
|
forgetCachedRegistries();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void forgetCachedRegistries() {
|
||||||
|
try {
|
||||||
|
Field cached = B.class.getDeclaredField("registries");
|
||||||
|
cached.setAccessible(true);
|
||||||
|
cached.set(null, null);
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
throw new IllegalStateException("B no longer caches its registries in a field named registries", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A solid, occluding block of the given name, unless it is an air. */
|
||||||
|
public static PlatformBlockState block(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]);
|
||||||
|
when(block.isSolid()).thenReturn(!key.contains("air"));
|
||||||
|
when(block.isOccluding()).thenReturn(!key.contains("air"));
|
||||||
|
return block;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package art.arcane.iris.engine.actuator;
|
package art.arcane.iris.engine.actuator;
|
||||||
|
|
||||||
import art.arcane.iris.engine.IrisComplex;
|
import art.arcane.iris.engine.IrisComplex;
|
||||||
|
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||||
import art.arcane.iris.engine.framework.SeedManager;
|
import art.arcane.iris.engine.framework.SeedManager;
|
||||||
@@ -8,10 +9,7 @@ import art.arcane.iris.engine.image.IrisImageMapRuntime;
|
|||||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||||
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
import art.arcane.iris.engine.object.world.region.IrisRegion;
|
||||||
import art.arcane.iris.spi.IrisPlatform;
|
|
||||||
import art.arcane.iris.spi.IrisPlatforms;
|
|
||||||
import art.arcane.iris.spi.PlatformBlockState;
|
import art.arcane.iris.spi.PlatformBlockState;
|
||||||
import art.arcane.iris.spi.PlatformRegistries;
|
|
||||||
import art.arcane.iris.util.project.context.ChunkContext;
|
import art.arcane.iris.util.project.context.ChunkContext;
|
||||||
import art.arcane.iris.util.project.context.ChunkedDataCache;
|
import art.arcane.iris.util.project.context.ChunkedDataCache;
|
||||||
import art.arcane.iris.util.project.hunk.Hunk;
|
import art.arcane.iris.util.project.hunk.Hunk;
|
||||||
@@ -20,9 +18,6 @@ import art.arcane.volmlib.util.math.RNG;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
@@ -31,7 +26,6 @@ import static org.junit.Assert.assertSame;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -47,13 +41,13 @@ public class TerrainModuleTest {
|
|||||||
|
|
||||||
@After
|
@After
|
||||||
public void unbindPlatform() {
|
public void unbindPlatform() {
|
||||||
IrisPlatforms.unbind();
|
UsableBlockPlatform.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void aColumnIsBedrockThenRockThenLayersThenFluid() {
|
public void aColumnIsBedrockThenRockThenLayersThenFluid() {
|
||||||
bindPlatform();
|
UsableBlockPlatform.bind();
|
||||||
TerrainModule.TerrainShaper shaper = new TerrainModule.TerrainShaper(engine());
|
TerrainModule.TerrainShaper shaper = new TerrainModule.TerrainShaper(engine());
|
||||||
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 64, 16);
|
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 64, 16);
|
||||||
IrisBiome biome = mock(IrisBiome.class);
|
IrisBiome biome = mock(IrisBiome.class);
|
||||||
@@ -110,26 +104,4 @@ public class TerrainModuleTest {
|
|||||||
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
|
when(engine.getMetrics()).thenReturn(new EngineMetrics(16));
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindPlatform() {
|
|
||||||
IrisPlatforms.unbind();
|
|
||||||
PlatformRegistries registries = mock(PlatformRegistries.class);
|
|
||||||
// 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));
|
|
||||||
IrisPlatform platform = mock(IrisPlatform.class);
|
|
||||||
when(platform.registries()).thenReturn(registries);
|
|
||||||
IrisPlatforms.bind(platform);
|
|
||||||
}
|
|
||||||
|
|
||||||
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]);
|
|
||||||
when(block.isSolid()).thenReturn(!key.contains("air"));
|
|
||||||
when(block.isOccluding()).thenReturn(!key.contains("air"));
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package art.arcane.iris.engine.modifier;
|
package art.arcane.iris.engine.modifier;
|
||||||
|
|
||||||
import art.arcane.iris.core.link.Identifier;
|
import art.arcane.iris.core.link.Identifier;
|
||||||
|
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||||
import art.arcane.iris.spi.PlatformBlockState;
|
import art.arcane.iris.spi.PlatformBlockState;
|
||||||
@@ -10,6 +11,8 @@ import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
|||||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||||
import art.arcane.volmlib.util.matter.Matter;
|
import art.arcane.volmlib.util.matter.Matter;
|
||||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
@@ -23,6 +26,16 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
/** A custom block goes into the mantle as its placement key and is replaced by its base state, in a chunk the mantle flags as having some. */
|
/** A custom block goes into the mantle as its placement key and is replaced by its base state, in a chunk the mantle flags as having some. */
|
||||||
public class CustomModuleTest {
|
public class CustomModuleTest {
|
||||||
|
@Before
|
||||||
|
public void bindPlatform() {
|
||||||
|
UsableBlockPlatform.bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void unbindPlatform() {
|
||||||
|
UsableBlockPlatform.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
private static final int CHUNK_X = 3;
|
private static final int CHUNK_X = 3;
|
||||||
private static final int CHUNK_Z = -2;
|
private static final int CHUNK_Z = -2;
|
||||||
private static final int Y = 20;
|
private static final int Y = 20;
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package art.arcane.iris.engine.modifier;
|
||||||
|
|
||||||
|
import art.arcane.iris.engine.IrisComplex;
|
||||||
|
import art.arcane.iris.engine.UpperDimensionContext;
|
||||||
|
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||||
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
|
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||||
|
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||||
|
import art.arcane.iris.spi.PlatformBlockState;
|
||||||
|
import art.arcane.iris.util.project.hunk.Hunk;
|
||||||
|
import art.arcane.iris.util.project.stream.ProceduralStream;
|
||||||
|
import art.arcane.volmlib.util.function.Consumer4;
|
||||||
|
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||||
|
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||||
|
import art.arcane.volmlib.util.matter.Matter;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoInteractions;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
/** Inserting copies the mantle's blocks of a chunk into it, below the upper dimension's surface where there is one. */
|
||||||
|
public class MatterModuleTest {
|
||||||
|
@Before
|
||||||
|
public void bindPlatform() {
|
||||||
|
UsableBlockPlatform.bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void unbindPlatform() {
|
||||||
|
UsableBlockPlatform.unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final int CHUNK_X = 1;
|
||||||
|
private static final int CHUNK_Z = 2;
|
||||||
|
private static final int UPPER_SURFACE = 100;
|
||||||
|
|
||||||
|
private final PlatformBlockState planned = mock(PlatformBlockState.class);
|
||||||
|
private final Mantle<Matter> mantle = mockMantle();
|
||||||
|
private final MantleChunk<Matter> mantleChunk = mockMantleChunk();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aDimensionWithoutAMantleIsLeftAlone() {
|
||||||
|
IrisDimension dimension = dimension(false);
|
||||||
|
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 128, 16);
|
||||||
|
|
||||||
|
new MatterModule.MatterInsertion(engine(dimension, null)).insert(CHUNK_X, CHUNK_Z, blocks);
|
||||||
|
|
||||||
|
verifyNoInteractions(mantle);
|
||||||
|
assertNull(blocks.get(3, 50, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void plannedBlocksAreCopiedIntoTheChunk() {
|
||||||
|
plan(new int[]{3, 50, 4}, new int[]{3, 120, 4});
|
||||||
|
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 128, 16);
|
||||||
|
|
||||||
|
new MatterModule.MatterInsertion(engine(dimension(true), null)).insert(CHUNK_X, CHUNK_Z, blocks);
|
||||||
|
|
||||||
|
assertSame(planned, blocks.get(3, 50, 4));
|
||||||
|
assertSame(planned, blocks.get(3, 120, 4));
|
||||||
|
verify(mantleChunk).release();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blocksAtOrAboveTheUpperDimensionSurfaceAreLeftOut() {
|
||||||
|
plan(new int[]{3, UPPER_SURFACE - 1, 4}, new int[]{3, UPPER_SURFACE, 4});
|
||||||
|
UpperDimensionContext upper = mock(UpperDimensionContext.class);
|
||||||
|
when(upper.getUpperSurfaceY(anyInt(), anyInt())).thenReturn(UPPER_SURFACE);
|
||||||
|
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 128, 16);
|
||||||
|
|
||||||
|
new MatterModule.MatterInsertion(engine(dimension(true), upper)).insert(CHUNK_X, CHUNK_Z, blocks);
|
||||||
|
|
||||||
|
assertSame(planned, blocks.get(3, UPPER_SURFACE - 1, 4));
|
||||||
|
assertNull(blocks.get(3, UPPER_SURFACE, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The mantle chunk holds {@code planned} at each of the given {@code {x, y, z}} positions. */
|
||||||
|
private void plan(int[]... positions) {
|
||||||
|
org.mockito.Mockito.doAnswer(invocation -> {
|
||||||
|
Consumer4<Integer, Integer, Integer, PlatformBlockState> consumer = invocation.getArgument(1);
|
||||||
|
for (int[] at : positions) {
|
||||||
|
consumer.accept(at[0], at[1], at[2], planned);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}).when(mantleChunk).iterate(any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
private IrisDimension dimension(boolean useMantle) {
|
||||||
|
IrisDimension dimension = mock(IrisDimension.class);
|
||||||
|
when(dimension.isUseMantle()).thenReturn(useMantle);
|
||||||
|
when(dimension.getUpperDimensionGap()).thenReturn(0);
|
||||||
|
return dimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Engine engine(IrisDimension dimension, UpperDimensionContext upper) {
|
||||||
|
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||||
|
when(engineMantle.getMantle()).thenReturn(mantle);
|
||||||
|
ProceduralStream<Double> heights = mock(ProceduralStream.class);
|
||||||
|
when(heights.get(anyDouble(), anyDouble())).thenReturn(0D);
|
||||||
|
IrisComplex complex = mock(IrisComplex.class);
|
||||||
|
when(complex.getHeightStream()).thenReturn(heights);
|
||||||
|
Engine engine = mock(Engine.class);
|
||||||
|
when(engine.getDimension()).thenReturn(dimension);
|
||||||
|
when(engine.getMantle()).thenReturn(engineMantle);
|
||||||
|
when(engine.getUpperContext()).thenReturn(upper);
|
||||||
|
when(engine.getComplex()).thenReturn(complex);
|
||||||
|
return engine;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private Mantle<Matter> mockMantle() {
|
||||||
|
return mock(Mantle.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
private MantleChunk<Matter> mockMantleChunk() {
|
||||||
|
MantleChunk<Matter> chunk = mock(MantleChunk.class);
|
||||||
|
when(chunk.use()).thenReturn(chunk);
|
||||||
|
when(mantle.getChunk(CHUNK_X, CHUNK_Z)).thenReturn(chunk);
|
||||||
|
return chunk;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,30 +1,23 @@
|
|||||||
package art.arcane.iris.engine.modifier;
|
package art.arcane.iris.engine.modifier;
|
||||||
|
|
||||||
|
import art.arcane.iris.engine.UsableBlockPlatform;
|
||||||
import art.arcane.iris.engine.framework.Engine;
|
import art.arcane.iris.engine.framework.Engine;
|
||||||
import art.arcane.iris.engine.framework.EngineMetrics;
|
import art.arcane.iris.engine.framework.EngineMetrics;
|
||||||
import art.arcane.iris.engine.framework.SeedManager;
|
import art.arcane.iris.engine.framework.SeedManager;
|
||||||
import art.arcane.iris.engine.mantle.EngineMantle;
|
import art.arcane.iris.engine.mantle.EngineMantle;
|
||||||
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
import art.arcane.iris.engine.object.world.biome.IrisBiome;
|
||||||
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
import art.arcane.iris.engine.object.world.dimension.IrisDimension;
|
||||||
import art.arcane.iris.spi.IrisPlatform;
|
|
||||||
import art.arcane.iris.spi.IrisPlatforms;
|
|
||||||
import art.arcane.iris.spi.PlatformBlockState;
|
import art.arcane.iris.spi.PlatformBlockState;
|
||||||
import art.arcane.iris.spi.PlatformRegistries;
|
|
||||||
import art.arcane.iris.util.project.context.ChunkContext;
|
import art.arcane.iris.util.project.context.ChunkContext;
|
||||||
import art.arcane.iris.util.project.context.ChunkedDataCache;
|
import art.arcane.iris.util.project.context.ChunkedDataCache;
|
||||||
import art.arcane.iris.util.project.hunk.Hunk;
|
import art.arcane.iris.util.project.hunk.Hunk;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -35,16 +28,16 @@ public class SurfaceSmoothingTest {
|
|||||||
private static final int NIB_HEIGHT = 10;
|
private static final int NIB_HEIGHT = 10;
|
||||||
private static final int NEIGHBOUR_HEIGHT = 4;
|
private static final int NEIGHBOUR_HEIGHT = 4;
|
||||||
|
|
||||||
private final PlatformBlockState stone = block("minecraft:stone");
|
private final PlatformBlockState stone = UsableBlockPlatform.block("minecraft:stone");
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void unbindPlatform() {
|
public void unbindPlatform() {
|
||||||
IrisPlatforms.unbind();
|
UsableBlockPlatform.unbind();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aNibFloatingAboveItsFourNeighboursIsRemoved() {
|
public void aNibFloatingAboveItsFourNeighboursIsRemoved() {
|
||||||
bindPlatform();
|
UsableBlockPlatform.bind();
|
||||||
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 32, 16);
|
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 32, 16);
|
||||||
blocks.set(NIB_X, NIB_HEIGHT, NIB_Z, stone);
|
blocks.set(NIB_X, NIB_HEIGHT, NIB_Z, stone);
|
||||||
|
|
||||||
@@ -56,7 +49,7 @@ public class SurfaceSmoothingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void aFlatSurfaceIsLeftAlone() {
|
public void aFlatSurfaceIsLeftAlone() {
|
||||||
bindPlatform();
|
UsableBlockPlatform.bind();
|
||||||
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 32, 16);
|
Hunk<PlatformBlockState> blocks = Hunk.newArrayHunk(16, 32, 16);
|
||||||
blocks.set(NIB_X, NEIGHBOUR_HEIGHT, NIB_Z, stone);
|
blocks.set(NIB_X, NEIGHBOUR_HEIGHT, NIB_Z, stone);
|
||||||
|
|
||||||
@@ -92,26 +85,4 @@ public class SurfaceSmoothingTest {
|
|||||||
when(context.getBiome()).thenReturn(biomes);
|
when(context.getBiome()).thenReturn(biomes);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
|
||||||
Map<String, PlatformBlockState> states = new HashMap<>();
|
|
||||||
when(registries.block(anyString())).thenAnswer(invocation -> states.computeIfAbsent(
|
|
||||||
invocation.<String>getArgument(0).toLowerCase(Locale.ROOT), SurfaceSmoothingTest::block));
|
|
||||||
IrisPlatform platform = mock(IrisPlatform.class);
|
|
||||||
when(platform.registries()).thenReturn(registries);
|
|
||||||
IrisPlatforms.bind(platform);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PlatformBlockState block(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]);
|
|
||||||
when(block.isSolid()).thenReturn(!key.contains("air"));
|
|
||||||
when(block.isOccluding()).thenReturn(!key.contains("air"));
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user