mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Merge lane B structures
This commit is contained in:
commit
b08d181823
68 files changed
+2268
-319
No files matched your search
+59
-4
@@ -18,8 +18,13 @@
|
||||
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
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.block.TileData;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import org.junit.Test;
|
||||
@@ -36,6 +41,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -48,7 +54,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
public void canopyCommitRechecksSolidsAndSkipsAssociatedMetadata() {
|
||||
IslandObjectPlacer delegate = createPlacer(true);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
NativeBlockState canopy = mock(NativeBlockState.class);
|
||||
NativeBlockState trunk = mock(NativeBlockState.class);
|
||||
when(trunk.isSolid()).thenReturn(true);
|
||||
@@ -70,7 +76,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
public void unsupportedFinalTerrainRejectsBlocksTilesAndMarkersTogether() {
|
||||
IslandObjectPlacer delegate = createPlacer(false);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
NativeBlockState first = mock(NativeBlockState.class);
|
||||
NativeBlockState second = mock(NativeBlockState.class);
|
||||
TileData tile = mock(TileData.class);
|
||||
@@ -97,7 +103,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
public void supportedNeighborChunkCommitsBlocksTilesAndMarkers() {
|
||||
IslandObjectPlacer delegate = createPlacer(true);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
NativeBlockState first = mock(NativeBlockState.class);
|
||||
NativeBlockState second = mock(NativeBlockState.class);
|
||||
TileData tile = mock(TileData.class);
|
||||
@@ -143,7 +149,7 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
NativeBlockState state = mock(NativeBlockState.class);
|
||||
when(state.key()).thenReturn("minecraft:oak_log");
|
||||
ObjectContinuationBundle.PlacementKey key = new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 7);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate, key);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate, key, false);
|
||||
transaction.set(15, 101, 8, state);
|
||||
transaction.set(16, 101, 8, state);
|
||||
transaction.setData(16, 101, 8, "floating-tree@7");
|
||||
@@ -158,6 +164,55 @@ public class FloatingObjectPlacementTransactionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void floatingObjectsKeepSolidBlocksOutOfRiverWaterUnlessTheyEnterWater() {
|
||||
IObjectPlacer delegate = mock(IObjectPlacer.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(delegate.getEngine()).thenReturn(engine);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(complex.allowsNewDiscreteContentAt(anyInt(), anyInt())).thenReturn(true);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(9);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(5);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.role(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> (double) raster.waterHead(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.terrainHeight(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
when(stone.isSolid()).thenReturn(true);
|
||||
ObjectContinuationBundle.PlacementKey key = new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0);
|
||||
|
||||
FloatingObjectPlacementTransaction land = new FloatingObjectPlacementTransaction(delegate, key, false);
|
||||
land.set(3, 7, 3, stone);
|
||||
land.set(3, 10, 3, stone);
|
||||
assertEquals(FloatingObjectPlacementTransaction.CommitResult.COMMITTED, land.commit());
|
||||
verify(delegate, never()).set(3, 7, 3, stone);
|
||||
verify(delegate).set(3, 10, 3, stone);
|
||||
|
||||
FloatingObjectPlacementTransaction water = new FloatingObjectPlacementTransaction(delegate, key, true);
|
||||
water.set(3, 7, 3, stone);
|
||||
assertEquals(FloatingObjectPlacementTransaction.CommitResult.COMMITTED, water.commit());
|
||||
verify(delegate).set(3, 7, 3, stone);
|
||||
}
|
||||
|
||||
private static int local(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue()) & 15;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private IslandObjectPlacer createPlacer(boolean supportNeighborChunk) {
|
||||
IslandObjectPlacer placer = mock(IslandObjectPlacer.class);
|
||||
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.configuration.IrisSettings;
|
||||
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.pack.loading.IrisData;
|
||||
import art.arcane.iris.structure.object.ObjectPlaceMode;
|
||||
import art.arcane.iris.structure.placement.IrisStructure;
|
||||
import art.arcane.iris.structure.placement.IrisStructurePlacement;
|
||||
import art.arcane.iris.structure.object.IrisObject;
|
||||
import art.arcane.iris.structure.object.IrisObjectRotation;
|
||||
import art.arcane.iris.structure.placement.IrisStructureTerrain;
|
||||
import art.arcane.iris.structure.placement.PlacedStructurePiece;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.structure.StructureCarveShape;
|
||||
import art.arcane.volmlib.util.structure.StructureTerrainMode;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.calls;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class IrisStructureComponentCarveWaterTest {
|
||||
private static final int RIVER_BED = 60;
|
||||
private static final int RIVER_HEAD = 64;
|
||||
private static final int LAND = 70;
|
||||
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private IrisStructureComponent component;
|
||||
private MantleWriter writer;
|
||||
private IrisSettings previousSettings;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
previousSettings = IrisSettings.settings;
|
||||
IrisSettings.settings = new IrisSettings();
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
when(engineMantle.getComplex()).thenReturn(complex);
|
||||
when(engineMantle.getData()).thenReturn(mock(IrisData.class));
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getMinHeight()).thenReturn(-64);
|
||||
when(engine.getHeight()).thenReturn(384);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> river(call.getArgument(0)) ? WaterRole.CHANNEL : WaterRole.NONE);
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> river(call.getArgument(0)) ? RIVER_BED : LAND);
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> river(call.getArgument(0)) ? (double) RIVER_HEAD : 63D);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
component = new IrisStructureComponent(engineMantle);
|
||||
writer = mock(MantleWriter.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
IrisSettings.settings = previousSettings;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boreSkipsRiverColumnsAndTheirBanks() {
|
||||
component.boreStructure(writer, box(), terrain(StructureTerrainMode.BORE, StructureCarveShape.BOX));
|
||||
|
||||
assertRiverKept();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forceCarveBoxSkipsRiverColumnsAndTheirBanks() {
|
||||
component.forceCarveStructure(writer, box(), terrain(StructureTerrainMode.FORCE_CARVE, StructureCarveShape.BOX));
|
||||
|
||||
assertRiverKept();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundedForceCarveSkipsRiverColumnsAndTheirBanks() {
|
||||
component.forceCarveStructure(writer, slab(), terrain(StructureTerrainMode.FORCE_CARVE, StructureCarveShape.ROUNDED));
|
||||
|
||||
verify(writer, never()).setForcedCarve(eq(3), eq(60), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(1), eq(60), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(3), eq(55), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(0), eq(60), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(8), eq(60), eq(1), any(MatterCavern.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void piecesPlaceInsideAWaterAwareObjectPlacement() {
|
||||
IrisStructure structure = new IrisStructure().setPlaceMode(ObjectPlaceMode.STRUCTURE_PIECE);
|
||||
IrisStructurePlacement placement = new IrisStructurePlacement();
|
||||
|
||||
component.placePieces(writer, placement, structure, slab(), new RNG(3L));
|
||||
placement.setAllowWater(true);
|
||||
component.placePieces(writer, placement, structure, slab(), new RNG(3L));
|
||||
|
||||
InOrder order = inOrder(writer);
|
||||
order.verify(writer).beginObjectPlacement(false);
|
||||
order.verify(writer, calls(1)).set(anyInt(), anyInt(), anyInt(), any(NativeBlockState.class));
|
||||
order.verify(writer).endObjectPlacement(anyInt());
|
||||
order.verify(writer).beginObjectPlacement(true);
|
||||
order.verify(writer, calls(1)).set(anyInt(), anyInt(), anyInt(), any(NativeBlockState.class));
|
||||
order.verify(writer).endObjectPlacement(anyInt());
|
||||
}
|
||||
|
||||
private void assertRiverKept() {
|
||||
verify(writer, never()).setForcedCarve(eq(3), eq(62), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(4), eq(68), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(1), eq(58), eq(1), any(MatterCavern.class));
|
||||
verify(writer, never()).setForcedCarve(eq(6), eq(64), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(3), eq(55), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(1), eq(66), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(0), eq(62), eq(1), any(MatterCavern.class));
|
||||
verify(writer).setForcedCarve(eq(7), eq(62), eq(1), any(MatterCavern.class));
|
||||
}
|
||||
|
||||
private static boolean river(Object x) {
|
||||
int blockX = (int) Math.floor(((Number) x).doubleValue());
|
||||
return blockX == 3 || blockX == 4;
|
||||
}
|
||||
|
||||
private static IrisStructureTerrain terrain(StructureTerrainMode mode, StructureCarveShape shape) {
|
||||
return new IrisStructureTerrain()
|
||||
.setMode(mode)
|
||||
.setShape(shape)
|
||||
.setFloorPadding(10)
|
||||
.setCeilingPadding(4);
|
||||
}
|
||||
|
||||
private static KList<PlacedStructurePiece> box() {
|
||||
return new KList<>(new PlacedStructurePiece(null, null, 4, -4, 1, IrisObjectRotation.of(0, 0, 0),
|
||||
0, -4, 0, 8, 0, 2));
|
||||
}
|
||||
|
||||
private static KList<PlacedStructurePiece> slab() {
|
||||
NativeBlockState stone = mock(NativeBlockState.class);
|
||||
when(stone.isSolid()).thenReturn(true);
|
||||
when(stone.key()).thenReturn("minecraft:stone");
|
||||
when(stone.materialKey()).thenReturn("minecraft:stone");
|
||||
IrisObject object = new IrisObject(9, 1, 3);
|
||||
for (int x = 0; x < 9; x++) {
|
||||
for (int z = 0; z < 3; z++) {
|
||||
object.setUnsigned(x, 0, z, stone);
|
||||
}
|
||||
}
|
||||
return new KList<>(new PlacedStructurePiece(null, object, 4, -4, 1, IrisObjectRotation.of(0, 0, 0),
|
||||
0, -4, 0, 8, -4, 2));
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
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 art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
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;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
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, false);
|
||||
|
||||
assertTrue(config.isForcePlace());
|
||||
assertEquals(-1, object.place(0, 0, placer, config, new RNG(7L), world.data()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureTurnedTowardsTheSlopeStaysOutOfRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heights = mock(ProceduralStream.class);
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(invocation -> (double) world.floorAt(
|
||||
(int) Math.floor((Double) invocation.getArgument(0)), (int) Math.floor((Double) invocation.getArgument(1))));
|
||||
when(world.complex().getHeightStream()).thenReturn(heights);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT, false);
|
||||
config.setRotateTowardsSlope(true);
|
||||
|
||||
assertEquals(-1, object.place(0, 0, placer, config, new RNG(7L), world.data()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureThatAllowsWaterPlacesOnFlatRiverWater() {
|
||||
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, true);
|
||||
|
||||
assertTrue(config.entersWater());
|
||||
assertTrue(object.place(0, 0, placer, config, new RNG(7L), world.data()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcedSinglePieceStructureStillPlacesOnDryLand() {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
IrisObject object = HydrologyWaterFixture.raft();
|
||||
IrisObjectPlacement config = IrisStructureComponent.piecePlacement(new IrisStructure(), piece(object), ObjectPlaceMode.CENTER_HEIGHT, false);
|
||||
|
||||
assertTrue(object.place(0, 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
-1
@@ -103,7 +103,7 @@ public class MantleObjectComponentEngineFailureTest {
|
||||
doAnswer((InvocationOnMock invocation) -> {
|
||||
placements.incrementAndGet();
|
||||
throw placementFailure;
|
||||
}).when(object).place(anyInt(), anyInt(), anyInt(), any(IObjectPlacer.class), any(IrisObjectPlacement.class),
|
||||
}).when(object).place(anyInt(), anyInt(), any(IObjectPlacer.class), any(IrisObjectPlacement.class),
|
||||
any(RNG.class), any(), any(), any());
|
||||
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
package art.arcane.iris.generation.mantle;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.cave.HydrologyCaveCell;
|
||||
import art.arcane.iris.generation.hydrology.engine.HydrologyRuntime;
|
||||
import art.arcane.iris.generation.hydrology.raster.ChunkWaterRaster;
|
||||
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.terrain.IrisDimension;
|
||||
import art.arcane.iris.integration.Identifier;
|
||||
import art.arcane.iris.testsupport.PlatformBinding;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.mantle.runtime.Mantle;
|
||||
import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.matter.MatterSlice;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyDouble;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class MantleWriterObjectWaterTest {
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private MantleWriter writer;
|
||||
private MatterSlice<NativeBlockState> blocks;
|
||||
private MatterSlice<MatterCavern> caverns;
|
||||
private NativeBlockState stone;
|
||||
private NativeBlockState air;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUp() {
|
||||
EngineMantle engineMantle = mock(EngineMantle.class);
|
||||
Engine engine = mock(Engine.class);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
Mantle<Matter> mantle = mock(Mantle.class);
|
||||
MantleChunk<Matter> chunk = mock(MantleChunk.class);
|
||||
Matter matter = mock(Matter.class);
|
||||
blocks = mock(MatterSlice.class);
|
||||
caverns = mock(MatterSlice.class);
|
||||
when(engineMantle.getEngine()).thenReturn(engine);
|
||||
when(engineMantle.getComplex()).thenReturn(complex);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(engine.getDimension()).thenReturn(mock(IrisDimension.class));
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.terrainHeight(anyInt(), anyInt())).thenReturn(12);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(9);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(5);
|
||||
followRaster(complex, raster);
|
||||
when(mantle.getWorldHeight()).thenReturn(64);
|
||||
when(mantle.getChunk(0, 0)).thenReturn(chunk);
|
||||
when(chunk.use()).thenReturn(chunk);
|
||||
when(mantle.useChunk(0, 0)).thenAnswer(call -> chunk.use());
|
||||
when(chunk.getOrCreate(0)).thenReturn(matter);
|
||||
when(chunk.exists(0)).thenReturn(true);
|
||||
when(chunk.get(0)).thenReturn(matter);
|
||||
when(matter.getClass(any())).thenAnswer(call -> call.getArgument(0).getClass());
|
||||
doReturn(blocks).when(matter).slice(NativeBlockState.class);
|
||||
doReturn(caverns).when(matter).slice(MatterCavern.class);
|
||||
doReturn(mock(MatterSlice.class)).when(matter).getSlice(Identifier.class);
|
||||
doReturn(null).when(matter).getSlice(HydrologyCaveCell.class);
|
||||
stone = mock(NativeBlockState.class);
|
||||
when(stone.isSolid()).thenReturn(true);
|
||||
air = mock(NativeBlockState.class);
|
||||
writer = new MantleWriter(engineMantle, mantle, 0, 0, 0, false);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structurePiecesKeepOutOfRiverWaterUnlessTheyAllowIt() {
|
||||
MatterCavern cavern = new MatterCavern(true, "", (byte) 3);
|
||||
int land = writer.beginObjectPlacement(false);
|
||||
writer.set(3, 7, 3, stone);
|
||||
writer.set(3, 8, 3, air);
|
||||
writer.setData(3, 6, 3, cavern);
|
||||
writer.set(3, 5, 3, stone);
|
||||
writer.set(3, 10, 3, stone);
|
||||
writer.set(8, 7, 8, stone);
|
||||
writer.endObjectPlacement(land);
|
||||
|
||||
verify(blocks, never()).set(3, 7, 3, stone);
|
||||
verify(blocks, never()).set(3, 8, 3, air);
|
||||
verify(caverns, never()).set(3, 6, 3, cavern);
|
||||
verify(blocks).set(3, 5, 3, stone);
|
||||
verify(blocks).set(3, 10, 3, stone);
|
||||
verify(blocks).set(8, 7, 8, stone);
|
||||
|
||||
int water = writer.beginObjectPlacement(true);
|
||||
writer.set(3, 6, 3, stone);
|
||||
writer.set(3, 9, 3, air);
|
||||
writer.endObjectPlacement(water);
|
||||
|
||||
verify(blocks).set(3, 6, 3, stone);
|
||||
verify(blocks, never()).set(3, 9, 3, air);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writesOutsideAnObjectPlacementAreNotVetoed() {
|
||||
int land = writer.beginObjectPlacement(false);
|
||||
writer.endObjectPlacement(land);
|
||||
|
||||
writer.set(3, 7, 3, stone);
|
||||
writer.set(3, 8, 3, air);
|
||||
|
||||
verify(blocks).set(3, 7, 3, stone);
|
||||
verify(blocks).set(3, 8, 3, air);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void followRaster(IrisComplex complex, ChunkWaterRaster raster) {
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.role(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> (double) raster.waterHead(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.terrainHeight(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
}
|
||||
|
||||
private static int local(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue()) & 15;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class MutationLogTest {
|
||||
new ObjectDestinationTransaction.SetMutation(new ObjectDestinationTransaction.DataKey(3, 70, -2, String.class), "marker", true),
|
||||
new ObjectDestinationTransaction.CustomBlockMutation(new ObjectDestinationTransaction.DataKey(-17, 4, 40, NativeBlockState.class), state, false)));
|
||||
for (int index = 0; index < 100; index++) {
|
||||
log.add(index, index + 1, -index, "grow" + index, (index & 1) == 0, (index & 2) == 0);
|
||||
log.add(index, index + 1, -index, "grow" + index, (index & 1) == 0, (index & 2) == 0, (index & 4) == 0);
|
||||
}
|
||||
|
||||
assertEquals(102, log.size());
|
||||
@@ -41,6 +41,9 @@ public class MutationLogTest {
|
||||
assertFalse(log.custom(101));
|
||||
assertTrue(log.canopy(98));
|
||||
assertFalse(log.canopy(100));
|
||||
assertFalse(log.entersWater(0));
|
||||
assertTrue(log.entersWater(98));
|
||||
assertFalse(log.entersWater(6));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +62,7 @@ public class MutationLogTest {
|
||||
int z = (index * 5) - 20;
|
||||
String value = "value" + (index % 9);
|
||||
boolean canopy = index % 4 == 0;
|
||||
log.add(x, y, z, value, false, canopy);
|
||||
log.add(x, y, z, value, false, canopy, false);
|
||||
if (index >= 10) {
|
||||
tail.add(new ObjectDestinationTransaction.SetMutation(new ObjectDestinationTransaction.DataKey(x, y, z, String.class), value, canopy));
|
||||
}
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ public class ObjectContinuationCanopyTest {
|
||||
when(firstChunk.getOrCreate(0)).thenReturn(first);
|
||||
when(secondChunk.getOrCreate(0)).thenReturn(second);
|
||||
FloatingObjectPlacementTransaction transaction = new FloatingObjectPlacementTransaction(delegate,
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0));
|
||||
new ObjectContinuationBundle.PlacementKey(ObjectContinuationBundle.Kind.FLOATING, 0, 0, 0), false);
|
||||
transaction.set(15, 5, 1, trunk);
|
||||
assertTrue(transaction.beginTreeCanopy(new BlockPosition(16, 5, 1)));
|
||||
transaction.set(16, 5, 1, custom);
|
||||
|
||||
@@ -58,14 +58,14 @@ public class ObjectContinuationTest {
|
||||
public void onlyAcceptedCrossingPlacementsLeaveFutureFragments() throws Exception {
|
||||
Fixture fixture = new Fixture();
|
||||
ObjectDestinationTransaction source = new ObjectDestinationTransaction(fixture.writer, 0, 0);
|
||||
int checkpoint = source.beginObjectPlacement();
|
||||
int checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(1, 5, 1, "inside");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
checkpoint = source.beginObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(15, 5, 1, "crossing");
|
||||
source.setData(16, 5, 1, "crossing");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
checkpoint = source.beginObjectPlacement();
|
||||
checkpoint = source.beginObjectPlacement(false);
|
||||
source.setData(32, 5, 1, "unrelated");
|
||||
source.setData(48, 5, 1, "unrelated");
|
||||
source.endObjectPlacement(checkpoint);
|
||||
|
||||
+174
-3
@@ -19,6 +19,12 @@ import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
import art.arcane.volmlib.util.math.BlockPosition;
|
||||
import art.arcane.iris.structure.object.DecayControlPlacer;
|
||||
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.spi.PlatformRegistries;
|
||||
import art.arcane.iris.testsupport.BukkitTestServer;
|
||||
import art.arcane.iris.world.storage.matter.IrisMatterSupport;
|
||||
@@ -27,6 +33,7 @@ import art.arcane.volmlib.util.mantle.runtime.MantleChunk;
|
||||
import art.arcane.volmlib.util.matter.IrisMatter;
|
||||
import art.arcane.volmlib.util.matter.Matter;
|
||||
import art.arcane.volmlib.util.matter.MatterCavern;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
@@ -44,6 +51,7 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
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.Mockito.doAnswer;
|
||||
@@ -139,7 +147,7 @@ public class ObjectDestinationTransactionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void solidObjectBlocksMayDisplaceWaterButNothingOpenOrCarvedBreaksContainment() {
|
||||
public void onlyUnderwaterObjectsDisplaceWaterAndNothingOpenOrCarvedBreaksContainment() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
@@ -163,6 +171,7 @@ public class ObjectDestinationTransactionTest {
|
||||
when(raster.terrainHeight(6, 6)).thenReturn(20);
|
||||
when(raster.role(9, 9)).thenReturn(WaterRole.SHORE);
|
||||
when(raster.terrainHeight(9, 9)).thenReturn(20);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState pier = mock(NativeBlockState.class);
|
||||
when(pier.isSolid()).thenReturn(true);
|
||||
NativeBlockState vine = mock(NativeBlockState.class);
|
||||
@@ -179,10 +188,19 @@ public class ObjectDestinationTransactionTest {
|
||||
assertEquals("open blocks and carves stay out of water, its bed and the bank below the head, and nothing enters a fall", start,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.set(3, 10, 3, pier);
|
||||
transaction.set(4, 15, 3, pier);
|
||||
assertEquals("a land object's pier stays out of the river", start, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 9, 3, pier);
|
||||
transaction.set(6, 18, 6, pier);
|
||||
assertEquals("a pier keeps its blocks on the river bed and the shore", start + 2, transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 10, 3, pier);
|
||||
transaction.set(4, 15, 3, pier);
|
||||
assertEquals("a pier into the river keeps its blocks", start + 4, transaction.mutationCheckpoint());
|
||||
assertEquals("an underwater pier keeps its blocks in the river", start + 4, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 12, 3, pier);
|
||||
transaction.set(3, 10, 3, vine);
|
||||
assertEquals("an underwater object still keeps out of falls and open water", start + 4, transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(false);
|
||||
transaction.set(3, 16, 3, vine);
|
||||
transaction.set(3, 8, 3, vine);
|
||||
transaction.set(6, 19, 6, vine);
|
||||
@@ -208,6 +226,7 @@ public class ObjectDestinationTransactionTest {
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.INLET);
|
||||
when(raster.waterHead(3, 3)).thenReturn(12);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(9);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState boulder = mock(NativeBlockState.class);
|
||||
when(boulder.isSolid()).thenReturn(true);
|
||||
NativeBlockState leaves = mock(NativeBlockState.class);
|
||||
@@ -217,16 +236,145 @@ public class ObjectDestinationTransactionTest {
|
||||
transaction.set(3, 13, 3, boulder);
|
||||
transaction.set(3, 30, 3, boulder);
|
||||
transaction.set(3, 14, 3, leaves);
|
||||
transaction.set(3, 10, 3, boulder);
|
||||
assertEquals("nothing an object places roofs or fills the slot between its water and the cliff top", start,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 10, 3, boulder);
|
||||
assertEquals("a solid block below the water may still sit on the slot bed", start + 1, transaction.mutationCheckpoint());
|
||||
transaction.set(3, 12, 3, boulder);
|
||||
assertEquals("an underwater object's solid block below the water may still sit on the slot bed", start + 1,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.beginObjectPlacement(false);
|
||||
transaction.set(3, 31, 3, leaves);
|
||||
transaction.set(3, 36, 3, leaves);
|
||||
transaction.set(3, 33, 3, boulder);
|
||||
assertEquals("a tree canopy above the cliff top keeps its leaves and wood", start + 4, transaction.mutationCheckpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canopiesDoNotFillChannels() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(writer.getEngine().getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.terrainHeight(anyInt(), anyInt())).thenReturn(20);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(10);
|
||||
when(raster.role(4, 3)).thenReturn(WaterRole.POND);
|
||||
when(raster.waterHead(4, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(4, 3)).thenReturn(8);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState leaves = mock(NativeBlockState.class);
|
||||
when(leaves.isSolid()).thenReturn(true);
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
int start = transaction.mutationCheckpoint();
|
||||
for (int y = 11; y <= 14; y++) {
|
||||
setCanopy(transaction, 3, y, 3, leaves);
|
||||
}
|
||||
for (int y = 9; y <= 14; y++) {
|
||||
setCanopy(transaction, 4, y, 3, leaves);
|
||||
}
|
||||
assertEquals("canopy leaves never fill a channel or pond between its bed and its surface", start,
|
||||
transaction.mutationCheckpoint());
|
||||
setCanopy(transaction, 3, 10, 3, leaves);
|
||||
setCanopy(transaction, 3, 15, 3, leaves);
|
||||
setCanopy(transaction, 4, 8, 3, leaves);
|
||||
setCanopy(transaction, 5, 14, 3, leaves);
|
||||
assertEquals("the bed, the air above the surface and dry land keep their leaves", start + 4,
|
||||
transaction.mutationCheckpoint());
|
||||
int underwater = transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 12, 3, leaves);
|
||||
transaction.set(4, 9, 3, leaves);
|
||||
assertEquals("an underwater object keeps its solid blocks in the water", underwater + 2,
|
||||
transaction.mutationCheckpoint());
|
||||
transaction.endObjectPlacement(underwater);
|
||||
ObjectDestinationTransaction destination = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
destination.apply(transaction.sourcePlanSince(start));
|
||||
assertEquals("the destination replay keeps the underwater blocks", 6, destination.mutationCheckpoint());
|
||||
assertSame(leaves, destination.get(3, 12, 3));
|
||||
assertSame(leaves, destination.get(4, 9, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterRaftsAndOwnForcedObjectsKeepTheirLayerOnRiversButForcedStructurePiecesDoNot() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(writer.getEngine().getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
for (int x = 3; x <= 5; x++) {
|
||||
when(raster.role(x, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(x, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(x, 3)).thenReturn(10);
|
||||
}
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState plank = mock(NativeBlockState.class);
|
||||
when(plank.isSolid()).thenReturn(true);
|
||||
IrisObjectPlacement raft = new IrisObjectPlacement().setOnwater(true);
|
||||
IrisObjectPlacement forced = new IrisObjectPlacement().setForcePlace(true);
|
||||
IrisObjectPlacement piece = IrisStructureComponent.piecePlacement(new IrisStructure(), new PlacedStructurePiece(null,
|
||||
new IrisObject(1, 1, 1), 4, 14, 3, IrisObjectRotation.of(0, 0, 0), 4, 14, 3, 4, 14, 3), ObjectPlaceMode.CENTER_HEIGHT, false);
|
||||
assertTrue(piece.isForcePlace());
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
|
||||
int raftStart = transaction.beginObjectPlacement(raft.entersWater());
|
||||
for (int x = 3; x <= 5; x++) {
|
||||
transaction.set(x, 14, 3, plank);
|
||||
}
|
||||
assertEquals("a one-block onwater raft keeps its layer on the river surface", raftStart + 3, transaction.mutationCheckpoint());
|
||||
int forcedStart = transaction.beginObjectPlacement(forced.entersWater());
|
||||
transaction.set(3, 13, 3, plank);
|
||||
assertEquals("an object's own forcePlace keeps its solid blocks in the river", forcedStart + 1, transaction.mutationCheckpoint());
|
||||
int pieceStart = transaction.beginObjectPlacement(piece.entersWater());
|
||||
transaction.set(4, 13, 3, plank);
|
||||
transaction.set(5, 11, 3, plank);
|
||||
assertEquals("a forced structure piece still keeps its solid blocks out of the river", pieceStart, transaction.mutationCheckpoint());
|
||||
ObjectDestinationTransaction destination = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
destination.apply(transaction.sourcePlanSince(raftStart));
|
||||
assertEquals("the destination replay keeps the raft and the forced block", 4, destination.mutationCheckpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endingAWaterPlacementReturnsTheTransactionToLandRules() {
|
||||
MantleWriter writer = writer();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
HydrologyRuntime runtime = mock(HydrologyRuntime.class);
|
||||
ChunkWaterRaster raster = mock(ChunkWaterRaster.class);
|
||||
when(writer.getEngine().getComplex()).thenReturn(complex);
|
||||
when(complex.getHydrologyRuntime()).thenReturn(runtime);
|
||||
when(runtime.enabled()).thenReturn(true);
|
||||
when(runtime.raster(anyInt(), anyInt())).thenReturn(raster);
|
||||
when(raster.role(anyInt(), anyInt())).thenReturn(WaterRole.NONE);
|
||||
when(raster.waterHead(anyInt(), anyInt())).thenReturn(Integer.MIN_VALUE);
|
||||
when(raster.role(3, 3)).thenReturn(WaterRole.CHANNEL);
|
||||
when(raster.waterHead(3, 3)).thenReturn(14);
|
||||
when(raster.terrainHeight(3, 3)).thenReturn(10);
|
||||
followRasterStreams(complex, raster);
|
||||
NativeBlockState pier = mock(NativeBlockState.class);
|
||||
when(pier.isSolid()).thenReturn(true);
|
||||
ObjectDestinationTransaction transaction = new ObjectDestinationTransaction(writer, 0, 0);
|
||||
|
||||
int raft = transaction.beginObjectPlacement(true);
|
||||
transaction.set(3, 12, 3, pier);
|
||||
transaction.endObjectPlacement(raft);
|
||||
int afterRaft = transaction.mutationCheckpoint();
|
||||
transaction.set(3, 13, 3, pier);
|
||||
|
||||
assertEquals("a write after the water placement ends follows land rules", afterRaft, transaction.mutationCheckpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceCaptureCannotReplaceAuthoredRoomSolids() {
|
||||
MantleWriter writer = writer();
|
||||
@@ -769,6 +917,29 @@ public class ObjectDestinationTransactionTest {
|
||||
verify(writer).restoreData(0, 4, 0, Identifier.class, originalIdentifier);
|
||||
}
|
||||
|
||||
private static void setCanopy(ObjectDestinationTransaction transaction, int x, int y, int z, NativeBlockState state) {
|
||||
assertTrue(transaction.beginTreeCanopy(new BlockPosition(x, y, z)));
|
||||
transaction.set(x, y, z, state);
|
||||
transaction.endTreeCanopy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void followRasterStreams(IrisComplex complex, ChunkWaterRaster raster) {
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.role(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenAnswer(call -> (double) raster.waterHead(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(heights.get(anyDouble(), anyDouble())).thenAnswer(call -> raster.terrainHeight(local(call.getArgument(0)), local(call.getArgument(1))));
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
}
|
||||
|
||||
private static int local(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue()) & 15;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static MantleWriter writer() {
|
||||
MantleWriter writer = mock(MantleWriter.class);
|
||||
|
||||
@@ -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")))));
|
||||
}
|
||||
|
||||
+8
-2
@@ -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);
|
||||
@@ -264,7 +270,7 @@ public class NativeStructureObjectVetoTest {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setForcePlace(true);
|
||||
|
||||
assertEquals(-1, tree().place(0, -1, 0, placer, placement, new RNG(1234L), data));
|
||||
assertEquals(-1, tree().place(0, 0, placer, placement, new RNG(1234L), data));
|
||||
assertTrue(placer.written().isEmpty());
|
||||
}
|
||||
|
||||
@@ -304,7 +310,7 @@ public class NativeStructureObjectVetoTest {
|
||||
}
|
||||
|
||||
private int place(RecordingPlacer placer) {
|
||||
return tree().place(0, -1, 0, placer, placement(), new RNG(1234L), data);
|
||||
return tree().place(0, 0, placer, placement(), new RNG(1234L), data);
|
||||
}
|
||||
|
||||
private IrisObjectPlacement placement() {
|
||||
|
||||
+193
@@ -4,29 +4,53 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
import art.arcane.iris.structure.placement.StructurePlacementGrid;
|
||||
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.iris.generation.terrain.IrisDimension;
|
||||
import art.arcane.iris.platform.bukkit.nms.BukkitStructureStagePolicy;
|
||||
import art.arcane.iris.structure.placement.IrisStructureAnchorMode;
|
||||
import art.arcane.iris.structure.placement.IrisStructurePlacement;
|
||||
import art.arcane.iris.structure.placement.IrisStructureTerrain;
|
||||
import art.arcane.volmlib.util.structure.StructureTerrainMode;
|
||||
import art.arcane.iris.structure.placement.StructureDistribution;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureStagePolicy;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWater;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterColumn;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.StructureWaterRules;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
import art.arcane.volmlib.util.math.RNG;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
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.when;
|
||||
|
||||
public class NativeStructurePlacementPlannerTest {
|
||||
private static final int BED = 140;
|
||||
private static final int HEAD = 143;
|
||||
private static final long LAND_IDENTITY = 7387932304999188754L;
|
||||
private static final List<StructureStagePolicy.Footprint> VILLAGE = List.of(
|
||||
new StructureStagePolicy.Footprint(0, 0, 15, 15),
|
||||
new StructureStagePolicy.Footprint(16, 0, 39, 15));
|
||||
|
||||
@Test
|
||||
public void undergroundPlanIsDeterministicAndUsesConfiguredBand() {
|
||||
Engine engine = engine(982374L, -64, 384, 90);
|
||||
@@ -130,6 +154,134 @@ public class NativeStructurePlacementPlannerTest {
|
||||
verify(waterHead).get(8, 8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void structuresAvoidRivers() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
WaterRole[] water = {WaterRole.CHANNEL, WaterRole.POND, WaterRole.CASCADE, WaterRole.WATERFALL};
|
||||
for (int x = 36; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), water[(x + z) & 3]);
|
||||
}
|
||||
}
|
||||
IrisStructurePlacement placement = nativePlacement();
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
|
||||
assertNotNull(plan);
|
||||
assertTrue("64 of 640 piece columns, all beyond the start chunk, are 10% river",
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
|
||||
roles.put(columnKey(35, 15), WaterRole.CHANNEL);
|
||||
assertFalse("65 of 640 piece columns are more than 10% river",
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
|
||||
roles.clear();
|
||||
WaterRole[] dry = {WaterRole.MOUTH, WaterRole.INLET, WaterRole.SHORE, WaterRole.POND_SHORE, WaterRole.BANK, WaterRole.DAM};
|
||||
int column = 0;
|
||||
for (int x = 0; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), dry[column++ % dry.length]);
|
||||
}
|
||||
}
|
||||
assertTrue("mouths, inlets, shores, banks and dams do not count as river water",
|
||||
StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void riverInTheStartChunkLeavesTheDecisionToThePieces() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
flood(roles);
|
||||
|
||||
assertNotNull(NativeStructurePlacementPlanner.planAt(engine, nativePlacement(), 0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stageWaterReportsWorldHeights() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
roles.put(columnKey(3, 4), WaterRole.MOUTH);
|
||||
roles.put(columnKey(5, 4), WaterRole.POND);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
|
||||
assertEquals(new StructureWaterColumn(true, false, BED - 64, HEAD - 64), stageWater.column(3, 4));
|
||||
assertEquals(new StructureWaterColumn(true, true, BED - 64, HEAD - 64), stageWater.column(5, 4));
|
||||
assertEquals(StructureWaterColumn.DRY, stageWater.column(6, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undergroundPlansIgnoreRiversAbove() {
|
||||
Engine engine = engine(982374L, -64, 384, 90);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
flood(roles);
|
||||
IrisStructurePlacement placement = nativePlacement()
|
||||
.setUnderground(true)
|
||||
.setMinHeight(-45)
|
||||
.setMaxHeight(-20);
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.planAt(engine, placement, 12, -7);
|
||||
|
||||
assertNotNull(plan);
|
||||
assertTrue(StructureWaterRules.admitsStart(plan, new BukkitStructureStagePolicy(engine).water(engine), VILLAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowWaterLetsNativeStructuresCoverRivers() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
Map<Long, WaterRole> roles = new HashMap<>();
|
||||
waterComplex(engine, roles, false);
|
||||
flood(roles);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
IrisStructurePlacement placement = nativePlacement();
|
||||
|
||||
assertFalse(StructureWaterRules.admitsStart(
|
||||
NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0), stageWater, VILLAGE));
|
||||
|
||||
placement.setAllowWater(true);
|
||||
NativeStructureStartPlan plan = NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0);
|
||||
assertTrue(plan.allowWater());
|
||||
assertTrue(StructureWaterRules.admitsStart(plan, stageWater, VILLAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void provisionalWaterAnswersNeverPlaceANativeStructure() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
IrisComplex complex = waterComplex(engine, new HashMap<>(), true);
|
||||
StructureWater stageWater = new BukkitStructureStagePolicy(engine).water(engine);
|
||||
|
||||
ProvisionalAnswerException failure = assertThrows(ProvisionalAnswerException.class,
|
||||
() -> stageWater.column(20, 3));
|
||||
assertTrue(failure.getMessage().contains("20,3"));
|
||||
|
||||
when(complex.isPlatformMainThread()).thenReturn(true);
|
||||
assertEquals("the server thread answers from what it has, as for heights",
|
||||
StructureWaterColumn.DRY, stageWater.column(20, 3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allowWaterSeparatesOtherwiseIdenticalPlacements() {
|
||||
IrisStructurePlacement land = nativePlacement();
|
||||
IrisStructurePlacement water = nativePlacement().setAllowWater(true);
|
||||
|
||||
assertEquals("placements that keep out of water keep their identity",
|
||||
LAND_IDENTITY, StructurePlacementGrid.placementIdentity(land));
|
||||
assertNotEquals(StructurePlacementGrid.placementIdentity(land), StructurePlacementGrid.placementIdentity(water));
|
||||
assertEquals("a placementId stays the whole identity",
|
||||
StructurePlacementGrid.placementIdentity(nativePlacement().setPlacementId("hut")),
|
||||
StructurePlacementGrid.placementIdentity(nativePlacement().setPlacementId("hut").setAllowWater(true)));
|
||||
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
bindPlacements(engine, land, water);
|
||||
IrisStructurePlacement first = NativeStructurePlacementPlanner.plansAt(engine, 0, 0).getFirst().placement();
|
||||
bindPlacements(engine, water, land);
|
||||
assertSame("the deduplicated start does not depend on list order",
|
||||
first, NativeStructurePlacementPlanner.plansAt(engine, 0, 0).getFirst().placement());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duplicateSelectedStructureUsesOneDeterministicPlan() {
|
||||
Engine engine = engine(77L, -64, 384, 150);
|
||||
@@ -218,6 +370,47 @@ public class NativeStructurePlacementPlannerTest {
|
||||
return engine;
|
||||
}
|
||||
|
||||
private IrisComplex waterComplex(Engine engine, Map<Long, WaterRole> roles, boolean provisional) {
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> heads = mock(ProceduralStream.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roleStream = mock(ProceduralStream.class);
|
||||
when(heads.get(anyDouble(), anyDouble())).thenReturn(0D);
|
||||
when(heads.getDouble(anyDouble(), anyDouble())).thenReturn((double) HEAD);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Integer> heights = mock(ProceduralStream.class);
|
||||
when(heights.get(anyDouble(), anyDouble())).thenReturn(BED);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(heights);
|
||||
when(roleStream.get(anyDouble(), anyDouble())).thenAnswer(call -> {
|
||||
if (provisional) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
return roles.getOrDefault(columnKey(block(call.getArgument(0)), block(call.getArgument(1))), WaterRole.NONE);
|
||||
});
|
||||
when(complex.getWaterHeadStream()).thenReturn(heads);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roleStream);
|
||||
when(complex.allowsNewGenerationChunk(anyInt(), anyInt())).thenReturn(true);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
return complex;
|
||||
}
|
||||
|
||||
private static void flood(Map<Long, WaterRole> roles) {
|
||||
for (int x = 0; x <= 39; x++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
roles.put(columnKey(x, z), WaterRole.CHANNEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int block(Object coordinate) {
|
||||
return (int) Math.floor(((Number) coordinate).doubleValue());
|
||||
}
|
||||
|
||||
private static long columnKey(int x, int z) {
|
||||
return ((long) x << 32) ^ (z & 0xffffffffL);
|
||||
}
|
||||
|
||||
private void bindPlacements(Engine engine, IrisStructurePlacement... placements) {
|
||||
IrisDimension dimension = engine.getDimension();
|
||||
KList<IrisStructurePlacement> configured = new KList<>();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
-11
@@ -17,6 +17,8 @@ import org.junit.ClassRule;
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.stream.ProvisionalAnswerException;
|
||||
import art.arcane.iris.generation.stream.ProvisionalSampling;
|
||||
import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume;
|
||||
import art.arcane.iris.structure.placement.PlacedObject;
|
||||
import art.arcane.iris.spi.IrisPlatform;
|
||||
@@ -140,7 +142,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
placement.setMode(ObjectPlaceMode.MAX_HEIGHT);
|
||||
placement.setRotation(IrisObjectRotation.of(0, 45, 0));
|
||||
|
||||
boxObject(5, 1, 3).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
boxObject(5, 1, 3).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertTrue(placer.sampledColumns().contains("-2:-2"));
|
||||
assertTrue(placer.sampledColumns().contains("2:2"));
|
||||
@@ -254,7 +256,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement config = placement();
|
||||
config.setMode(ObjectPlaceMode.ERODE_STILT);
|
||||
assertEquals(ANCHOR_Y, lineObject(1).place(0, -1, 0, placer, config, new RNG(2L), data));
|
||||
assertEquals(ANCHOR_Y, lineObject(1).place(0, 0, placer, config, new RNG(2L), data));
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@@ -293,17 +295,42 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement config = placement();
|
||||
config.setFromBottom(true);
|
||||
assertEquals(2, lineObject(1).place(0, -1, 0, placer, config, new RNG(2L), data));
|
||||
assertEquals(2, lineObject(1).place(0, 0, placer, config, new RNG(2L), data));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitNegativeWorldYPlacesAtThatYWithoutSamplingTerrain() {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
|
||||
assertEquals(-20, lineObject(3).place(0, -20, 0, placer, placement(), new RNG(2L), data));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == -20));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void explicitNegativeWorldYIsNotGuardedAgainstProvisionalAnswers() {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
placer.provisional = true;
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement(), new RNG(2L), data));
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == -1));
|
||||
RecordingPlacer automatic = new RecordingPlacer(null);
|
||||
automatic.provisional = true;
|
||||
assertThrows(ProvisionalAnswerException.class,
|
||||
() -> lineObject(3).place(0, 0, automatic, placement(), new RNG(2L), data));
|
||||
assertTrue(automatic.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eligibilityGuardsRejectBeforeBoreAndOwnTheirForcePlaceExemptions() {
|
||||
for (String reason : List.of("carving-anchor", "underwater-anchor", "onwater-anchor", "cave-clearance", "fluid-height", "height-clamp")) {
|
||||
RecordingPlacer placer = new RecordingPlacer(null);
|
||||
IrisObjectPlacement config = placement().setBore(true).setSnow(0.1);
|
||||
CarveResult cave = null;
|
||||
int anchor = ANCHOR_Y;
|
||||
boolean automatic = false;
|
||||
switch (reason) {
|
||||
case "carving-anchor" -> {
|
||||
placer.carved = true;
|
||||
@@ -311,11 +338,11 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
}
|
||||
case "underwater-anchor" -> {
|
||||
placer.underwater = true;
|
||||
anchor = -1;
|
||||
automatic = true;
|
||||
}
|
||||
case "onwater-anchor" -> {
|
||||
config.setOnwater(true);
|
||||
anchor = -1;
|
||||
automatic = true;
|
||||
}
|
||||
case "cave-clearance" -> cave = new CarveResult(ANCHOR_Y, ANCHOR_Y + 1);
|
||||
case "fluid-height" -> {
|
||||
@@ -324,13 +351,13 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
}
|
||||
case "height-clamp" -> config.getClamp().setMaximumHeight(ANCHOR_Y - 1);
|
||||
}
|
||||
PlacementState result = execute(config, anchor, placer, cave);
|
||||
PlacementState result = automatic ? executeAutomatic(config, placer, cave) : execute(config, ANCHOR_Y, placer, cave);
|
||||
assertEquals(reason, result.getRejection());
|
||||
assertEquals(-1, result.heightOrRejected());
|
||||
assertTrue(reason, placer.writes().isEmpty());
|
||||
|
||||
config.setForcePlace(true);
|
||||
assertFalse(reason, execute(config, anchor, placer, cave).isRejected());
|
||||
assertFalse(reason, (automatic ? executeAutomatic(config, placer, cave) : execute(config, ANCHOR_Y, placer, cave)).isRejected());
|
||||
assertFalse(reason, placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -429,7 +456,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
IrisObjectPlacement config = placement();
|
||||
config.setHeightmap(new IrisNoiseGenerator(false).setOffsetY(93));
|
||||
|
||||
assertEquals(93, lineObject(1).place(0, -1, 0, placer, config, rng, data));
|
||||
assertEquals(93, lineObject(1).place(0, 0, placer, config, rng, data));
|
||||
assertTrue(placer.sampledColumns().isEmpty());
|
||||
assertEquals(expected.nextLong(), rng.nextLong());
|
||||
}
|
||||
@@ -478,6 +505,11 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
new PlacementContext(config, data, placer, cave, new RNG(2L), lineObject(1), 0, 0, y, null));
|
||||
}
|
||||
|
||||
private PlacementState executeAutomatic(IrisObjectPlacement config, RecordingPlacer placer, CarveResult cave) {
|
||||
return PlacementLifecycles.defaults().get(config.getMode()).execute(PlacementContext.automatic(
|
||||
config, data, placer, cave, new RNG(2L), lineObject(1), IrisObjectPlacementAlignment.CENTER, 0, 0, null));
|
||||
}
|
||||
|
||||
private IrisObject lineObject(int width) {
|
||||
IrisObject object = new IrisObject(width, 1, 1);
|
||||
for (int x = 0; x < width; x++) {
|
||||
@@ -522,6 +554,7 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
private boolean debugSmartBore;
|
||||
private boolean carved;
|
||||
private boolean underwater;
|
||||
private boolean provisional;
|
||||
private int fluidHeight;
|
||||
|
||||
private RecordingPlacer(Engine engine) {
|
||||
@@ -550,13 +583,13 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data) {
|
||||
sampledColumns.add(x + ":" + z);
|
||||
return ANCHOR_Y;
|
||||
return getHighest(x, z, data, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||
sampledColumns.add(x + ":" + z);
|
||||
markProvisional();
|
||||
return ANCHOR_Y;
|
||||
}
|
||||
|
||||
@@ -581,9 +614,16 @@ public class IrisObjectPlacementLifecycleRegressionTest {
|
||||
|
||||
@Override
|
||||
public boolean isCarved(int x, int y, int z) {
|
||||
markProvisional();
|
||||
return carved;
|
||||
}
|
||||
|
||||
private void markProvisional() {
|
||||
if (provisional) {
|
||||
ProvisionalSampling.mark();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSolid(int x, int y, int z) {
|
||||
NativeBlockState state = get(x, y, z);
|
||||
|
||||
+14
-14
@@ -144,11 +144,11 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setOnwater(true);
|
||||
RecordingPlacer dry = new RecordingPlacer(null);
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, dry, placement, new RNG(2L), data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, dry, placement, new RNG(2L), data));
|
||||
assertTrue(dry.writes().isEmpty());
|
||||
RecordingPlacer wet = new RecordingPlacer(null);
|
||||
wet.setUnderwater(true);
|
||||
assertNotEquals(-1, lineObject(3).place(0, -1, 0, wet, placement, new RNG(2L), data));
|
||||
assertNotEquals(-1, lineObject(3).place(0, 0, wet, placement, new RNG(2L), data));
|
||||
assertFalse(wet.writes().isEmpty());
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placement.setMode(ObjectPlaceMode.MAX_HEIGHT);
|
||||
placement.setRotation(IrisObjectRotation.of(0, 45, 0));
|
||||
|
||||
boxObject(5, 1, 3).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
boxObject(5, 1, 3).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertTrue(placer.sampledColumns().contains("-2:-2"));
|
||||
assertTrue(placer.sampledColumns().contains("2:2"));
|
||||
@@ -375,7 +375,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT)
|
||||
.setRequireSurfaceSupport(true).setSurfaceSupportBuffer(0);
|
||||
|
||||
assertEquals(80, lineObject(5).place(0, -1, 0, placer, placement, new RNG(2L), data));
|
||||
assertEquals(80, lineObject(5).place(0, 0, placer, placement, new RNG(2L), data));
|
||||
|
||||
assertEquals(5, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == 80));
|
||||
@@ -387,7 +387,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placer.terrain(1, 0, 0, 20);
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT);
|
||||
|
||||
lineObject(5).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
lineObject(5).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.x() <= 0 && write.y() == 80));
|
||||
@@ -400,7 +400,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placer.terrain(x, 0, 0, 80 + x * 3);
|
||||
}
|
||||
|
||||
lineObject(13).place(0, -1, 0, placer, placement().setMode(ObjectPlaceMode.PAINT), new RNG(2L), data);
|
||||
lineObject(13).place(0, 0, placer, placement().setMode(ObjectPlaceMode.PAINT), new RNG(2L), data);
|
||||
|
||||
assertEquals(13, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == 80 + write.x() * 3));
|
||||
@@ -412,7 +412,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
placer.highestFollowsWrites = true;
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT).setBore(true);
|
||||
|
||||
boxObject(1, 3, 1).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
boxObject(1, 3, 1).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
|
||||
assertEquals(3, placer.writesOf(solid).size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() >= 80 && write.y() <= 82));
|
||||
@@ -430,7 +430,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
RNG rng = mock(RNG.class);
|
||||
when(rng.i(0, 3)).thenReturn(3);
|
||||
|
||||
assertEquals(113, lineObject(3).place(0, -1, 0, placer, placement, rng, data));
|
||||
assertEquals(113, lineObject(3).place(0, 0, placer, placement, rng, data));
|
||||
|
||||
assertEquals(3, placer.writesOf(solid).size());
|
||||
assertEquals(3, placer.writesOf(IrisObject.States.air()).size());
|
||||
@@ -450,12 +450,12 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
RNG rng = mock(RNG.class);
|
||||
when(rng.i(0, 3)).thenReturn(3);
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement, rng, data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, placer, placement, rng, data));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(
|
||||
new KList<>(NativeStructureVolume.of("test", 1, 101, 0, 1, 101, 0)));
|
||||
assertEquals(83, lineObject(3).place(0, -1, 0, placer, placement, rng, data));
|
||||
assertEquals(83, lineObject(3).place(0, 0, placer, placement, rng, data));
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.y() == 85));
|
||||
}
|
||||
|
||||
@@ -473,11 +473,11 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(
|
||||
new KList<>(NativeStructureVolume.of("test", 3, 80, 2, 3, 80, 2)));
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement, new RNG(2L), data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, placer, placement, new RNG(2L), data));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
|
||||
when(engine.getNativeStructureVolumes(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(NativeStructureVolume.NONE);
|
||||
lineObject(3).place(0, -1, 0, placer, placement, new RNG(2L), data);
|
||||
lineObject(3).place(0, 0, placer, placement, new RNG(2L), data);
|
||||
assertEquals(3, placer.writes().size());
|
||||
assertTrue(placer.writes().stream().allMatch(write -> write.x() >= 1 && write.x() <= 3
|
||||
&& write.z() == 2 && write.y() == 80));
|
||||
@@ -490,7 +490,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = placement().setMode(ObjectPlaceMode.PAINT)
|
||||
.setRequireSurfaceSupport(true).setSurfaceSupportBuffer(0).setSurfaceSupportDepth(2);
|
||||
|
||||
assertEquals(-1, lineObject(3).place(0, -1, 0, placer, placement, new RNG(2L), data));
|
||||
assertEquals(-1, lineObject(3).place(0, 0, placer, placement, new RNG(2L), data));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@@ -711,7 +711,7 @@ public class IrisObjectPlacementRunnerRegressionTest {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement()
|
||||
.setRotation(IrisObjectRotation.of(0, 0, 0));
|
||||
|
||||
assertTrue(tree.place(0, -1, 0, placer, placement, new RNG(2L), data) >= 0);
|
||||
assertTrue(tree.place(0, 0, placer, placement, new RNG(2L), data) >= 0);
|
||||
|
||||
assertSame(wood, placer.get(1, 167, 0));
|
||||
assertNull(placer.get(1, 166, 0));
|
||||
|
||||
+2
@@ -88,6 +88,7 @@ public class IrisObjectPlacementToPlacementTest {
|
||||
source.setAllowedCollisions(allowedCollisions);
|
||||
source.setForbiddenCollisions(forbiddenCollisions);
|
||||
source.setForcePlace(true);
|
||||
source.setForcedByStructure(true);
|
||||
|
||||
IrisObjectPlacement copy = source.toPlacement("objects/replaced");
|
||||
|
||||
@@ -132,5 +133,6 @@ public class IrisObjectPlacementToPlacementTest {
|
||||
assertSame(allowedCollisions, copy.getAllowedCollisions());
|
||||
assertSame(forbiddenCollisions, copy.getForbiddenCollisions());
|
||||
assertTrue(copy.isForcePlace());
|
||||
assertTrue(copy.isForcedByStructure());
|
||||
}
|
||||
}
|
||||
+12
-19
@@ -68,7 +68,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
placer.carve(0, SURFACE_Y, 0);
|
||||
|
||||
assertEquals("mode " + mode + " must skip over a carved column",
|
||||
-1, place(placer, placement(mode), -1));
|
||||
-1, place(placer, placement(mode)));
|
||||
assertTrue("mode " + mode + " must not write blocks", placer.written().isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
placer.carve(2, SURFACE_Y, 0);
|
||||
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1));
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,14 +86,14 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
placer.carve(6, SURFACE_Y, 0);
|
||||
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1) >= 0);
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void solidGroundStillPlaces() {
|
||||
SurfacePlacer placer = new SurfacePlacer();
|
||||
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1) >= 0);
|
||||
assertTrue(place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,18 +101,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
when(complex.hasWaterOrShore(0, 0)).thenReturn(true);
|
||||
SurfacePlacer placer = new SurfacePlacer(engine);
|
||||
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT), -1));
|
||||
assertTrue(placer.written().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void automaticForcePlacementCannotOverlapRiverWater() {
|
||||
when(complex.hasWaterOrShore(0, 0)).thenReturn(true);
|
||||
SurfacePlacer placer = new SurfacePlacer(engine);
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.setForcePlace(true);
|
||||
|
||||
assertEquals(-1, place(placer, placement, -1));
|
||||
assertEquals(-1, place(placer, placement(ObjectPlaceMode.CENTER_HEIGHT)));
|
||||
assertTrue(placer.written().isEmpty());
|
||||
}
|
||||
|
||||
@@ -140,7 +129,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.setForcePlace(true);
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,7 +139,7 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
placement.setRequireSurfaceSupport(false);
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,7 +224,11 @@ public class IrisObjectSurfaceSupportPlacementTest {
|
||||
IrisObjectPlacement placement = placement(ObjectPlaceMode.FLOATING);
|
||||
placement.setTranslate(new IrisObjectTranslate().setY(SURFACE_Y + 40));
|
||||
|
||||
assertTrue(place(placer, placement, -1) >= 0);
|
||||
assertTrue(place(placer, placement) >= 0);
|
||||
}
|
||||
|
||||
private int place(SurfacePlacer placer, IrisObjectPlacement placement) {
|
||||
return object().place(0, 0, placer, placement, new RNG(1234L), data);
|
||||
}
|
||||
|
||||
private int place(SurfacePlacer placer, IrisObjectPlacement placement, int anchorY) {
|
||||
|
||||
@@ -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;
|
||||
@@ -47,6 +48,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -110,8 +112,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);
|
||||
@@ -154,16 +159,15 @@ public class ObjectPlacementGoldenTest {
|
||||
List<String> listened = new ArrayList<>();
|
||||
int x = 400 + index * 3 + seed;
|
||||
int z = -900 + rotationIndex * 5 - seed;
|
||||
int y = explicitY ? 90 + seed : -1;
|
||||
BiConsumer<BlockPosition, NativeBlockState> listener =
|
||||
(position, state) -> listened.add(position.getX() + "," + position.getY() + "," + position.getZ() + "=" + state.key());
|
||||
int result;
|
||||
if (placement.getMode() == ObjectPlaceMode.ORGANIC_STILT && explicitY && seed % 2 == 0) {
|
||||
result = object.placeOnFloor(x, 70, z, placer, placement, rng,
|
||||
(position, state) -> listened.add(position.getX() + "," + position.getY() + "," + position.getZ() + "=" + state.key()),
|
||||
data);
|
||||
result = object.placeOnFloor(x, 70, z, placer, placement, rng, listener, data);
|
||||
} else if (explicitY) {
|
||||
result = object.place(x, 90 + seed, z, placer, placement, rng, listener, null, data);
|
||||
} else {
|
||||
result = object.place(x, y, z, placer, placement, rng,
|
||||
(position, state) -> listened.add(position.getX() + "," + position.getY() + "," + position.getZ() + "=" + state.key()),
|
||||
null, data);
|
||||
result = object.place(x, z, placer, placement, rng, listener, null, data);
|
||||
}
|
||||
long hash = placer.hash;
|
||||
hash = mix(hash, result);
|
||||
@@ -245,8 +249,9 @@ public class ObjectPlacementGoldenTest {
|
||||
for (int seed = 0; seed < 150; seed++) {
|
||||
RNG rng = new RNG(index * 104_729L + seed);
|
||||
GoldenPlacer placer = new GoldenPlacer(engine, (seed & 1) == 0);
|
||||
int y = seed % 3 == 0 ? 90 + (seed & 7) : -1;
|
||||
int result = object.place(300 + seed, y, -400 + index * 7, placer, placement, rng, null, null, data);
|
||||
int result = seed % 3 == 0
|
||||
? object.place(300 + seed, 90 + (seed & 7), -400 + index * 7, placer, placement, rng, null, null, data)
|
||||
: object.place(300 + seed, -400 + index * 7, placer, placement, rng, null, null, data);
|
||||
long hash = mix(placer.hash, result);
|
||||
hash = mix(hash, rng.nextLong());
|
||||
combined = mix(combined, hash);
|
||||
|
||||
@@ -149,8 +149,8 @@ public class PlacementLifecycleTest {
|
||||
when(object.getW()).thenReturn(3);
|
||||
when(object.getH()).thenReturn(1);
|
||||
when(object.getD()).thenReturn(1);
|
||||
PlacementContext context = new PlacementContext(config, mock(IrisData.class), placer, null,
|
||||
new RNG(1), object, x, 0, -1, null);
|
||||
PlacementContext context = PlacementContext.automatic(config, mock(IrisData.class), placer, null,
|
||||
new RNG(1), object, IrisObjectPlacementAlignment.CENTER, x, 0, null);
|
||||
PlacementState state = new PlacementState(context);
|
||||
plan.run(PlacementStage.PREPARE, context, state, null);
|
||||
plan.run(PlacementStage.HEIGHT, context, state, null);
|
||||
@@ -168,8 +168,8 @@ public class PlacementLifecycleTest {
|
||||
builder.add(id("dependent"), PlacementStage.HEIGHT, (c, s, v) -> s.y = 99, id("guard"));
|
||||
PlacementLifecycle plan = builder.build();
|
||||
IrisObjectPlacement config = new IrisObjectPlacement();
|
||||
PlacementContext context = new PlacementContext(config, mock(IrisData.class), mock(IObjectPlacer.class),
|
||||
null, new RNG(1), mock(IrisObject.class), 0, 0, -1, null);
|
||||
PlacementContext context = PlacementContext.automatic(config, mock(IrisData.class), mock(IObjectPlacer.class),
|
||||
null, new RNG(1), mock(IrisObject.class), IrisObjectPlacementAlignment.CENTER, 0, 0, null);
|
||||
PlacementState rejected = new PlacementState(context);
|
||||
plan.run(PlacementStage.HEIGHT, context, rejected, null);
|
||||
assertEquals(-1, rejected.heightOrRejected());
|
||||
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
package art.arcane.iris.structure.object;
|
||||
|
||||
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 org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
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.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class PlacementModuleSurfaceSupportTest {
|
||||
@Rule
|
||||
public final PlatformBinding platform = PlatformBinding.mockPlatform();
|
||||
|
||||
private final HydrologyWaterFixture world = new HydrologyWaterFixture();
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsPlaceInPonds() {
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, underwater()) >= 0);
|
||||
assertFalse(placer.writes().isEmpty());
|
||||
assertEquals(world.floorAt(0, 0), placer.lowestWrite());
|
||||
assertTrue(placer.highestWrite() < world.headAt(0, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void underwaterObjectsSkipWaterTooShallowForTheirResolvedY() {
|
||||
world.water(WaterRole.POND, 9, 13);
|
||||
HydrologyWaterFixture.Placer deep = world.placer();
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), deep, underwater()) >= 0);
|
||||
|
||||
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() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, onwater()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onwaterObjectsSkipDryColumns() {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertEquals(-1, place(HydrologyWaterFixture.pillar(), placer, onwater()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void forcePlaceObjectsPlaceInRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertTrue(place(HydrologyWaterFixture.pillar(), placer, forced()) >= 0);
|
||||
assertEquals(world.headAt(0, 0), placer.lowestWrite());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landObjectsStayOutOfRiverWater() {
|
||||
world.water(WaterRole.CHANNEL, 9, 13);
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
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() {
|
||||
world.water(WaterRole.POND, 7, 13);
|
||||
world.provisional();
|
||||
|
||||
for (IrisObjectPlacement placement : List.of(underwater(), onwater(), forced())) {
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
ProvisionalAnswerException error = assertThrows(ProvisionalAnswerException.class,
|
||||
() -> place(HydrologyWaterFixture.pillar(), placer, placement));
|
||||
|
||||
assertTrue(error.getMessage().contains("provisional"));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void landObjectsNeverPlaceOnProvisionalHydrology() {
|
||||
world.provisional();
|
||||
HydrologyWaterFixture.Placer placer = world.placer();
|
||||
|
||||
assertThrows(ProvisionalAnswerException.class, () -> place(HydrologyWaterFixture.pillar(), placer, placement()));
|
||||
assertTrue(placer.writes().isEmpty());
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
@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 place(IrisObject object, HydrologyWaterFixture.Placer placer, IrisObjectPlacement placement) {
|
||||
return object.place(0, 0, placer, placement, new RNG(1234L), world.data());
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement placement() {
|
||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||
placement.setMode(ObjectPlaceMode.CENTER_HEIGHT);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement underwater() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setUnderwater(true);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement onwater() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setOnwater(true);
|
||||
return placement;
|
||||
}
|
||||
|
||||
private static IrisObjectPlacement forced() {
|
||||
IrisObjectPlacement placement = placement();
|
||||
placement.setForcePlace(true);
|
||||
return placement;
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class TreeGroundingPlacementTest {
|
||||
terrain.heights.put(new Column(1, 0), 70);
|
||||
Map<Position, NativeBlockState> observed = new HashMap<>();
|
||||
|
||||
int result = tree(true).place(0, -1, 0, terrain.placer, placement(), new RNG(42L),
|
||||
int result = tree(true).place(0, 0, terrain.placer, placement(), new RNG(42L),
|
||||
(position, state) -> observed.put(new Position(position.getX(), position.getY(), position.getZ()), state),
|
||||
null, data);
|
||||
|
||||
@@ -143,7 +143,7 @@ public class TreeGroundingPlacementTest {
|
||||
placement.setRotation(IrisObjectRotation.of(0, 90, 0));
|
||||
placement.setTranslate(new IrisObjectTranslate().setX(2).setY(1).setZ(3));
|
||||
|
||||
int result = tree(true).place(10, -1, 20, terrain.placer, placement, new RNG(42L), data);
|
||||
int result = tree(true).place(10, 20, terrain.placer, placement, new RNG(42L), data);
|
||||
|
||||
assertTrue(result >= 0);
|
||||
assertSame(wood, terrain.written.get(new Position(13, 81, 18)));
|
||||
@@ -173,7 +173,7 @@ public class TreeGroundingPlacementTest {
|
||||
terrain.heights.put(new Column(1, 0), 77);
|
||||
Map<Position, NativeBlockState> observed = new HashMap<>();
|
||||
|
||||
int result = tree(true).place(0, -1, 0, terrain.placer, placement(), new RNG(42L),
|
||||
int result = tree(true).place(0, 0, terrain.placer, placement(), new RNG(42L),
|
||||
(position, state) -> observed.put(new Position(position.getX(), position.getY(), position.getZ()), state),
|
||||
null, data);
|
||||
|
||||
@@ -322,14 +322,14 @@ public class TreeGroundingPlacementTest {
|
||||
Terrain terrain = new Terrain();
|
||||
IrisObject earlier = tree(true);
|
||||
earlier.getBlocks().put(new IrisBlockVector(0, 1, 0), wood);
|
||||
assertTrue(earlier.place(4, -1, 0, terrain.placer, placement(), new RNG(42L), data) >= 0);
|
||||
assertTrue(earlier.place(4, 0, terrain.placer, placement(), new RNG(42L), data) >= 0);
|
||||
IrisObject later = tree(true);
|
||||
later.getBlocks().put(new IrisBlockVector(4, 2, 0), leaves);
|
||||
later.setTreeGrounding(TreeGrounding.create(later.getTreeGrounding().roots(), 3,
|
||||
Set.of(new TreeBlockCanvas.Vec(4, 1, 0), new TreeBlockCanvas.Vec(4, 2, 0))));
|
||||
Map<Position, NativeBlockState> observed = new HashMap<>();
|
||||
|
||||
int result = later.place(0, -1, 0, terrain.placer, placement(), new RNG(42L),
|
||||
int result = later.place(0, 0, terrain.placer, placement(), new RNG(42L),
|
||||
(position, state) -> observed.put(new Position(position.getX(), position.getY(), position.getZ()), state),
|
||||
null, data);
|
||||
|
||||
@@ -398,7 +398,7 @@ public class TreeGroundingPlacementTest {
|
||||
}
|
||||
|
||||
private int place(IrisObject tree, Terrain terrain, IrisObjectPlacement placement) {
|
||||
return tree.place(0, -1, 0, terrain.placer, placement, new RNG(42L), data);
|
||||
return tree.place(0, 0, terrain.placer, placement, new RNG(42L), data);
|
||||
}
|
||||
|
||||
private IrisObjectPlacement placement() {
|
||||
|
||||
+81
@@ -26,6 +26,7 @@ import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.generation.runtime.SeedManager;
|
||||
|
||||
import art.arcane.iris.pack.loading.IrisData;
|
||||
import art.arcane.iris.generation.hydrology.raster.WaterRole;
|
||||
import art.arcane.iris.generation.runtime.IrisComplex;
|
||||
import art.arcane.iris.structure.graph.StructureGraphCatalog;
|
||||
import art.arcane.iris.pack.value.IrisDirection;
|
||||
@@ -45,6 +46,7 @@ import art.arcane.volmlib.util.math.RNG;
|
||||
import art.arcane.volmlib.util.stream.ProceduralStream;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -447,6 +449,77 @@ public class IrisStructureLocatorContractTest {
|
||||
assertEquals(IrisStructureLocator.LocateStatus.NOT_FOUND, result.status());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void irisStructuresAvoidRivers() {
|
||||
Engine engine = densityEngine(1.0, false, -64, 384, -2032, 2032);
|
||||
IrisObject object = engine.getData().load(IrisObject.class, "test:density/object", false);
|
||||
when(object.getW()).thenReturn(10);
|
||||
when(object.getD()).thenReturn(10);
|
||||
Set<Long> river = new HashSet<>();
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(waterHead);
|
||||
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(63D);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenAnswer(call -> river.contains(columnKey(
|
||||
(int) Math.floor(call.<Double>getArgument(0)), (int) Math.floor(call.<Double>getArgument(1))))
|
||||
? WaterRole.CHANNEL : WaterRole.NONE);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Integer> beds = mock(ProceduralStream.class);
|
||||
when(beds.get(anyDouble(), anyDouble())).thenReturn(120);
|
||||
when(complex.getRoundedHeighteightStream()).thenReturn(beds);
|
||||
when(waterHead.getDouble(anyDouble(), anyDouble())).thenReturn(124D);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(128);
|
||||
when(engine.getDimension().getFluidHeight()).thenReturn(63);
|
||||
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
|
||||
|
||||
IrisStructureLocator.ResolvedPlacement dry = IrisStructureLocator.resolvePlacement(engine, placement, 3, 4);
|
||||
assertNotNull(dry);
|
||||
assertEquals(1, dry.pieces().size());
|
||||
PlacedStructurePiece piece = dry.pieces().getFirst();
|
||||
int columns = (piece.getMaxX() - piece.getMinX() + 1) * (piece.getMaxZ() - piece.getMinZ() + 1);
|
||||
int allowed = columns / 10;
|
||||
assertTrue("the footprint must span enough columns to tell 10% apart", allowed >= 4);
|
||||
for (int index = 0; index < allowed; index++) {
|
||||
river.add(columnKey(piece.getMinX() + index, piece.getMinZ()));
|
||||
}
|
||||
|
||||
assertNotNull("a footprint at most 10% river keeps its structure",
|
||||
IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
|
||||
river.add(columnKey(piece.getMinX(), piece.getMaxZ()));
|
||||
assertNull("a footprint more than 10% river is skipped",
|
||||
IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
|
||||
placement.setAllowWater(true);
|
||||
assertNotNull(IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undergroundIrisStructuresIgnoreRiversAbove() {
|
||||
Engine engine = densityEngine(1.0, true, -64, 384, -40, -20);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
when(engine.getComplex()).thenReturn(complex);
|
||||
when(complex.allowsNewGenerationFootprint(anyInt(), anyInt(), anyInt(), anyInt())).thenReturn(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(waterHead);
|
||||
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(63D);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.CHANNEL);
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(128);
|
||||
IrisStructurePlacement placement = engine.getDimension().getStructures().get(0);
|
||||
|
||||
assertNotNull(IrisStructureLocator.resolvePlacement(engine, placement, 3, 4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locateRanksEditableStartsByResolvedBlockOrigin() {
|
||||
Engine engine = densityEngine(1.0, false, -64, 384, -2032, 2032);
|
||||
@@ -457,6 +530,10 @@ public class IrisStructureLocatorContractTest {
|
||||
ProceduralStream<Double> waterHead = mock(ProceduralStream.class);
|
||||
when(complex.getWaterHeadStream()).thenReturn(waterHead);
|
||||
when(waterHead.get(anyDouble(), anyDouble())).thenReturn(63D);
|
||||
@SuppressWarnings("unchecked")
|
||||
ProceduralStream<WaterRole> roles = mock(ProceduralStream.class);
|
||||
when(complex.getWaterRoleStream()).thenReturn(roles);
|
||||
when(roles.get(anyDouble(), anyDouble())).thenReturn(WaterRole.NONE);
|
||||
when(engine.getAllBiomes()).thenReturn(new KList<>());
|
||||
when(engine.getHeight(anyInt(), anyInt(), eq(true))).thenReturn(128);
|
||||
when(engine.getDimension().getFluidHeight()).thenReturn(63);
|
||||
@@ -826,6 +903,10 @@ public class IrisStructureLocatorContractTest {
|
||||
return dx * dx + dz * dz;
|
||||
}
|
||||
|
||||
private static long columnKey(int x, int z) {
|
||||
return ((long) x << 32) ^ (z & 0xffffffffL);
|
||||
}
|
||||
|
||||
private PlacedStructurePiece piece(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
|
||||
return new PlacedStructurePiece(null, null, 0, 0, 0, null, minX, minY, minZ, maxX, maxY, maxZ);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
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.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.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.iris.world.task.J;
|
||||
import art.arcane.volmlib.nativelib.terrain.NativeBlockState;
|
||||
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.BlockState;
|
||||
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.times;
|
||||
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 saplingBelowZeroGrowsAtItsOwnHeight() {
|
||||
Fixture fixture = new Fixture(SAPLING_Y);
|
||||
StructureGrowEvent event = fixture.event();
|
||||
|
||||
fixture.grow(event);
|
||||
|
||||
assertTrue(event.isCancelled());
|
||||
verify(fixture.saplings).forEach(any());
|
||||
verify(fixture.world).getBlockAt(8, SAPLING_Y, 8);
|
||||
verify(fixture.world).getBlockAt(8, SAPLING_Y + 1, 8);
|
||||
verify(fixture.block, times(2)).getState();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rejectedTreeKeepsTheSapling() {
|
||||
Fixture fixture = new Fixture(0);
|
||||
StructureGrowEvent event = fixture.event();
|
||||
|
||||
fixture.grow(event);
|
||||
|
||||
assertTrue(event.isCancelled());
|
||||
verify(fixture.saplings, never()).forEach(any());
|
||||
verify(fixture.block, never()).getState();
|
||||
}
|
||||
|
||||
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 final Block block = mock(Block.class);
|
||||
|
||||
private Fixture(int lowestTreeY) {
|
||||
IrisDimension dimension = new IrisDimension();
|
||||
dimension.getTreeSettings().setEnabled(true);
|
||||
IrisComplex complex = mock(IrisComplex.class);
|
||||
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(lowestTreeY));
|
||||
|
||||
EngineTarget target = mock(EngineTarget.class);
|
||||
when(target.getWorld()).thenReturn(mock(IrisWorld.class));
|
||||
@SuppressWarnings("unchecked")
|
||||
ResourceLoader<IrisObject> objects = mock(ResourceLoader.class);
|
||||
IrisObject tree = tree();
|
||||
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);
|
||||
|
||||
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(block.getState()).thenReturn(mock(BlockState.class));
|
||||
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 IrisObject tree() {
|
||||
NativeBlockState log = mock(NativeBlockState.class);
|
||||
when(log.isSolid()).thenReturn(true);
|
||||
when(log.key()).thenReturn("minecraft:oak_log");
|
||||
when(log.materialKey()).thenReturn("minecraft:oak_log");
|
||||
when(log.nativeHandle()).thenReturn(mock(BlockData.class));
|
||||
IrisObject object = new IrisObject(3, 3, 3);
|
||||
object.setUnsigned(1, 0, 1, log);
|
||||
object.setUnsigned(1, 1, 1, log);
|
||||
return object;
|
||||
}
|
||||
|
||||
private static IrisBiome biome(int lowestTreeY) {
|
||||
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);
|
||||
placement.setRequireSurfaceSupport(false);
|
||||
placement.getClamp().setMinimumHeight(lowestTreeY);
|
||||
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);
|
||||
MockedStatic<J> tasks = mockStatic(J.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