From f601630f05878d4f562a0a9401491bbfe5419843 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 20:28:36 +0200 Subject: [PATCH] LAN guest: fall damage, regeneration and hunger on the host Nothing hurt a guest: the host only set a guest's position from its move packets, so a fall did nothing, and their body never ticked on the server (no damage clock, no regeneration, no food tick). Each tick the host now runs a guest's server-side body like ServerPlayer: the damage clock and Entity.baseTick's fluid phase, then ServerPlayer.doCheckFallDamage for every move packet accepted that tick (the supporting block, the fall distance and the landing, through the same landing code as the host's own falls, so water resets a fall and lava halves it), then peaceful regeneration and the food tick. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/lan_actions.rs | 49 ++++++++++++++++++- crates/horizon-client/src/lan/guest.rs | 4 ++ crates/horizon-client/src/lan/hub.rs | 8 +-- 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 7faba7f6c..8846ae102 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -12,13 +12,14 @@ use horizon_client::{ entities::Experience, items::ItemStack, lan::{guest::SPECTATOR, menu::Rules}, - motion::PlayerMotion, + motion::{MotionWorld, PlayerMotion}, }; use horizon_core::geometry::Vec3; use horizon_protocol::{ packets::play::{self, Clientbound as C, Serverbound as S}, text::literal, }; +use horizon_world::entity_move::EntityMoveWorld; use winit::keyboard::KeyCode; /// Per-guest state of the gameplay code that lives outside `Guest`. @@ -698,6 +699,7 @@ impl Game<'_> { } }); } + self.guest_server_tick(host, conn); self.guest_dig_feedback(host, conn); self.guest_pickups(host, gi); let g = &mut host.hub.guests[gi]; @@ -715,6 +717,51 @@ impl Game<'_> { } } + /// The guest's body on the server each tick: ServerPlayer.tick's damage + /// clock and Entity.baseTick's fluid phase, then + /// ServerPlayer.doCheckFallDamage for each move the guest made (the fall + /// distance grows while they go down and hurts them where they land, as + /// the host's own landing does; water resets it, lava halves it), then + /// regeneration and the food tick (ServerPlayer.doTick). + fn guest_server_tick(&mut self, host: &mut LanHost, conn: u32) { + let Some(g) = host.hub.guest_mut(conn) else { + return; + }; + let moves = std::mem::take(&mut g.moves); + if g.spectator() { + return; + } + self.as_guest(host, conn, |game| { + let (rules, health) = (game.world.health_rules, &game.motion.health); + let Some(player) = game.player.as_mut() else { + return; + }; + let mut w = MotionWorld { + player, + scene: &mut game.world, + assets: &game.res.assets, + collision_binding: game.collision, + resources: game.motion, + }; + w.player.health.advance_clock(); + let _ = w.fluid_base_tick(); + for (moved, on_ground) in moves { + let movement = Vec3::new(moved[0], moved[1], moved[2]); + let landed = (|| -> horizon_client::Result<()> { + w.set_on_ground_with_movement(on_ground, false, movement)?; + let pos = w.legacy_on_position()?; + let state = w.block_state(pos)?; + w.check_fall_damage(moved[1], on_ground, state, pos) + })(); + if landed.is_err() { + break; + } + } + let _ = w.player.peaceful_regeneration(rules); + let _ = w.player.food_tick(health, rules); + }); + } + /// The crack animation other players see. fn guest_dig_feedback(&mut self, host: &mut LanHost, conn: u32) { let Some(gi) = host.hub.guests.iter().position(|g| g.conn == conn) else { diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs index 49dec3f21..3fbb9b8a7 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -95,6 +95,9 @@ pub struct Guest { pub inbox: VecDeque, pub joined_tick: u64, pub ticks: u64, + /// The moves accepted since the game last looked (movement, on ground), + /// for ServerPlayer.doCheckFallDamage. + pub moves: Vec<([f64; 3], bool)>, pub dead: bool, /// The join packets were sent (PlayerList.placeNewPlayer ran). pub placed: bool, @@ -168,6 +171,7 @@ impl Guest { inbox: VecDeque::new(), joined_tick: 0, ticks: 0, + moves: Vec::new(), dead: false, placed: false, menu: None, diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index 2486fd1a5..8f4fc010e 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -1394,9 +1394,7 @@ impl Hub { S::MovePlayerRot(p) => { self.move_player(i, None, Some((p.yaw, p.pitch)), p.flags); } - S::MovePlayerStatus(p) => { - self.guests[i].on_ground = p.flags & 1 != 0; - } + S::MovePlayerStatus(p) => self.move_player(i, None, None, p.flags), S::PlayerLoaded(_) => self.guests[i].loaded = true, S::ChunkBatchReceived(p) => { let g = &mut self.guests[i]; @@ -1460,6 +1458,10 @@ impl Hub { g.previous_position = g.position; g.position = p; } + let moved = pos.map_or([0.0; 3], |_| { + [0, 1, 2].map(|k| g.position[k] - g.previous_position[k]) + }); + g.moves.push((moved, flags & 1 != 0)); if let Some((yaw, pitch)) = rot && yaw.is_finite() && pitch.is_finite()