Fix Bard music restarting/duplicating when opening dialogs

Two issues were causing the bug:
1. GuiDialogInteract.close() called stopAllSounds() unconditionally,
   which stopped Bard music even when the dialog had no sound or
   when a different Bard was playing nearby.

2. MusicController.stopMusic() didn't set playDelay, allowing Bards
   to immediately restart their music after dialog close.

Changes:
- MusicController.stopMusic() now sets playDelay=20 and clears entity
  reference to prevent immediate music restart
- Added MusicController.stopSound(key) to stop specific sounds
- Dialog GUIs now track their dialog sound and only stop that on close,
  preserving Bard music and other sounds
This commit is contained in:
Claude committed 2026-01-02 03:54:19 +00:00
1 parent 8dad290486
commit f5deb8a823
3 files changed
+56 -1

No files matched your search

@@ -66,6 +66,8 @@ public class MusicController {
this.playingSound.stopSound();
this.sounds.remove(this.playingSound.sound);
this.playingSound = null;
this.entity = null;
this.playDelay = 20; // Prevent immediate restart when music is stopped
} else if (soundHandler != null) {
try {
soundHandler.stopSounds();
@@ -193,4 +195,26 @@ public class MusicController {
}
this.sounds.clear();
}
/**
* Stops a specific sound by its resource key.
* This is used to stop dialog sounds without affecting Bard music.
* @param soundKey The sound resource key to stop
*/
public void stopSound(String soundKey) {
if (soundKey == null || soundKey.isEmpty()) {
return;
}
ScriptClientSound sound = this.sounds.remove(soundKey);
if (sound != null) {
SoundHandler soundHandler = Minecraft.getMinecraft().getSoundHandler();
if (soundHandler != null) {
try {
soundHandler.stopSound(sound);
} catch (Exception ignored) {
}
}
sound.stopSound();
}
}
}