Skip to content

Commit 6ce7e00

Browse files
Fix surface terrain in LOD chunks
There were two issues: - the slope for erosion was calculated incorrectly causing some shallow hills to erode unexpectedly - the "fill entirety of underground chunks with stone" LOD behavior did not account for air blocks right at the border
1 parent 1eeea43 commit 6ce7e00

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/server/terrain/biomes.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub const BlockStructure = struct { // MARK: BlockStructure
472472

473473
pub fn addSubTerranian(self: BlockStructure, chunk: *ServerChunk, startingDepth: i32, minDepth: i32, slope: i32, soilCreep: f32, x: i32, y: i32, seed: *u64) i32 {
474474
var depth = startingDepth;
475-
var remainingSkippedBlocks = @as(i32, @intFromFloat(@as(f32, @floatFromInt(slope))*soilCreep)) - chunk.super.pos.voxelSize;
475+
var remainingSkippedBlocks = @as(i32, @intFromFloat(@as(f32, @floatFromInt(slope))*soilCreep)) - 1;
476476
for(self.structure) |blockStack| {
477477
const total = blockStack.min + main.random.nextIntBounded(u32, seed, @as(u32, 1) + blockStack.max - blockStack.min);
478478
for(0..total) |_| {

src/server/terrain/chunkgen/TerrainGenerator.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn generate(worldSeed: u64, chunk: *main.chunk.ServerChunk, caveMap: CaveMap
3939
while(dy < main.chunk.chunkSize + 1) : (dy += 1) {
4040
const height = biomeMap.getSurfaceHeight(chunk.super.pos.wx +% dx*chunk.super.pos.voxelSize, chunk.super.pos.wy +% dy*chunk.super.pos.voxelSize);
4141
maxHeight = @max(maxHeight, height);
42-
minHeight = @min(minHeight, height);
42+
minHeight = @min(minHeight, height - chunk.super.pos.voxelSize);
4343
}
4444
}
4545
if(minHeight > chunk.super.pos.wz +| chunk.super.width) {
@@ -81,10 +81,10 @@ pub fn generate(worldSeed: u64, chunk: *main.chunk.ServerChunk, caveMap: CaveMap
8181
const move = direction*@as(Vec3i, @splat(@intCast(chunk.super.pos.voxelSize)));
8282
if(caveMap.isSolid(x + move[0], y + move[1], z + move[2])) {
8383
const diff = caveMap.findTerrainChangeAbove(x + move[0], y + move[1], z + move[2]) - chunk.super.pos.voxelSize - surfaceBlock;
84-
maxUp = @max(maxUp, diff);
84+
maxUp = @max(maxUp, diff >> chunk.super.voxelSizeShift);
8585
} else {
8686
const diff = caveMap.findTerrainChangeBelow(x + move[0], y + move[1], z + move[2]) - surfaceBlock;
87-
maxDown = @max(maxDown, -diff);
87+
maxDown = @max(maxDown, -diff >> chunk.super.voxelSizeShift);
8888
}
8989
}
9090
const slope = @min(maxUp, maxDown);

0 commit comments

Comments
 (0)