Merge pull request #2980 from feeldev12/fix/own-skin-first-person

fix(client): the first-person arm and the player models wear the player's own skin
This commit is contained in:
rdbt
2026-10-28 00:47:14 +00:00
committed by GitHub
3 changed files with 51 additions and 14 deletions
+7 -4
View File
@@ -10496,11 +10496,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;
+36 -10
View File
@@ -3087,6 +3087,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<horizon_client::skins::Textures> {
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.
@@ -3095,11 +3109,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
@@ -3123,27 +3146,30 @@ impl Game<'_> {
.map(|(id, uuid)| (*id as u32, *uuid))
.collect::<Vec<_>>(),
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
+8
View File
@@ -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));