Play the bubble pop sound when an air bubble bursts

This commit is contained in:
Kacpherek
2026-10-26 19:30:29 +01:00
parent 3a5aa2b3e7
commit 0cc3f567fc
3 changed files with 29 additions and 0 deletions
@@ -223,6 +223,7 @@ fn decorations(c: &Value, atlas: &HudAtlas) -> Vec<GuiDraw> {
display_health: int("displayHealth", 0),
last_health_time: millis - i64::from(int("lastHealthAgo", 0)),
health_blink_time: i64::from(int("healthBlinkTime", 0)),
..HealthHud::default()
};
let kind = if has("minecraft:poison") {
HeartKind::Poisoned
+13
View File
@@ -5275,6 +5275,19 @@ impl Game<'_> {
};
let draws = self.health_hud.layout(&inputs, wi, hi);
hud_layout::paint(&mut batch, atlas, &draws);
// Hud.playAirBubblePoppedSound: Player.playSound (PLAYERS), heard
// by this client only.
if let Some((volume, pitch)) = self.health_hud.bubble_pop_sound.take() {
let at = [p.position.x, p.position.y, p.position.z];
let players = horizon_client::settings::SOUND_SOURCES
.iter()
.position(|s| *s == "player")
.unwrap_or(0);
let capture = self.audio.capture.take();
self.audio
.play_on(players, "ui.hud.bubble_pop", Some(at), volume, pitch);
self.audio.capture = capture;
}
}
if contextual == ContextualBar::Locator {
let draws = self.locator_bar_draws(wi, hi);
+15
View File
@@ -485,6 +485,11 @@ pub struct HealthHud {
/// `Util.getMillis()` of the last health change.
pub last_health_time: i64,
pub health_blink_time: i64,
/// `Hud.lastBubblePopSoundPlayed`.
pub last_bubble_pop_sound: i32,
/// The `ui.hud.bubble_pop` volume and pitch `playAirBubblePoppedSound`
/// asked for this frame; the caller plays it and clears it.
pub bubble_pop_sound: Option<(f32, f32)>,
}
pub struct HealthInputs {
@@ -751,12 +756,22 @@ impl HealthHud {
let popping = bubble(0);
let delay = i32::from(air != 0 && i.under_water);
let empty = 10 - bubble(delay);
if !i.under_water {
self.last_bubble_pop_sound = 0;
}
for b in 1..=10 {
let x = x_right - (b - 1) * 8 - 9;
if b <= full {
out.push(sprite("hud/air", x, y, 9, 9));
} else if full != popping && b == popping && i.under_water {
out.push(sprite("hud/air_bursting", x, y, 9, 9));
// Hud.playAirBubblePoppedSound.
if self.last_bubble_pop_sound != b {
let volume = 0.5 + 0.1 * (empty - 3 + 1).max(0) as f32;
let pitch = 1.0 + 0.1 * (empty - 5 + 1).max(0) as f32;
self.bubble_pop_sound = Some((volume, pitch));
self.last_bubble_pop_sound = b;
}
} else if b > 10 - empty {
let wobble = if empty == 10 && i.tick % 2 == 0 {
next(2)