From 8bdd266decb220c028ef7da99520894ae95506de Mon Sep 17 00:00:00 2001 From: bconlon Date: Sun, 17 Sep 2023 10:44:10 -0700 Subject: [PATCH] feat: Bring back MusicManagerMixin --- .../mixins/client/MusicManagerMixin.java | 26 +++++++++++++++++++ src/main/resources/cumulus_menus.mixins.json | 1 + 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/aetherteam/cumulus/mixin/mixins/client/MusicManagerMixin.java diff --git a/src/main/java/com/aetherteam/cumulus/mixin/mixins/client/MusicManagerMixin.java b/src/main/java/com/aetherteam/cumulus/mixin/mixins/client/MusicManagerMixin.java new file mode 100644 index 0000000..d81437c --- /dev/null +++ b/src/main/java/com/aetherteam/cumulus/mixin/mixins/client/MusicManagerMixin.java @@ -0,0 +1,26 @@ +package com.aetherteam.cumulus.mixin.mixins.client; + +import com.aetherteam.cumulus.client.CumulusClient; +import net.minecraft.client.Minecraft; +import net.minecraft.client.sounds.MusicManager; +import net.minecraft.sounds.Music; +import net.minecraft.sounds.Musics; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(MusicManager.class) +public class MusicManagerMixin { + /** + * This mixin modifies the return of {@link Minecraft#getSituationalMusic()} as it is given to the music variable in {@link MusicManager}. + * @param music The original {@link Music} variable. + * @return The modified {@link Music} variable. + */ + @ModifyVariable(method = "tick()V", at = @At(value = "STORE")) + public Music injected(Music music) { + if (music == Musics.MENU && CumulusClient.MENU_HELPER.getActiveMusic() != null) { + return CumulusClient.MENU_HELPER.getActiveMusic(); + } + return music; + } +} diff --git a/src/main/resources/cumulus_menus.mixins.json b/src/main/resources/cumulus_menus.mixins.json index d041e86..46fe9d7 100644 --- a/src/main/resources/cumulus_menus.mixins.json +++ b/src/main/resources/cumulus_menus.mixins.json @@ -10,6 +10,7 @@ "defaultRequire": 1 }, "client": [ + "client.MusicManagerMixin", "client.accessor.CreateWorldScreenAccessor", "client.accessor.RealmsPlayerScreenAccessor", "client.accessor.ScreenAccessor",