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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-15 19:41:09 +02:00
parent aca5f3a8ba
commit 8e6a129f6b
4 changed files with 73 additions and 12 deletions
+15 -10
View File
@@ -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" {
+8 -1
View File
@@ -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);
+11 -1
View File
@@ -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::<Vec<_>>(),
}),
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);
}
}
+39
View File
@@ -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<Arc<str>>)> = 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::<Vec<_>>(),
// 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::<Vec<_>>(),
"player_positions": r
.entities
.values()