Merge branch 'claude/fix-bard-music-dialog-bug-Rm8DP' into dev

This commit is contained in:
Kam committed 2026-01-02 00:09:38 -05:00
commit 6cc78a62aa
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();
}
}
}
@@ -75,6 +75,12 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose {
*/
private boolean sentClosePacket = false;
/**
* Tracks the dialog sound that was played, so we can stop only this sound
* on close without affecting Bard music or other sounds.
*/
private String dialogSound = null;
public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog) {
super(npc);
this.dialog = dialog;
@@ -671,8 +677,13 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose {
this.options = new ArrayList<Integer>();
if (dialog.sound != null && !dialog.sound.isEmpty()) {
// Stop any previous dialog sound before playing new one
if (this.dialogSound != null) {
MusicController.Instance.stopSound(this.dialogSound);
}
MusicController.Instance.stopMusic();
MusicController.Instance.playSound(dialog.sound, (float) npc.posX, (float) npc.posY, (float) npc.posZ);
this.dialogSound = dialog.sound;
}
if (!dialog.showPreviousBlocks) {
@@ -707,7 +718,11 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose {
super.close();
if (parent != null)
NoppesUtil.openGUI(player, parent);
MusicController.Instance.stopAllSounds();
// Only stop the dialog sound, not Bard music or other sounds
if (this.dialogSound != null) {
MusicController.Instance.stopSound(this.dialogSound);
this.dialogSound = null;
}
}
@Override
@@ -63,6 +63,12 @@ public class GuiModernDialogInteract extends GuiNPCInterface implements IGuiClos
*/
private boolean sentClosePacket = false;
/**
* Tracks the dialog sound that was played, so we can stop only this sound
* on close without affecting Bard music or other sounds.
*/
private String dialogSound = null;
public GuiModernDialogInteract(EntityNPCInterface npc, Dialog dialog) {
super(npc);
this.dialog = dialog;
@@ -380,8 +386,13 @@ public class GuiModernDialogInteract extends GuiNPCInterface implements IGuiClos
this.options = new ArrayList<Integer>();
if (dialog.sound != null && !dialog.sound.isEmpty()) {
// Stop any previous dialog sound before playing new one
if (this.dialogSound != null) {
MusicController.Instance.stopSound(this.dialogSound);
}
MusicController.Instance.stopMusic();
MusicController.Instance.playSound(dialog.sound, (float) npc.posX, (float) npc.posY, (float) npc.posZ);
this.dialogSound = dialog.sound;
}
if (!dialog.showPreviousBlocks) {
@@ -440,6 +451,11 @@ public class GuiModernDialogInteract extends GuiNPCInterface implements IGuiClos
}
closed();
}
// Only stop the dialog sound, not Bard music or other sounds
if (this.dialogSound != null) {
MusicController.Instance.stopSound(this.dialogSound);
this.dialogSound = null;
}
super.onGuiClosed();
}
}