diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 1d86fe990..f42765de8 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7674,12 +7674,21 @@ impl Game<'_> { // The hurt or death sound the mob raised (getHurtSound / getDeathSound, // its voice pitch from its own random). let queued = std::mem::take(&mut self.mobs[index].outbox); + let mut infested = false; for event in queued { - if let horizon_client::mobs::MobEvent::Sound(s, at, volume, pitch) = event { - self.audio - .play(&format!("minecraft:{s}"), Some(at), volume, pitch); + match event { + horizon_client::mobs::MobEvent::Sound(s, at, volume, pitch) => { + self.audio + .play(&format!("minecraft:{s}"), Some(at), volume, pitch); + } + horizon_client::mobs::MobEvent::Infested { .. } => infested = true, + _ => {} } } + if infested { + let id = self.mobs[index].id; + self.mob_infested(id); + } self.weapon_hit(index); } else { self.audio diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index de1cd1bee..f45e7e6a0 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -852,6 +852,18 @@ impl Game<'_> { } } } + /// `InfestedMobEffect.onMobHurt` for a mob: silverfish from half its height up. + pub(super) fn mob_infested(&mut self, mob: u32) { + if let Some(m) = self.mobs.iter().find(|m| m.id == mob) { + let at = [ + m.position.x, + m.position.y + f64::from(m.height()) / 2.0, + m.position.z, + ]; + let look = m.view_vector(); + self.infested_hurt(at, look); + } + } pub(super) fn handle_mob_events(&mut self, events: Vec) -> Result<()> { for e in events { match e { @@ -941,6 +953,7 @@ impl Game<'_> { } => { let mut killed = false; let mut hurt = false; + let mut infested = false; if let Some(t) = self.mobs.iter_mut().find(|m| m.id == target) { let hit = t.damage(amount, source); hurt = hit; @@ -949,17 +962,24 @@ impl Game<'_> { // The hurt or death sound the mob raised. let center = t.center(); for event in std::mem::take(&mut t.outbox) { - if let MobEvent::Sound(s, _, volume, pitch) = event { - self.audio.play( - &format!("minecraft:{s}"), - Some(center), - volume, - pitch, - ); + match event { + MobEvent::Sound(s, _, volume, pitch) => { + self.audio.play( + &format!("minecraft:{s}"), + Some(center), + volume, + pitch, + ); + } + MobEvent::Infested { .. } => infested = true, + _ => {} } } } } + if infested { + self.mob_infested(target); + } if hurt && let Some(Who::Mob(attacker)) = source.attacker && let Some(m) = self @@ -1005,17 +1025,7 @@ impl Game<'_> { } MobEvent::BecomeStatue { mob } => self.golem_become_statue(mob), MobEvent::EnterHive { mob, hive } => self.bee_enter_hive(mob, hive), - MobEvent::Infested { mob } => { - if let Some(m) = self.mobs.iter().find(|m| m.id == mob) { - let at = [ - m.position.x, - m.position.y + f64::from(m.height()) / 2.0, - m.position.z, - ]; - let look = m.view_vector(); - self.infested_hurt(at, look); - } - } + MobEvent::Infested { mob } => self.mob_infested(mob), MobEvent::Gift { target, item } => { if let Some(m) = self.mobs.iter_mut().find(|m| m.id == target) && m.saddle_item().is_none()