diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 1269d8e68..a262f92fa 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1177,6 +1177,8 @@ struct WorldRest { end_environment: Environment, behaviours: Behaviours, player_arm: Option, + /// The slim model's right arm (3 pixels wide). + player_arm_slim: Option, player_type: Option>, /// `SpinAttackEffectModel` (Riptide's spinning boxes). spin_attack: Option, @@ -1249,8 +1251,12 @@ impl Resources { fn threads(&self) -> usize { self.core.threads } - fn player_arm(&self) -> &Option { - &self.rest().player_arm + fn player_arm(&self, slim: bool) -> &Option { + if slim { + &self.rest().player_arm_slim + } else { + &self.rest().player_arm + } } fn player_type(&self) -> &Option> { &self.rest().player_type @@ -10456,7 +10462,8 @@ impl Game<'_> { if hand == Hand::Off { continue; } - let Some(arm) = self.res.player_arm().clone() else { + let slim = self.player_model.as_ref().is_some_and(|m| m.slim); + let Some(arm) = self.res.player_arm(slim).clone() else { continue; }; // The player's own skin, as the inventory's model shows it. @@ -14514,6 +14521,8 @@ fn load_world_rest( player_type: perspective::player_type(root), player_arm: horizon_client::mobs::load_model(root, "minecraft:player#main") .and_then(|m| m.children.into_iter().find(|c| c.name == "right_arm")), + player_arm_slim: horizon_client::mobs::load_model(root, "minecraft:player_slim#main") + .and_then(|m| m.children.into_iter().find(|c| c.name == "right_arm")), spin_attack: horizon_client::mobs::load_model(root, "minecraft:spin_attack#main"), }) } diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs index ceb4507de..9eb56338d 100644 --- a/crates/horizon-client/src/game/perspective.rs +++ b/crates/horizon-client/src/game/perspective.rs @@ -158,7 +158,10 @@ pub(super) fn player_type(root: &Path) -> Option> { ambient_interval: 80, flags: Default::default(), model: Arc::new(model), - layers: Default::default(), + // PlayerModel's slim arms, for slim skins. + layers: horizon_client::mobs::load_model(root, "minecraft:player_slim#main") + .map(|slim| [("player_slim#main".to_owned(), Arc::new(slim))].into()) + .unwrap_or_default(), texture: "entity/player/wide/steve".into(), brain: Brain::Passive, anim: Anim::Humanoid { zombie_arms: false }, diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 4d5cf3b33..180effbb3 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -3123,6 +3123,8 @@ impl Game<'_> { entries.push((local, own)); } let mut resolved: Vec<(u128, String)> = Vec::new(); + // PlayerSkin.model of each resolved skin: the textures' `slim`. + let mut slim = std::collections::HashSet::new(); for (uuid, textures) in entries { // PlayerInfo.createSkinLookup: only the local player's own skin // may be unsigned. @@ -3133,10 +3135,22 @@ impl Game<'_> { }) }; if let Some(skin) = skin { + if textures.slim { + slim.insert(uuid); + } resolved.push((uuid, skin)); } } resolved.retain(|(_, skin)| !skin.starts_with("skins/") || self.again_skin(skin)); + // PlayerInfo.getSkin: the downloaded skin and its model, else the + // profile's default skin (DefaultPlayerSkin.get), slim or wide. + let skin_of = |skins: &HashMap, uuid: u128| match skins.get(&uuid) { + Some(skin) => (skin.clone(), slim.contains(&uuid)), + None => { + let skin = horizon_client::tab_list::default_skin(uuid); + (skin.to_owned(), skin.contains("/slim/")) + } + }; let Some((level, skins, own)) = self.remote.as_mut().map(|r| { r.skins = resolved.into_iter().collect(); ( @@ -3145,30 +3159,26 @@ impl Game<'_> { .map(|(id, uuid)| (*id as u32, *uuid)) .collect::>(), r.skins.clone(), - // 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)), + r.profile, ) }) else { return; }; for (id, uuid) in level { - let skin = skins - .get(&uuid) - .cloned() - .unwrap_or_else(|| horizon_client::tab_list::default_model_skin(uuid)); + let (skin, is_slim) = skin_of(&skins, uuid); if let Some(mob) = self .mobs .iter_mut() .find(|m| m.id == id && &*m.kind.id == "minecraft:player") { mob.skin = Some(skin); + mob.slim = is_slim; } } if let Some(mob) = self.player_model.as_mut() { - mob.skin = Some(own); + let (skin, is_slim) = skin_of(&skins, own); + mob.skin = Some(skin); + mob.slim = is_slim; } // ClientMannequin.updateSkin (PlayerSkinRenderCache.lookup): a // mannequin's DATA_PROFILE `textures` property resolves like a @@ -3218,7 +3228,7 @@ impl Game<'_> { (m.id, textures) }) .collect(); - let mut resolved: Vec<(u32, Option)> = Vec::new(); + let mut resolved: Vec<(u32, Option, bool)> = Vec::new(); for (id, textures) in mannequins { let skin = { let mut downloads = self.skin_downloads.borrow_mut(); @@ -3226,15 +3236,17 @@ impl Game<'_> { downloads.state(kind, url) }) }; - resolved.push((id, skin)); + let slim = skin.is_some() && textures.slim; + resolved.push((id, skin, slim)); } - for (id, skin) in resolved { + for (id, skin, slim) in resolved { let skin = skin.filter(|s| !s.starts_with("skins/") || self.again_skin(s)); if let Some(mob) = self .mobs .iter_mut() .find(|m| m.id == id && &*m.kind.id == "minecraft:mannequin") { + mob.slim = slim && skin.is_some(); mob.skin = skin; } } diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index db617e7c9..5d3b8dfc1 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -937,6 +937,8 @@ pub struct Mob { /// The skin texture of a player mob (`PlayerInfo.getSkin`), which /// replaces the type's default when its download is ready. pub skin: Option, + /// `PlayerSkin.model` is `SLIM`: the player model with 3-pixel arms. + pub slim: bool, /// A mannequin's `DATA_PROFILE` (ResolvableProfile): the profile's /// `textures` property resolves to `skin` like a player's. pub profile: Option, @@ -1908,6 +1910,7 @@ impl Mob { rider: None, outbox: Vec::new(), skin: None, + slim: false, profile: None, attrs: Attrs { speed: kind.speed, diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs index aa47b2a96..68f6bb4e7 100644 --- a/crates/horizon-client/src/mobs/render.rs +++ b/crates/horizon-client/src/mobs/render.rs @@ -115,8 +115,9 @@ pub fn body(m: &Mob) -> (String, String) { } }; if avatar(m) { + // AvatarRenderer: PlayerModel's slim layer for a slim skin. return ( - "main".into(), + if m.slim { "player_slim#main" } else { "main" }.into(), m.skin.clone().unwrap_or_else(|| m.kind.texture.clone()), ); } @@ -784,7 +785,8 @@ pub fn layers(m: &Mob) -> Vec { /// `HumanoidArmorLayer`: the armour models of the mob's main model with the /// equipment textures (leather tinted, with its overlay). fn humanoid_armor(m: &Mob, v: &mut Vec) { - if super::equine::is_equine(m.species()) { + // A player's or mannequin's armour is drawn by the game's armour layers. + if super::equine::is_equine(m.species()) || avatar(m) { return; } let (model, _) = body(m); diff --git a/crates/horizon-client/src/mobs/species.rs b/crates/horizon-client/src/mobs/species.rs index 201632706..b2e206d77 100644 --- a/crates/horizon-client/src/mobs/species.rs +++ b/crates/horizon-client/src/mobs/species.rs @@ -1331,6 +1331,7 @@ impl Def { let mut v = vec![base]; let extra: &[&str] = match self.species { Species::Pig => &["pig_baby", "cold_pig"], + Species::Mannequin => &["player_slim"], Species::Cow => &[ "cow_baby", "cold_cow", diff --git a/crates/horizon-client/src/skins.rs b/crates/horizon-client/src/skins.rs index 76bb79f6c..0393e75d0 100644 --- a/crates/horizon-client/src/skins.rs +++ b/crates/horizon-client/src/skins.rs @@ -17,6 +17,8 @@ pub enum Signature { #[derive(Clone, Debug, Default, PartialEq, Eq)] pub struct Textures { pub skin: Option, + /// The skin's `metadata.model` is `slim` (`PlayerModelType.SLIM`). + pub slim: bool, pub cape: Option, pub elytra: Option, pub signed: bool, @@ -101,6 +103,13 @@ pub fn unpack(value: &str, signature: Signature, valid_uris: &[&str]) -> Texture if !allowed { return empty; } + if kind == "SKIN" { + out.slim = texture + .get("metadata") + .and_then(|m| m.get("model")) + .and_then(|m| m.as_str()) + == Some("slim"); + } let slot = match kind.as_str() { "SKIN" => &mut out.skin, "CAPE" => &mut out.cape, @@ -809,6 +818,21 @@ pub fn sha1(data: &[u8]) -> [u8; 20] { #[cfg(test)] mod tests { + /// `MinecraftProfileTexture.getMetadata("model")`: `slim` marks a slim + /// skin; no metadata is the wide (classic) model. + #[test] + fn a_skins_model_comes_from_its_metadata() { + use super::{Signature, TEXTURE_URIS, unpack}; + let slim = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHBzOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2FiYyIsIm1ldGFkYXRhIjp7Im1vZGVsIjoic2xpbSJ9fX19"; + let wide = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHBzOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2FiYyJ9fX0="; + let t = unpack(slim, Signature::Signed, &TEXTURE_URIS); + assert_eq!( + t.skin.as_deref(), + Some("https://textures.minecraft.net/texture/abc") + ); + assert!(t.slim); + assert!(!unpack(wide, Signature::Signed, &TEXTURE_URIS).slim); + } #[test] fn profiles_parse_like_resolvable_profiles() { use super::{NameOrId, Signature, parse_profile}; diff --git a/crates/horizon-client/src/tab_list.rs b/crates/horizon-client/src/tab_list.rs index a8e60cd76..b6d5f3dbd 100644 --- a/crates/horizon-client/src/tab_list.rs +++ b/crates/horizon-client/src/tab_list.rs @@ -80,12 +80,6 @@ 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 { @@ -645,8 +639,6 @@ 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));