From eeceb9c2de52bee63cd84d2fdebd65df6ed27737 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 06:27:40 +0100 Subject: [PATCH] Let a fishing hook catch and pull other players --- crates/horizon-client/src/game/creatures.rs | 4 + crates/horizon-client/src/game/fishing.rs | 103 +++++++++++++++++- crates/horizon-client/src/game/lan.rs | 2 + crates/horizon-client/src/game/lan_actions.rs | 4 + 4 files changed, 109 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 2bc40a7af..281bf4d4e 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -46,6 +46,10 @@ pub(super) struct Creatures { pub projectiles: Vec, /// Wind bursts from a guest's turn, waiting for it to end (game/wind.rs). pub wind_bursts: Vec, + /// The players a fishing hook can catch, taken as the hooks tick, and + /// the pulls on them waiting for the hub (game/fishing.rs). + pub hook_targets: Vec, + pub hook_pulls: Vec<(u32, horizon_core::geometry::Vec3)>, /// Ticks left of the elder guardian's apparition (MobAppearanceParticle). pub elder_apparition: i32, /// The wandering trader spawner's clock. diff --git a/crates/horizon-client/src/game/fishing.rs b/crates/horizon-client/src/game/fishing.rs index 39f9e5ffe..dbf4c37b7 100644 --- a/crates/horizon-client/src/game/fishing.rs +++ b/crates/horizon-client/src/game/fishing.rs @@ -1,7 +1,7 @@ //! Fishing: `FishingRodItem.use` (cast / reel in), the `FishingHook` (flight, //! bobbing, lure and bite timers, open water, hooking mobs, retrieving the //! `gameplay/fishing` loot) and `FishingHookRenderer` (bobber and line). -use super::{Game, view_vector}; +use super::{Game, lan::LanHost, lan_mobs::guest_bounds, view_vector}; use horizon_client::lan::{entity::States, hub::Hub}; use horizon_client::{ blocks::Fluid, @@ -45,6 +45,13 @@ pub(super) struct Hook { luck: i32, lure: i32, } +/// A player a hook can catch (`canHitEntity`): their entity id, which +/// guest they are (none: the host) and their box. +pub(super) struct HookTarget { + id: u32, + conn: Option, + bounds: Aabb, +} const SIZE: f64 = 0.25; fn bounds(p: Vec3) -> Aabb { let h = SIZE / 2.0; @@ -166,6 +173,11 @@ impl Game<'_> { } else if let Some(item) = self.dropped.iter_mut().find(|i| i.id == id) { item.velocity = pulled(item.velocity); hooked_item = true; + } else if self.creatures.hook_targets.iter().any(|t| t.id == id) { + // A player: the hub moves them when the tick ends. + self.creatures + .hook_pulls + .push((id, Vec3::new(d.x * 0.1, d.y * 0.1, d.z * 0.1))); } // `hookedIn instanceof ItemEntity ? 3 : 5`. damage = if hooked_item { 3 } else { 5 }; @@ -449,6 +461,15 @@ impl Game<'_> { if !self.holds_rod() || d2 > 1024.0 { return; } + // The players it can catch, as they stand now (the host's own hook; + // guests' hooks use the ones taken as their turns start). + if self.lan_acting.is_none() + && matches!(h.state, State::Flying | State::Hooked(_)) + && let Some(host) = self.lan.take() + { + self.refresh_hook_targets(&host); + self.lan = Some(host); + } h.previous = h.position; if h.on_ground { h.life += 1; @@ -474,8 +495,8 @@ impl Game<'_> { self.hook = Some(h); return; } - // checkCollision: hook the first living mob it touches, or (via - // `canHitEntity`) a dropped item. + // checkCollision: hook the first living mob or other player it + // touches, or (via `canHitEntity`) a dropped item. let bb = bounds(h.position); let (lo, hi) = (bb.min_position(), bb.max_position()); let touches = |b: Aabb| { @@ -487,6 +508,14 @@ impl Game<'_> { .iter() .find(|m| m.alive() && touches(m.bounds())) .map(|m| m.id) + .or_else(|| { + let owner = self.lan_acting; + self.creatures + .hook_targets + .iter() + .find(|t| t.conn != owner && touches(t.bounds)) + .map(|t| t.id) + }) .or_else(|| { self.dropped .iter() @@ -501,12 +530,25 @@ impl Game<'_> { } } State::Hooked(id) => { - // updateHookedEntity: ride the hooked mob or item at 0.8 of its height. + // updateHookedEntity: ride the hooked mob, player or item at 0.8 of its height. let hooked = self .mobs .iter() .find(|m| m.id == id && m.alive()) .map(|m| (m.position, f64::from(m.height()))) + .or_else(|| { + self.creatures + .hook_targets + .iter() + .find(|t| t.id == id) + .map(|t| { + let (lo, hi) = (t.bounds.min_position(), t.bounds.max_position()); + ( + Vec3::new((lo.x + hi.x) / 2.0, lo.y, (lo.z + hi.z) / 2.0), + hi.y - lo.y, + ) + }) + }) .or_else(|| { self.dropped .iter() @@ -575,6 +617,59 @@ impl Game<'_> { ); self.hook = Some(h); } + /// The players a hook can catch: everyone but spectators and the dead + /// (`Projectile.canHitEntity`), the host and the guests in the level. + pub(super) fn refresh_hook_targets(&mut self, host: &LanHost) { + let mut targets = Vec::new(); + if self.options.dedicated.is_none() + && !self.spectator() + && let Some(p) = self.player.as_ref() + && !p.health.dead_or_dying() + { + targets.push(HookTarget { + id: host.host_entity as u32, + conn: None, + bounds: p.bounds(), + }); + } + for g in &host.hub.guests { + if host.hub.here(g) && g.loaded && !g.dead && !g.spectator() { + targets.push(HookTarget { + id: g.entity_id as u32, + conn: Some(g.conn), + bounds: guest_bounds(g), + }); + } + } + self.creatures.hook_targets = targets; + } + /// `FishingHook.pullEntity` on the players the hooks reeled in this tick + /// pulled: their velocity moves, and a guest's reaches their client. + pub(super) fn flush_hook_pulls(&mut self) { + let pulls = std::mem::take(&mut self.creatures.hook_pulls); + let Some(mut host) = self.lan.take() else { + return; + }; + for (id, delta) in pulls { + let push = |g: &mut Self| { + if let Some(p) = g.player.as_mut() { + p.velocity = p.velocity.add_vector(delta); + } + }; + if id == host.host_entity as u32 { + push(self); + } else if let Some(conn) = host + .hub + .guests + .iter() + .find(|g| g.entity_id as u32 == id) + .map(|g| g.conn) + { + self.guest_hit_by(&mut host, conn, push); + } + } + self.lan = Some(host); + } /// `FishingRodCast`: the stack in the arm holding the rod /// (`FishingHookRenderer.getHoldingArm`) while the hook is out. pub(super) fn cast_rod(&self) -> Option<&ItemStack> { diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 28ec3fe8a..cbe559578 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -1166,6 +1166,8 @@ impl Game<'_> { self.lan = Some(host); // A mace's wind burst from a guest's attack. let _ = self.flush_wind_bursts(); + // A reeled-in hook pulling a player. + self.flush_hook_pulls(); } fn lan_guest_joined( diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 8c51a3f2a..0c6896daf 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -1899,6 +1899,10 @@ impl Game<'_> { .filter(|g| host.hub.here(g) && g.loaded) .map(|g| g.conn) .collect(); + // The players the guests' hooks can catch. + if host.play.values().any(|p| p.hook.is_some()) { + self.refresh_hook_targets(host); + } for conn in conns { let Some(gi) = host.hub.guests.iter().position(|g| g.conn == conn) else { continue;