Player heads: read the profile's skin once, and no skull on a piston head

- Skull keeps what its profile draws (the skin URL, its skins/<sha1>
  sprite and the default skin), computed when the block entity loads,
  instead of decoding base64 JSON and hashing it for every head every
  frame; skull_skin_at no longer scans the chunk's saved block entities.
- BlockEntity::for_block gave minecraft:piston_head a skull block entity
  (it ends in _head), which would have been saved as minecraft:skull.
- AGENTS.md is left as it is on main: the workflow note is not part of
  this fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-26 00:06:22 +01:00
parent 820cc211d3
commit 6824224a33
5 changed files with 74 additions and 41 deletions
-4
View File
@@ -27,10 +27,6 @@ Feature → files → harness for the most-changed areas: [docs/architecture.md]
change), none for a fix. Agents never add `release-now`: the maintainer decides it. Merges ship in batches of 5, or after
6 hours ([docs/release-flow.md](docs/release-flow.md)).
- Contributors first: `gh pr list --state open --search <area>` before you start; never duplicate theirs.
- Asked for a feature? Run the whole loop: check open PRs for the area (above), work in a new worktree,
`git fetch` the upstream remote (`ludovic111/horizon`) and start from its latest `main`, build, run
`tools/pr_ready.py`, then push to your fork and open the pull request against upstream's `main` —
never against the fork itself.
## Crates
@@ -733,7 +733,7 @@ pub struct Scene<'a> {
/// The skin sprite a `player_head` shows at a position (`SkullBlockRenderer`
/// profile → skin): a downloaded `skins/<sha1>` slot or the profile's
/// `DefaultPlayerSkin` fallback; None keeps `SKIN_BY_TYPE` (steve).
pub skull: &'a dyn Fn([i32; 3]) -> Option<String>,
pub skull: &'a dyn Fn([i32; 3]) -> Option<&'a str>,
/// Font glyph cell (none for blank glyphs such as the space) and advance.
pub glyph: &'a dyn Fn(char) -> (Option<Rect>, f32),
}
@@ -1285,10 +1285,8 @@ impl BlockEntityRenderer {
};
// SkullBlockRenderer.getRenderType: the profile's skin when it
// resolves, `SKIN_BY_TYPE` (steve) otherwise.
let skin;
let texture = if *kind == SkullType::Player {
skin = (scene.skull)(pos);
skin.as_deref().unwrap_or(texture)
(scene.skull)(pos).unwrap_or(texture)
} else {
texture
};
+46 -4
View File
@@ -82,14 +82,56 @@ pub enum BlockEntity {
/// `SkullBlockEntity` of every skull and head block.
Skull(Skull),
}
/// `SkullBlockEntity`: the player profile the head shows (kept as loaded —
/// `SkullOwner` is a compound, or a string when it names a player only),
/// the note block sound and `custom_name`.
/// `SkullBlockEntity`: the player profile the head shows (kept as loaded:
/// a compound, or a string when it names a player only), the note block
/// sound and `custom_name`.
#[derive(Clone, Debug, Default)]
pub struct Skull {
pub profile: Option<horizon_world::nbt::Tag>,
pub note_block_sound: Option<String>,
pub custom_name: Option<horizon_world::nbt::Tag>,
/// What `profile` draws, read from it once rather than every frame.
pub skin: Option<SkullSkin>,
}
impl Skull {
pub fn new(
profile: Option<horizon_world::nbt::Tag>,
note_block_sound: Option<String>,
custom_name: Option<horizon_world::nbt::Tag>,
) -> Self {
let skin = profile.as_ref().map(SkullSkin::of);
Self {
profile,
note_block_sound,
custom_name,
skin,
}
}
}
/// `SkullBlockRenderer.getPlayerSkin` of a head's profile: its skin's URL
/// with the `skins/<sha1>` sprite it downloads to, and the
/// `DefaultPlayerSkin` drawn until that sprite is there (steve for a
/// profile with no id).
#[derive(Clone, Debug)]
pub struct SkullSkin {
pub download: Option<(String, String)>,
pub fallback: &'static str,
}
impl SkullSkin {
pub fn of(profile: &horizon_world::nbt::Tag) -> Self {
let download = crate::skins::profile_skin_url_nbt(profile).and_then(|url| {
let location = crate::skins::skin_location(&crate::skins::texture_hash(&url)?);
Some((url, location))
});
let fallback = crate::skins::profile_uuid_nbt(profile)
.map_or("entity/player/wide/steve", crate::tab_list::default_skin);
Self { download, fallback }
}
}
/// The skull and head blocks (`SkullBlock`, `WallSkullBlock`): every
/// `*_skull` and `*_head` but the piston's head.
fn is_skull(name: &str) -> bool {
name.ends_with("_skull") || (name.ends_with("_head") && name != "minecraft:piston_head")
}
/// `CrafterBlockEntity`: nine slots that can be disabled, the powered flag
/// and the ticks left in the crafting animation.
@@ -244,7 +286,7 @@ impl BlockEntity {
if name.ends_with("_banner") {
return Some(Self::Banner(Banner::default()));
}
if name.ends_with("_head") || name.ends_with("_skull") {
if is_skull(name) {
return Some(Self::Skull(Skull::default()));
}
if name == "minecraft:beacon" {
@@ -394,34 +394,25 @@ impl Game<'_> {
pub(super) fn chest_lid(&self, pos: [i32; 3], partial: f32) -> f32 {
self.be_anims.lid(pos, partial)
}
/// `SkullBlockRenderer.getPlayerSkin`: the skin sprite of the `profile` of
/// `SkullBlockRenderer.getPlayerSkin`: the skin sprite of the profile of
/// the player head at `pos`. The skin download is started here; while it
/// is in flight (or when it cannot be got) the profile's uuid picks the
/// `DefaultPlayerSkin` for it, and a profile with no id keeps steve. A
/// head with no profile answers None so `SKIN_BY_TYPE` applies.
pub(super) fn skull_skin_at(&self, pos: [i32; 3]) -> Option<String> {
let key = (pos[0], pos[1], pos[2]);
let profile = match self.world.block_entities.get(&key) {
Some(BlockEntity::Skull(s)) => s.profile.clone(),
_ => None,
}
.or_else(|| self.saved_tag(pos).and_then(|t| t.get("profile").cloned()));
let profile = profile?;
if let Some(url) = skins::profile_skin_url_nbt(&profile)
&& let Some(location) =
skins::texture_hash(&url).map(|hash| skins::skin_location(&hash))
{
/// is in flight (or when it cannot be got) the profile's default skin
/// stands in. A head with no profile answers None: `SKIN_BY_TYPE`.
pub(super) fn skull_skin_at(&self, pos: [i32; 3]) -> Option<&str> {
let Some(BlockEntity::Skull(skull)) =
self.world.block_entities.get(&(pos[0], pos[1], pos[2]))
else {
return None;
};
let skin = skull.skin.as_ref()?;
if let Some((url, location)) = &skin.download {
self.skin_downloads
.borrow_mut()
.state(skins::Kind::Skin, &url);
if self.gui.atlas.sprites.contains_key(&location) {
.state(skins::Kind::Skin, url);
if self.gui.atlas.sprites.contains_key(location) {
return Some(location);
}
}
Some(
skins::profile_uuid_nbt(&profile)
.map(|uuid| horizon_client::tab_list::default_skin(uuid).to_owned())
.unwrap_or_else(|| "entity/player/wide/steve".to_owned()),
)
Some(skin.fallback)
}
}
+12 -6
View File
@@ -637,13 +637,12 @@ pub fn decode_block_entity(tag: &Tag) -> Option<((i32, i32, i32), crate::contain
if id == "minecraft:skull" {
return Some((
pos,
BlockEntity::Skull(crate::containers::Skull {
profile: tag.get("profile").cloned(),
note_block_sound: text(tag.get("note_block_sound")),
custom_name: tag
.get("custom_name")
BlockEntity::Skull(crate::containers::Skull::new(
tag.get("profile").cloned(),
text(tag.get("note_block_sound")),
tag.get("custom_name")
.and_then(crate::block_entity_nbt::component),
}),
)),
));
}
// A spawner's block entity id is not its block's name.
@@ -3940,6 +3939,13 @@ mod tests {
);
let (_, decoded) = decode_block_entity(&plain).expect("plain skull");
assert!(matches!(decoded, crate::containers::BlockEntity::Skull(_)));
// The heads and skulls have one; the piston's head is no skull.
use crate::containers::BlockEntity;
assert!(matches!(
BlockEntity::for_block("minecraft:player_wall_head"),
Some(BlockEntity::Skull(_))
));
assert!(BlockEntity::for_block("minecraft:piston_head").is_none());
}
#[test]