Scan for the motion-blocking top from the world surface, not the build limit

getHeightmapPos(MOTION_BLOCKING) walked every column from y 319 down,
one block lookup per y. Each precipitation roll (3 in 48 per ticking
chunk per tick) and each isRainingAt paid for it: with the chunks of 10
players ticking it was most of tick_blocks. Only air lies above the
WORLD_SURFACE heightmap the chunk already keeps, and air neither blocks
motion nor holds a fluid, so the scan starts there. LevelAccess gains
world_surface (the build limit by default, so other levels scan as before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-19 00:55:45 +02:00
parent a9bcaa6ed5
commit e805e9886c
3 changed files with 13 additions and 2 deletions
+3
View File
@@ -510,6 +510,9 @@ impl EntityObstructionWorld for PlayerObstruction {
}
}
impl LevelAccess for GameLevel<'_> {
fn world_surface(&self, x: i32, z: i32) -> i32 {
self.world.world_surface(x, z, |s| self.facts.is_air(s))
}
fn precipitation(&self, pos: BlockPos) -> Option<horizon_world::level::Precipitation> {
self.behaviours.precipitation_info(self, pos)
}
+6
View File
@@ -301,6 +301,12 @@ pub trait LevelAccess {
fn max_y(&self) -> i32 {
320
}
/// `getHeight(WORLD_SURFACE, x, z)`: one above the column's highest
/// block that isn't air. Only air lies above it, so scans for the other
/// heightmaps start there. The default, `max_y`, scans the whole column.
fn world_surface(&self, _x: i32, _z: i32) -> i32 {
self.max_y()
}
/// Vanilla `level.random` (a `LegacyRandomSource`).
fn random(&mut self) -> &mut LegacyRandom;
fn game_time(&self) -> i64;
+4 -2
View File
@@ -40,14 +40,16 @@ impl Behaviours {
BiomePrecipitation::Rain
}
}
/// `getHeightmapPos(MOTION_BLOCKING, pos)`.
/// `getHeightmapPos(MOTION_BLOCKING, pos)`, scanning down from the
/// world surface (air neither blocks motion nor holds a fluid).
pub fn motion_blocking_top<L: LevelAccess + ?Sized>(
&self,
level: &L,
pos: BlockPos,
) -> BlockPos {
let blocks = self.tag("minecraft:blocks_motion_in_heightmap");
for y in (level.min_y()..level.max_y()).rev() {
let top = level.world_surface(pos.x, pos.z).min(level.max_y());
for y in (level.min_y()..top).rev() {
let state = level.block_state(BlockPos::new(pos.x, y, pos.z));
let fluid = self.fluid(state).kind() != FluidKind::Empty;
if fluid || blocks.is_some_and(|t| t.contains(self.block(state))) {