diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 8e591cf3b..1269d8e68 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -10459,11 +10459,14 @@ impl Game<'_> { let Some(arm) = self.res.player_arm().clone() else { continue; }; + // The player's own skin, as the inventory's model shows it. + let sprites = &self.gui.atlas.sprites; let Some(r) = self - .gui - .atlas - .sprites - .get("entity/player/wide/steve") + .player_model + .as_ref() + .and_then(|m| m.skin.as_deref()) + .and_then(|skin| sprites.get(skin)) + .or_else(|| sprites.get("entity/player/wide/steve")) .copied() else { continue; diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 988fb438c..4d5cf3b33 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -3086,6 +3086,20 @@ impl Game<'_> { .collect(); Some((players, r.online_mode, upside_down)) } + /// The signed-in account's `textures`, once the services answered. + fn own_textures(&self) -> Option { + use horizon_client::skins::{self, NameOrId, Resolve}; + let auth = horizon_client::auth::current()?; + let state = self + .skin_profiles + .borrow_mut() + .state(&NameOrId::Id(auth.uuid)); + let Resolve::Done(Some(profile)) = state else { + return None; + }; + let (value, signature) = profile.textures()?; + Some(skins::unpack(&value, signature, &skins::TEXTURE_URIS)) + } /// `PlayerInfo.getSkin` for every player entity, including NPCs that are /// never in the tab list: resolve each profile's textures and give the /// level's player models their skin. @@ -3094,11 +3108,20 @@ impl Game<'_> { return; }; let local = r.profile; - let entries: Vec<(u128, horizon_client::skins::Textures)> = r + let mut entries: Vec<(u128, horizon_client::skins::Textures)> = r .skin_textures .iter() .map(|(uuid, textures)| (*uuid, textures.clone())) .collect(); + // Minecraft.profileFuture: the signed-in account's own profile, fetched from the + // services, gives the local player its skin where the server sends none (single + // player's offline-mode server). + if !entries.iter().any(|(u, t)| *u == local && t.skin.is_some()) + && let Some(own) = self.own_textures() + { + entries.retain(|(u, _)| *u != local); + entries.push((local, own)); + } let mut resolved: Vec<(u128, String)> = Vec::new(); for (uuid, textures) in entries { // PlayerInfo.createSkinLookup: only the local player's own skin @@ -3122,27 +3145,30 @@ impl Game<'_> { .map(|(id, uuid)| (*id as u32, *uuid)) .collect::>(), r.skins.clone(), - r.skins.get(&r.profile).cloned(), + // Without a skin, the profile's default one (DefaultPlayerSkin.get). + r.skins + .get(&r.profile) + .cloned() + .unwrap_or_else(|| horizon_client::tab_list::default_model_skin(r.profile)), ) }) else { return; }; for (id, uuid) in level { - let Some(skin) = skins.get(&uuid) else { - continue; - }; + let skin = skins + .get(&uuid) + .cloned() + .unwrap_or_else(|| horizon_client::tab_list::default_model_skin(uuid)); if let Some(mob) = self .mobs .iter_mut() .find(|m| m.id == id && &*m.kind.id == "minecraft:player") { - mob.skin = Some(skin.clone()); + mob.skin = Some(skin); } } - if let Some(skin) = own - && let Some(mob) = self.player_model.as_mut() - { - mob.skin = Some(skin); + if let Some(mob) = self.player_model.as_mut() { + mob.skin = Some(own); } // ClientMannequin.updateSkin (PlayerSkinRenderCache.lookup): a // mannequin's DATA_PROFILE `textures` property resolves like a diff --git a/crates/horizon-client/src/tab_list.rs b/crates/horizon-client/src/tab_list.rs index b6d5f3dbd..a8e60cd76 100644 --- a/crates/horizon-client/src/tab_list.rs +++ b/crates/horizon-client/src/tab_list.rs @@ -80,6 +80,12 @@ pub fn default_skin(uuid: u128) -> &'static str { SKINS[hash.rem_euclid(SKINS.len() as i32) as usize] } +/// The default skin a player model wears: `default_skin`'s character, in its wide variant, since +/// the player model has no slim arms. +pub fn default_model_skin(uuid: u128) -> String { + default_skin(uuid).replace("/slim/", "/wide/") +} + /// `blitSprite(sprite, x, y, w, h)`. fn sprite(name: &'static str, x: i32, y: i32, w: i32, h: i32) -> GuiDraw { GuiDraw::Sprite { @@ -639,6 +645,8 @@ mod tests { assert_eq!(ping_sprite(1000), "icon/ping_1"); // UUID.hashCode of 0 is 0: the first default skin. assert_eq!(default_skin(0), "entity/player/slim/alex"); + // The player model wears the same character with wide arms. + assert_eq!(default_model_skin(0), "entity/player/wide/alex"); assert!(!visible(true, true, 1, false)); assert!(visible(true, true, 1, true)); assert!(visible(true, false, 1, false));