From 1d95a4c7710fd35929c03df6babacf3e2894aad0 Mon Sep 17 00:00:00 2001 From: paulevsGitch Date: Thu, 31 Dec 2020 07:55:56 +0300 Subject: [PATCH] Music option --- .../ru/betterend/client/ClientOptions.java | 10 +++ .../mixin/client/MusicTrackerMixin.java | 63 ++++++++++--------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/main/java/ru/betterend/client/ClientOptions.java b/src/main/java/ru/betterend/client/ClientOptions.java index cc4cac0f..de13c4ec 100644 --- a/src/main/java/ru/betterend/client/ClientOptions.java +++ b/src/main/java/ru/betterend/client/ClientOptions.java @@ -5,10 +5,12 @@ import ru.betterend.config.Configs; public class ClientOptions { private static boolean customSky; private static boolean useFogDensity; + private static boolean blendBiomeMusic; public static void init() { setCustomSky(Configs.CLENT_CONFIG.getBooleanRoot("customSky", true)); setUseFogDensity(Configs.CLENT_CONFIG.getBooleanRoot("useFogDensity", true)); + setBlendBiomeMusic(Configs.CLENT_CONFIG.getBooleanRoot("blendBiomeMusic", true)); Configs.CLENT_CONFIG.saveChanges(); } @@ -27,4 +29,12 @@ public class ClientOptions { public static void setUseFogDensity(boolean useFogDensity) { ClientOptions.useFogDensity = useFogDensity; } + + public static boolean blendBiomeMusic() { + return blendBiomeMusic; + } + + public static void setBlendBiomeMusic(boolean blendBiomeMusic) { + ClientOptions.blendBiomeMusic = blendBiomeMusic; + } } diff --git a/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java b/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java index 5e0f531e..0e93e7c9 100644 --- a/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java +++ b/src/main/java/ru/betterend/mixin/client/MusicTrackerMixin.java @@ -16,6 +16,7 @@ import net.minecraft.client.sound.SoundInstance; import net.minecraft.sound.MusicSound; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; +import ru.betterend.client.ClientOptions; @Mixin(MusicTracker.class) public class MusicTrackerMixin { @@ -39,42 +40,44 @@ public class MusicTrackerMixin { @Inject(method = "tick", at = @At("HEAD"), cancellable = true) public void beOnTick(CallbackInfo info) { - MusicSound musicSound = client.getMusicType(); - if (volume > 0 && beIsInEnd() && beShouldChangeSound(musicSound)) { - if (volume > 0) { - if (srcVolume < 0) { - srcVolume = current.getVolume(); - } - if (current instanceof AbstractSoundInstance) { - ((AbstractSoundInstanceAccessor) current).setVolume(volume); - } - client.getSoundManager().updateSoundVolume(current.getCategory(), current.getVolume() * volume); - long t = System.currentTimeMillis(); - if (volume == 1 && time == 0) { + if (ClientOptions.blendBiomeMusic()) { + MusicSound musicSound = client.getMusicType(); + if (volume > 0 && beIsInEnd() && beShouldChangeSound(musicSound)) { + if (volume > 0) { + if (srcVolume < 0) { + srcVolume = current.getVolume(); + } + if (current instanceof AbstractSoundInstance) { + ((AbstractSoundInstanceAccessor) current).setVolume(volume); + } + client.getSoundManager().updateSoundVolume(current.getCategory(), current.getVolume() * volume); + long t = System.currentTimeMillis(); + if (volume == 1 && time == 0) { + time = t; + } + float delta = (t - time) * 0.0005F; time = t; + volume -= delta; + if (volume < 0) { + volume = 0; + } } - float delta = (t - time) * 0.0005F; - time = t; - volume -= delta; - if (volume < 0) { - volume = 0; + if (volume == 0) { + volume = 1; + time = 0; + srcVolume = -1; + this.client.getSoundManager().stop(this.current); + this.timeUntilNextSong = MathHelper.nextInt(this.random, 0, musicSound.getMinDelay() / 2); + this.current = null; } + if (this.current == null && this.timeUntilNextSong-- <= 0) { + this.play(musicSound); + } + info.cancel(); } - if (volume == 0) { + else { volume = 1; - time = 0; - srcVolume = -1; - this.client.getSoundManager().stop(this.current); - this.timeUntilNextSong = MathHelper.nextInt(this.random, 0, musicSound.getMinDelay() / 2); - this.current = null; } - if (this.current == null && this.timeUntilNextSong-- <= 0) { - this.play(musicSound); - } - info.cancel(); - } - else { - volume = 1; } }