Merge pull request #952 from ludovic111/perf/heightmap-scan-from-surface

🤖 Agent: merged after verify and CI parity passed. tick_blocks finds the motion-blocking height from the top of the terrain: 1.98 → 1.36 ms per tick with 10 bots on the Mac mini (−31%).
This commit is contained in:
Ludovic Marie
2026-10-19 04:05:57 +02:00
committed by GitHub
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))) {