Merge pull request #1802 from ludovic111/fix/mob-flags-and-swings

🤖 Agent: merged after verify and the parity harnesses this change reaches passed on its head.
This commit is contained in:
Ludovic Marie
2026-10-25 20:01:58 +01:00
committed by GitHub
3 changed files with 40 additions and 14 deletions
+19 -5
View File
@@ -55,8 +55,8 @@ pub(super) struct LanHost {
pub play: HashMap<u32, super::lan_actions::GuestPlay>,
/// Blocks broken this tick (their sound is a level event for the guests).
pub broken: Vec<[f64; 3]>,
/// Hurt and death state of the mobs guests see.
mob_state: HashMap<super::Dim, HashMap<u32, (i32, bool)>>,
/// Hurt time, death and swing time (while swinging) of the mobs guests see.
mob_state: HashMap<super::Dim, HashMap<u32, (i32, bool, Option<i32>)>>,
/// The guest each mob sees as its player, when not the host (game/lan_mobs.rs).
pub mob_players: HashMap<u32, u32>,
/// An integrated server's owner (game/integrated.rs).
@@ -168,11 +168,15 @@ fn mob_meta(
meta.push((9, serializer::FLOAT, Value::Float(health)));
}
defaults.push((9, serializer::FLOAT, Value::Float(1.0)));
// Mob.DATA_MOB_FLAGS_ID: no AI 1, left-handed 2.
let flags = i8::from(m.no_ai) | i8::from(m.extra.left_handed) << 1;
// Mob.DATA_MOB_FLAGS_ID: no AI 1, left-handed 2, aggressive 4 (what
// draws a vindicator's axe, a skeleton's drawn bow, a piglin's raised
// weapon).
let flags =
i8::from(m.no_ai) | i8::from(m.extra.left_handed) << 1 | i8::from(m.ai.aggressive) << 2;
if flags != 0 {
meta.push((15, serializer::BYTE, Value::Byte(flags)));
}
defaults.push((15, serializer::BYTE, Value::Byte(0)));
// AgeableMob.DATA_BABY_ID (and Zombie's, Piglin's).
if let Some(index) = baby_index(kind) {
if m.is_baby() {
@@ -1193,7 +1197,17 @@ impl Game<'_> {
if dead && !old.is_some_and(|o| o.1) {
host.hub.entity_event(m.id as i32, 3, at);
}
seen.insert(m.id, (m.hurt_time, dead));
// LivingEntity.swing on a server (a melee hit, a thrown potion):
// ClientboundSwingAnimationPacket for the players around. A swing
// started since the last flush, or restarted (its time went back).
let swing = m.ai.swinging.then_some(m.ai.swing_time);
if let Some(time) = swing
&& !dead
&& old.and_then(|o| o.2).is_none_or(|before| time < before)
{
host.hub.swing(m.id as i32, 0, at, None);
}
seen.insert(m.id, (m.hurt_time, dead, swing));
}
host.mob_state.insert(self.dim, seen);
}
-9
View File
@@ -2070,15 +2070,6 @@ impl Game<'_> {
}
}
}
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
&& m.species() == horizon_client::mobs::Species::Rabbit
{
for (index, _, value) in &p.values {
if let (15, Value::Byte(flags)) = (index, value) {
m.no_ai = flags & 1 != 0;
}
}
}
self.remote_mob_data(p.id, &p.values);
if let Some(m) = self.mobs.iter_mut().find(|m| m.id == p.id as u32)
&& m.species() == horizon_client::mobs::Species::Creeper
@@ -23,6 +23,14 @@ fn apply(m: &mut Mob, values: &[(u8, i32, Value)], builtin: &Builtin) {
// LivingEntity.DATA_HEALTH_ID: the boss bars and the death
// animation follow it.
(9, Value::Float(health)) => m.health = *health,
// Mob.DATA_MOB_FLAGS_ID: no AI 1, left-handed 2, aggressive 4.
// Mob.isAggressive draws the illagers' and skeletons' attack
// poses and the vindicator's axe.
(15, Value::Byte(flags)) => {
m.no_ai = flags & 1 != 0;
m.extra.left_handed = flags & 2 != 0;
m.ai.aggressive = flags & 4 != 0;
}
(i, Value::Bool(b)) if Some(i) == baby => m.extra.age = if *b { -1 } else { 0 },
_ => {}
}
@@ -178,6 +186,19 @@ mod tests {
assert_eq!(m.fire_ticks, 0);
}
#[test]
fn mob_flags_turn_aggression_on_and_off() {
let Some(mut m) = mob("minecraft:vindicator") else {
return;
};
apply(&mut m, &[(15, s::BYTE, Value::Byte(4 | 2))]);
assert!(m.ai.aggressive && m.extra.left_handed && !m.no_ai);
assert!(horizon_client::mobs::illager::shows_item(&m));
apply(&mut m, &[(15, s::BYTE, Value::Byte(0))]);
assert!(!m.ai.aggressive && !m.extra.left_handed);
assert!(!horizon_client::mobs::illager::shows_item(&m));
}
#[test]
fn a_villager_takes_its_type_profession_and_level() {
let Some(mut m) = mob("minecraft:villager") else {