mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Transition water caps
- Saved and blended columns find solid layers that cap water at the water head - Surface search passes over a water cap to the ground below it - A capped column keeps its fluid height at the top of the cap - A painted cap counts only where the blended column keeps the same blocks - Saved terrain sources report their water surface - Displacement fluid keys come from the first fluid at or below the fluid height - Empty fluid keys never win the fluid blend
This commit is contained in:
1 parent
c2eca3e6bd
commit
2462330787
11 files changed
+533
-58
No files matched your search
+40
-5
@@ -43,14 +43,14 @@ public final class IrisTransitionGeometryActuator extends EngineAssignedComponen
|
||||
if (plan == null || !plan.hasTransitionAtChunk(x >> 4, z >> 4)) {
|
||||
return;
|
||||
}
|
||||
GeometrySource source = new GeometrySource(blocks, biomes, getEngine().getMinHeight(), context);
|
||||
GeometrySource source = new GeometrySource(x, z, blocks, biomes, getEngine().getMinHeight(), context);
|
||||
blendGeometry(x, z, blocks, context, source, plan);
|
||||
}
|
||||
|
||||
public static SavedTerrainChunk capture(int x, int z, Hunk<NativeBlockState> blocks,
|
||||
Hunk<NativeBiome> biomes, int minimumY,
|
||||
ChunkContext context, boolean boundaryOnly) throws IOException {
|
||||
GeometrySource source = new GeometrySource(blocks, biomes, minimumY, context);
|
||||
GeometrySource source = new GeometrySource(x, z, blocks, biomes, minimumY, context);
|
||||
return boundaryOnly
|
||||
? SavedTerrainChunk.captureBoundary(x >> 4, z >> 4, minimumY, blocks.getHeight(), "minecraft:noise", source)
|
||||
: SavedTerrainChunk.capture(x >> 4, z >> 4, minimumY, blocks.getHeight(), "minecraft:noise", source);
|
||||
@@ -74,8 +74,10 @@ public final class IrisTransitionGeometryActuator extends EngineAssignedComponen
|
||||
if (blended == current) {
|
||||
continue;
|
||||
}
|
||||
double expectedFloor = context.getRoundedHeight(localX, localZ);
|
||||
int floor = blended.surfaceOffsetNear(expectedFloor);
|
||||
int ground = context.getRoundedHeight(localX, localZ);
|
||||
BoundaryColumnGeometry.WaterCap cap = paintedCap(current, blended, ground,
|
||||
waterHead(complex, x + localX, z + localZ, current.height()));
|
||||
int floor = blended.surfaceOffsetNear(ground, cap);
|
||||
List<BoundaryColumnGeometry.Voxel> voxels = blended.voxels();
|
||||
for (int offset = 0; offset < voxels.size(); offset++) {
|
||||
BoundaryColumnGeometry.Voxel voxel = voxels.get(offset);
|
||||
@@ -95,6 +97,9 @@ public final class IrisTransitionGeometryActuator extends EngineAssignedComponen
|
||||
&& voxels.get(fluidHeight + 1).phase() == BoundaryColumnGeometry.Phase.FLUID) {
|
||||
fluidHeight++;
|
||||
}
|
||||
if (blended.capsWater(cap, floor)) {
|
||||
fluidHeight = cap.top();
|
||||
}
|
||||
if (fluidHeight == floor) {
|
||||
fluidHeight = -1;
|
||||
}
|
||||
@@ -105,7 +110,29 @@ public final class IrisTransitionGeometryActuator extends EngineAssignedComponen
|
||||
}
|
||||
}
|
||||
|
||||
private static BoundaryColumnGeometry.WaterCap paintedCap(BoundaryColumnGeometry painted, BoundaryColumnGeometry blended,
|
||||
int ground, int waterHead) {
|
||||
BoundaryColumnGeometry.WaterCap cap = painted.waterCap(ground, waterHead);
|
||||
if (!cap.present()) {
|
||||
return cap;
|
||||
}
|
||||
int top = Math.min(cap.top() + 1, painted.height() - 1);
|
||||
for (int offset = cap.bottom(); offset <= top; offset++) {
|
||||
int y = painted.minimumY() + offset;
|
||||
if (!painted.voxelAt(y).equals(blended.voxelAt(y))) {
|
||||
return BoundaryColumnGeometry.WaterCap.none();
|
||||
}
|
||||
}
|
||||
return cap;
|
||||
}
|
||||
|
||||
private static int waterHead(IrisComplex complex, int blockX, int blockZ, int height) {
|
||||
return Math.clamp(Math.round(complex.getWaterHeadStream().getDouble(blockX, blockZ)), -1, height - 1);
|
||||
}
|
||||
|
||||
private static final class GeometrySource implements SavedTerrainChunk.VoxelSource {
|
||||
private final int originX;
|
||||
private final int originZ;
|
||||
private final Hunk<NativeBlockState> blocks;
|
||||
private final Hunk<NativeBiome> biomes;
|
||||
private final int minimumY;
|
||||
@@ -116,7 +143,10 @@ public final class IrisTransitionGeometryActuator extends EngineAssignedComponen
|
||||
private NativeBlockState lastState;
|
||||
private BoundaryColumnGeometry.Voxel lastVoxel;
|
||||
|
||||
private GeometrySource(Hunk<NativeBlockState> blocks, Hunk<NativeBiome> biomes, int minimumY, ChunkContext context) {
|
||||
private GeometrySource(int originX, int originZ, Hunk<NativeBlockState> blocks, Hunk<NativeBiome> biomes,
|
||||
int minimumY, ChunkContext context) {
|
||||
this.originX = originX;
|
||||
this.originZ = originZ;
|
||||
this.blocks = blocks;
|
||||
this.biomes = biomes;
|
||||
this.minimumY = minimumY;
|
||||
@@ -178,6 +208,11 @@ public final class IrisTransitionGeometryActuator extends EngineAssignedComponen
|
||||
return OptionalInt.of(Math.max(0, Math.min(blocks.getHeight() - 1, context.getRoundedHeight(localX, localZ))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt waterSurface(int localX, int localZ) {
|
||||
return OptionalInt.of(waterHead(context.getComplex(), originX + localX, originZ + localZ, blocks.getHeight()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String biome(int localX, int worldY, int localZ) throws IOException {
|
||||
NativeBiome biome = biomes.getRaw(localX, worldY - minimumY, localZ);
|
||||
|
||||
@@ -139,33 +139,73 @@ public final class BoundaryColumnGeometry implements NativeBlockColumn {
|
||||
return List.copyOf(values);
|
||||
}
|
||||
|
||||
public int surfaceOffsetNear(double expectedOffset) {
|
||||
public WaterCap waterCap(int groundOffset, int waterSurfaceOffset) {
|
||||
if (waterSurfaceOffset <= groundOffset || waterSurfaceOffset < 0 || waterSurfaceOffset >= height()
|
||||
|| waterSurfaceOffset + 1 < height() && voxelAtOffset(waterSurfaceOffset + 1).phase() != Phase.AIR) {
|
||||
return WaterCap.none();
|
||||
}
|
||||
int lowest = Math.max(0, groundOffset + 1);
|
||||
int bottom = waterSurfaceOffset + 1;
|
||||
for (int run = runAt(waterSurfaceOffset); run >= 0 && bottom > lowest && isCapMaterial(runVoxel(run)); run--) {
|
||||
bottom = Math.max(lowest, run == 0 ? 0 : runEnds[run - 1]);
|
||||
}
|
||||
return bottom > waterSurfaceOffset ? WaterCap.none() : new WaterCap(bottom, waterSurfaceOffset);
|
||||
}
|
||||
|
||||
public boolean capsWater(WaterCap cap, int floorOffset) {
|
||||
if (!cap.present() || cap.top() <= floorOffset) {
|
||||
return false;
|
||||
}
|
||||
int below = cap.bottom() - 1;
|
||||
return below == floorOffset || below >= 0 && !voxelAtOffset(below).fluidStateKey().isEmpty();
|
||||
}
|
||||
|
||||
public String fluidStateKeyAtOrBelow(int surfaceOffset, int floorOffset) {
|
||||
for (int offset = Math.min(surfaceOffset, height() - 1); offset > floorOffset && offset >= 0; offset--) {
|
||||
String fluidStateKey = voxelAtOffset(offset).fluidStateKey();
|
||||
if (!fluidStateKey.isEmpty()) {
|
||||
return fluidStateKey;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public int surfaceOffsetNear(double expectedOffset, WaterCap cap) {
|
||||
Objects.requireNonNull(cap, "Water cap");
|
||||
if (!Double.isFinite(expectedOffset) || height() == 0) {
|
||||
throw new IllegalArgumentException("A surface reference requires finite height and nonempty geometry");
|
||||
}
|
||||
int nearest = -1;
|
||||
double nearestDistance = Double.POSITIVE_INFINITY;
|
||||
for (int run = 0; run + 1 < runEnds.length; run++) {
|
||||
Voxel current = palette.get(paletteIndices[run]);
|
||||
Voxel above = palette.get(paletteIndices[run + 1]);
|
||||
if (current.phase() != Phase.SOLID || current.protectedContent()
|
||||
|| above.phase() == Phase.SOLID && !above.protectedContent()) {
|
||||
int offset = runEnds[run] - 1;
|
||||
if (!isTerrain(offset, runVoxel(run), cap) || isTerrain(offset + 1, runVoxel(run + 1), cap)) {
|
||||
continue;
|
||||
}
|
||||
int offset = runEnds[run] - 1;
|
||||
double distance = Math.abs(offset - expectedOffset);
|
||||
if (distance < nearestDistance) {
|
||||
nearest = offset;
|
||||
nearestDistance = distance;
|
||||
}
|
||||
}
|
||||
int belowCap = cap.bottom() - 1;
|
||||
if (cap.present() && belowCap >= 0 && cap.bottom() < height() && isTerrain(belowCap, voxelAtOffset(belowCap), cap)) {
|
||||
double distance = Math.abs(belowCap - expectedOffset);
|
||||
if (distance < nearestDistance || distance == nearestDistance && belowCap < nearest) {
|
||||
nearest = belowCap;
|
||||
}
|
||||
}
|
||||
if (nearest >= 0) {
|
||||
return nearest;
|
||||
}
|
||||
for (int run = runEnds.length - 1; run >= 0; run--) {
|
||||
Voxel current = palette.get(paletteIndices[run]);
|
||||
if (current.phase() == Phase.SOLID && !current.protectedContent()) {
|
||||
return runEnds[run] - 1;
|
||||
Voxel current = runVoxel(run);
|
||||
if (current.phase() != Phase.SOLID || current.protectedContent()) {
|
||||
continue;
|
||||
}
|
||||
int top = cap.contains(runEnds[run] - 1) ? belowCap : runEnds[run] - 1;
|
||||
if (top >= (run == 0 ? 0 : runEnds[run - 1])) {
|
||||
return top;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -220,6 +260,18 @@ public final class BoundaryColumnGeometry implements NativeBlockColumn {
|
||||
return index >= 0 ? index : -index - 1;
|
||||
}
|
||||
|
||||
private static boolean isTerrain(int offset, Voxel voxel, WaterCap cap) {
|
||||
return voxel.phase() == Phase.SOLID && !voxel.protectedContent() && !cap.contains(offset);
|
||||
}
|
||||
|
||||
private static boolean isCapMaterial(Voxel voxel) {
|
||||
return voxel.phase() == Phase.SOLID && !voxel.protectedContent() && voxel.fluidStateKey().isEmpty();
|
||||
}
|
||||
|
||||
private Voxel voxelAtOffset(int offset) {
|
||||
return palette.get(paletteIndices[runAt(offset)]);
|
||||
}
|
||||
|
||||
private void validate() {
|
||||
if (palette.size() > Short.MAX_VALUE + 1 || runEnds.length > MAXIMUM_HEIGHT
|
||||
|| runEnds.length != paletteIndices.length) {
|
||||
@@ -333,6 +385,22 @@ public final class BoundaryColumnGeometry implements NativeBlockColumn {
|
||||
FLUID
|
||||
}
|
||||
|
||||
public record WaterCap(int bottom, int top) {
|
||||
private static final WaterCap NONE = new WaterCap(0, -1);
|
||||
|
||||
public static WaterCap none() {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public boolean present() {
|
||||
return bottom <= top;
|
||||
}
|
||||
|
||||
public boolean contains(int offset) {
|
||||
return offset >= bottom && offset <= top;
|
||||
}
|
||||
}
|
||||
|
||||
public record Voxel(String stateKey, Phase phase, String fluidStateKey, boolean protectedContent) {
|
||||
public Voxel {
|
||||
Objects.requireNonNull(stateKey, "Block state key");
|
||||
|
||||
@@ -91,10 +91,15 @@ public final class SavedTerrainChunk {
|
||||
BoundaryColumnGeometry geometry = scan.runs.build(minimumY);
|
||||
OptionalInt groundSurface = source.groundSurface(x, z);
|
||||
if (groundSurface.isPresent()) {
|
||||
floor = geometry.surfaceOffsetNear(groundSurface.getAsInt());
|
||||
int ground = groundSurface.getAsInt();
|
||||
BoundaryColumnGeometry.WaterCap cap = geometry.waterCap(ground, source.waterSurface(x, z).orElse(ground));
|
||||
floor = geometry.surfaceOffsetNear(ground, cap);
|
||||
if (floor < 0 || floor >= height) {
|
||||
throw new IOException("Natural terrain ground surface is outside the chunk height");
|
||||
}
|
||||
if (geometry.capsWater(cap, floor)) {
|
||||
fluid = cap.top();
|
||||
}
|
||||
surface = Math.max(floor, fluid);
|
||||
}
|
||||
columns.add(new TerrainBoundarySignature(
|
||||
@@ -200,6 +205,10 @@ public final class SavedTerrainChunk {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
default OptionalInt waterSurface(int localX, int localZ) {
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
BoundaryColumnGeometry.Voxel voxel(int localX, int worldY, int localZ) throws IOException;
|
||||
|
||||
String biome(int localX, int worldY, int localZ) throws IOException;
|
||||
|
||||
@@ -153,8 +153,8 @@ public final class TransitionDisplacementField {
|
||||
}
|
||||
residual = signature.oceanFloorHeight() - nativeHeight;
|
||||
if (wet) {
|
||||
int y = signature.geometry().minimumY() + signature.fluidHeight().getAsInt();
|
||||
fluidKey = signature.geometry().voxelAt(y).fluidStateKey();
|
||||
fluidKey = signature.geometry().fluidStateKeyAtOrBelow(signature.fluidHeight().getAsInt(),
|
||||
signature.oceanFloorHeight());
|
||||
}
|
||||
}
|
||||
column.total += weight;
|
||||
@@ -164,7 +164,7 @@ public final class TransitionDisplacementField {
|
||||
column.wetHeight += weight * signature.fluidHeight().getAsInt();
|
||||
column.minimumWetHeight = Math.min(column.minimumWetHeight, signature.fluidHeight().getAsInt());
|
||||
column.maximumWetHeight = Math.max(column.maximumWetHeight, signature.fluidHeight().getAsInt());
|
||||
if (weight > column.fluidKeyWeight) {
|
||||
if (weight > column.fluidKeyWeight && !fluidKey.isEmpty()) {
|
||||
column.fluidKeyWeight = weight;
|
||||
column.fluidKey = fluidKey;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user