Render mannequin entities (server NPCs)
Servers on 26.3 spawn NPCs as minecraft:mannequin — the avatar entity vanilla added for exactly this — instead of fake players (gommehd.net's "Gommunity" lobby NPCs are invisible today). The client never registered the type: MobTypes.load only builds species::ALL, so AddEntity produced a tracked entity but nothing to draw. - EntityDataSerializers.RESOLVABLE_PROFILE (41) decodes into Value::Profile. Before, the entry list ended at it and the mannequin's DATA_IMMOVABLE and DATA_DESCRIPTION after it never decoded. - species::ALL gains mannequin (player#main model, Humanoid anim), and the player-only render paths — skin texture, sleep pose, AvatarRenderer's 0.9375 scale — take an avatar() check instead of the id string. - SetEntityData's apply stores DATA_PROFILE on the mob, and update_remote_skins resolves its textures property through PlayerSkinRenderCache's rules (unsigned allowed, SkinManager's insecure path) the way a tab player's skin resolves. - Mannequins get the shared-flags crouch and sleeping-position handling other players already had. Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1906,10 +1906,14 @@ impl Game<'_> {
|
||||
}
|
||||
// LivingEntity.DATA_LIVING_ENTITY_FLAGS: for another player
|
||||
// too, remote_mob_data's apply reads index 8 above.
|
||||
let other = self
|
||||
.remote
|
||||
.as_ref()
|
||||
.is_some_and(|r| r.level_players.contains_key(&p.id) && r.entity_id != p.id);
|
||||
let mannequin = self
|
||||
.mobs
|
||||
.iter()
|
||||
.any(|m| m.id == p.id as u32 && &*m.kind.id == "minecraft:mannequin");
|
||||
let other = mannequin
|
||||
|| self.remote.as_ref().is_some_and(|r| {
|
||||
r.level_players.contains_key(&p.id) && r.entity_id != p.id
|
||||
});
|
||||
// LivingEntity.onSyncedDataUpdated(SLEEPING_POS_ID): another
|
||||
// player lies down in their bed (drawn lying in it), or gets up.
|
||||
if other {
|
||||
@@ -1960,11 +1964,13 @@ impl Game<'_> {
|
||||
}
|
||||
}
|
||||
// Entity.DATA_SHARED_FLAGS_ID's crouching bit: another
|
||||
// player's crouch (their model and Entity.isDiscrete's name tag).
|
||||
if self
|
||||
.remote
|
||||
.as_ref()
|
||||
.is_some_and(|r| r.level_players.contains_key(&p.id))
|
||||
// player's or a mannequin's crouch (their model and
|
||||
// Entity.isDiscrete's name tag).
|
||||
if (mannequin
|
||||
|| self
|
||||
.remote
|
||||
.as_ref()
|
||||
.is_some_and(|r| r.level_players.contains_key(&p.id)))
|
||||
&& let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
|
||||
{
|
||||
for (index, _, value) in &p.values {
|
||||
@@ -2781,6 +2787,53 @@ impl Game<'_> {
|
||||
{
|
||||
mob.skin = Some(skin);
|
||||
}
|
||||
// ClientMannequin.updateSkin (PlayerSkinRenderCache.lookup): a
|
||||
// mannequin's DATA_PROFILE `textures` property resolves like a
|
||||
// player's, never required to be signed.
|
||||
let mannequins: Vec<(u32, horizon_client::skins::Textures)> = self
|
||||
.mobs
|
||||
.iter()
|
||||
.filter(|m| &*m.kind.id == "minecraft:mannequin" && m.profile.is_some())
|
||||
.map(|m| {
|
||||
let t = m
|
||||
.profile
|
||||
.as_ref()
|
||||
.and_then(|p| p.properties.iter().find(|p| p.name == "textures"));
|
||||
let textures = t.map_or_else(Default::default, |t| {
|
||||
let signature = if t.signature.is_some() {
|
||||
horizon_client::skins::Signature::Signed
|
||||
} else {
|
||||
horizon_client::skins::Signature::Unsigned
|
||||
};
|
||||
horizon_client::skins::unpack(
|
||||
&t.value,
|
||||
signature,
|
||||
&horizon_client::skins::TEXTURE_URIS,
|
||||
)
|
||||
});
|
||||
(m.id, textures)
|
||||
})
|
||||
.collect();
|
||||
let mut resolved: Vec<(u32, Option<String>)> = Vec::new();
|
||||
for (id, textures) in mannequins {
|
||||
let skin = {
|
||||
let mut downloads = self.skin_downloads.borrow_mut();
|
||||
horizon_client::skins::lookup(&textures, false, |kind, url| {
|
||||
downloads.state(kind, url)
|
||||
})
|
||||
};
|
||||
resolved.push((id, skin));
|
||||
}
|
||||
for (id, skin) in resolved {
|
||||
let skin = skin.filter(|s| !s.starts_with("skins/") || self.show_skin(s));
|
||||
if let Some(mob) = self
|
||||
.mobs
|
||||
.iter_mut()
|
||||
.find(|m| m.id == id && &*m.kind.id == "minecraft:mannequin")
|
||||
{
|
||||
mob.skin = skin;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// Puts a downloaded skin in an atlas skin slot: a free one, else the
|
||||
/// least recently shown.
|
||||
|
||||
@@ -75,6 +75,11 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin) {
|
||||
// Zombie's three): what VillagerProfessionLayer draws.
|
||||
(Species::Villager, 19, Value::Ids(data))
|
||||
| (Species::ZombieVillager, 20, Value::Ids(data)) => villager_data(m, data, builtin),
|
||||
// Mannequin.DATA_PROFILE (after Avatar's two): whose skin it
|
||||
// wears; update_remote_skins resolves it like a tab player's.
|
||||
(Species::Mannequin, 17, Value::Profile(profile)) => {
|
||||
m.profile = Some(profile.clone());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -295,4 +300,22 @@ mod tests {
|
||||
apply(&mut e, &[(17, s::BYTE, Value::Byte(2))]);
|
||||
assert_eq!(e.extra.variant2, 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_mannequin_exists_and_takes_its_profile() {
|
||||
let Some(mut m) = mob("minecraft:mannequin") else {
|
||||
return;
|
||||
};
|
||||
assert_eq!(&*m.kind.id, "minecraft:mannequin");
|
||||
let profile = horizon_protocol::entity_data::Profile {
|
||||
name: Some("Gommunity".into()),
|
||||
uuid: Some(1),
|
||||
..Default::default()
|
||||
};
|
||||
apply(
|
||||
&mut m,
|
||||
&[(17, s::RESOLVABLE_PROFILE, Value::Profile(profile.clone()))],
|
||||
);
|
||||
assert_eq!(m.profile, Some(profile));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -861,6 +861,9 @@ 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<String>,
|
||||
/// A mannequin's `DATA_PROFILE` (ResolvableProfile): the profile's
|
||||
/// `textures` property resolves to `skin` like a player's.
|
||||
pub profile: Option<horizon_protocol::entity_data::Profile>,
|
||||
}
|
||||
/// Events a mob tick asks the game to act on.
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -1586,6 +1589,7 @@ impl Mob {
|
||||
rider: None,
|
||||
outbox: Vec::new(),
|
||||
skin: None,
|
||||
profile: None,
|
||||
attrs: Attrs {
|
||||
speed: kind.speed,
|
||||
attack_damage: kind.attack_damage,
|
||||
|
||||
@@ -92,6 +92,11 @@ fn climate(m: &Mob) -> &'static str {
|
||||
_ => "temperate",
|
||||
}
|
||||
}
|
||||
/// `AvatarRenderer` entities: a mannequin draws exactly like a player —
|
||||
/// the player model, its resolved skin and the same scale.
|
||||
fn avatar(m: &Mob) -> bool {
|
||||
matches!(&*m.kind.id, "minecraft:player" | "minecraft:mannequin")
|
||||
}
|
||||
/// The model layer key and texture for the mob's body.
|
||||
pub fn body(m: &Mob) -> (String, String) {
|
||||
use Species as S;
|
||||
@@ -103,7 +108,7 @@ pub fn body(m: &Mob) -> (String, String) {
|
||||
s.to_owned()
|
||||
}
|
||||
};
|
||||
if &*m.kind.id == "minecraft:player" {
|
||||
if avatar(m) {
|
||||
return (
|
||||
"main".into(),
|
||||
m.skin.clone().unwrap_or_else(|| m.kind.texture.clone()),
|
||||
@@ -334,7 +339,7 @@ pub fn body_color(m: &Mob, alpha: f32) -> u32 {
|
||||
pub fn layers(m: &Mob) -> Vec<Layer> {
|
||||
use Species as S;
|
||||
let mut v = Vec::new();
|
||||
if &*m.kind.id == "minecraft:player" {
|
||||
if avatar(m) {
|
||||
return v;
|
||||
}
|
||||
let white = 0xFFFF_FFFF;
|
||||
@@ -754,7 +759,7 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4
|
||||
body += (f64::from(ticks * 3.25).cos() * std::f64::consts::PI * 0.4) as f32;
|
||||
}
|
||||
// A sleeping villager, or another player lying in their bed.
|
||||
let sleep = (m.species() == Species::Villager || m.kind.id == "minecraft:player")
|
||||
let sleep = (m.species() == Species::Villager || avatar(m))
|
||||
.then(|| super::villager::sleep_pose(m))
|
||||
.flatten();
|
||||
let rotation = match sleep {
|
||||
@@ -873,7 +878,7 @@ fn red_overlay(m: &Mob) -> bool {
|
||||
m.hurt_time > 0 || (m.death_time > 0 && !super::creaking::tearing_down(m))
|
||||
}
|
||||
fn species_scale(m: &Mob, alpha: f32) -> glam::Mat4 {
|
||||
if m.kind.id == "minecraft:player" {
|
||||
if avatar(m) {
|
||||
// AvatarRenderer.scale, shared by the inventory and world renderer.
|
||||
return glam::Mat4::from_scale(glam::Vec3::splat(0.9375));
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ pub enum Species {
|
||||
Nautilus,
|
||||
ZombieNautilus,
|
||||
SulfurCube,
|
||||
Mannequin,
|
||||
}
|
||||
/// Baby bounding boxes (each class's BABY_DIMENSIONS).
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@@ -1307,6 +1308,18 @@ pub const ALL: &[Def] = &[
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
// Mannequin: the player model; the DATA_PROFILE ResolvableProfile picks
|
||||
// its skin, this texture only while that has none.
|
||||
def!(
|
||||
Mannequin,
|
||||
"mannequin",
|
||||
"player#main",
|
||||
"entity/player/wide/steve",
|
||||
A::Humanoid { zombie_arms: false },
|
||||
["", "entity.generic.hurt", "entity.generic.death"],
|
||||
None,
|
||||
Baby::None
|
||||
),
|
||||
];
|
||||
pub fn def(s: Species) -> &'static Def {
|
||||
ALL.iter().find(|d| d.species == s).unwrap_or(&ALL[0])
|
||||
@@ -1488,7 +1501,7 @@ impl Def {
|
||||
// Nautilus.handleAirSupply: it dries out on land.
|
||||
needs_water: aquatic || s == S::Nautilus,
|
||||
water_sensitive: matches!(s, S::Enderman | S::Blaze | S::SnowGolem),
|
||||
animal: !matches!(s, S::Bat | S::SulfurCube)
|
||||
animal: !matches!(s, S::Bat | S::SulfurCube | S::Mannequin)
|
||||
&& !self.hostile_class()
|
||||
&& !aquatic
|
||||
&& !matches!(
|
||||
|
||||
@@ -34,6 +34,98 @@ pub enum Value {
|
||||
Particle(Particle),
|
||||
/// A particle list (PARTICLES: a VarInt count, then each particle).
|
||||
Particles(Vec<Particle>),
|
||||
/// A `ResolvableProfile` (a mannequin's DATA_PROFILE).
|
||||
Profile(Profile),
|
||||
}
|
||||
/// `ResolvableProfile.STREAM_CODEC`: the GameProfile a mannequin or player
|
||||
/// head resolves — either a full profile (id, name and properties on the
|
||||
/// wire) or a partial one (a name and/or id to look up) — followed by a
|
||||
/// `PlayerSkin.Patch` of texture overrides.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct Profile {
|
||||
pub name: Option<String>,
|
||||
pub uuid: Option<u128>,
|
||||
/// `PropertyMap`: its `textures` property carries the skin.
|
||||
pub properties: Vec<crate::packets::login::Property>,
|
||||
/// `PlayerSkin.Patch`: texture asset ids overriding the profile's.
|
||||
pub body: Option<String>,
|
||||
pub cape: Option<String>,
|
||||
pub elytra: Option<String>,
|
||||
/// `PlayerModelType`: true is the slim (4px arms) model.
|
||||
pub slim: Option<bool>,
|
||||
}
|
||||
/// `ByteBufCodecs.GAME_PROFILE_PROPERTIES`.
|
||||
fn read_properties(r: &mut Reader) -> Result<Vec<crate::packets::login::Property>> {
|
||||
use crate::buf::Codec;
|
||||
let n = r.count(16)?;
|
||||
(0..n)
|
||||
.map(|_| crate::packets::login::Property::read(r))
|
||||
.collect()
|
||||
}
|
||||
fn write_properties(p: &[crate::packets::login::Property], w: &mut Writer) {
|
||||
use crate::buf::Codec;
|
||||
w.varint(p.len() as i32);
|
||||
p.iter()
|
||||
.for_each(|p| crate::packets::login::Property::write(p, w));
|
||||
}
|
||||
fn read_profile(r: &mut Reader) -> Result<Profile> {
|
||||
let mut p = Profile::default();
|
||||
// ByteBufCodecs.either: true is the full GameProfile, false a Partial.
|
||||
if r.bool()? {
|
||||
p.uuid = Some(r.uuid()?);
|
||||
p.name = Some(r.string(16)?);
|
||||
p.properties = read_properties(r)?;
|
||||
} else {
|
||||
if r.bool()? {
|
||||
p.name = Some(r.string(16)?);
|
||||
}
|
||||
if r.bool()? {
|
||||
p.uuid = Some(r.uuid()?);
|
||||
}
|
||||
p.properties = read_properties(r)?;
|
||||
}
|
||||
// PlayerSkin.Patch: three optional texture ids, then the model type.
|
||||
if r.bool()? {
|
||||
p.body = Some(r.string(32767)?);
|
||||
}
|
||||
if r.bool()? {
|
||||
p.cape = Some(r.string(32767)?);
|
||||
}
|
||||
if r.bool()? {
|
||||
p.elytra = Some(r.string(32767)?);
|
||||
}
|
||||
if r.bool()? {
|
||||
p.slim = Some(r.bool()?);
|
||||
}
|
||||
Ok(p)
|
||||
}
|
||||
fn write_profile(p: &Profile, w: &mut Writer) {
|
||||
let full = p.uuid.is_some() && p.name.is_some();
|
||||
w.bool(full);
|
||||
if full {
|
||||
w.uuid(p.uuid.unwrap_or(0));
|
||||
w.string(p.name.as_deref().unwrap_or(""));
|
||||
} else {
|
||||
w.bool(p.name.is_some());
|
||||
if let Some(name) = &p.name {
|
||||
w.string(name);
|
||||
}
|
||||
w.bool(p.uuid.is_some());
|
||||
if let Some(uuid) = p.uuid {
|
||||
w.uuid(uuid);
|
||||
}
|
||||
}
|
||||
write_properties(&p.properties, w);
|
||||
for texture in [&p.body, &p.cape, &p.elytra] {
|
||||
w.bool(texture.is_some());
|
||||
if let Some(texture) = texture {
|
||||
w.string(texture);
|
||||
}
|
||||
}
|
||||
w.bool(p.slim.is_some());
|
||||
if let Some(slim) = p.slim {
|
||||
w.bool(slim);
|
||||
}
|
||||
}
|
||||
/// One `ParticleTypes.STREAM_CODEC` value: the `minecraft:particle_type` id,
|
||||
/// then the data its type carries (26.3 registry order).
|
||||
@@ -258,6 +350,7 @@ fn read_value(kind: i32, r: &mut Reader) -> Result<Option<Value>> {
|
||||
| HUMANOID_ARM
|
||||
| DYE_COLOR => Value::Id(r.varint()?),
|
||||
PARTICLE => Value::Particle(Particle::read(r)?),
|
||||
RESOLVABLE_PROFILE => Value::Profile(read_profile(r)?),
|
||||
PARTICLES => {
|
||||
let n = r.count(65536)?;
|
||||
let mut list = Vec::with_capacity(n.min(64));
|
||||
@@ -305,6 +398,7 @@ fn write_value(kind: i32, v: &Value, w: &mut Writer) {
|
||||
w.varint(list.len() as i32);
|
||||
list.iter().for_each(|p| p.write(w));
|
||||
}
|
||||
Value::Profile(p) => write_profile(p, w),
|
||||
}
|
||||
let _ = kind;
|
||||
}
|
||||
@@ -455,4 +549,53 @@ mod tests {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// RESOLVABLE_PROFILE (a mannequin's DATA_PROFILE): both ResolvableProfile
|
||||
/// contents round-trip, and an entry after it still decodes.
|
||||
#[test]
|
||||
fn resolvable_profile_round_trips() {
|
||||
use crate::packets::login::Property;
|
||||
let full = Profile {
|
||||
name: Some("Gommunity".into()),
|
||||
uuid: Some(0x0123_4567_89AB_CDEF_0123_4567_89AB_CDEF),
|
||||
properties: vec![Property {
|
||||
name: "textures".into(),
|
||||
value: "e30=".into(),
|
||||
signature: Some("sig".into()),
|
||||
}],
|
||||
body: Some("minecraft:entity/player/wide/steve".into()),
|
||||
cape: None,
|
||||
elytra: None,
|
||||
slim: Some(false),
|
||||
};
|
||||
let partial = Profile {
|
||||
name: Some("Gommunity".into()),
|
||||
..Profile::default()
|
||||
};
|
||||
let mut w = Writer::new();
|
||||
EntityData::write(
|
||||
&vec![
|
||||
(
|
||||
17,
|
||||
serializer::RESOLVABLE_PROFILE,
|
||||
Value::Profile(full.clone()),
|
||||
),
|
||||
(
|
||||
17,
|
||||
serializer::RESOLVABLE_PROFILE,
|
||||
Value::Profile(partial.clone()),
|
||||
),
|
||||
(18, serializer::BOOLEAN, Value::Bool(true)),
|
||||
],
|
||||
&mut w,
|
||||
);
|
||||
assert_eq!(
|
||||
EntityData::read(&mut Reader::new(&w.data)).unwrap(),
|
||||
vec![
|
||||
(17, serializer::RESOLVABLE_PROFILE, Value::Profile(full)),
|
||||
(17, serializer::RESOLVABLE_PROFILE, Value::Profile(partial)),
|
||||
(18, serializer::BOOLEAN, Value::Bool(true)),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user