mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 05:19:41 +00:00
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:
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user