mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 16:54:04 +00:00
Water objects need flat water
- Single-piece structures stay forced but keep the river and pond exclusion - Water-flagged objects skip footprints on dams, cascades, waterfalls or water at another head - The provisional guard runs before any bore and throws an engine failure - Saplings stay when a tree override is rejected or the terrain is still being planned - Object paste reports a retry when the terrain is still being planned - Tests cover structures over rivers, flat water, lava, bore ordering, explicit Y and saplings
This commit is contained in:
1 parent
2d52cc409e
commit
65d06ae83c
37 files changed
+777
-242
No files matched your search
+51
@@ -0,0 +1,51 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.structure.object.HydrologyWaterFixture;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
import art.arcane.iris.structure.placement.IrisStructure;
|
||||
import art.arcane.iris.structure.placement.PlacedStructurePiece;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class IrisStructureComponentWaterTest {
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private final HydrologyWaterFixture world = new HydrologyWaterFixture();
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureStaysOutOfRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT);
|
||||
|
||||
assertTrue(config.isForcePlace());
|
||||
assertEquals(-1, object.place(0, -1, 0, placer, config, new RNG(7L), world.data()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureStillPlacesOnDryLand() {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT);
|
||||
|
||||
assertTrue(object.place(0, -1, 0, placer, config, new RNG(7L), world.data()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
private static PlacedStructurePiece piece(IrisObject object) {
|
||||
return new PlacedStructurePiece(null, object, 0, 0, 0, IrisObjectRotation.of(0, 0, 0), -1, 0, -1, 1, 2, 1);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.generation.runtime;
|
||||
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.world.history.SavedBiomeUnavailableException;
|
||||
import art.arcane.volmlib.util.mantle.MantleClosedException;
|
||||
import org.junit.Test;
|
||||
@@ -24,6 +25,7 @@ public class GenerationFailuresTest {
|
||||
assertTrue(GenerationFailures.isEngineFailure(new SavedBiomeUnavailableException("loading", true)));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new GenerationSessionException("sealed", true)));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new OutOfMemoryError()));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new ProvisionalAnswerException("water not planned")));
|
||||
assertTrue(GenerationFailures.isEngineFailure(new CompletionException(
|
||||
new IllegalStateException("placement failed", new GenerationClosedException("router closed")))));
|
||||
}
|
||||
|
||||
+6
@@ -3,6 +3,7 @@ package art.arcane.iris.structure.nativegen;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume;
|
||||
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.structure.object.IObjectPlacer;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
@@ -30,6 +31,7 @@ import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -52,8 +54,12 @@ public class NativeStructureObjectVetoTest {
|
||||
log = state("minecraft:oak_log", true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heightStream = mock(ProceduralStream.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.NONE);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(complex.getHeightStream()).thenReturn(heightStream);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getHeight(anyInt(), anyInt())).thenReturn(SURFACE_Y);
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public final class HydrologyWaterFixture {
|
||||
public static final int LAND_ABOVE_SEA = 17;
|
||||
public static final int WATER_RADIUS = 8;
|
||||
|
||||
private final Map<Long, Column> columns = new HashMap<>();
|
||||
private final IrisData data;
|
||||
private final Engine engine;
|
||||
private final IrisComplex complex;
|
||||
private final int seaLevel;
|
||||
private Column water;
|
||||
private boolean provisional;
|
||||
|
||||
public HydrologyWaterFixture() {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
seaLevel = dimension.getFluidHeight();
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
when(heads.get(anyDouble(), anyDouble())).thenAnswer(invocation -> (double) headAt(block(invocation.getArgument(0)), block(invocation.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(invocation -> (double) headAt(block(invocation.getArgument(0)), block(invocation.getArgument(1))));
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(invocation -> roleAt(block(invocation.getArgument(0)), block(invocation.getArgument(1))));
|
||||
complex = mock(IrisComplex.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.hasWaterOrShore(anyInt(), anyInt())).thenAnswer(invocation -> waterOrShore(roleAt(invocation.getArgument(0), invocation.getArgument(1))));
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
}
|
||||
|
||||
public IrisData data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public IrisComplex complex() {
|
||||
return complex;
|
||||
}
|
||||
|
||||
public int seaLevel() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
public void water(WaterRole role, int floorAboveSea, int headAboveSea) {
|
||||
water = new Column(role, seaLevel + floorAboveSea, seaLevel + headAboveSea);
|
||||
}
|
||||
|
||||
public void column(int x, int z, WaterRole role, int floorAboveSea, int headAboveSea) {
|
||||
columns.put(key(x, z), new Column(role, seaLevel + floorAboveSea, seaLevel + headAboveSea));
|
||||
}
|
||||
|
||||
public void provisional() {
|
||||
provisional = true;
|
||||
}
|
||||
|
||||
public int floorAt(int x, int z) {
|
||||
return columnAt(x, z).floor();
|
||||
}
|
||||
|
||||
public int headAt(int x, int z) {
|
||||
Column column = columnAt(x, z);
|
||||
return column.role().wet() ? column.head() : seaLevel;
|
||||
}
|
||||
|
||||
public Placer placer() {
|
||||
return new Placer();
|
||||
}
|
||||
|
||||
public static IrisObject pillar() {
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, 0, 1, solid());
|
||||
object.setUnsigned(1, 1, 1, solid());
|
||||
return object;
|
||||
}
|
||||
|
||||
public static IrisObject raft() {
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int z = 0; z < 3; z++) {
|
||||
object.setUnsigned(x, 0, z, solid());
|
||||
}
|
||||
}
|
||||
object.setUnsigned(1, 1, 1, solid());
|
||||
return object;
|
||||
}
|
||||
|
||||
private static NativeBlockState solid() {
|
||||
NativeBlockState solid = mock(NativeBlockState.class);
|
||||
when(solid.isSolid()).thenReturn(true);
|
||||
when(solid.key()).thenReturn("minecraft:stone");
|
||||
when(solid.materialKey()).thenReturn("minecraft:stone");
|
||||
return solid;
|
||||
}
|
||||
|
||||
private WaterRole roleAt(int x, int z) {
|
||||
return columnAt(x, z).role();
|
||||
}
|
||||
|
||||
private Column columnAt(int x, int z) {
|
||||
if (provisional) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
Column override = columns.get(key(x, z));
|
||||
if (override != null) {
|
||||
return override;
|
||||
}
|
||||
if (water != null && Math.abs(x) <= WATER_RADIUS && Math.abs(z) <= WATER_RADIUS) {
|
||||
return water;
|
||||
}
|
||||
return new Column(WaterRole.NONE, seaLevel + LAND_ABOVE_SEA, seaLevel);
|
||||
}
|
||||
|
||||
private static boolean waterOrShore(WaterRole role) {
|
||||
return switch (role) {
|
||||
case CHANNEL, POND, MOUTH, CASCADE, WATERFALL, INLET, SHORE, POND_SHORE, DAM -> true;
|
||||
case NONE, BANK -> false;
|
||||
};
|
||||
}
|
||||
|
||||
private static int block(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue());
|
||||
}
|
||||
|
||||
private static long key(int x, int z) {
|
||||
return ((long) x << 32) ^ (z & 0xffffffffL);
|
||||
}
|
||||
|
||||
private record Column(WaterRole role, int floor, int head) {
|
||||
}
|
||||
|
||||
public final class Placer implements IObjectPlacer {
|
||||
private final List<Integer> writes = new ArrayList<>();
|
||||
|
||||
public List<Integer> writes() {
|
||||
return writes;
|
||||
}
|
||||
|
||||
public int lowestWrite() {
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
for (int y : writes) {
|
||||
lowest = Math.min(lowest, y);
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
public int highestWrite() {
|
||||
int highest = Integer.MIN_VALUE;
|
||||
for (int y : writes) {
|
||||
highest = Math.max(highest, y);
|
||||
}
|
||||
return highest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return getHighest(x, z, data, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
int floor = floorAt(x, z);
|
||||
return ignoreFluid ? floor : Math.max(floor, getFluidHeight(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState state) {
|
||||
writes.add(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeBlockState get(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return getHighest(x, z, data, true) < getFluidHeight(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return seaLevel;
|
||||
}
|
||||
|
||||
@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 value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getData(int x, int y, int z, Class<T> type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.block.BlockDataMergeSupport;
|
||||
import art.arcane.iris.generation.block.IrisBlockData;
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
@@ -110,8 +111,11 @@ public class ObjectPlacementGoldenTest {
|
||||
|
||||
ProceduralStream<NativeBlockState> rock = mock(ProceduralStream.class, withSettings().stubOnly());
|
||||
when(rock.get(anyDouble(), anyDouble())).thenAnswer(invocation -> state("minecraft:stone"));
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class, withSettings().stubOnly());
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.NONE);
|
||||
IrisComplex complex = mock(IrisComplex.class, withSettings().stubOnly());
|
||||
when(complex.getRockStream()).thenReturn(rock);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
IrisDimension dimension = mock(IrisDimension.class, withSettings().stubOnly());
|
||||
engine = mock(Engine.class, withSettings().stubOnly());
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
|
||||
+127
-211
@@ -1,27 +1,19 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
import art.arcane.iris.generation.block.TileData;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -30,125 +22,133 @@ public class PlacementModuleSurfaceSupportTest {
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private static final int LAND_ABOVE_SEA = 17;
|
||||
private static final int WATER_RADIUS = 8;
|
||||
|
||||
private IrisData data;
|
||||
private Engine engine;
|
||||
private IrisComplex complex;
|
||||
private int dimensionFluidHeight;
|
||||
private int waterFloor;
|
||||
private int waterHead;
|
||||
private boolean provisionalWater;
|
||||
|
||||
@Before
|
||||
public void bindEngine() {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimensionFluidHeight = dimension.getFluidHeight();
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> waterHeads = mock(ProceduralStream.class);
|
||||
when(waterHeads.get(anyDouble(), anyDouble())).thenAnswer(invocation -> {
|
||||
if (provisionalWater) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
return (double) headAt((int) Math.floor((double) invocation.getArgument(0)), (int) Math.floor((double) invocation.getArgument(1)));
|
||||
});
|
||||
complex = mock(IrisComplex.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(waterHeads);
|
||||
when(complex.hasWaterOrShore(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
if (provisionalWater) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
return isWater(invocation.getArgument(0), invocation.getArgument(1));
|
||||
});
|
||||
engine = mock(Engine.class);
|
||||
when(engine.getHeight()).thenReturn(256);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
data = mock(IrisData.class);
|
||||
when(data.getEngine()).thenReturn(engine);
|
||||
}
|
||||
private final HydrologyWaterFixture world = new HydrologyWaterFixture();
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsPlaceInPonds() {
|
||||
water(7, 13);
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setUnderwater(true);
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, underwater()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
assertEquals(waterFloor, placer.lowestWrite());
|
||||
assertTrue(placer.highestWrite() < waterHead);
|
||||
assertEquals(world.floorAt(0, 0), placer.lowestWrite());
|
||||
assertTrue(placer.highestWrite() < world.headAt(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsNeedWaterAboveTheirBase() {
|
||||
water(12, 13);
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setUnderwater(true);
|
||||
public void underwaterObjectsSkipWaterTooShallowForTheirResolvedY() {
|
||||
world.water(WaterRole.POND, 9, 13);
|
||||
HydrologyWaterFixture.Placer deep = world.placer();
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), deep, underwater()) >= 0);
|
||||
|
||||
assertEquals(-1, place(placer, placement));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
world.water(WaterRole.POND, 10, 13);
|
||||
HydrologyWaterFixture.Placer shallow = world.placer();
|
||||
assertEquals(-1, place(HydrologyWaterFixture.pillar(), shallow, underwater()));
|
||||
assertTrue(shallow.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsTreatLavaPondsLikeLavaSeas() {
|
||||
NativeBlockState lava = mock(NativeBlockState.class);
|
||||
when(lava.key()).thenReturn("minecraft:lava");
|
||||
when(world.complex().resolveWaterFluid(anyInt(), anyInt())).thenReturn(lava);
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, underwater()) >= 0);
|
||||
assertEquals(world.floorAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsFloatOnRivers() {
|
||||
water(9, 13);
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setOnwater(true);
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
assertEquals(waterHead, placer.lowestWrite());
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, onwater()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsSkipDryColumns() {
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setOnwater(true);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(placer, placement));
|
||||
assertEquals(-1, place(HydrologyWaterFixture.pillar(), placer, onwater()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcePlaceObjectsPlaceInRiverWater() {
|
||||
water(9, 13);
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setForcePlace(true);
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
assertEquals(waterHead, placer.lowestWrite());
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, forced()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landObjectsStayOutOfRiverWater() {
|
||||
water(9, 13);
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(placer, placement()));
|
||||
assertEquals(-1, place(HydrologyWaterFixture.pillar(), placer, placement()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flatPondsTakeWideWaterObjects() {
|
||||
world.water(WaterRole.POND, 5, 13);
|
||||
|
||||
for (IrisObjectPlacement placement : List.of(underwater(), onwater(), forced())) {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.raft(), placer, placement) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsSkipCascadeSteps() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
world.column(1, 0, WaterRole.CASCADE, 8, 11);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.raft(), placer, onwater()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsSkipDamWalls() {
|
||||
world.water(WaterRole.POND, 5, 13);
|
||||
world.column(1, 0, WaterRole.DAM, 14, 0);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.raft(), placer, underwater()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterObjectsSkipWaterAtAnotherHead() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
world.column(1, 0, WaterRole.CHANNEL, 8, 12);
|
||||
|
||||
for (IrisObjectPlacement placement : List.of(underwater(), onwater(), forced())) {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.raft(), placer, placement));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waterObjectsNeverPlaceOnProvisionalHydrology() {
|
||||
water(7, 13);
|
||||
provisionalWater = true;
|
||||
IrisObjectPlacement underwater = placement();
|
||||
underwater.setUnderwater(true);
|
||||
IrisObjectPlacement onwater = placement();
|
||||
onwater.setOnwater(true);
|
||||
IrisObjectPlacement forced = placement();
|
||||
forced.setForcePlace(true);
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
world.provisional();
|
||||
|
||||
for (IrisObjectPlacement placement : List.of(underwater, onwater, forced)) {
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
for (IrisObjectPlacement placement : List.of(underwater(), onwater(), forced())) {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
IllegalStateException error = assertThrows(IllegalStateException.class, () -> place(placer, placement));
|
||||
ProvisionalAnswerException error = assertThrows(ProvisionalAnswerException.class,
|
||||
() -> place(HydrologyWaterFixture.pillar(), placer, placement));
|
||||
|
||||
assertTrue(error.getMessage().contains("provisional"));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
@@ -157,34 +157,36 @@ public class PlacementModuleSurfaceSupportTest {
|
||||
|
||||
@Test
|
||||
public void landObjectsNeverPlaceOnProvisionalHydrology() {
|
||||
provisionalWater = true;
|
||||
WaterPlacer placer = new WaterPlacer();
|
||||
world.provisional();
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
IllegalStateException error = assertThrows(IllegalStateException.class, () -> place(placer, placement()));
|
||||
|
||||
assertTrue(error.getMessage().contains("provisional"));
|
||||
assertThrows(ProvisionalAnswerException.class, () -> place(HydrologyWaterFixture.pillar(), placer, placement()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
private void water(int floorAboveSea, int headAboveSea) {
|
||||
waterFloor = dimensionFluidHeight + floorAboveSea;
|
||||
waterHead = dimensionFluidHeight + headAboveSea;
|
||||
@Test
|
||||
public void provisionalAnswersStopABoreBeforeItClearsAir() {
|
||||
world.provisional();
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setBore(true);
|
||||
|
||||
assertThrows(ProvisionalAnswerException.class, () -> place(HydrologyWaterFixture.pillar(), placer, placement));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
private boolean isWater(int x, int z) {
|
||||
return waterHead > waterFloor && Math.abs(x) <= WATER_RADIUS && Math.abs(z) <= WATER_RADIUS;
|
||||
@Test
|
||||
public void explicitPlacementsIgnoreProvisionalAnswers() {
|
||||
world.provisional();
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
int surface = world.floorAt(0, 0);
|
||||
|
||||
assertTrue(HydrologyWaterFixture.pillar().place(0, surface + 1, 0, placer, placement(), new RNG(1234L), world.data()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
private int headAt(int x, int z) {
|
||||
return isWater(x, z) ? waterHead : dimensionFluidHeight;
|
||||
}
|
||||
|
||||
private int floorAt(int x, int z) {
|
||||
return isWater(x, z) ? waterFloor : dimensionFluidHeight + LAND_ABOVE_SEA;
|
||||
}
|
||||
|
||||
private int place(WaterPlacer placer, IrisObjectPlacement placement) {
|
||||
return object().place(0, -1, 0, placer, placement, new RNG(1234L), data);
|
||||
private int place(IrisObject object, HydrologyWaterFixture.Placer placer, IrisObjectPlacement placement) {
|
||||
return object.place(0, -1, 0, placer, placement, new RNG(1234L), world.data());
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement placement() {
|
||||
@@ -193,107 +195,21 @@ public class PlacementModuleSurfaceSupportTest {
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObject object() {
|
||||
NativeBlockState solid = mock(NativeBlockState.class);
|
||||
when(solid.isSolid()).thenReturn(true);
|
||||
when(solid.key()).thenReturn("minecraft:stone");
|
||||
when(solid.materialKey()).thenReturn("minecraft:stone");
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, 0, 1, solid);
|
||||
object.setUnsigned(1, 1, 1, solid);
|
||||
return object;
|
||||
private static IrisObjectPlacement underwater() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setUnderwater(true);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private final class WaterPlacer implements IObjectPlacer {
|
||||
private final List<Integer> writes = new ArrayList<>();
|
||||
private static IrisObjectPlacement onwater() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setOnwater(true);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private List<Integer> writes() {
|
||||
return writes;
|
||||
}
|
||||
|
||||
private int lowestWrite() {
|
||||
int lowest = Integer.MAX_VALUE;
|
||||
for (int y : writes) {
|
||||
lowest = Math.min(lowest, y);
|
||||
}
|
||||
return lowest;
|
||||
}
|
||||
|
||||
private int highestWrite() {
|
||||
int highest = Integer.MIN_VALUE;
|
||||
for (int y : writes) {
|
||||
highest = Math.max(highest, y);
|
||||
}
|
||||
return highest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
return getHighest(x, z, data, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
int floor = floorAt(x, z);
|
||||
return ignoreFluid ? floor : Math.max(floor, getFluidHeight(x, z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState state) {
|
||||
writes.add(y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeBlockState get(int x, int y, int z) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPreventingDecay() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnderwater(int x, int z) {
|
||||
return getHighest(x, z, data, true) < getFluidHeight(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFluidHeight() {
|
||||
return dimensionFluidHeight;
|
||||
}
|
||||
|
||||
@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 value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getData(int x, int y, int z, Class<T> type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine getEngine() {
|
||||
return engine;
|
||||
}
|
||||
private static IrisObjectPlacement forced() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setForcePlace(true);
|
||||
return placement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package art.arcane.iris.world.tree;
|
||||
|
||||
import art.arcane.iris.generation.biome.IrisBiome;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisTree;
|
||||
import art.arcane.iris.generation.decoration.tree.IrisTreeSize;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.EngineTarget;
|
||||
import art.arcane.iris.generation.runtime.GenerationSessionManager;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.pack.validation.PackCompatReport;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.pack.loading.ResourceLoader;
|
||||
import art.arcane.iris.platform.generation.PlatformChunkGenerator;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.structure.object.HydrologyWaterFixture;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectPlacement;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.iris.world.IrisToolbelt;
|
||||
import art.arcane.iris.world.IrisWorld;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.data.Cuboid;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TreeSVCSaplingTest {
|
||||
private static final int SAPLING_Y = -20;
|
||||
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
@Test
|
||||
public void provisionalTerrainCancelsGrowthAndKeepsTheSapling() {
|
||||
Fixture fixture = new Fixture(true);
|
||||
StructureGrowEvent event = fixture.event();
|
||||
|
||||
fixture.grow(event);
|
||||
|
||||
assertTrue(event.isCancelled());
|
||||
verify(fixture.saplings, never()).forEach(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedTreeKeepsTheSapling() {
|
||||
Fixture fixture = new Fixture(false);
|
||||
StructureGrowEvent event = fixture.event();
|
||||
|
||||
fixture.grow(event);
|
||||
|
||||
assertTrue(event.isCancelled());
|
||||
verify(fixture.saplings, never()).forEach(any());
|
||||
}
|
||||
|
||||
private static final class Fixture {
|
||||
private final Engine engine = mock(Engine.class);
|
||||
private final World world = mock(World.class);
|
||||
private final PlatformChunkGenerator generator = mock(PlatformChunkGenerator.class);
|
||||
private final TreeSVC service = spy(new TreeSVC());
|
||||
private final Cuboid saplings = mock(Cuboid.class);
|
||||
|
||||
private Fixture(boolean provisionalWater) {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.getTreeSettings().setEnabled(true);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(complex.hasWaterOrShore(anyInt(), anyInt())).thenAnswer(invocation -> {
|
||||
if (provisionalWater) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
return false;
|
||||
});
|
||||
when(engine.getGenerationSessions()).thenReturn(new GenerationSessionManager(true));
|
||||
when(engine.getDimension()).thenReturn(dimension);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getBiome(8, SAPLING_Y, 8)).thenReturn(biome());
|
||||
|
||||
EngineTarget target = mock(EngineTarget.class);
|
||||
when(target.getWorld()).thenReturn(mock(IrisWorld.class));
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisObject> objects = mock(ResourceLoader.class);
|
||||
IrisObject tree = HydrologyWaterFixture.pillar();
|
||||
when(objects.load(anyString())).thenReturn(tree);
|
||||
IrisData data = mock(IrisData.class);
|
||||
when(data.getObjectLoader()).thenReturn(objects);
|
||||
when(data.getCompatReport()).thenReturn(mock(PackCompatReport.class));
|
||||
when(generator.getEngine()).thenReturn(engine);
|
||||
when(generator.getTarget()).thenReturn(target);
|
||||
when(generator.getData()).thenReturn(data);
|
||||
|
||||
Block block = mock(Block.class);
|
||||
BlockData blockData = mock(BlockData.class);
|
||||
when(world.getBlockAt(anyInt(), anyInt(), anyInt())).thenReturn(block);
|
||||
when(world.getBlockAt(any(Location.class))).thenReturn(block);
|
||||
when(block.getBlockData()).thenReturn(blockData);
|
||||
when(blockData.clone()).thenReturn(blockData);
|
||||
when(saplings.getCenter()).thenReturn(new Location(world, 8, SAPLING_Y, 8));
|
||||
doReturn(saplings).when(service).getSaplings(any(), any(), any());
|
||||
}
|
||||
|
||||
private static IrisBiome biome() {
|
||||
IrisTree tree = new IrisTree();
|
||||
tree.getTreeTypes().add(TreeType.TREE.name());
|
||||
tree.getSizes().add(new IrisTreeSize());
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.getPlace().add("trees/oak");
|
||||
placement.getTrees().add(tree);
|
||||
IrisBiome biome = new IrisBiome();
|
||||
biome.getObjects().add(placement);
|
||||
return biome;
|
||||
}
|
||||
|
||||
private StructureGrowEvent event() {
|
||||
return new StructureGrowEvent(new Location(world, 8, SAPLING_Y, 8), TreeType.TREE, false, null, List.of());
|
||||
}
|
||||
|
||||
private void grow(StructureGrowEvent event) {
|
||||
try (MockedStatic<IrisToolbelt> toolbelt = mockStatic(IrisToolbelt.class);
|
||||
MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
toolbelt.when(() -> IrisToolbelt.isIrisWorld(world)).thenReturn(true);
|
||||
toolbelt.when(() -> IrisToolbelt.access(world)).thenReturn(generator);
|
||||
service.on(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user