From 8e6a129f6b6ab1fabd52f85aee940f07a9cc813d Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 19:41:09 +0200 Subject: [PATCH] LAN: every player model wears its own armour The host drew each guest with the host's own armour (player_armor_layers), and a guest ignored ClientboundSetEquipmentPacket, so it drew the host and other guests bare-handed and without armour. Player models now carry what they wear in extra.head..feet: the host fills it from the guest's armour, the guest from SetEquipment (main and off hand too, for mobs as well), and both draw HumanoidArmorLayer from it. The host also draws what a guest holds. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/armor_stands.rs | 25 +++++++----- crates/horizon-client/src/game/creatures.rs | 9 ++++- crates/horizon-client/src/game/lan.rs | 12 +++++- crates/horizon-client/src/game/remote.rs | 39 +++++++++++++++++++ 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/crates/horizon-client/src/game/armor_stands.rs b/crates/horizon-client/src/game/armor_stands.rs index 78eb22330..fd988b19c 100644 --- a/crates/horizon-client/src/game/armor_stands.rs +++ b/crates/horizon-client/src/game/armor_stands.rs @@ -7,7 +7,7 @@ use horizon_client::{ entities::ArmorStand, items::ItemStack, mesher::Vertex, - mobs::{Part, anim::Poses}, + mobs::{Mob, Part, anim::Poses}, }; use horizon_core::{ geometry::{Aabb, Vec3}, @@ -92,21 +92,26 @@ impl Game<'_> { /// `HumanoidArmorLayer` for the player: (model, texture rect, colour) of /// each worn piece, head to feet. pub(super) fn player_armor_layers(&self) -> Vec<(&Part, [f32; 4], u32)> { + self.armor_layers(self.armor.each_ref().map(|s| s.as_ref().map(|s| &*s.item))) + } + /// `HumanoidArmorLayer` for another player's model: the armour it wears + /// (`extra.head` .. `extra.feet`). + pub(super) fn worn_armor_layers(&self, m: &Mob) -> Vec<(&Part, [f32; 4], u32)> { + let e = &m.extra; + self.armor_layers([&e.head, &e.chest, &e.legs, &e.feet].map(|s| s.as_deref())) + } + /// The layers of the armour items `worn`, head to feet. + fn armor_layers(&self, worn: [Option<&str>; 4]) -> Vec<(&Part, [f32; 4], u32)> { let assets = &self.armor_stand_assets; let mut out = Vec::new(); - for (i, layer) in ["helmet", "chestplate", "leggings", "boots"] + for (item, layer) in worn .into_iter() - .enumerate() + .zip(["helmet", "chestplate", "leggings", "boots"]) { - let Some(stack) = &self.armor[i] else { + let Some(item) = item else { continue; }; - let Some(asset) = self - .res - .items - .get(&stack.item) - .and_then(|i| i.equip_asset.clone()) - else { + let Some(asset) = self.res.items.get(item).and_then(|i| i.equip_asset.clone()) else { continue; }; let kind = if layer == "leggings" { diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index aea114d30..48a28ebca 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -2731,13 +2731,20 @@ impl Game<'_> { if mob.fire_ticks > 0 || matches!(mob.species(), Species::Blaze | Species::MagmaCube) { packed = (15 * 16) | ((15 * 16) << 8); } - horizon_client::mobs::render::render( + // Other players on a server: PlayerRenderer's HumanoidArmorLayer. + let armor = if &*mob.kind.id == "minecraft:player" { + self.worn_armor_layers(mob) + } else { + Vec::new() + }; + horizon_client::mobs::render::render_with( mob, alpha as f32, camera, &lookup, packed, &self.res.mob_data, + &armor, out, ); self.mob_block_geometry(mob, camera, alpha, packed, out); diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 1bce62bb8..dd316cc44 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -334,6 +334,11 @@ impl Game<'_> { "game_mode": g.game_mode, "chunks": g.sent_chunks.len(), "tracked": g.tracker.len(), + // The armour the host draws on this guest, head to feet. + "model_armor": h.models.get(&g.conn).map(|m| { + [&m.extra.head, &m.extra.chest, &m.extra.legs, &m.extra.feet] + .map(|s| s.as_deref()) + }), })).collect::>(), }), None => json!({ "open": false }), @@ -839,6 +844,10 @@ impl Game<'_> { .and_then(|s| s.as_ref()) .map(|s| s.item.clone()); m.extra.off_hand = g.offhand.as_ref().map(|s| s.item.clone()); + [m.extra.head, m.extra.chest, m.extra.legs, m.extra.feet] = g + .armor + .each_ref() + .map(|s| s.as_ref().map(|s| s.item.clone())); m.extra.crouching = g.sneaking; } } @@ -869,9 +878,10 @@ impl Game<'_> { &lookup, packed, &self.res.mob_data, - &self.player_armor_layers(), + &self.worn_armor_layers(m), out, ); + self.held_item_geometry(m, camera, alpha, packed, true, out); } } diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 6ad981151..ac2c604f5 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -979,6 +979,29 @@ impl Game<'_> { } } } + // ClientPacketListener.handleSetEquipment: what a mob or another + // player holds and wears (EquipmentSlot ordinals). + C::SetEquipment(p) => { + let items: Vec<(u8, Option>)> = p + .slots + .iter() + .map(|(slot, stack)| (*slot, stack.as_ref().map(|s| self.item_name(s.item)))) + .collect(); + if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) { + for (slot, item) in items { + let e = &mut m.extra; + match slot { + 0 => e.main_hand = item, + 1 => e.off_hand = item, + 2 => e.feet = item, + 3 => e.legs = item, + 4 => e.chest = item, + 5 => e.head = item, + _ => {} + } + } + } + } C::TakeItemEntity(p) => { if self .remote @@ -2733,6 +2756,22 @@ impl Game<'_> { }), "players": r.players.values().collect::>(), // Where the other players' entities are (harnesses check movement). + // What the other players hold and wear, as this client draws them. + "player_equipment": self + .mobs + .iter() + .filter(|m| r.level_players.contains_key(&(m.id as i32))) + .map(|m| { + let e = &m.extra; + let armor = [&e.head, &e.chest, &e.legs, &e.feet].map(|s| s.as_deref()); + serde_json::json!({ + "id": m.id, + "armor": armor, + "main_hand": e.main_hand.as_deref(), + "off_hand": e.off_hand.as_deref(), + }) + }) + .collect::>(), "player_positions": r .entities .values()