Structures respect rivers

- Add the allowWater structure placement field and recapture the schema digest
- Skip surface Iris structures whose piece footprint is more than 10% channel, pond, cascade or waterfall water
- Skip surface native placements whose start chunk is more than 10% of that water
- Fail closed on a provisional water answer off the server thread
- Keep BORE and FORCE_CARVE out of water columns from two blocks below the floor and out of the two-block bank up to the water surface
- Run structure pieces and stilts inside a MantleWriter object placement that applies the object water veto unless the placement allows water
- Let forced single pieces of allowWater structures enter water like an object's own forcePlace
- Apply the object water veto to floating-island object transactions
- Share the veto between the destination transaction, MantleWriter and floating transactions
- Reset the destination transaction's water flag when an object placement ends
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 07:16:22 -05:00
1 parent cabfca700a
commit ba0bb1a2c0
20 files changed
+1052 -165

No files matched your search

@@ -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);
@@ -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));
}
}
@@ -32,7 +32,7 @@ public class IrisStructureComponentWaterTest {
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);
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()));
@@ -49,18 +49,30 @@ public class IrisStructureComponentWaterTest {
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);
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);
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());
@@ -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;
}
}
@@ -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);
@@ -325,7 +325,7 @@ public class ObjectDestinationTransactionTest {
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);
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);
@@ -346,6 +346,35 @@ public class ObjectDestinationTransactionTest {
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();
@@ -84,7 +84,7 @@ public class SchemaBuilderIdentityTest {
@ClassRule
public static final PlatformLeakGuard PLATFORM_GUARD = PlatformLeakGuard.clean();
private static final String EXPECTED_SCHEMA_DIGEST = "52d7194d5b45874dc57b5446125e1fa66c32a821733cf38c1c8256f1e52738f7";
private static final String EXPECTED_SCHEMA_DIGEST = "8d12b6f21c37ae79655854e2a0e5fed57c12f294b28fb988674cf8d7b565f405";
private static final List<Class<?>> SCHEMA_ROOTS = List.of(
IrisDimension.class,
@@ -4,7 +4,10 @@ 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.structure.placement.IrisStructureAnchorMode;
import art.arcane.iris.structure.placement.IrisStructurePlacement;
@@ -16,12 +19,18 @@ 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.Map;
import static org.junit.Assert.assertEquals;
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;
@@ -130,6 +139,77 @@ 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);
IrisStructurePlacement placement = nativePlacement();
WaterRole[] water = {WaterRole.CHANNEL, WaterRole.POND, WaterRole.CASCADE, WaterRole.WATERFALL};
for (int column = 0; column < 25; column++) {
roles.put(columnKey(column & 15, column >> 4), water[column & 3]);
}
assertNotNull("25 of 256 start-chunk columns of river, pond and fall water are within 10%",
NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
roles.put(columnKey(9, 1), WaterRole.CHANNEL);
assertNull("26 of 256 columns are more than 10% water",
NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
roles.clear();
WaterRole[] dry = {WaterRole.MOUTH, WaterRole.INLET, WaterRole.SHORE, WaterRole.POND_SHORE, WaterRole.BANK, WaterRole.DAM};
for (int column = 0; column < 256; column++) {
roles.put(columnKey(column & 15, column >> 4), dry[column % dry.length]);
}
assertNotNull("mouths, inlets, shores, banks and dams do not count as river water",
NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
}
@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);
assertNotNull(NativeStructurePlacementPlanner.planAt(engine, placement, 12, -7));
}
@Test
public void allowWaterLetsNativeStructuresCoverRivers() {
Engine engine = engine(77L, -64, 384, 150);
Map<Long, WaterRole> roles = new HashMap<>();
waterComplex(engine, roles, false);
flood(roles);
IrisStructurePlacement placement = nativePlacement();
assertNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
placement.setAllowWater(true);
assertNotNull(NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
}
@Test
public void provisionalWaterAnswersNeverPlaceANativeStructure() {
Engine engine = engine(77L, -64, 384, 150);
IrisComplex complex = waterComplex(engine, new HashMap<>(), true);
IrisStructurePlacement placement = nativePlacement();
ProvisionalAnswerException failure = assertThrows(ProvisionalAnswerException.class,
() -> NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
assertTrue(failure.getMessage().contains("minecraft:ancient_city"));
assertTrue(failure.getMessage().contains("0,0"));
when(complex.isPlatformMainThread()).thenReturn(true);
assertNotNull("the server thread answers from what it has, as for heights",
NativeStructurePlacementPlanner.planAt(engine, placement, 0, 0));
}
@Test
public void duplicateSelectedStructureUsesOneDeterministicPlan() {
Engine engine = engine(77L, -64, 384, 150);
@@ -218,6 +298,40 @@ 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(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 column = 0; column < 256; column++) {
roles.put(columnKey(column & 15, column >> 4), 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<>();
@@ -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,72 @@ 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);
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 +525,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 +898,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);
}