From 18217532af91668d2be99db0fecac32a0d9bddd5 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 06:24:15 +0100 Subject: [PATCH] Show other players gliding, swimming, spinning and holding a loaded crossbow --- crates/horizon-client/src/game/creatures.rs | 12 ++++++++ crates/horizon-client/src/game/lan.rs | 30 +++++++++++++++++++ crates/horizon-client/src/game/perspective.rs | 29 +++++++++++++----- crates/horizon-client/src/game/remote.rs | 18 +++++++++++ .../src/game/remote_mob_data.rs | 18 +++++++++++ crates/horizon-client/src/lan/hub.rs | 2 +- crates/horizon-client/src/mobs.rs | 21 +++++++++++++ 7 files changed, 122 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 2bc40a7af..d377564e7 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -3471,6 +3471,18 @@ impl Game<'_> { &armor, out, ); + if &*mob.kind.id == "minecraft:player" { + // PlayerRenderer's WingsLayer and SpinAttackEffectLayer. + self.player_elytra_geometry( + mob, + mob.extra.chest.as_deref(), + camera, + alpha as f32, + packed, + out, + ); + self.spin_attack_geometry(mob, camera, alpha as f32, packed, out); + } self.mob_block_geometry(mob, camera, alpha, packed, out); // Glowing outlines and a guardian's beam remain visible independently // of whether the body is hidden behind terrain. diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 28ec3fe8a..dd5268a92 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -1492,6 +1492,27 @@ impl Game<'_> { .map(|s| s.as_ref().map(|s| s.item.clone())); m.extra.crouching = g.sneaking; m.extra.sprinting = g.sprinting; + // Entity.DATA_POSE and the shared and living flags the others + // get (hub::guest_body): gliding, swimming, Riptide's spin. + let body = lan::hub::guest_body(g); + m.extra.fall_flying = body.gliding; + m.extra.synced_pose = if body.swimming || body.crawling { 3 } else { 0 }; + m.extra.auto_spin_attack = body.spin_attack; + m.velocity = g + .motion + .as_ref() + .map_or(Vec3::new(dx, dy, dz), |motion| motion.velocity); + m.tick_avatar_pose( + g.motion + .as_ref() + .is_some_and(|motion| motion.fluids.was_touching_water), + ); + // CrossbowItem.isCharged: the held crossbow's projectiles. + m.extra.charged = g + .inventory + .get(g.selected) + .and_then(|s| s.as_ref()) + .is_some_and(|s| s.data().is_some_and(|d| !d.charged.is_empty())); // LivingEntity.DATA_EFFECT_PARTICLES: the swirls of its visible effects. let visible = || g.effects.list.iter().filter(|e| e.visible); m.extra.effect_particles = visible() @@ -1558,6 +1579,15 @@ impl Game<'_> { ), out, ); + self.player_elytra_geometry( + m, + m.extra.chest.as_deref(), + camera, + alpha as f32, + packed, + out, + ); + self.spin_attack_geometry(m, camera, alpha as f32, packed, out); self.held_item_geometry(m, camera, alpha, packed, true, out); if !m.glowing { self.cull_entity_vertices(out, entity_start); diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs index caf49883b..5b65486d6 100644 --- a/crates/horizon-client/src/game/perspective.rs +++ b/crates/horizon-client/src/game/perspective.rs @@ -453,7 +453,14 @@ impl Game<'_> { &self.player_armor_layers(), out, ); - self.player_elytra_geometry(m, camera, alpha as f32, packed, out); + self.player_elytra_geometry( + m, + self.armor[1].as_ref().map(|s| &*s.item), + camera, + alpha as f32, + packed, + out, + ); self.spin_attack_geometry(m, camera, alpha as f32, packed, out); self.held_item_geometry(m, camera, alpha, packed, true, out); } @@ -509,7 +516,14 @@ impl Game<'_> { &self.player_armor_layers(), &mut verts, ); - self.player_elytra_geometry(&m, camera, 1.0, 240 | 240 << 8, &mut verts); + self.player_elytra_geometry( + &m, + self.armor[1].as_ref().map(|s| &*s.item), + camera, + 1.0, + 240 | 240 << 8, + &mut verts, + ); self.held_item_geometry(&m, camera, 1.0, 240 | 240 << 8, false, &mut verts); let height = if m.extra.crouching { 1.5 } else { 1.8 }; // PictureInPictureRenderer: the box centre, (size, size, -size); @@ -548,17 +562,18 @@ impl Game<'_> { } impl Game<'_> { - fn player_elytra_geometry( + /// `WingsLayer` for a player wearing `chest`. + pub(super) fn player_elytra_geometry( &self, m: &Mob, + chest: Option<&str>, camera: glam::DVec3, partial: f32, light: u32, out: &mut Vec, ) { - let Some(asset) = self.armor[1] - .as_ref() - .and_then(|s| self.res.items().get(&s.item)) + let Some(asset) = chest + .and_then(|item| self.res.items().get(item)) .and_then(|i| i.equip_asset.as_ref()) else { return; @@ -598,7 +613,7 @@ impl Game<'_> { } /// `SpinAttackEffectLayer`: Riptide's two boxes turning around a spinning /// player (`SpinAttackEffectModel.setupAnim`). - fn spin_attack_geometry( + pub(super) fn spin_attack_geometry( &self, m: &Mob, camera: glam::DVec3, diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 77e143f9a..3559dbb71 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -2029,7 +2029,23 @@ impl Game<'_> { .iter() .map(|(slot, stack)| (*slot, stack.as_ref().map(|s| self.item_name(s.item)))) .collect(); + // CrossbowItem.isCharged: the main hand's `charged_projectiles` + // (AvatarRenderer.getArmPose holds a loaded crossbow up). + let charged = p.slots.iter().find(|(slot, _)| *slot == 0).map(|(_, s)| { + s.as_ref().is_some_and(|s| { + matches!( + s.component(horizon_protocol::item::component::CHARGED_PROJECTILES), + Some(horizon_protocol::item::Component::Stacks(list)) + if !list.is_empty() + ) + }) + }); if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) { + if let Some(charged) = charged + && &*m.kind.id == "minecraft:player" + { + m.extra.charged = charged; + } for (slot, item) in items { let e = &mut m.extra; match slot { @@ -3632,6 +3648,8 @@ impl Game<'_> { // a player's body following its walk and look. if player { remote_player_head_turn(m); + // LivingEntity.tick: the glide count, wings and swim amount. + m.tick_avatar_pose(m.fluids.in_water); } else if m.alive() { m.body_rotation_tick(); } diff --git a/crates/horizon-client/src/game/remote_mob_data.rs b/crates/horizon-client/src/game/remote_mob_data.rs index 65bbbfbbe..932ecaa32 100644 --- a/crates/horizon-client/src/game/remote_mob_data.rs +++ b/crates/horizon-client/src/game/remote_mob_data.rs @@ -15,6 +15,9 @@ use horizon_protocol::registry::Builtin; fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_entity: i32) { let species = m.species(); let baby = super::lan::baby_index(&m.kind.id); + if &*m.kind.id == "minecraft:player" { + player_poses(m, values); + } for (index, _, value) in values { match (*index, value) { // Entity.DATA_SHARED_FLAGS_ID's FLAG_ONFIRE: Entity.isOnFire on a @@ -115,6 +118,21 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_enti } } +/// What another player's pose draws from: gliding (Entity.isFallFlying, flag +/// 0x80 of the shared flags), the pose (swimming), Riptide's spin +/// (LivingEntity.isAutoSpinAttack, flag 4) and a loaded crossbow in the +/// hand (the held stack comes with SetEquipment). +fn player_poses(m: &mut Mob, values: &[(u8, i32, Value)]) { + for (index, _, value) in values { + match (*index, value) { + (0, Value::Byte(flags)) => m.extra.fall_flying = flags & -128 != 0, + (6, Value::Id(pose)) => m.extra.synced_pose = (*pose).clamp(0, 17) as u8, + (8, Value::Byte(flags)) => m.extra.auto_spin_attack = flags & 4 != 0, + _ => {} + } + } +} + /// The options of a synched particle list: an entity effect carries its ARGB /// colour, the omens none. fn swirls(list: &[Particle], builtin: &Builtin) -> Vec { diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index f9b6e8ce7..e16d8f36c 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -2714,7 +2714,7 @@ fn ticking_state(rate: f32, frozen: bool) -> C { } /// What the others see of a guest's body, from its server-side state. -fn guest_body(g: &Guest) -> BodyFlags { +pub fn guest_body(g: &Guest) -> BodyFlags { let m = g.motion.as_deref(); BodyFlags { gliding: g.fall_flying, diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 2325c3f5b..00f256343 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -705,6 +705,8 @@ pub struct Extra { pub blocking: bool, pub fall_flying: bool, pub fall_fly_ticks: i32, + /// `Entity.DATA_POSE` of another player, as the server sent it. + pub synced_pose: u8, /// `LivingEntity.isAutoSpinAttack` (Riptide). pub auto_spin_attack: bool, pub main_hand_left: bool, @@ -2321,6 +2323,25 @@ impl SwimAnimation { } } +impl Mob { + /// The part of `LivingEntity.tick` and `aiStep` that animates another + /// player from its synched pose and flags: the glide count, the wings + /// (`elytraAnimationState`) and the swim amount (`updateSwimAmount`). + pub fn tick_avatar_pose(&mut self, in_water: bool) { + let e = &mut self.extra; + e.fall_fly_ticks = if e.fall_flying { + e.fall_fly_ticks + 1 + } else { + 0 + }; + // LivingEntity.isVisuallySwimming: the swimming pose, or the gliding + // pose after the glide ended. + let visually = e.synced_pose == 3 || (!e.fall_flying && e.synced_pose == 1); + e.elytra.tick(e.fall_flying, e.crouching, self.velocity); + e.swim.tick(visually, in_water); + } +} + #[cfg(test)] mod elytra_tests { use super::*;