From ad61c30f465d8a57559d53761c2b3ca86a34711e Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 19:49:57 +0100 Subject: [PATCH] Award target hit and honey slide advancements --- crates/horizon-client/src/game.rs | 7 +++- .../horizon-client/src/game/advancements.rs | 36 +++++++++++++++++++ crates/horizon-client/src/game/creatures.rs | 19 ++++++++-- crates/horizon-client/src/game/lan_actions.rs | 9 ++++- crates/horizon-client/src/motion.rs | 5 ++- 5 files changed, 71 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 8e591cf3b..fc8eec1ff 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -5259,8 +5259,13 @@ impl Game<'_> { MotionEvent::Snowflake { position, velocity } => self.snowflake(position, velocity), MotionEvent::EnterBlock { state } => self.trigger_enter_block(state), MotionEvent::HoneySlide { - sound, particles, .. + pos, + sound, + particles, } => { + if self.world.game_time % 20 == 0 { + self.trigger_honey_slide([pos.x, pos.y, pos.z]); + } if sound { self.audio .play("minecraft:block.honey_block.slide", Some(feet), 1.0, 1.0); diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index 79e836322..bc066c6bc 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -993,6 +993,42 @@ impl Game<'_> { block_ok && state_ok && adv::conditions(&c["player"], &pctx, w) }); } + /// `SlideDownBlockTrigger`: match the actual block and its state. + pub(super) fn trigger_honey_slide(&mut self, pos: [i32; 3]) { + let me = self.player_entity(); + self.trigger("minecraft:slide_down_block", move |c, w| { + let ctx = adv::Entities { + this: Some(&me), + origin: me.position, + tool: None, + block_pos: None, + }; + adv::conditions(&c["player"], &ctx, w) && adv::block(c, pos, w) + }); + } + + /// `TargetBlockTrigger`: signal and projectile conditions are evaluated in + /// the shooter's context, including distance from the shooter. + pub(super) fn trigger_target_hit(&mut self, projectile: &EntityView, strength: i32) { + let me = self.player_entity(); + let projectile = projectile.clone(); + self.trigger("minecraft:target_hit", move |c, w| { + let player = adv::Entities { + this: Some(&me), + origin: me.position, + tool: None, + block_pos: None, + }; + let target = adv::Entities { + this: Some(&projectile), + ..player + }; + adv::conditions(&c["player"], &player, w) + && adv::range_i(&c["signal_strength"], i64::from(strength)) + && adv::conditions(&c["projectile"], &target, w) + }); + } + /// `ItemUsedOnLocationTrigger` (placed_block, item_used_on_block). pub(super) fn trigger_block(&mut self, name: &str, pos: [i32; 3], stack: &ItemStack) { let me = self.player_entity(); diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 3145c2f75..f7d4828f1 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -2666,10 +2666,25 @@ impl Game<'_> { let hit = self.with_level(|b, level, ticks| { b.target_projectile_hit(level, ticks, block, location, face, arrow) }); - if hit.is_some() { + if let Some(strength) = hit { let _ = self.process_level_events(); - if p.owner == Some(Who::Player) { + if p.owner == Some(Who::Player) && (p.guest.is_none() || p.guest == self.lan_acting) { self.stats.custom("target_hit", 1); + let kind = if p + .arrow + .as_ref() + .is_some_and(|a| &*a.pickup_item.item == "minecraft:spectral_arrow") + { + "minecraft:spectral_arrow" + } else { + p.kind.id() + }; + let projectile = horizon_client::advancements::EntityView { + kind: kind.to_owned(), + position: [p.position.x, p.position.y, p.position.z], + ..Default::default() + }; + self.trigger_target_hit(&projectile, strength); } } } diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index da4b6a1a8..acff3d91e 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2706,8 +2706,15 @@ impl Game<'_> { // others (Player.playSound excludes the player, whose client // plays it), the entity event 53 everyone around. MotionEvent::HoneySlide { - sound, particles, .. + pos, + sound, + particles, } => { + if self.world.game_time % 20 == 0 { + self.as_guest(host, conn, |game| { + game.trigger_honey_slide([pos.x, pos.y, pos.z]) + }); + } let Some((id, at)) = host.hub.guest(conn).map(|g| (g.entity_id, g.position)) else { continue; diff --git a/crates/horizon-client/src/motion.rs b/crates/horizon-client/src/motion.rs index e9899ad40..7536d0fc6 100644 --- a/crates/horizon-client/src/motion.rs +++ b/crates/horizon-client/src/motion.rs @@ -1551,7 +1551,10 @@ impl MotionWorld<'_, '_, '_> { // Only the server broadcasts event 53 (`!level.isClientSide()`). let particles = !self.player.client_side && random.next_int_bound(5).map_err(|e| format!("{e:?}"))? == 0; - if sound || particles { + // The server also checks the slide criterion every 20 game ticks, + // including ticks without a sound or a particle event. + let criterion = !self.player.client_side && self.scene.game_time % 20 == 0; + if sound || particles || criterion { self.player.events.push(MotionEvent::HoneySlide { pos, sound,