Restore the subsurface layers: real above_preliminary_surface and surface depth

Every land column was one block of grass sitting straight on stone. No dirt
under grass, no sandstone under sand, nothing. Two stubs did it together:

above_preliminary_surface compared blockY against the column's actual top block,
so of every position in the column exactly one passed -- and the entire
biome-specific half of the surface rule tree hangs under that condition.
Vanilla compares against a minimum surface level: the preliminary surface level
sampled at the four corners of the 16-block cell, bilinearly interpolated, plus
the surface depth less 8. That is about twenty blocks of reach on ordinary
terrain, which is what the biome subtree is written against.

Surface depth was hardcoded to 0. Vanilla is surfaceNoise*2.75 + 3 with a
per-column jitter, so it comes out around three; it sets how thick the band is
and feeds every add_surface_depth term in the tree. Zero collapsed them all.

Also samples surface_secondary, so stone_depth's secondary_depth_range widens
its band instead of being parsed and dropped.

Grass columns now read grass, two to four dirt, stone -- the histogram over 256
columns is {2: 223, 3: 33}, against vanilla's 2..4. gendump prints it and fails
if the band collapses again; TestGrassColumnsHaveDirt guards it in the suite.
This commit is contained in:
Master290 2026-07-27 02:15:14 +03:00
parent e77fe3dc07
commit 1083e47211
9 changed files with 231 additions and 32 deletions

View file

@ -199,7 +199,7 @@ func fillVanillaColumn(od *worldgen.OverworldDensity, aq *worldgen.Aquifer, flui
rng := newColumnRand(wx, wz, int(seed))
if rule != nil {
applySurfaceRule(out, wx, wz, SeaLevel, MinY, biomeName, rule, rng, top)
applySurfaceRule(od, out, wx, wz, SeaLevel, MinY, biomeName, rule, rng)
} else {
fillLegacySurface(out, top, beach, deepWater, rng)
}
@ -241,7 +241,7 @@ func substance(aq *worldgen.Aquifer, fluidPicker worldgen.FluidPicker, x, y, z i
// One *rand.Rand is created per column (not per block) — bandlands/gradient
// consume from it sequentially, which is correct because vanilla seeds those
// per-column too. This avoids ~98k rand.New allocations per chunk.
func applySurfaceRule(out *[WorldHeight]uint16, wx, wz, seaLevel, minY int, biomeName string, rule worldgen.SurfaceRule, rng chunkRand, topSolid int) {
func applySurfaceRule(od *worldgen.OverworldDensity, out *[WorldHeight]uint16, wx, wz, seaLevel, minY int, biomeName string, rule worldgen.SurfaceRule, rng chunkRand) {
top := -1
for i := WorldHeight - 1; i >= 0; i-- {
if out[i] != StateAir {
@ -254,23 +254,23 @@ func applySurfaceRule(out *[WorldHeight]uint16, wx, wz, seaLevel, minY int, biom
}
// One per-column RNG for all surface rules in this column.
colRng := rng.toRand()
// Surface noise sample (the "minecraft:surface" noise used by noise_threshold
// conditions). Cheap deterministic value derived from the column so the
// rule's coarse_dirt/terracotta bands vary per column.
surfaceNoise := colRng.Float64()*2 - 1 // [-1, 1]
// Column-constant surface quantities, computed once per column exactly as
// SurfaceRules.Context.updateXZ does.
surfaceDepth := od.Surface.SurfaceDepth(wx, wz)
// Reuse one context across the column (mutated per block) to avoid ~98k
// heap allocations per chunk; the fields that vary per block are set inside
// the loop, the rest are column-constant.
sctx := &worldgen.SurfaceContext{
X: wx,
Z: wz,
SeaLevel: seaLevel,
BiomeName: biomeName,
MinY: minY,
SurfaceNoise: surfaceNoise,
SurfaceDepth: 0,
PreliminarySurface: minY + topSolid,
Rng: colRng,
X: wx,
Z: wz,
SeaLevel: seaLevel,
BiomeName: biomeName,
MinY: minY,
SurfaceNoise: od.Surface.Noise(wx, wz),
SurfaceSecondary: od.Surface.SurfaceSecondary(wx, wz),
SurfaceDepth: surfaceDepth,
MinSurfaceLevel: od.MinSurfaceLevelAt(wx, wz, surfaceDepth),
Rng: colRng,
}
stoneDepthAbove := 0
waterHeight := worldgen.NoWaterAbove