feat(world-gen): implement worm cave pass in CaveCarver

This commit is contained in:
2026-06-01 15:32:56 +02:00
parent 070bdfeac1
commit 15be8f6059
2 changed files with 186 additions and 1 deletions

View File

@@ -115,4 +115,72 @@ public class CaveCarverTests
Assert.True(airAtSeamC1 > 0, "c1 seam column had no air — carve too sparse?");
Assert.True(airAtSeamC2 > 0, "c2 seam column had no air — carve too sparse?");
}
[Fact]
public void WormCaves_IsDeterministic_ForSameSeedAndChunkPos()
{
var c1 = new CaveCarver(seed: 999, Blocks, Cfg);
var c2 = new CaveCarver(seed: 999, Blocks, Cfg);
Chunk a = MakeStoneChunk();
Chunk b = MakeStoneChunk();
c1.CarveWormCaves(a, new Vector3i(0, 4, 0));
c2.CarveWormCaves(b, new Vector3i(0, 4, 0));
for (int x = 0; x < Chunk.Size; x++)
for (int y = 0; y < Chunk.Size; y++)
for (int z = 0; z < Chunk.Size; z++)
Assert.Equal(a[x, y, z], b[x, y, z]);
}
[Fact]
public void WormCaves_OnlyConvertsSolidToAir_NeverWater()
{
var carver = new CaveCarver(seed: 999, Blocks, Cfg);
Chunk c = MakeStoneChunk();
// Set every voxel along a diagonal to water — must survive.
for (int i = 0; i < Chunk.Size; i++)
c[i, i, i] = Blocks.Water.Id;
carver.CarveWormCaves(c, new Vector3i(0, 4, 0));
for (int i = 0; i < Chunk.Size; i++)
Assert.Equal(Blocks.Water.Id, c[i, i, i]);
}
[Fact]
public void WormCaves_RespectsBedrockFloor()
{
var carver = new CaveCarver(seed: 999, Blocks, Cfg);
Chunk c = MakeStoneChunk();
carver.CarveWormCaves(c, new Vector3i(0, 0, 0)); // worldY = 0..15
for (int x = 0; x < Chunk.Size; x++)
for (int z = 0; z < Chunk.Size; z++)
Assert.Equal(Blocks.Stone.Id, c[x, 0, z]); // bedrock untouched
}
[Fact]
public void WormCaves_SeamContinuity_VoxelAtSharedWorldCoord_IsSame()
{
var carver = new CaveCarver(seed: 999, Blocks, Cfg);
Chunk c1 = MakeStoneChunk();
Chunk c2 = MakeStoneChunk();
carver.CarveWormCaves(c1, new Vector3i(0, 4, 0));
carver.CarveWormCaves(c2, new Vector3i(1, 4, 0));
int airC1Seam = 0, airC2Seam = 0;
for (int y = 1; y < Chunk.Size; y++)
for (int z = 0; z < Chunk.Size; z++)
{
if (c1[15, y, z] == Blocks.Air.Id) airC1Seam++;
if (c2[0, y, z] == Blocks.Air.Id) airC2Seam++;
}
bool bothEmpty = airC1Seam == 0 && airC2Seam == 0;
bool bothCarved = airC1Seam > 0 && airC2Seam > 0;
Assert.True(bothEmpty || bothCarved,
$"seam mismatch: c1={airC1Seam}, c2={airC2Seam}");
}
}