feat(world-gen): implement noise-threshold cave pass
This commit is contained in:
@@ -28,6 +28,34 @@ public sealed class CaveCarver
|
||||
|
||||
public void Carve(VoxelChunk chunk, Vector3i chunkPos)
|
||||
{
|
||||
// Implemented in Tasks 5 and 6.
|
||||
this.CarveNoiseCaves(chunk, chunkPos);
|
||||
// Worm pass added in Task 6.
|
||||
}
|
||||
|
||||
// Per-voxel 3D simplex threshold. Public for direct testability,
|
||||
// matching the pattern of WorldGenerator.BlockAt.
|
||||
public void CarveNoiseCaves(VoxelChunk chunk, Vector3i chunkPos)
|
||||
{
|
||||
int baseX = chunkPos.X * VoxelChunk.Size;
|
||||
int baseY = chunkPos.Y * VoxelChunk.Size;
|
||||
int baseZ = chunkPos.Z * VoxelChunk.Size;
|
||||
|
||||
for (int x = 0; x < VoxelChunk.Size; x++)
|
||||
for (int y = 0; y < VoxelChunk.Size; y++)
|
||||
for (int z = 0; z < VoxelChunk.Size; z++)
|
||||
{
|
||||
int worldY = baseY + y;
|
||||
if (worldY <= 0) continue;
|
||||
|
||||
ushort id = chunk[x, y, z];
|
||||
if (id == this._blocks.Air.Id) continue;
|
||||
if (id == this._blocks.Water.Id) continue;
|
||||
|
||||
float density = this._caveNoise.GetNoise(baseX + x, worldY, baseZ + z);
|
||||
if (density < this._cfg.CaveNoiseThreshold)
|
||||
{
|
||||
chunk[x, y, z] = this._blocks.Air.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user