Natural spawning reads a kept WORLD_SURFACE heightmap

Every spawn attempt (`NaturalSpawner.getRandomPosWithin`) asks for the
WORLD_SURFACE height of a column. Horizon scanned the column down for it
each time, a chunk-map lookup and a block-name compare per block. Vanilla
reads the chunk's heightmap.

Chunks now keep WORLD_SURFACE: built on the first read, and dropped by a
`set` that can move a column's surface (`Heightmap.update` leaves writes
two or more below it alone). Natural spawning, the spawn rules' bat check
and beacons read it.

The unused `heights` field (never written after `Chunk::empty`) is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-18 15:11:04 +02:00
parent 6e09dbe10a
commit e8247df5f0
6 changed files with 118 additions and 18 deletions
@@ -589,11 +589,7 @@ impl SpawnLevel for super::MobWorld<'_> {
self.sea_level
}
fn world_surface(&self, x: i32, z: i32) -> i32 {
let top = crate::chunk::MIN_Y + crate::chunk::HEIGHT;
(crate::chunk::MIN_Y..top)
.rev()
.find(|&y| !self.facts.is_air(self.world.block(x, y, z)))
.map_or(crate::chunk::MIN_Y, |y| y + 1)
self.world.world_surface(x, z, |id| self.facts.is_air(id))
}
fn peaceful(&self) -> bool {
self.difficulty.effective == 0.0