diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 8e4038b80..dafc68cba 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1640,6 +1640,9 @@ struct Game<'a> { guest_use: Option, /// Level events of this tick for the guests, and the guest acting now. lan_events: Vec<(i32, [i32; 3], i32, Option)>, + /// Jukebox level events 1010 (song name) and 1011 (`None`) for the guests; + /// the song's network id is only known once the hub is in hand. + lan_songs: Vec<([i32; 3], Option)>, /// Block events (position, b0, b1, state) and entity events (id, event, /// position) for the guests. lan_block_events: Vec<([i32; 3], i32, i32, u32)>, @@ -12664,6 +12667,7 @@ impl<'a> Game<'a> { forced_hit: None, guest_use: None, lan_events: Vec::new(), + lan_songs: Vec::new(), lan_block_events: Vec::new(), lan_entity_events: Vec::new(), lan_critical_hits: Vec::new(), diff --git a/crates/horizon-client/src/game/jukebox.rs b/crates/horizon-client/src/game/jukebox.rs index 5c55c5f54..895b69490 100644 --- a/crates/horizon-client/src/game/jukebox.rs +++ b/crates/horizon-client/src/game/jukebox.rs @@ -99,7 +99,7 @@ impl Game<'_> { } /// Level event 1010: the song from the jukebox, and the "Now Playing" overlay. fn start_song(&mut self, pos: [i32; 3], song: &str) { - self.stop_song(pos); + self.stop_sound(pos); let Some(s) = self.res.items().songs.get(song).cloned() else { return; }; @@ -112,12 +112,22 @@ impl Game<'_> { .set_overlay(Text::translate("record.nowPlaying", &[description]), true); self.update_song_volumes(); self.notify_record_playing(pos, true); + if self.audio.capture.is_some() { + self.lan_songs.push((pos, Some(song.to_owned()))); + } } - fn stop_song(&mut self, pos: [i32; 3]) { + fn stop_sound(&mut self, pos: [i32; 3]) { if let Some(id) = self.jukebox_sounds.remove(&(pos[0], pos[1], pos[2])) { self.audio.stop_and_release(id); } + } + /// Level event 1011: the song ends, here and for the guests. + fn stop_song(&mut self, pos: [i32; 3]) { + self.stop_sound(pos); self.notify_record_playing(pos, false); + if self.audio.capture.is_some() { + self.lan_songs.push((pos, None)); + } } /// `LevelEventHandler.notifyNearbyEntities` (level events 1010 and 1011): /// parrots within three blocks of the jukebox start or stop dancing. diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 5292cd31b..cb6c0b470 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -664,6 +664,7 @@ impl Game<'_> { self.world.light_log = None; self.audio.capture = None; self.lan_events.clear(); + self.lan_songs.clear(); self.lan_critical_hits.clear(); self.streaming.extra.clear(); if announce { @@ -1255,6 +1256,16 @@ impl Game<'_> { } host.hub.level_event(kind, pos, data, acting); } + // Level events 1010 and 1011: the guests' parrots dance or stop. + for (pos, song) in std::mem::take(&mut self.lan_songs) { + match song { + Some(name) => { + let id = host.hub.registry_id("minecraft:jukebox_song", &name); + host.hub.level_event(1010, pos, id.unwrap_or(0), None); + } + None => host.hub.level_event(1011, pos, 0, None), + } + } for (pos, b0, b1, state) in std::mem::take(&mut self.lan_block_events) { host.hub.block_event(pos, b0, b1, state); }