From b676a00c1cc8bf1047261e3e18d2c5096e37e846 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 23 Oct 2024 15:01:31 +0900 Subject: [PATCH] Pause MCMusic when "Ping" packet is received This prevents Minecraft's music from playing at the same time as user-provided battle/silly music. --- .../TurnBasedMinecraft/client/BattleMusic.java | 4 ++-- .../TurnBasedMinecraft/client/ClientProxy.java | 12 +++++++++++- .../TurnBasedMinecraft/common/CommonProxy.java | 5 ++++- .../common/networking/PacketBattlePing.java | 3 ++- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleMusic.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleMusic.java index 035d877..1d6f450 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleMusic.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/BattleMusic.java @@ -180,7 +180,7 @@ public class BattleMusic if(initialized && next != null) { logger.debug("play called with file " + next.getName() + " and vol " + volume); - Minecraft.getInstance().getSoundManager().pause(); + TurnBasedMinecraftMod.proxy.pauseMCMusic(); String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase(); if(suffix.equals("mid") && sequencer != null) { @@ -362,7 +362,7 @@ public class BattleMusic } if(resumeMCSounds) { - Minecraft.getInstance().getSoundManager().resume(); + TurnBasedMinecraftMod.proxy.resumeMCMusic(); } isPlaying = false; } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java index baaa74f..ed07861 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java @@ -1483,4 +1483,14 @@ public class ClientProxy extends CommonProxy { public void showClientConfigGui() { Minecraft.getInstance().setScreen(new ClientConfigGui()); } -} \ No newline at end of file + + @Override + public void pauseMCMusic() { + Minecraft.getInstance().getSoundManager().pause(); + } + + @Override + public void resumeMCMusic() { + Minecraft.getInstance().getSoundManager().resume(); + } +} diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java index 1ef973b..8d19927 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java @@ -175,4 +175,7 @@ public class CommonProxy public void handlePacket(MSG msg,CustomPayloadEvent.Context ctx) {} public void showClientConfigGui() {} -} \ No newline at end of file + + public void pauseMCMusic() {} + public void resumeMCMusic() {} +} diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java index d640f0b..c9f057b 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/networking/PacketBattlePing.java @@ -52,8 +52,9 @@ public class PacketBattlePing { TurnBasedMinecraftMod.proxy.setBattleGuiAsGui(); TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); TurnBasedMinecraftMod.proxy.setBattleGuiTime(pkt.decisionSeconds); + TurnBasedMinecraftMod.proxy.pauseMCMusic(); }); ctx.setPacketHandled(true); } } -} \ No newline at end of file +}