From 886a84dea086f4c67674a40a4b72e3b90dd904ac Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:14:04 +0100 Subject: [PATCH 1/3] Fly thrown tridents on by themselves between server updates --- crates/horizon-client/src/game/remote.rs | 13 +++ .../src/game/remote_projectiles.rs | 39 ++++++++- crates/horizon-client/src/game/trident.rs | 83 +++++++++++++++---- 3 files changed, 115 insertions(+), 20 deletions(-) diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 3cfbd15e3..6b0d2477d 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -1406,6 +1406,17 @@ impl Game<'_> { { return; } + // A thrown trident is an arrow: placed at once, flown on by its tick. + if let Some(t) = self.tridents.iter_mut().find(|t| t.id == id as u32) { + if path.is_some() { + t.position = Vec3::new(position[0], position[1], position[2]); + } + if let Some((yaw, pitch)) = rotation { + t.yaw = yaw; + t.pitch = pitch; + } + return; + } // A dragon fireball keeps Entity's NO_OP InterpolationHandler too: // the server's position replaces its own at once. if let Some(b) = self.dragon_fireballs.iter_mut().find(|b| b.id == id as u32) { @@ -3016,6 +3027,8 @@ impl Game<'_> { p.velocity = v; } else if let Some(b) = self.dragon_fireballs.iter_mut().find(|b| b.id == id as u32) { b.velocity = v; + } else if let Some(t) = self.tridents.iter_mut().find(|t| t.id == id as u32) { + t.velocity = v; } else if let Some(p) = self .remote .as_mut() diff --git a/crates/horizon-client/src/game/remote_projectiles.rs b/crates/horizon-client/src/game/remote_projectiles.rs index 897999c6b..133c2b9fd 100644 --- a/crates/horizon-client/src/game/remote_projectiles.rs +++ b/crates/horizon-client/src/game/remote_projectiles.rs @@ -122,6 +122,8 @@ impl Game<'_> { "minecraft:trident" => { let mut t = super::trident::ThrownTrident::remote(id, at, yaw, pitch); t.velocity = velocity; + // Projectile.getAddEntityPacket: the owner's id is the data. + t.owner = data as u32; self.tridents.push(t); } "minecraft:firework_rocket" => { @@ -261,6 +263,15 @@ impl Game<'_> { (9, Value::Bool(show)) => c.show_bottom = *show, _ => {} } + } else if let Some(t) = self.tridents.iter_mut().find(|t| t.id == id) { + // AbstractArrow.ID_FLAGS (no physics) and IN_GROUND, and + // ThrownTrident.ID_LOYALTY. + match (index, value) { + (8, Value::Byte(flags)) => t.no_physics = flags & 2 != 0, + (10, Value::Bool(in_ground)) => t.in_ground = *in_ground, + (11, Value::Byte(loyalty)) => t.loyalty = u32::from(*loyalty as u8), + _ => {} + } } else if let Some(p) = self.creatures.projectiles.iter_mut().find(|p| p.id == id) { match (&mut p.kind, index, value) { // AbstractArrow.ID_FLAGS (critical) and IN_GROUND. @@ -294,6 +305,25 @@ impl Game<'_> { } } + /// `Entity.getEyePosition` of a projectile's owner: this game's player or + /// another player the server sent. + fn remote_eye(&self, id: u32) -> Option { + let me = self + .remote + .as_ref() + .and_then(|r| u32::try_from(r.entity_id).ok()); + if me == Some(id) { + let eye = self.eye_position()?; + return Some(Vec3::new(eye[0], eye[1], eye[2])); + } + let m = self.mobs.iter().find(|m| m.id == id)?; + Some(Vec3::new( + m.position.x, + m.position.y + m.eye_height(), + m.position.z, + )) + } + /// One tick of interpolation, as `tick_remote_objects`. pub(super) fn tick_remote_projectiles(&mut self, mut step: impl FnMut(u32, Vec3) -> Vec3) { // PrimedTnt.tick runs on a client too: it falls, bounces and burns its @@ -326,6 +356,7 @@ impl Game<'_> { // updates (10 to 20 ticks apart); a block stops them there, and only // the server decides what they hit. let mut projectiles = std::mem::take(&mut self.creatures.projectiles); + let mut tridents = std::mem::take(&mut self.tridents); { let w = self.mob_world_base(&[]); let world = super::creatures::ProjWorld { @@ -348,12 +379,12 @@ impl Game<'_> { } } } + for t in &mut tridents { + t.remote_tick(&world, self.remote_eye(t.owner)); + } } self.creatures.projectiles = projectiles; - for t in &mut self.tridents { - let id = t.id; - t.remote_step(|at| step(id, at)); - } + self.tridents = tridents; // FireworkRocketEntity.tick: a rocket attached to the gliding local // player boosts it client-side too (attachedToEntity.isFallFlying). let me = self diff --git a/crates/horizon-client/src/game/trident.rs b/crates/horizon-client/src/game/trident.rs index c31094596..75b546804 100644 --- a/crates/horizon-client/src/game/trident.rs +++ b/crates/horizon-client/src/game/trident.rs @@ -8,6 +8,7 @@ use horizon_client::{ items::ItemStack, mesher::Vertex, mobs::{Damage, DamageKind, Who, anim::Poses}, + projectiles::ProjectileWorld, }; use horizon_core::{ geometry::{Aabb, Vec3}, @@ -30,6 +31,8 @@ pub(super) struct ThrownTrident { pub(super) no_physics: bool, returning: u32, creative_only: bool, + /// The entity id a server sent as its owner (the one Loyalty returns it to). + pub(super) owner: u32, } impl ThrownTrident { /// A trident a server sent (`handleAddEntity`): placed and moved by it. @@ -49,12 +52,71 @@ impl ThrownTrident { no_physics: false, returning: 0, creative_only: false, + owner: 0, } } - /// One tick of a server's client: the previous position, then `step`. - pub(super) fn remote_step(&mut self, step: impl FnOnce(Vec3) -> Vec3) { + /// `ThrownTrident.tick`'s Loyalty return: pulled up and towards the + /// owner's eye. + fn loyalty_pull(&mut self, owner_eye: Vec3) { + let v = Vec3::new( + owner_eye.x - self.position.x, + owner_eye.y - self.position.y, + owner_eye.z - self.position.z, + ); + self.position.y += v.y * 0.015 * f64::from(self.loyalty); + let len = (v.x * v.x + v.y * v.y + v.z * v.z).sqrt().max(1e-9); + let accel = 0.05 * f64::from(self.loyalty); + self.velocity = Vec3::new( + self.velocity.x * 0.95 + v.x / len * accel, + self.velocity.y * 0.95 + v.y / len * accel, + self.velocity.z * 0.95 + v.z / len * accel, + ); + } + /// `ThrownTrident.tick` on a server's client: it flies on by itself + /// between the server's updates (`AbstractArrow.tick`: gravity and drag, + /// a block holds it), and Loyalty pulls it back to its owner; only the + /// server decides what it hits. + pub(super) fn remote_tick(&mut self, w: &impl ProjectileWorld, owner_eye: Option) { self.previous = self.position; - self.position = step(self.position); + if self.in_ground_time > 4 { + self.dealt_damage = true; + } + if self.loyalty > 0 + && (self.dealt_damage || self.no_physics) + && let Some(eye) = owner_eye + { + self.no_physics = true; + self.in_ground = false; + self.loyalty_pull(eye); + } + if self.in_ground && !self.no_physics { + self.in_ground_time += 1; + return; + } + self.in_ground_time = 0; + let m = self.velocity; + let (x, z) = if self.no_physics { + (-m.x, -m.z) + } else { + (m.x, m.z) + }; + self.yaw = x.atan2(z).to_degrees() as f32; + self.pitch = m.y.atan2(m.x.hypot(m.z)).to_degrees() as f32; + let to = self.position.add_vector(m); + if !self.no_physics + && let Some((at, _, _)) = w.clip(self.position, to) + { + self.position = at; + self.velocity = Vec3::ZERO; + self.in_ground = true; + return; + } + self.position = to; + // A trident's water inertia (0.99) equals the air drag. + self.velocity = self.velocity.scale(0.99); + if !self.no_physics { + self.velocity.y -= 0.05; + } } } const HALF: f64 = 0.25; @@ -240,6 +302,7 @@ impl Game<'_> { no_physics: false, returning: 0, creative_only: self.creative, + owner: 0, }); self.player_projectile_shot(); self.audio @@ -261,19 +324,7 @@ impl Game<'_> { if t.loyalty > 0 && (t.dealt_damage || t.no_physics) { t.no_physics = true; t.in_ground = false; - let v = Vec3::new( - owner_eye.x - t.position.x, - owner_eye.y - t.position.y, - owner_eye.z - t.position.z, - ); - t.position.y += v.y * 0.015 * f64::from(t.loyalty); - let len = (v.x * v.x + v.y * v.y + v.z * v.z).sqrt().max(1e-9); - let accel = 0.05 * f64::from(t.loyalty); - t.velocity = Vec3::new( - t.velocity.x * 0.95 + v.x / len * accel, - t.velocity.y * 0.95 + v.y / len * accel, - t.velocity.z * 0.95 + v.z / len * accel, - ); + t.loyalty_pull(owner_eye); if t.returning == 0 { self.audio.play( "minecraft:item.trident.return", From 10872bdd64bcb3c96cf02a8d544d0645020111c6 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 19:22:53 +0100 Subject: [PATCH 2/3] Add the tridents field to the remote motion test fixture --- tests/test_remote_motion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_remote_motion.py b/tests/test_remote_motion.py index b00e5f0a9..3a6e28de5 100644 --- a/tests/test_remote_motion.py +++ b/tests/test_remote_motion.py @@ -35,7 +35,7 @@ impl End { fn remote_eye_motion(&mut self, _id: u32, _v: [f64; 3]) {} } #[derive(Default)] struct Game { mobs: Vec, dropped: Vec, falling: Vec, tnts: Vec, - creatures: Creatures, dragon_fireballs: Vec, remote: Option, + creatures: Creatures, dragon_fireballs: Vec, tridents: Vec, remote: Option, potions: Potions, end: End, } impl Game { From d97b58fd4a836bd2ba0d5cc4a842c4ef431b3f8a Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 21:15:49 +0100 Subject: [PATCH 3/3] Send the thrower's entity id with a tracked trident --- crates/horizon-client/src/game/lan_entities.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/horizon-client/src/game/lan_entities.rs b/crates/horizon-client/src/game/lan_entities.rs index 529666590..3c5b11988 100644 --- a/crates/horizon-client/src/game/lan_entities.rs +++ b/crates/horizon-client/src/game/lan_entities.rs @@ -386,6 +386,9 @@ impl Game<'_> { let mut e = state(t.id, "minecraft:trident", at(t.position), t.yaw, false); e.pitch = t.pitch; e.velocity = at(t.velocity); + // Projectile.getAddEntityPacket: the owner's id; a trident here is + // always the host player's. + e.data = owner(Some(horizon_client::mobs::Who::Player)); e.meta = arrow_meta(false, t.no_physics, 0, t.in_ground); // ThrownTrident.ID_LOYALTY and ID_FOIL. if t.loyalty != 0 {