From af49fd7dc3b7248f47b7f2cf066df183abee353e Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 16:07:14 +0100 Subject: [PATCH] Use a collision-shape raycast for the spyglass line-of-sight check --- .../horizon-client/src/game/advancements.rs | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index 67615b628..5908926a1 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -9,6 +9,7 @@ use horizon_client::{ text::{self, Style, Text}, toasts::Slide, }; +use horizon_core::geometry::Vec3; use serde_json::Value; use std::{ collections::{BTreeMap, BTreeSet, VecDeque}, @@ -751,19 +752,12 @@ impl Game<'_> { .filter(|m| m.alive()) .filter_map(|m| Some((m, super::ray_box(eye, dir, 100.0, m.bounds())?))) .min_by(|a, b| a.1.total_cmp(&b.1))?; - // Eye to the target's centre, two samples per block. - let to = m.center(); - let reach = (0..3).map(|i| (to[i] - eye[i]).powi(2)).sum::().sqrt(); - let steps = (reach * 2.0).ceil().max(1.0) as i32; - let clear = (1..steps).all(|i| { - let f = f64::from(i) / f64::from(steps); - let p = [0, 1, 2].map(|a| (eye[a] + (to[a] - eye[a]) * f).floor() as i32); - !self - .res - .facts() - .get(self.world.block(p[0], p[1], p[2])) - .full_collision - }); + // `LivingEntity.hasLineOfSight`: eye to the target's eye height, + // `ClipContext.Block.COLLIDER`, no fluids, within 128 blocks. + let from = Vec3::new(eye[0], eye[1], eye[2]); + let to = Vec3::new(m.position.x, m.eye_y(), m.position.z); + let world = self.mob_world_base(&[]); + let clear = to.distance(from) <= 128.0 && world.clear_between(from, to, false); clear.then(|| self.mob_entity(m)) } /// A player condition plus one item (`item` key).