From 57e8de0007d63eee598d96c3f9a305659f39327d Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Mon, 26 Oct 2026 22:42:59 +0100 Subject: [PATCH] Send the drowning entity event (67) and draw the bubbles on clients --- crates/horizon-client/src/game.rs | 23 +++------- crates/horizon-client/src/game/combat.rs | 43 ++++++++++++++++++- crates/horizon-client/src/game/creatures.rs | 9 ++++ crates/horizon-client/src/game/lan_actions.rs | 9 ++++ crates/horizon-client/src/game/remote.rs | 3 ++ crates/horizon-client/src/mobs.rs | 6 +++ crates/horizon-client/src/mobs/ai.rs | 4 ++ 7 files changed, 78 insertions(+), 19 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 7596ee871..96da5c51c 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -4555,25 +4555,12 @@ impl Game<'_> { .play("minecraft:entity.player.swim", Some(feet), volume, pitch); } MotionEvent::Drown => { - // LivingEntity.makeDrownParticles: eight bubbles moving - // with the player. - use horizon_client::particles::{ParticleOptions, ParticleType}; - for _ in 0..8 { - let mut triangle = || { - let r = self.particles.random(); - r.next_double() - r.next_double() - }; - let p = [ - feet[0] + triangle(), - feet[1] + triangle(), - feet[2] + triangle(), - ]; - self.particles.add( - &ParticleOptions::simple(ParticleType::Bubble), - p, - player_velocity, - ); + // The guests see the entity event 67 too. + if let Some(host) = &self.lan { + host.hub + .entity_event(host.host_entity, combat::DROWN_EVENT, feet); } + self.drown_particles(feet, player_velocity); } MotionEvent::BubbleColumnParticle { bubble, position } => { // ServerLevel.sendParticles: SPLASH (speed 1) or BUBBLE diff --git a/crates/horizon-client/src/game/combat.rs b/crates/horizon-client/src/game/combat.rs index 6e1d5d82b..1ae609587 100644 --- a/crates/horizon-client/src/game/combat.rs +++ b/crates/horizon-client/src/game/combat.rs @@ -1,7 +1,16 @@ //! The player's `CombatTracker`: the damage taken lately, who dealt it and //! where the player fell from, turned into the vanilla death message. use super::{Game, chat::PLAYER_NAME}; -use horizon_client::{health::HealthEvent, motion::MotionEvent, text::Text}; +use horizon_client::{ + health::HealthEvent, + motion::MotionEvent, + particles::{ParticleOptions, ParticleType}, + text::Text, +}; +use horizon_core::random::RandomSource; + +/// `EntityEvent.DROWN_PARTICLES`: broadcast with the drowning damage. +pub(super) const DROWN_EVENT: i8 = 67; struct Entry { damage_type: String, @@ -40,6 +49,38 @@ pub(super) struct CombatTracker { fall_before: f64, } impl Game<'_> { + /// `LivingEntity.makeDrownParticles`: eight bubbles around the entity, + /// moving with it. + pub(super) fn drown_particles(&mut self, at: [f64; 3], velocity: [f64; 3]) { + let bubble = ParticleOptions::simple(ParticleType::Bubble); + for _ in 0..8 { + let mut triangle = || { + let r = self.particles.random(); + r.next_double() - r.next_double() + }; + let p = [at[0] + triangle(), at[1] + triangle(), at[2] + triangle()]; + self.particles.add(&bubble, p, velocity); + } + } + /// Entity event 67 from a server, for this client's own player or an + /// entity it draws. + pub(super) fn remote_drown(&mut self, id: i32) { + let own = self.remote.as_ref().is_some_and(|r| r.entity_id == id); + let body = if own { + self.player.as_ref().map(|p| { + let (at, v) = (p.position, p.velocity); + ([at.x, at.y, at.z], [v.x, v.y, v.z]) + }) + } else { + self.mobs.iter().find(|m| m.id == id as u32).map(|m| { + let (at, v) = (m.position, m.velocity); + ([at.x, at.y, at.z], [v.x, v.y, v.z]) + }) + }; + if let Some((at, v)) = body { + self.drown_particles(at, v); + } + } /// The display name of a mob: its custom name or its type's name. pub(super) fn mob_display_name(&self, id: u32) -> Option { let m = self.mobs.iter().find(|m| m.id == id)?; diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index f6961ab13..6fcbc7166 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -897,6 +897,15 @@ impl Game<'_> { match e { MobEvent::SquidCycle { mob, at } => self.lan_entity_event(mob as i32, 19, at), MobEvent::RabbitHop { mob, at } => self.lan_entity_event(mob as i32, 1, at), + MobEvent::Drown { mob, at } => { + self.lan_entity_event(mob as i32, super::combat::DROWN_EVENT, at); + let v = self + .mobs + .iter() + .find(|m| m.id == mob) + .map_or([0.0; 3], |m| [m.velocity.x, m.velocity.y, m.velocity.z]); + self.drown_particles(at, v); + } MobEvent::Sound(name, at, volume, pitch) | MobEvent::LocalSound(name, at, volume, pitch) => { self.audio diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 98162ae46..6c7f76e16 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2312,6 +2312,15 @@ impl Game<'_> { match event { MotionEvent::HurtSound(sound) => self.player_hurt_sound(sound, at), MotionEvent::Fall(event) => self.landing_block_updates(&event), + // LivingEntity.baseTick's entity event 67, to every client + // around, the guest's own included; this window draws it too. + MotionEvent::Drown => { + if let Some(g) = host.hub.guest(conn) { + host.hub + .entity_event(g.entity_id, super::combat::DROWN_EVENT, at); + } + self.drown_particles(at, [0.0; 3]); + } _ => {} } } diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 945af4585..845b1880d 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -2138,6 +2138,9 @@ impl Game<'_> { if p.event == super::totem::TOTEM_EVENT { self.remote_totem(p.id); } + if p.event == super::combat::DROWN_EVENT { + self.remote_drown(p.id); + } } C::Animate(p) => self.remote_animate(p.id, p.action), // ClientPacketListener.handleSwingAnimation: the entity swings diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index f4086216d..53a62fe3c 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -885,6 +885,12 @@ pub enum MobEvent { mob: u32, at: [f64; 3], }, + /// `LivingEntity.baseTick`'s drowning damage: entity event 67, the + /// clients' `makeDrownParticles`. + Drown { + mob: u32, + at: [f64; 3], + }, Sound(&'static str, [f64; 3], f32, f32), /// `ChestBlockEntity.startOpen` / `stopOpen` by a copper golem: the /// chest's opener count goes up or down (interaction range 3). diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 258c1ccc7..8eacdd732 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -517,6 +517,10 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) { m.air -= 1; if m.air == -20 { m.air = 0; + events.push(MobEvent::Drown { + mob: m.id, + at: [m.position.x, m.position.y, m.position.z], + }); m.damage(2.0, Damage::of(DamageKind::Drown)); } } else if m.air < 300 {