Fix structures tearing apart and floating due to inconsistent baseY calculations
This commit is contained in:
parent
788983dc88
commit
8f7cacf9d9
7 changed files with 33 additions and 27 deletions
|
|
@ -14,19 +14,37 @@ func PlaceStructures(cw ChunkWriter, od *OverworldDensity, cx, cz int32, seed in
|
|||
if originCx%spacing == 0 && originCz%spacing == 0 {
|
||||
t := GetTemplate("plains_small_house_1")
|
||||
if t != nil {
|
||||
baseY := -64 // MinY
|
||||
if dx == 0 && dz == 0 {
|
||||
baseY += surfTop[8][8] + 1
|
||||
} else {
|
||||
// sample height at center of origin chunk
|
||||
_ = SampleColumn2D(od, 63, originCx*16+8, originCz*16+8)
|
||||
// We don't have a fast exact heightmap lookup without running the column,
|
||||
// but this is acceptable for a quick prototype.
|
||||
baseY = 70
|
||||
// Deterministically evaluate the surface height at the origin so the structure
|
||||
// is flush with the ground and consistent across all chunks.
|
||||
baseY := EvaluateHeight(od, originCx*16+8, originCz*16+8)
|
||||
|
||||
// Only place if it's above sea level (so we don't spawn houses in the ocean)
|
||||
if baseY >= 63 {
|
||||
// Offset by -1 so the floor embeds into the grass, rather than floating on it.
|
||||
t.Place(cw, cx, cz, originCx*16+8, baseY-1, originCz*16+8)
|
||||
}
|
||||
t.Place(cw, cx, cz, originCx*16+8, baseY, originCz*16+8)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// EvaluateHeight computes the top solid block Y coordinate at (wx, wz).
|
||||
func EvaluateHeight(od *OverworldDensity, wx, wz int) int {
|
||||
interp := make([]float64, len(od.Interpolated))
|
||||
|
||||
// Binary search or linear scan. A linear scan from 120 down to 0 is fast enough.
|
||||
for y := 120; y >= -64; y-- {
|
||||
ctx := FunctionContext{X: float64(wx), Y: float64(y), Z: float64(wz)}
|
||||
// Since we don't have the cell grid, we just evaluate the interpolated nodes directly!
|
||||
for n, node := range od.Interpolated {
|
||||
interp[n] = node.Inner.Compute(ctx)
|
||||
}
|
||||
ctx = ctx.WithInterp(interp)
|
||||
|
||||
if od.Final.Compute(ctx) > 0 {
|
||||
return y
|
||||
}
|
||||
}
|
||||
return 64
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue