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:
Brian Neumann-Fopiano committed 2026-11-02 05:46:52 -05:00
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]);
}
@@ -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);