Rafts keep their deck

- IrisObjectPlacement.entersWater is true for underwater, onwater and an object's own forcePlace, not for forced structure pieces
- Object placements pass entersWater to the destination transaction, so onwater and self-forced objects keep solid blocks in channel and pond water
- The water surface support gate reads the same predicate
- The mutation log and source plans carry the flag as entersWater
- Tests cover a one-block onwater raft and a self-forced block kept on a river, a forced structure piece still vetoed, and replay
This commit is contained in:
Brian Neumann-Fopiano committed 2026-11-02 06:21:42 -05:00
1 parent 6041077c8a
commit e15dcceca0
9 files changed
+90 -40

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(placement.isUnderwater());
int continuation = writer.beginObjectPlacement(placement.entersWater());
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(effectivePlacement.isUnderwater());
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
int result = v.place(xx, 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(effectivePlacement.isUnderwater());
int continuation = writer.beginObjectPlacement(effectivePlacement.entersWater());
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(placement.isUnderwater());
int continuation = writer.beginObjectPlacement(placement.entersWater());
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,7 +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 static final byte ENTERS_WATER = 4;
private int size;
private int[] x = new int[32];
@@ -39,7 +39,7 @@ final class MutationLog {
return log;
}
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy, boolean underwater) {
void add(int blockX, int blockY, int blockZ, Object value, boolean custom, boolean canopy, boolean entersWater) {
if (size == values.length) {
int capacity = size * 2;
x = Arrays.copyOf(x, capacity);
@@ -52,7 +52,7 @@ final class MutationLog {
y[size] = blockY;
z[size] = blockZ;
values[size] = value;
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0) | (underwater ? UNDERWATER : 0));
flags[size] = (byte) ((custom ? CUSTOM : 0) | (canopy ? CANOPY : 0) | (entersWater ? ENTERS_WATER : 0));
size++;
}
@@ -84,8 +84,8 @@ final class MutationLog {
return (flags[index] & CANOPY) != 0;
}
boolean underwater(int index) {
return (flags[index] & UNDERWATER) != 0;
boolean entersWater(int index) {
return (flags[index] & ENTERS_WATER) != 0;
}
Class<?> type(int index) {
@@ -47,7 +47,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
private boolean subterrainProtects;
private boolean hydrologyKnown;
private HydrologyRuntime hydrology;
private boolean underwaterPlacement;
private boolean waterPlacement;
ObjectDestinationTransaction(MantleWriter writer, int destinationChunkX, int destinationChunkZ) {
this.writer = writer;
@@ -79,8 +79,8 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
}
@Override
public int beginObjectPlacement(boolean underwater) {
underwaterPlacement = underwater;
public int beginObjectPlacement(boolean entersWater) {
waterPlacement = entersWater;
return log.size();
}
@@ -108,7 +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);
boolean entersWater = ObjectSourcePlan.entersWater(cell);
if (custom || value instanceof NativeBlockState) {
NativeBlockState existing = canopy ? get(x, y, z) : null;
skipCanopy = existing != null && existing.isSolid();
@@ -117,9 +117,9 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
continue;
}
if (custom) {
set(x, y, z, (NativeBlockState) value, canopy, underwater);
set(x, y, z, (NativeBlockState) value, canopy, entersWater);
} else {
setData(x, y, z, value, canopy, underwater);
setData(x, y, z, value, canopy, entersWater);
}
}
}
@@ -184,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, isCanopy(x, y, z), underwaterPlacement);
set(x, y, z, state, isCanopy(x, y, z), waterPlacement);
}
private void set(int x, int y, int z, NativeBlockState state, boolean canopy, boolean underwater) {
private void set(int x, int y, int z, NativeBlockState state, boolean canopy, boolean entersWater) {
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(), underwater)) {
if (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, baseState.isSolid(), entersWater)) {
return;
}
Identifier identifier = Identifier.fromString(placementKey);
@@ -202,10 +202,10 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
cell.block = baseState;
cell.tile = CLEARED;
cell.identifier = identifier;
log.add(x, y, z, state, true, canopy, underwater);
log.add(x, y, z, state, true, canopy, entersWater);
return;
}
setData(x, y, z, state, canopy, underwater);
setData(x, y, z, state, canopy, entersWater);
}
@Override
@@ -296,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, isCanopy(x, y, z), underwaterPlacement);
setData(x, y, z, data, isCanopy(x, y, z), waterPlacement);
}
private void setData(int x, int y, int z, Object data, boolean canopy, boolean underwater) {
private void setData(int x, int y, int z, Object data, boolean canopy, boolean entersWater) {
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(), underwater))) {
if (data instanceof NativeBlockState state && (!canSetBlock(x, y, z) || hydrologyKeeps(x, y, z, state.isSolid(), entersWater))) {
return;
}
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false, underwater))) {
if (data instanceof MatterCavern && (hasProtectedHydrology(x, y, z) || hydrologyKeeps(x, y, z, false, entersWater))) {
return;
}
Class<?> type = data instanceof NativeBlockState ? NativeBlockState.class : data.getClass();
@@ -319,7 +319,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
} else {
cell.put(type, data);
}
log.add(x, y, z, data, false, canopy, underwater);
log.add(x, y, z, data, false, canopy, entersWater);
}
@Override
@@ -416,7 +416,7 @@ final class ObjectDestinationTransaction implements ObjectPassPlacer {
&& !protectsSubterrain(x, y, z);
}
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, boolean underwater) {
private boolean hydrologyKeeps(int x, int y, int z, boolean solid, boolean entersWater) {
HydrologyRuntime runtime = hydrology();
if (runtime == null) {
return false;
@@ -429,7 +429,7 @@ 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)) {
if (solid && !entersWater && fillsWater(x, y, z)) {
return true;
}
if (role.wet()) {
@@ -8,7 +8,7 @@ public interface ObjectPassPlacer extends IObjectPlacer {
byte[] getCarvedColumn(int x, int z, int height);
default int beginObjectPlacement(boolean underwater) {
default int beginObjectPlacement(boolean entersWater) {
return -1;
}
@@ -32,7 +32,7 @@ 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 UNDERWATER_BIT = 1 << 10;
private static final int ENTERS_WATER_BIT = 1 << 10;
private static final int Y_SHIFT = 11;
private static final int MAXIMUM_Y = (1 << (31 - Y_SHIFT)) - 1;
@@ -91,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.underwater(logged) ? UNDERWATER_BIT : 0) | ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
| (log.entersWater(logged) ? ENTERS_WATER_BIT : 0) | ((log.z(logged) & 15) << 4) | (log.x(logged) & 15);
valueIndexes[position] = table.indexOf(log.value(logged));
}
values = table.values.toArray();
@@ -242,8 +242,8 @@ final class ObjectSourcePlan {
return (cell & CANOPY_BIT) != 0;
}
static boolean isUnderwater(int cell) {
return (cell & UNDERWATER_BIT) != 0;
static boolean entersWater(int cell) {
return (cell & ENTERS_WATER_BIT) != 0;
}
ObjectDestinationTransaction.Mutation mutationAt(int chunkX, int chunkZ, int index) {
@@ -307,6 +307,10 @@ public class IrisObjectPlacement {
return place.size() == 1 ? place.getFirst() : place.toString(", ");
}
public boolean entersWater() {
return underwater || onwater || forcePlace && !forcedByStructure;
}
public IrisObjectPlacement toPlacement(String... place) {
IrisObjectPlacement p = new IrisObjectPlacement();
p.setPlace(new KList<>(place));
@@ -61,7 +61,7 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
return null;
}
boolean painted = state.paintProjection != null;
if (entersWater(config)) {
if (config.entersWater()) {
return (painted
? IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, null, null, 0, 0, 0, state.paintSupport)
: IrisSurfaceSupport.intersectsUnevenWater(context.placer, context.x, context.z, config.getTranslate(),
@@ -75,10 +75,6 @@ final class PlacementModuleSurfaceSupport implements PlacementModule {
? "hydrology-support" : null;
}
private static boolean entersWater(IrisObjectPlacement config) {
return config.isUnderwater() || config.isOnwater() || config.isForcePlace() && !config.isForcedByStructure();
}
private static void warnImplausibleBedrockPlacement(IrisObject self, IObjectPlacer placer, IrisObjectPlacement config, int x, int y, int z) {
String key = self.getLoadKey();
String fingerprint = (key == null ? "<null>" : key) + "|" + config.getMode();
@@ -41,9 +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));
assertFalse(log.entersWater(0));
assertTrue(log.entersWater(98));
assertFalse(log.entersWater(6));
}
@Test
@@ -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;
@@ -296,6 +302,50 @@ public class ObjectDestinationTransactionTest {
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);
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 sourceCaptureCannotReplaceAuthoredRoomSolids() {
MantleWriter writer = writer();