Biome-aware surface rules from the vanilla rule tree

Replaces the biome-blind fillVanillaColumn heuristics with a full
interpreter for the overworld surface_rule tree (already embedded in
overworld.json): block/sequence/condition/bandlands rules plus all 11
condition tests (biome, steep, hole, water, temperature, y_above,
stone_depth, noise_threshold, not, vertical_gradient,
above_preliminary_surface).

- worldgen/blockids.go: name(+Properties)→network-ID table for surface
  blocks (grass/sand/terracotta/mycelium/podzol/coarse_dirt/sandstone/
  calcite/snow/ice/...), with snowy property variants.
- worldgen/surface.go: rule-tree parser + interpreter + SurfaceContext;
  LoadOverworldSurfaceRule caches the seed-independent tree.
- loader.go: OverworldDensity.SurfaceRule() exposes the parsed tree.
- biome_lookup.go: BiomeNameAt returns the biome name for biome tests.
- vanilla.go: samples the 2D climate + biome before column fill, threads
  the rule tree and biome name into fillVanillaColumn, and applies it
  top-down with stone as the default for non-matching (deeper) blocks.
  The above_preliminary_surface gate uses an inclusive bound so the top
  solid block reaches the biome dispatch.
- Performance: one per-column RNG and a reused SurfaceContext keep the
  overhead to ~+13ms/chunk (71ms vs 58ms baseline), within the gate.
This commit is contained in:
Master290 2026-06-24 19:44:07 +03:00
parent d3142e7687
commit 4dcf938a85
8 changed files with 934 additions and 26 deletions

View file

@ -0,0 +1,99 @@
package worldgen
// blockids.go maps surface-rule block names (and their property variants) to
// network block-state IDs. The IDs are captured verbatim from the 26.1.2
// generated blocks.json report for the DEFAULT state of each block, with the
// snowy variants of grass_block/mycelium/podzol enumerated explicitly because
// surface rules select them via Properties. Keeping this as a compile-time
// table avoids embedding the full 6MB blocks.json.
//
// Default-state IDs (from generated/reports/blocks.json, 26.1.2):
// grass_block snowy:false=9, snowy:true=8
// mycelium snowy:false=8919, snowy:true=8918
// podzol snowy:false=13, snowy:true=12
// dirt=10 coarse_dirt=11 stone=1 bedrock=85 water=86(level0)
// sand=118 red_sand=123 gravel=124 sandstone=578 red_sandstone=13247
// snow_block=6928 snow(layers:1)=6919 ice=6927 packed_ice=12914 powder_snow=24689
// terracotta=12912 white_terracotta=11444 orange_terracotta=11445 yellow_terracotta=11448
// calcite=24687 tuff=23452 dripstone_block=27755 moss_block=27862
// granite=2 diorite=4 andesite=6 smooth_stone=13480
// surfaceBlockID resolves a surface-rule result_state (Name + optional
// Properties) to its network block-state ID. It handles the snowy property on
// snowable blocks and the layers property on snow; unknown blocks return 0
// (air) so a missing entry is visually obvious rather than crashing.
func surfaceBlockID(name string, props map[string]string) uint16 {
switch name {
case "minecraft:stone":
return 1
case "minecraft:granite":
return 2
case "minecraft:diorite":
return 4
case "minecraft:andesite":
return 6
case "minecraft:grass_block":
if props["snowy"] == "true" {
return 8
}
return 9
case "minecraft:dirt":
return 10
case "minecraft:coarse_dirt":
return 11
case "minecraft:podzol":
if props["snowy"] == "true" {
return 12
}
return 13
case "minecraft:bedrock":
return 85
case "minecraft:water":
return 86
case "minecraft:sand":
return 118
case "minecraft:red_sand":
return 123
case "minecraft:gravel":
return 124
case "minecraft:sandstone":
return 578
case "minecraft:red_sandstone":
return 13247
case "minecraft:snow_block":
return 6928
case "minecraft:snow":
// snow has a "layers" property 1..8; default layer 1 = 6919.
return 6919
case "minecraft:ice":
return 6927
case "minecraft:packed_ice":
return 12914
case "minecraft:powder_snow":
return 24689
case "minecraft:mycelium":
if props["snowy"] == "true" {
return 8918
}
return 8919
case "minecraft:terracotta":
return 12912
case "minecraft:white_terracotta":
return 11444
case "minecraft:orange_terracotta":
return 11445
case "minecraft:yellow_terracotta":
return 11448
case "minecraft:calcite":
return 24687
case "minecraft:tuff":
return 23452
case "minecraft:dripstone_block":
return 27755
case "minecraft:moss_block":
return 27862
case "minecraft:smooth_stone":
return 13480
}
return 0
}