From 749a2dc9bd5d0c0367701c59b814141e24b65b19 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:30:43 +0100 Subject: [PATCH] Global level events reach a server's players; explosions play their packet's sound ServerLevel.globalLevelEvent (an end portal opening, 1038; the dragon's death roar, 1028) went to the Game's own audio without a position, which is never forwarded: on the server thread, LAN and dedicated servers nobody heard them. They now go to every guest as a global LevelEvent, which a client plays two blocks from its camera towards the event (LevelEventHandler.globalLevelEvent). ClientPacketListener.handleExplosion plays the packet's explosionSound; the client always played entity.generic.explode (a vanilla server's wind charge sounded like TNT). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 3 ++ crates/horizon-client/src/game/dragon.rs | 7 ++-- crates/horizon-client/src/game/end.rs | 7 ++-- crates/horizon-client/src/game/lan.rs | 3 ++ .../horizon-client/src/game/lan_particles.rs | 12 +++---- .../src/game/level_particles.rs | 33 +++++++++++++++++++ crates/horizon-client/src/game/remote.rs | 30 +++++++++++------ crates/horizon-client/src/lan/containers.rs | 11 +++++++ 8 files changed, 84 insertions(+), 22 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 699468651..afd8181cc 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1544,6 +1544,8 @@ struct Game<'a> { /// position) for the guests. lan_block_events: Vec<([i32; 3], i32, i32, u32)>, lan_entity_events: Vec<(i32, i8, [f64; 3])>, + /// Global level events for every guest (`ServerLevel.globalLevelEvent`). + lan_global_events: Vec<(i32, [i32; 3], i32)>, /// `ContainerOpenersCounter`: how many players (the host and the guests) /// have each chest open. lid_openers: HashMap<(i32, i32, i32), i32>, @@ -11990,6 +11992,7 @@ impl<'a> Game<'a> { lan_events: Vec::new(), lan_block_events: Vec::new(), lan_entity_events: Vec::new(), + lan_global_events: Vec::new(), lid_openers: HashMap::new(), lan_acting: None, guest_packets: Vec::new(), diff --git a/crates/horizon-client/src/game/dragon.rs b/crates/horizon-client/src/game/dragon.rs index 54b260c67..fb555c2d8 100644 --- a/crates/horizon-client/src/game/dragon.rs +++ b/crates/horizon-client/src/game/dragon.rs @@ -1963,9 +1963,10 @@ impl Game<'_> { self.spawn_orbs([p.x, p.y, p.z], (xp as f32 * 0.08) as u32); } if t == 1 { - // Level event 1028: the death roar, heard everywhere. - self.audio - .play("minecraft:entity.ender_dragon.death", None, 5.0, 1.0); + // EnderDragon.tickDeath: global level event 1028, the death + // roar, heard everywhere. + let at = [p.x, p.y, p.z].map(|v| v.floor() as i32); + self.global_level_event(1028, at, 0); } if let Some(d) = self.dragon.as_mut() { d.position.y += 0.1; diff --git a/crates/horizon-client/src/game/end.rs b/crates/horizon-client/src/game/end.rs index 599158e3e..d3fb79172 100644 --- a/crates/horizon-client/src/game/end.rs +++ b/crates/horizon-client/src/game/end.rs @@ -311,9 +311,10 @@ impl Game<'_> { )?; } } - // Global LevelEvent 1038: END_PORTAL_SPAWN. - self.audio - .play("minecraft:block.end_portal.spawn", None, 1.0, 1.0); + // EnderEyeItem.useOn: global level event 1038 (END_PORTAL_SPAWN), + // heard by every player (vanilla places it at the frame's corner + // + (1, 0, 1); only its direction matters). + self.global_level_event(1038, c, 0); } Ok(true) } diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 8460f54e6..442c38a66 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -1150,6 +1150,9 @@ impl Game<'_> { for (id, event, at) in std::mem::take(&mut self.lan_entity_events) { host.hub.entity_event(id, event, at); } + for (kind, pos, data) in std::mem::take(&mut self.lan_global_events) { + host.hub.global_level_event(kind, pos, data); + } self.lan_broadcast_effects(host); if host.hub.guests.is_empty() { host.mob_state.clear(); diff --git a/crates/horizon-client/src/game/lan_particles.rs b/crates/horizon-client/src/game/lan_particles.rs index 1efb4ac58..0e35392bf 100644 --- a/crates/horizon-client/src/game/lan_particles.rs +++ b/crates/horizon-client/src/game/lan_particles.rs @@ -161,12 +161,12 @@ impl Game<'_> { + (self.particles.random().next_float() - self.particles.random().next_float()) * 0.2) * 0.7; - self.audio.play( - "minecraft:entity.generic.explode", - Some(p.center), - 4.0, - pitch, - ); + // The packet's explosionSound: a wind charge's burst, a bed's + // or anchor's blast, a modded sound. + let sound = self + .remote_sound_name(&p.sound) + .unwrap_or_else(|| "minecraft:entity.generic.explode".to_owned()); + self.audio.play(&sound, Some(p.center), 4.0, pitch); } if let Some(options) = self.received_particle(&p.particle, p.center) { self.particles.add(&options, p.center, [1.0, 0.0, 0.0]); diff --git a/crates/horizon-client/src/game/level_particles.rs b/crates/horizon-client/src/game/level_particles.rs index d239c69d0..f12aedc5b 100644 --- a/crates/horizon-client/src/game/level_particles.rs +++ b/crates/horizon-client/src/game/level_particles.rs @@ -101,6 +101,39 @@ impl Game<'_> { } } } + /// `ServerLevel.globalLevelEvent`: heard by every player on the server + /// (an end portal opening, the dragon's death roar): here, and sent to + /// every guest whatever their dimension. + pub(super) fn global_level_event(&mut self, id: i32, pos: [i32; 3], data: i32) { + self.global_level_event_sound(id, pos); + if self.audio.capture.is_some() { + self.lan_global_events.push((id, pos, data)); + } + } + /// `LevelEventHandler.globalLevelEvent`: the sound two blocks from the + /// camera towards the event, so it is heard from anywhere. + pub(super) fn global_level_event_sound(&mut self, id: i32, pos: [i32; 3]) { + let (sound, volume) = match id { + 1023 => ("minecraft:entity.wither.spawn", 1.0), + 1028 => ("minecraft:entity.ender_dragon.death", 5.0), + 1038 => ("minecraft:block.end_portal.spawn", 1.0), + _ => return, + }; + let at = self.eye_position().map(|eye| { + let d = [ + f64::from(pos[0]) + 0.5 - eye[0], + f64::from(pos[1]) + 0.5 - eye[1], + f64::from(pos[2]) + 0.5 - eye[2], + ]; + let length = (d[0] * d[0] + d[1] * d[1] + d[2] * d[2]).sqrt(); + if length < 1.0e-4 { + return eye; + } + [0, 1, 2].map(|k| eye[k] + d[k] / length * 2.0) + }); + // Each guest plays it from the global packet. + self.audio.play_unshared(sound, at, volume, 1.0); + } /// Queue and play level event `id` at `pos` (`Level.levelEvent`). pub(super) fn level_event_at(&mut self, id: i32, pos: [i32; 3], data: i32) { self.level_events.push(LevelEvent::LevelEvent { diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 044e43835..a80f0087a 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -255,6 +255,22 @@ fn number_format(f: &play::NumberFormat) -> horizon_client::scoreboard::NumberFo } impl Game<'_> { + /// A `Holder` off the wire: an inline event's location, or + /// the name of a registered one. + pub(super) fn remote_sound_name( + &self, + sound: &(i32, Option<(String, Option)>), + ) -> Option { + match &sound.1 { + Some((location, _)) => Some(location.clone()), + None => self.remote.as_ref().and_then(|r| { + r.builtin + .get("minecraft:sound_event")? + .name(sound.0) + .map(str::to_owned) + }), + } + } /// Leave the title for a server (ConnectScreen): an empty world fed by the connection. pub(super) fn connect_server(&mut self, address: &str, name: &str) -> Result<()> { if self.defer_world_entry(super::PendingWorldEntry::Server { @@ -1814,20 +1830,14 @@ impl Game<'_> { // ClientLevel.levelEvent: LevelEventHandler, as this client's own // level plays them (particles and sounds: a spawner's burst, bone // meal, waxing, a block broken by someone else). + // ClientPacketListener.handleLevelEvent: a global one is heard + // from anywhere (ClientLevel.globalLevelEvent). + C::LevelEvent(p) if p.global => self.global_level_event_sound(p.kind, p.pos), C::LevelEvent(p) => self.level_event_at(p.kind, p.pos, p.data), C::LevelParticles(p) => self.remote_level_particles(&p), C::Explode(p) => self.remote_explode(&p), C::Sound(p) => { - let name = match &p.sound.1 { - Some((location, _)) => Some(location.clone()), - None => self.remote.as_ref().and_then(|r| { - r.builtin - .get("minecraft:sound_event")? - .name(p.sound.0) - .map(str::to_owned) - }), - }; - if let Some(name) = name { + if let Some(name) = self.remote_sound_name(&p.sound) { let at = [ f64::from(p.x) / 8.0, f64::from(p.y) / 8.0, diff --git a/crates/horizon-client/src/lan/containers.rs b/crates/horizon-client/src/lan/containers.rs index d43cb5c27..f34d5ff58 100644 --- a/crates/horizon-client/src/lan/containers.rs +++ b/crates/horizon-client/src/lan/containers.rs @@ -78,6 +78,17 @@ impl Hub { ); } + /// `ServerLevel.globalLevelEvent`: the packet with its global flag, for + /// every player on the server (`PlayerList.broadcastAll`). + pub fn global_level_event(&self, kind: i32, pos: [i32; 3], data: i32) { + self.broadcast(&C::LevelEvent(play::LevelEvent { + kind, + pos, + data, + global: true, + })); + } + /// ClientboundBlockEventPacket (`PlayerList.broadcast` within 64 blocks). pub fn block_event(&self, pos: [i32; 3], b0: i32, b1: i32, state: u32) { let block = self