Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix master volume resetting to 100% when activating focused power state #145

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@

import dynamic_fps.impl.DynamicFPSMod;
import dynamic_fps.impl.util.duck.DuckSoundEngine;
import net.minecraft.client.Options;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.ChannelAccess;
import net.minecraft.client.sounds.SoundEngine;
import net.minecraft.sounds.SoundSource;

@Mixin(SoundEngine.class)
public class SoundEngineMixin implements DuckSoundEngine {
@Shadow
@Final
private Options options;

@Shadow
private boolean loaded;

Expand Down Expand Up @@ -97,10 +102,16 @@ private void play(SoundInstance instance, CallbackInfo callbackInfo) {
/**
* Applies the user's requested volume multiplier to any newly played sounds.
*/
@Inject(method = "getVolume", at = @At("RETURN"), cancellable = true)
@Inject(method = "getVolume", at = @At("HEAD"), cancellable = true)
private void getVolume(@Nullable SoundSource source, CallbackInfoReturnable<Float> callbackInfo) {
float base = 1.0f;

// Note: The original doesn't consider the user's setting when the source is MASTER
// In vanilla this doesn't matter because it's never called, but we use it when setting the gain
if (source != null) {
callbackInfo.setReturnValue(callbackInfo.getReturnValue() * DynamicFPSMod.volumeMultiplier(source));
base = this.options.getSoundSourceVolume(source);
}

callbackInfo.setReturnValue(base * DynamicFPSMod.volumeMultiplier(source));
}
}