diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 772a26730..a9ae6ccb6 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -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 { self.behaviours.precipitation_info(self, pos) } diff --git a/crates/horizon-world/src/level/mod.rs b/crates/horizon-world/src/level/mod.rs index f1f0b21ac..c706ca280 100644 --- a/crates/horizon-world/src/level/mod.rs +++ b/crates/horizon-world/src/level/mod.rs @@ -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; diff --git a/crates/horizon-world/src/level/weather.rs b/crates/horizon-world/src/level/weather.rs index c43d96b15..93027d889 100644 --- a/crates/horizon-world/src/level/weather.rs +++ b/crates/horizon-world/src/level/weather.rs @@ -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( &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))) {