diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 8460f54e6..97b4d2ba7 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -55,8 +55,8 @@ pub(super) struct LanHost { pub play: HashMap, /// 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>, + /// Hurt time, death and swing time (while swinging) of the mobs guests see. + mob_state: HashMap)>>, /// The guest each mob sees as its player, when not the host (game/lan_mobs.rs). pub mob_players: HashMap, /// 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); } diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 5def45095..ba069522c 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -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 diff --git a/crates/horizon-client/src/game/remote_mob_data.rs b/crates/horizon-client/src/game/remote_mob_data.rs index 5573d0f87..64c092142 100644 --- a/crates/horizon-client/src/game/remote_mob_data.rs +++ b/crates/horizon-client/src/game/remote_mob_data.rs @@ -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 {