mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-29 01:04:29 +00:00
Objects stop filling channels
- Wet hydrology columns reject solid object blocks between the bed and the surface unless the object is underwater - The column role, head and bed come from the water role, water head and height streams - Object placements tell the destination transaction whether they are underwater - The mutation log and source plans carry the underwater flag so destination replay applies the same rule - Tests cover canopies over channels and ponds, underwater exemptions, replay, piers and sea inlet slots
This commit is contained in:
1 parent
65d06ae83c
commit
0c7b0b7b80
8 files changed
+155
-35
No files matched your search
@@ -751,7 +751,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
try {
|
||||
int placeResult = -1;
|
||||
CaveObjectPlacementTransaction.CommitResult commitResult = CaveObjectPlacementTransaction.CommitResult.EMPTY;
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int continuation = writer.beginObjectPlacement(placement.isUnderwater());
|
||||
if (carving) {
|
||||
int caveFloorY = caveAnchor.y();
|
||||
if (golden) {
|
||||
@@ -1013,7 +1013,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
try {
|
||||
String marker = placementMarker(v, id, "surface");
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int continuation = writer.beginObjectPlacement(effectivePlacement.isUnderwater());
|
||||
int result = v.place(xx, -1, zz, placePlacer, effectivePlacement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
@@ -1198,7 +1198,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
IrisObjectPlacement effectivePlacement = resolveCavePlacement(objectPlacement, object, caveProfile);
|
||||
|
||||
try {
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int continuation = writer.beginObjectPlacement(effectivePlacement.isUnderwater());
|
||||
ContainedPlacementResult contained = placeContainedCaveObject(
|
||||
writer,
|
||||
object,
|
||||
@@ -1394,7 +1394,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
boolean treePlacement = isTreePlacement(v, objectPlacement);
|
||||
String marker = placementMarker(v, id, "upper");
|
||||
int continuation = writer.beginObjectPlacement();
|
||||
int continuation = writer.beginObjectPlacement(placement.isUnderwater());
|
||||
int result = v.place(xx, anchorY, zz, writer, placement, rng, (b, data) -> {
|
||||
if (marker != null) {
|
||||
writer.setData(b.getX(), b.getY(), b.getZ(), marker);
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.Objects;
|
||||
final class MutationLog {
|
||||
private static final byte CUSTOM = 1;
|
||||
private static final byte CANOPY = 2;
|
||||
private static final byte UNDERWATER = 4;
|
||||
|
||||
private int size;
|
||||
private int[] x = new int[32];
|
||||
@@ -29,16 +30,16 @@ final class MutationLog {
|
||||
throw new IllegalArgumentException("Object mutation type " + key.type().getName()
|
||||
+ " does not match its value " + value.getClass().getName());
|
||||
}
|
||||
log.add(key.x(), key.y(), key.z(), value, false, set.canopy());
|
||||
log.add(key.x(), key.y(), key.z(), value, false, set.canopy(), false);
|
||||
}
|
||||
case ObjectDestinationTransaction.CustomBlockMutation block -> log.add(key.x(), key.y(), key.z(),
|
||||
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy());
|
||||
Objects.requireNonNull(block.state(), "custom block state"), true, block.canopy(), false);
|
||||
}
|
||||
}
|
||||
return log;
|
||||
}
|
||||
|
||||
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy) {
|
||||
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy, boolean underwater) {
|
||||
if (size == values.length) {
|
||||
int capacity = size * 2;
|
||||
x = Arrays.copyOf(x, capacity);
|
||||
@@ -51,7 +52,7 @@ final class MutationLog {
|
||||
y[size] = blockY;
|
||||
z[size] = blockZ;
|
||||
values[size] = value;
|
||||
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0));
|
||||
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0) | (underwater ? UNDERWATER : 0));
|
||||
size++;
|
||||
}
|
||||
|
||||
@@ -83,6 +84,10 @@ final class MutationLog {
|
||||
return (flags[index] & CANOPY) != 0;
|
||||
}
|
||||
|
||||
boolean underwater(int index) {
|
||||
return (flags[index] & UNDERWATER) != 0;
|
||||
}
|
||||
|
||||
Class<?> type(int index) {
|
||||
return custom(index) ? NativeBlockState.class : ObjectSourcePlan.typeOf(values[index]);
|
||||
}
|
||||
|
||||
+31
-16
@@ -47,6 +47,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
private boolean subterrainProtects;
|
||||
private boolean hydrologyKnown;
|
||||
private HydrologyRuntime hydrology;
|
||||
private boolean underwaterPlacement;
|
||||
|
||||
ObjectDestinationTransaction(MantleWriter writer, int destinationChunkX, int destinationChunkZ) {
|
||||
this.writer = writer;
|
||||
@@ -78,7 +79,8 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int beginObjectPlacement() {
|
||||
public int beginObjectPlacement(boolean underwater) {
|
||||
underwaterPlacement = underwater;
|
||||
return log.size();
|
||||
}
|
||||
|
||||
@@ -106,6 +108,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
Object value = plan.valueAt(index);
|
||||
boolean custom = ObjectSourcePlan.isCustom(cell);
|
||||
boolean canopy = ObjectSourcePlan.isCanopy(cell);
|
||||
boolean underwater = ObjectSourcePlan.isUnderwater(cell);
|
||||
if (custom || value instanceof NativeBlockState) {
|
||||
NativeBlockState existing = canopy ? get(x, y, z) : null;
|
||||
skipCanopy = existing != null && existing.isSolid();
|
||||
@@ -114,9 +117,9 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
continue;
|
||||
}
|
||||
if (custom) {
|
||||
set(x, y, z, (NativeBlockState) value, true, canopy);
|
||||
set(x, y, z, (NativeBlockState) value, canopy, underwater);
|
||||
} else {
|
||||
setData(x, y, z, value, true, canopy);
|
||||
setData(x, y, z, value, canopy, underwater);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -181,17 +184,17 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, NativeBlockState state) {
|
||||
set(x, y, z, state, false, false);
|
||||
set(x, y, z, state, isCanopy(x, y, z), underwaterPlacement);
|
||||
}
|
||||
|
||||
private void set(int x, int y, int z, NativeBlockState state, boolean replayed, boolean replayedCanopy) {
|
||||
private void set(int x, int y, int z, NativeBlockState state, boolean canopy, boolean underwater) {
|
||||
if (state == null) {
|
||||
return;
|
||||
}
|
||||
String placementKey = state.deferredPlacementKey();
|
||||
NativeBlockState baseState = state.placementBaseState();
|
||||
if (state.isCustom() && placementKey != null && baseState != null) {
|
||||
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid())) {
|
||||
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid(), underwater)) {
|
||||
return;
|
||||
}
|
||||
Identifier identifier = Identifier.fromString(placementKey);
|
||||
@@ -199,10 +202,10 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
cell.block = baseState;
|
||||
cell.tile = CLEARED;
|
||||
cell.identifier = identifier;
|
||||
log.add(x, y, z, state, true, replayed ? replayedCanopy : isCanopy(x, y, z));
|
||||
log.add(x, y, z, state, true, canopy, underwater);
|
||||
return;
|
||||
}
|
||||
setData(x, y, z, state);
|
||||
setData(x, y, z, state, canopy, underwater);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -293,18 +296,18 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
|
||||
@Override
|
||||
public <T> void setData(int x, int y, int z, T data) {
|
||||
setData(x, y, z, data, false, false);
|
||||
setData(x, y, z, data, isCanopy(x, y, z), underwaterPlacement);
|
||||
}
|
||||
|
||||
private void setData(int x, int y, int z, Object data, boolean replayed, boolean replayedCanopy) {
|
||||
private void setData(int x, int y, int z, Object data, boolean canopy, boolean underwater) {
|
||||
if (data == null || y < 0 || y >= worldHeight
|
||||
|| protectsSubterrain(x, y, z)) {
|
||||
return;
|
||||
}
|
||||
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid()))) {
|
||||
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid(), underwater))) {
|
||||
return;
|
||||
}
|
||||
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false))) {
|
||||
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false, underwater))) {
|
||||
return;
|
||||
}
|
||||
Class<?> type = data instanceof NativeBlockState ? NativeBlockState.class : data.getClass();
|
||||
@@ -316,7 +319,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
} else {
|
||||
cell.put(type, data);
|
||||
}
|
||||
log.add(x, y, z, data, false, replayed ? replayedCanopy : isCanopy(x, y, z));
|
||||
log.add(x, y, z, data, false, canopy, underwater);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -413,7 +416,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
&& !protectsSubterrain(x, y, z);
|
||||
}
|
||||
|
||||
private boolean hydrologyKeeps(int x, int y, int z, boolean holdsWater) {
|
||||
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, boolean underwater) {
|
||||
HydrologyRuntime runtime = hydrology();
|
||||
if (runtime == null) {
|
||||
return false;
|
||||
@@ -426,15 +429,18 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
if (role == WaterRole.INLET && y >= raster.waterHead(x & 15, z & 15) && y <= getEngine().getComplex().naturalTrueHeight(x, z)) {
|
||||
return true;
|
||||
}
|
||||
if (solid && !underwater && fillsWater(x, y, z)) {
|
||||
return true;
|
||||
}
|
||||
if (role.wet()) {
|
||||
int surface = raster.waterHead(x & 15, z & 15);
|
||||
int fallTop = highestHead(runtime, raster, x, z);
|
||||
if (fallTop > surface && y >= surface && y <= fallTop) {
|
||||
return true;
|
||||
}
|
||||
return !holdsWater && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
|
||||
return !solid && y >= raster.terrainHeight(x & 15, z & 15) && y <= surface;
|
||||
}
|
||||
if (holdsWater || role == WaterRole.NONE) {
|
||||
if (solid || role == WaterRole.NONE) {
|
||||
return false;
|
||||
}
|
||||
int head = Integer.MIN_VALUE;
|
||||
@@ -451,6 +457,15 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
|
||||
return y > bed && y <= head;
|
||||
}
|
||||
|
||||
private boolean fillsWater(int x, int y, int z) {
|
||||
IrisComplex complex = getEngine().getComplex();
|
||||
if (!complex.getWaterRoleStream().get(x, z).wet()) {
|
||||
return false;
|
||||
}
|
||||
return y > complex.getRoundedHeighteightStream().get(x, z)
|
||||
&& y <= (int) Math.round(complex.getWaterHeadStream().getDouble(x, z));
|
||||
}
|
||||
|
||||
private static int highestHead(HydrologyRuntime runtime, ChunkWaterRaster raster, int x, int z) {
|
||||
int top = Integer.MIN_VALUE;
|
||||
for (int[] side : SIDES) {
|
||||
|
||||
@@ -8,7 +8,7 @@ public interface ObjectPassPlacer extends IObjectPlacer {
|
||||
|
||||
byte[] getCarvedColumn(int x, int z, int height);
|
||||
|
||||
default int beginObjectPlacement() {
|
||||
default int beginObjectPlacement(boolean underwater) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@ final class ObjectSourcePlan {
|
||||
private static final int UNKNOWN_PAYLOAD_BYTES = 256;
|
||||
private static final int CUSTOM_BIT = 1 << 8;
|
||||
private static final int CANOPY_BIT = 1 << 9;
|
||||
private static final int Y_SHIFT = 10;
|
||||
private static final int UNDERWATER_BIT = 1 << 10;
|
||||
private static final int Y_SHIFT = 11;
|
||||
private static final int MAXIMUM_Y = (1 << (31 - Y_SHIFT)) - 1;
|
||||
|
||||
private final long[] destinations;
|
||||
@@ -90,7 +91,7 @@ final class ObjectSourcePlan {
|
||||
throw new IllegalArgumentException("Object mutation height is outside the plan range: " + y);
|
||||
}
|
||||
cells[position] = (y << Y_SHIFT) | (log.custom(logged) ? CUSTOM_BIT : 0) | (log.canopy(logged) ? CANOPY_BIT : 0)
|
||||
| ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
|
||||
| (log.underwater(logged) ? UNDERWATER_BIT : 0) | ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
|
||||
valueIndexes[position] = table.indexOf(log.value(logged));
|
||||
}
|
||||
values = table.values.toArray();
|
||||
@@ -241,6 +242,10 @@ final class ObjectSourcePlan {
|
||||
return (cell & CANOPY_BIT) != 0;
|
||||
}
|
||||
|
||||
static boolean isUnderwater(int cell) {
|
||||
return (cell & UNDERWATER_BIT) != 0;
|
||||
}
|
||||
|
||||
ObjectDestinationTransaction.Mutation mutationAt(int chunkX, int chunkZ, int index) {
|
||||
int cell = cells[index];
|
||||
int x = (chunkX << 4) | cellX(cell);
|
||||
|
||||
@@ -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.underwater(0));
|
||||
assertTrue(log.underwater(98));
|
||||
assertFalse(log.underwater(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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
+95
-3
@@ -27,6 +27,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 +45,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 +141,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 +165,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 +182,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 +220,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 +230,72 @@ 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 sourceCaptureCannotReplaceAuthoredRoomSolids() {
|
||||
MantleWriter writer = writer();
|
||||
@@ -769,6 +838,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);
|
||||
|
||||
Reference in new issue
Block a user