diff --git a/common/src/main/java/org/orecruncher/dsurround/commands/MusicManagerCommand.java b/common/src/main/java/org/orecruncher/dsurround/commands/MusicManagerCommand.java index e8f7ff43..12cc8f68 100644 --- a/common/src/main/java/org/orecruncher/dsurround/commands/MusicManagerCommand.java +++ b/common/src/main/java/org/orecruncher/dsurround/commands/MusicManagerCommand.java @@ -10,12 +10,14 @@ public class MusicManagerCommand extends AbstractClientCommand { private static final String RESET = "reset"; private static final String PAUSE = "pause"; private static final String UNPAUSE = "unpause"; + private static final String WHATS_PLAYING = "whatsplaying"; @Override public void register(CommandDispatcher dispatcher, CommandBuildContext registryAccess) { dispatcher.register(ClientCommandRegistrationEvent.literal(COMMAND) .then(subCommand(RESET, MusicManagerCommandHandler::reset)) .then(subCommand(PAUSE, MusicManagerCommandHandler::pause)) - .then(subCommand(UNPAUSE, MusicManagerCommandHandler::unpause))); + .then(subCommand(UNPAUSE, MusicManagerCommandHandler::unpause)) + .then(subCommand(WHATS_PLAYING, MusicManagerCommandHandler::whatsPlaying))); } } diff --git a/common/src/main/java/org/orecruncher/dsurround/commands/handlers/MusicManagerCommandHandler.java b/common/src/main/java/org/orecruncher/dsurround/commands/handlers/MusicManagerCommandHandler.java index bf7f7f17..3888769c 100644 --- a/common/src/main/java/org/orecruncher/dsurround/commands/handlers/MusicManagerCommandHandler.java +++ b/common/src/main/java/org/orecruncher/dsurround/commands/handlers/MusicManagerCommandHandler.java @@ -2,6 +2,7 @@ import net.minecraft.network.chat.Component; import org.orecruncher.dsurround.lib.GameUtils; +import org.orecruncher.dsurround.lib.config.ConfigurationData; import org.orecruncher.dsurround.mixinutils.IMusicManager; public class MusicManagerCommandHandler { @@ -32,4 +33,13 @@ public static Component pause() { return Component.translatable("dsurround.command.dsmm.pause.failure", t.getMessage()); } } + + public static Component whatsPlaying() { + try { + var result = ((IMusicManager)(GameUtils.getMC().getMusicManager())).dsurround_whatsPlaying(); + return Component.translatable("dsurround.command.dsmm.whatsplaying.success", result); + } catch (Throwable t) { + return Component.translatable("dsurround.command.dsmm.whatsplaying.failure", t.getMessage()); + } + } } diff --git a/common/src/main/java/org/orecruncher/dsurround/mixins/audio/MixinMusicManager.java b/common/src/main/java/org/orecruncher/dsurround/mixins/audio/MixinMusicManager.java index 1ed5f006..a1153acb 100644 --- a/common/src/main/java/org/orecruncher/dsurround/mixins/audio/MixinMusicManager.java +++ b/common/src/main/java/org/orecruncher/dsurround/mixins/audio/MixinMusicManager.java @@ -2,9 +2,11 @@ import net.minecraft.client.resources.sounds.SoundInstance; import net.minecraft.client.sounds.MusicManager; +import net.minecraft.network.chat.Component; import net.minecraft.sounds.Music; import org.jetbrains.annotations.Nullable; import org.orecruncher.dsurround.gui.sound.SoundToast; +import org.orecruncher.dsurround.lib.gui.ColorPalette; import org.orecruncher.dsurround.mixinutils.IMusicManager; import org.orecruncher.dsurround.mixinutils.MixinHelpers; import org.spongepowered.asm.mixin.Mixin; @@ -64,6 +66,21 @@ public void dsurround_setPaused(boolean flag) { } } + @Override + public Component dsurround_whatsPlaying() { + if (this.currentMusic == null) + return Component.translatable("dsurround.text.musicmanager.nothing"); + + // Lookup meta information + var metaData = MixinHelpers.SOUND_LIBRARY.getSoundMetadata(this.currentMusic.getLocation()); + if (metaData == null || Component.empty().equals(metaData.getTitle())) + return Component.literal(this.currentMusic.getLocation().toString()); + + var title = metaData.getTitle().copy().withColor(ColorPalette.PUMPKIN_ORANGE.getValue()); + var author = metaData.getCredits().get(0).author().copy().withColor(ColorPalette.WHEAT.getValue()); + return Component.translatable("dsurround.text.musicmanager.playing", title, author, Component.translationArg(this.currentMusic.getLocation())); + } + @Inject(method = "tick()V", at = @At("HEAD"), cancellable = true) public void dsurround_pauseTickCheck(CallbackInfo ci) { if (this.dsurround_pauseTicking) diff --git a/common/src/main/java/org/orecruncher/dsurround/mixinutils/IMusicManager.java b/common/src/main/java/org/orecruncher/dsurround/mixinutils/IMusicManager.java index 59c83a78..bb46d418 100644 --- a/common/src/main/java/org/orecruncher/dsurround/mixinutils/IMusicManager.java +++ b/common/src/main/java/org/orecruncher/dsurround/mixinutils/IMusicManager.java @@ -1,5 +1,7 @@ package org.orecruncher.dsurround.mixinutils; +import net.minecraft.network.chat.Component; + public interface IMusicManager { String dsurround_getDiagnosticText(); @@ -7,4 +9,6 @@ public interface IMusicManager { void dsurround_doCommand(String command); void dsurround_setPaused(boolean flag); + + Component dsurround_whatsPlaying(); } diff --git a/common/src/main/java/org/orecruncher/dsurround/mixinutils/MixinHelpers.java b/common/src/main/java/org/orecruncher/dsurround/mixinutils/MixinHelpers.java index a972d490..68c29f8a 100644 --- a/common/src/main/java/org/orecruncher/dsurround/mixinutils/MixinHelpers.java +++ b/common/src/main/java/org/orecruncher/dsurround/mixinutils/MixinHelpers.java @@ -1,6 +1,7 @@ package org.orecruncher.dsurround.mixinutils; import org.orecruncher.dsurround.Configuration; +import org.orecruncher.dsurround.config.libraries.ISoundLibrary; import org.orecruncher.dsurround.config.libraries.ITagLibrary; import org.orecruncher.dsurround.lib.di.ContainerManager; import org.orecruncher.dsurround.lib.logging.IModLog; @@ -12,6 +13,7 @@ public class MixinHelpers { public static final IModLog LOGGER = ContainerManager.resolve(IModLog.class); public static final ITagLibrary TAG_LIBRARY = ContainerManager.resolve(ITagLibrary.class); + public static final ISoundLibrary SOUND_LIBRARY = ContainerManager.resolve(ISoundLibrary.class); public static final Configuration.SoundSystem soundSystemConfig = ContainerManager.resolve(Configuration.SoundSystem.class); public static final Configuration.FootstepAccents footstepAccentsConfig = ContainerManager.resolve(Configuration.FootstepAccents.class); public static final Configuration.ParticleTweaks particleTweaksConfig = ContainerManager.resolve(Configuration.ParticleTweaks.class); diff --git a/common/src/main/resources/assets/dsurround/lang/en_us.json b/common/src/main/resources/assets/dsurround/lang/en_us.json index f4820b90..8362dafe 100644 --- a/common/src/main/resources/assets/dsurround/lang/en_us.json +++ b/common/src/main/resources/assets/dsurround/lang/en_us.json @@ -60,6 +60,8 @@ "dsurround.command.dsmm.pause.failure": "Unable to pause the Music Manager: %1$s", "dsurround.command.dsmm.unpause.success": "Music Manager was unpaused", "dsurround.command.dsmm.unpause.failure": "Unable to unpause the Music Manager: %1$s", + "dsurround.command.dsmm.whatsplaying.success": "\u00a72Playing\u00a7r: %1$s", + "dsurround.command.dsmm.whatsplaying.failure": "Unable to determine what the Music Manager is playing: %1$s", "dsurround.config.title": "Dynamic Surroundings Configuration Options", "dsurround.config.tooltip.clientRestartRequired": "CLIENT restart required", "dsurround.config.tooltip.worldRestartRequired": "WORLD restart required", @@ -209,5 +211,7 @@ "dsurround.text.reloadassets": "[%1$s\u00a7r] \u00a7aReloaded configurations", "dsurround.text.seasons.spring": "Spring", "dsurround.text.toast.music.title": "Music \"%1$s\"", - "dsurround.text.toast.music.author": "by %1$s" + "dsurround.text.toast.music.author": "by %1$s", + "dsurround.text.musicmanager.nothing": "No music is playing", + "dsurround.text.musicmanager.playing": "%1$s by %2$s (%3$s)" }