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
|
|
@ -153,10 +153,11 @@ func (t *Template) Place(cw ChunkWriter, cx, cz int32, originX, originY, originZ
|
||||||
if wx >= minX && wx <= maxX && wz >= minZ && wz <= maxZ {
|
if wx >= minX && wx <= maxX && wz >= minZ && wz <= maxZ {
|
||||||
lx := wx - minX
|
lx := wx - minX
|
||||||
lz := wz - minZ
|
lz := wz - minZ
|
||||||
// Only place if not air, or if you want structures to hollow out space, place air too.
|
// 14851 = minecraft:structure_void
|
||||||
// Jigsaw structures use structure_void to mean "don't overwrite", and air to mean "overwrite with air".
|
// 21736 = minecraft:jigsaw
|
||||||
// Since we fallback to 0 for unknown blocks, we need to be careful.
|
if b.State == 14851 || b.State == 21736 {
|
||||||
// For now, place everything.
|
continue
|
||||||
|
}
|
||||||
cw.SetBlock(lx, wy, lz, b.State)
|
cw.SetBlock(lx, wy, lz, b.State)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,37 @@ func PlaceStructures(cw ChunkWriter, od *OverworldDensity, cx, cz int32, seed in
|
||||||
if originCx%spacing == 0 && originCz%spacing == 0 {
|
if originCx%spacing == 0 && originCz%spacing == 0 {
|
||||||
t := GetTemplate("plains_small_house_1")
|
t := GetTemplate("plains_small_house_1")
|
||||||
if t != nil {
|
if t != nil {
|
||||||
baseY := -64 // MinY
|
// Deterministically evaluate the surface height at the origin so the structure
|
||||||
if dx == 0 && dz == 0 {
|
// is flush with the ground and consistent across all chunks.
|
||||||
baseY += surfTop[8][8] + 1
|
baseY := EvaluateHeight(od, originCx*16+8, originCz*16+8)
|
||||||
} else {
|
|
||||||
// sample height at center of origin chunk
|
// Only place if it's above sea level (so we don't spawn houses in the ocean)
|
||||||
_ = SampleColumn2D(od, 63, originCx*16+8, originCz*16+8)
|
if baseY >= 63 {
|
||||||
// We don't have a fast exact heightmap lookup without running the column,
|
// Offset by -1 so the floor embeds into the grass, rather than floating on it.
|
||||||
// but this is acceptable for a quick prototype.
|
t.Place(cw, cx, cz, originCx*16+8, baseY-1, originCz*16+8)
|
||||||
baseY = 70
|
|
||||||
}
|
}
|
||||||
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
|
||||||
|
}
|
||||||
|
|
|
||||||
13
scratch.go
13
scratch.go
|
|
@ -1,13 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"regionio/internal/worldgen"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
tmpl, _ := worldgen.LoadTemplate("internal/worldgen/data/structure/village/plains/houses/plains_small_house_1.nbt")
|
|
||||||
for i, b := range tmpl.Palette {
|
|
||||||
fmt.Printf("Palette[%d] = %d\n", i, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BIN
world/region/r.-1.-1.mca
Normal file
BIN
world/region/r.-1.-1.mca
Normal file
Binary file not shown.
BIN
world/region/r.-1.0.mca
Normal file
BIN
world/region/r.-1.0.mca
Normal file
Binary file not shown.
BIN
world/region/r.0.-1.mca
Normal file
BIN
world/region/r.0.-1.mca
Normal file
Binary file not shown.
BIN
world/region/r.0.0.mca
Normal file
BIN
world/region/r.0.0.mca
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue