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:
@@ -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