From 90b5e162ae0f586d9494a68a86319400bb75db9c Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Sun, 25 Oct 2026 00:38:39 +0500 Subject: [PATCH] Play a placed block's sound once for its placer BlockItem.place plays it with playSound(player, ...): the server sends it to the others, and the placer's client plays it as its block appears. The server sent it to the placer too, so each block sounded twice. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/lan_actions.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 5bee2af96..dabd5c2a6 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -2439,6 +2439,32 @@ impl Game<'_> { .map_or(&[][..], |log| log.get(logged..).unwrap_or(&[])) .to_vec(); let facts = self.res.facts(); + // BlockItem.place: `playSound(player, ...)`, for the others only. The + // placer's client plays it as its block appears. + let placed: Vec<([f64; 3], String)> = changed + .iter() + .map(|&(x, y, z)| { + let at = [f64::from(x) + 0.5, f64::from(y) + 0.5, f64::from(z) + 0.5]; + let name = &facts.get(self.world.block(x, y, z)).sounds.place; + (at, name.trim_start_matches("minecraft:").to_owned()) + }) + .collect(); + if let Some(capture) = self.audio.capture.as_mut() { + let mut i = heard.min(capture.len()); + while i < capture.len() { + let (name, at, ..) = &capture[i]; + let place = placed + .iter() + .any(|(p, n)| p == at && name.trim_start_matches("minecraft:") == n.as_str()); + if place { + let (name, at, volume, pitch) = capture.remove(i); + let source = horizon_client::settings::sound_source(&name) as i32; + host.hub.sound(&name, at, volume, pitch, source, Some(conn)); + } else { + i += 1; + } + } + } if changed.is_empty() || !changed.iter().all(|&(x, y, z)| { super::remote::hand_operated(&facts.get(self.world.block(x, y, z)).name)