Pause MCMusic when "Ping" packet is received

This prevents Minecraft's music from playing at the same time as
user-provided battle/silly music.
This commit is contained in:
Stephen Seo 2024-10-23 15:01:31 +09:00
parent aac81f20bc
commit 7a5c9506c9
4 changed files with 16 additions and 2 deletions

View file

@ -180,7 +180,7 @@ public class BattleMusic
if(initialized && next != null) if(initialized && next != null)
{ {
logger.debug("play called with file " + next.getName() + " and vol " + volume); 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(); String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase();
if(suffix.equals("mid") && sequencer != null) if(suffix.equals("mid") && sequencer != null)
{ {
@ -362,7 +362,7 @@ public class BattleMusic
} }
if(resumeMCSounds) if(resumeMCSounds)
{ {
Minecraft.getInstance().getSoundManager().resume(); TurnBasedMinecraftMod.proxy.resumeMCMusic();
} }
isPlaying = false; isPlaying = false;
} }

View file

@ -1482,4 +1482,14 @@ public class ClientProxy extends CommonProxy {
public void showClientConfigGui() { public void showClientConfigGui() {
Minecraft.getInstance().setScreen(new ClientConfigGui(null, null)); Minecraft.getInstance().setScreen(new ClientConfigGui(null, null));
} }
@Override
public void pauseMCMusic() {
Minecraft.getInstance().getSoundManager().pause();
}
@Override
public void resumeMCMusic() {
Minecraft.getInstance().getSoundManager().resume();
}
} }

View file

@ -177,4 +177,7 @@ public class CommonProxy
public static final StreamCodec<ByteBuf, Collection<Integer>> COLLECTION_INT_CODEC = ByteBufCodecs.INT.apply(ByteBufCodecs.collection(ArrayList::new)); public static final StreamCodec<ByteBuf, Collection<Integer>> COLLECTION_INT_CODEC = ByteBufCodecs.INT.apply(ByteBufCodecs.collection(ArrayList::new));
public void showClientConfigGui() {} public void showClientConfigGui() {}
public void pauseMCMusic() {}
public void resumeMCMusic() {}
} }

View file

@ -37,6 +37,7 @@ public record PacketBattlePing(int battleID, int remainingSeconds) implements Cu
TurnBasedMinecraftMod.proxy.setBattleGuiAsGui(); TurnBasedMinecraftMod.proxy.setBattleGuiAsGui();
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
TurnBasedMinecraftMod.proxy.setBattleGuiTime(pkt.remainingSeconds); TurnBasedMinecraftMod.proxy.setBattleGuiTime(pkt.remainingSeconds);
TurnBasedMinecraftMod.proxy.pauseMCMusic();
}).exceptionally(e -> { }).exceptionally(e -> {
ctx.disconnect(Component.literal("Exception handling PacketBattlePing! " + e.getMessage())); ctx.disconnect(Component.literal("Exception handling PacketBattlePing! " + e.getMessage()));
return null; return null;