Merge pull request #2656 from kacpherek/fix/other-player-poses
🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19) after the contribution gate. Checked against vanilla 26.3 and proven in union/cg19-r2 (all round-2 PRs together: clippy, 1722 tests, 135 harnesses, lan_e2e in-frame and on the server thread) and union/cg19-r3 (the same PRs merged with today's main: 96/96 harnesses). Thanks @kacpherek.
This commit is contained in:
@@ -4224,6 +4224,18 @@ impl Game<'_> {
|
||||
&armor,
|
||||
out,
|
||||
);
|
||||
if &*mob.kind.id == "minecraft:player" {
|
||||
// PlayerRenderer's WingsLayer and SpinAttackEffectLayer.
|
||||
self.player_elytra_geometry(
|
||||
mob,
|
||||
mob.extra.chest.as_deref(),
|
||||
camera,
|
||||
alpha as f32,
|
||||
packed,
|
||||
out,
|
||||
);
|
||||
self.spin_attack_geometry(mob, camera, alpha as f32, packed, out);
|
||||
}
|
||||
self.mob_block_geometry(mob, camera, alpha, packed, out);
|
||||
if let Some(rgb) = outline {
|
||||
self.mark_outline(&out[entity_start..], rgb);
|
||||
|
||||
@@ -1990,6 +1990,27 @@ impl Game<'_> {
|
||||
m.extra.crouching = g.sneaking;
|
||||
m.extra.avatar_pose = g.pose();
|
||||
m.extra.sprinting = g.sprinting;
|
||||
// Entity.DATA_POSE and the shared and living flags the others
|
||||
// get (hub::guest_body): gliding, swimming, Riptide's spin.
|
||||
let body = lan::hub::guest_body(g);
|
||||
m.extra.fall_flying = body.gliding;
|
||||
m.extra.synced_pose = if body.swimming || body.crawling { 3 } else { 0 };
|
||||
m.extra.auto_spin_attack = body.spin_attack;
|
||||
m.velocity = g
|
||||
.motion
|
||||
.as_ref()
|
||||
.map_or(Vec3::new(dx, dy, dz), |motion| motion.velocity);
|
||||
m.tick_avatar_pose(
|
||||
g.motion
|
||||
.as_ref()
|
||||
.is_some_and(|motion| motion.fluids.was_touching_water),
|
||||
);
|
||||
// CrossbowItem.isCharged: the held crossbow's projectiles.
|
||||
m.extra.charged = g
|
||||
.inventory
|
||||
.get(g.selected)
|
||||
.and_then(|s| s.as_ref())
|
||||
.is_some_and(|s| s.data().is_some_and(|d| !d.charged.is_empty()));
|
||||
// LivingEntity.DATA_EFFECT_PARTICLES: the swirls of its visible effects.
|
||||
let visible = || g.effects.list.iter().filter(|e| e.visible);
|
||||
m.extra.effect_particles = visible()
|
||||
@@ -2064,6 +2085,15 @@ impl Game<'_> {
|
||||
),
|
||||
out,
|
||||
);
|
||||
self.player_elytra_geometry(
|
||||
m,
|
||||
m.extra.chest.as_deref(),
|
||||
camera,
|
||||
alpha as f32,
|
||||
packed,
|
||||
out,
|
||||
);
|
||||
self.spin_attack_geometry(m, camera, alpha as f32, packed, out);
|
||||
self.held_item_geometry(m, camera, alpha, packed, true, out);
|
||||
// LivingEntity.isCurrentlyGlowing: the guest's Glowing effect.
|
||||
let guest = host.hub.guest(*conn);
|
||||
|
||||
@@ -463,7 +463,14 @@ impl Game<'_> {
|
||||
&self.player_armor_layers(),
|
||||
out,
|
||||
);
|
||||
self.player_elytra_geometry(m, camera, alpha as f32, packed, out);
|
||||
self.player_elytra_geometry(
|
||||
m,
|
||||
self.armor[1].as_ref().map(|s| &*s.item),
|
||||
camera,
|
||||
alpha as f32,
|
||||
packed,
|
||||
out,
|
||||
);
|
||||
self.spin_attack_geometry(m, camera, alpha as f32, packed, out);
|
||||
self.held_item_geometry(m, camera, alpha, packed, true, out);
|
||||
// LivingEntity.isCurrentlyGlowing: the Glowing effect. A server's client is
|
||||
@@ -528,7 +535,14 @@ impl Game<'_> {
|
||||
&self.player_armor_layers(),
|
||||
&mut verts,
|
||||
);
|
||||
self.player_elytra_geometry(&m, camera, 1.0, 240 | 240 << 8, &mut verts);
|
||||
self.player_elytra_geometry(
|
||||
&m,
|
||||
self.armor[1].as_ref().map(|s| &*s.item),
|
||||
camera,
|
||||
1.0,
|
||||
240 | 240 << 8,
|
||||
&mut verts,
|
||||
);
|
||||
self.held_item_geometry(&m, camera, 1.0, 240 | 240 << 8, false, &mut verts);
|
||||
let height = if m.extra.crouching { 1.5 } else { 1.8 };
|
||||
// PictureInPictureRenderer: the box centre, (size, size, -size);
|
||||
@@ -567,17 +581,18 @@ impl Game<'_> {
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
fn player_elytra_geometry(
|
||||
/// `WingsLayer` for a player wearing `chest`.
|
||||
pub(super) fn player_elytra_geometry(
|
||||
&self,
|
||||
m: &Mob,
|
||||
chest: Option<&str>,
|
||||
camera: glam::DVec3,
|
||||
partial: f32,
|
||||
light: u32,
|
||||
out: &mut Vec<horizon_client::mesher::Vertex>,
|
||||
) {
|
||||
let Some(asset) = self.armor[1]
|
||||
.as_ref()
|
||||
.and_then(|s| self.res.items().get(&s.item))
|
||||
let Some(asset) = chest
|
||||
.and_then(|item| self.res.items().get(item))
|
||||
.and_then(|i| i.equip_asset.as_ref())
|
||||
else {
|
||||
return;
|
||||
@@ -617,7 +632,7 @@ impl Game<'_> {
|
||||
}
|
||||
/// `SpinAttackEffectLayer`: Riptide's two boxes turning around a spinning
|
||||
/// player (`SpinAttackEffectModel.setupAnim`).
|
||||
fn spin_attack_geometry(
|
||||
pub(super) fn spin_attack_geometry(
|
||||
&self,
|
||||
m: &Mob,
|
||||
camera: glam::DVec3,
|
||||
|
||||
@@ -2182,7 +2182,23 @@ impl Game<'_> {
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
// CrossbowItem.isCharged: the main hand's `charged_projectiles`
|
||||
// (AvatarRenderer.getArmPose holds a loaded crossbow up).
|
||||
let charged = p.slots.iter().find(|(slot, _)| *slot == 0).map(|(_, s)| {
|
||||
s.as_ref().is_some_and(|s| {
|
||||
matches!(
|
||||
s.component(horizon_protocol::item::component::CHARGED_PROJECTILES),
|
||||
Some(horizon_protocol::item::Component::Stacks(list))
|
||||
if !list.is_empty()
|
||||
)
|
||||
})
|
||||
});
|
||||
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32) {
|
||||
if let Some(charged) = charged
|
||||
&& &*m.kind.id == "minecraft:player"
|
||||
{
|
||||
m.extra.charged = charged;
|
||||
}
|
||||
// The body slot (6: horse armour, llama carpet, harness)
|
||||
// is kept in `head`, as Horizon's own mobs do.
|
||||
let body = horizon_client::mobs::drops::head_is_body(m.species());
|
||||
@@ -4026,6 +4042,8 @@ impl Game<'_> {
|
||||
// a player's body following its walk and look.
|
||||
if player {
|
||||
remote_player_head_turn(m);
|
||||
// LivingEntity.tick: the glide count, wings and swim amount.
|
||||
m.tick_avatar_pose(m.fluids.in_water);
|
||||
} else if m.alive() {
|
||||
m.body_rotation_tick();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ use horizon_protocol::registry::{Builtin, Dynamic};
|
||||
fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin, local_entity: i32) {
|
||||
let species = m.species();
|
||||
let baby = super::lan::baby_index(&m.kind.id);
|
||||
if &*m.kind.id == "minecraft:player" {
|
||||
player_poses(m, values);
|
||||
}
|
||||
for (index, _, value) in values {
|
||||
match (*index, value) {
|
||||
// Entity.DATA_POSE: a player's or mannequin's box follows it.
|
||||
@@ -287,6 +290,21 @@ fn apply_registry_data(
|
||||
}
|
||||
}
|
||||
|
||||
/// What another player's pose draws from: gliding (Entity.isFallFlying, flag
|
||||
/// 0x80 of the shared flags), the pose (swimming), Riptide's spin
|
||||
/// (LivingEntity.isAutoSpinAttack, flag 4) and a loaded crossbow in the
|
||||
/// hand (the held stack comes with SetEquipment).
|
||||
fn player_poses(m: &mut Mob, values: &[(u8, i32, Value)]) {
|
||||
for (index, _, value) in values {
|
||||
match (*index, value) {
|
||||
(0, Value::Byte(flags)) => m.extra.fall_flying = flags & -128 != 0,
|
||||
(6, Value::Id(pose)) => m.extra.synced_pose = (*pose).clamp(0, 17) as u8,
|
||||
(8, Value::Byte(flags)) => m.extra.auto_spin_attack = flags & 4 != 0,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The options of a synched particle list: an entity effect carries its ARGB
|
||||
/// colour, the omens none.
|
||||
fn swirls(list: &[Particle], builtin: &Builtin) -> Vec<ParticleOptions> {
|
||||
|
||||
@@ -2749,7 +2749,7 @@ fn ticking_state(rate: f32, frozen: bool) -> C {
|
||||
}
|
||||
|
||||
/// What the others see of a guest's body, from its server-side state.
|
||||
fn guest_body(g: &Guest) -> BodyFlags {
|
||||
pub fn guest_body(g: &Guest) -> BodyFlags {
|
||||
let m = g.motion.as_deref();
|
||||
BodyFlags {
|
||||
gliding: g.fall_flying,
|
||||
|
||||
@@ -741,6 +741,8 @@ pub struct Extra {
|
||||
pub blocking: bool,
|
||||
pub fall_flying: bool,
|
||||
pub fall_fly_ticks: i32,
|
||||
/// `Entity.DATA_POSE` of another player, as the server sent it.
|
||||
pub synced_pose: u8,
|
||||
/// `LivingEntity.isAutoSpinAttack` (Riptide).
|
||||
pub auto_spin_attack: bool,
|
||||
pub main_hand_left: bool,
|
||||
@@ -2638,6 +2640,25 @@ impl SwimAnimation {
|
||||
}
|
||||
}
|
||||
|
||||
impl Mob {
|
||||
/// The part of `LivingEntity.tick` and `aiStep` that animates another
|
||||
/// player from its synched pose and flags: the glide count, the wings
|
||||
/// (`elytraAnimationState`) and the swim amount (`updateSwimAmount`).
|
||||
pub fn tick_avatar_pose(&mut self, in_water: bool) {
|
||||
let e = &mut self.extra;
|
||||
e.fall_fly_ticks = if e.fall_flying {
|
||||
e.fall_fly_ticks + 1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
// LivingEntity.isVisuallySwimming: the swimming pose, or the gliding
|
||||
// pose after the glide ended.
|
||||
let visually = e.synced_pose == 3 || (!e.fall_flying && e.synced_pose == 1);
|
||||
e.elytra.tick(e.fall_flying, e.crouching, self.velocity);
|
||||
e.swim.tick(visually, in_water);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod elytra_tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user