Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ archives_base_name = soundcontroller
## Fabric: https://fabricmc.net/develop
## ModMenu: https://maven.terraformersmc.com/com/terraformersmc/modmenu

modmenu_version=15.0.0-beta.3
modmenu_version=16.0.0-rc.1

minecraft_version=1.21.6
yarn_mappings=1.21.6+build.1
loader_version=0.16.14
loom_version=1.10-SNAPSHOT
minecraft_version=1.21.10
yarn_mappings=1.21.10+build.2
loader_version=0.17.2
loom_version=1.11-SNAPSHOT

# Fabric API
fabric_version=0.127.1+1.21.6
fabric_version=0.135.0+1.21.10
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bvengo/soundcontroller/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class Utils {
public static void updateExistingSounds() {
SoundSystemAccessor soundSystem = (SoundSystemAccessor) ((SoundManagerAccessor) MinecraftClient.getInstance().getSoundManager()).getSoundSystem();
// Trigger updates for all existing sounds. AMBIENT is an arbitrary category - as long as it isn't MASTER, all existing volumes will be updated.
soundSystem.invokeUpdateSoundVolume(SoundCategory.AMBIENT, 1.0f);
soundSystem.invokeUpdateSoundVolume(SoundCategory.AMBIENT);
}
}
9 changes: 4 additions & 5 deletions src/main/java/com/bvengo/soundcontroller/VolumeData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bvengo.soundcontroller;

import com.bvengo.soundcontroller.mixin.SoundSystemAccessor;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.sound.PositionedSoundInstance;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.client.sound.SoundManager;
Expand Down Expand Up @@ -31,9 +30,9 @@ public Float getVolume() {
return volume;
}

public Float getAdjustedVolume(SoundInstance sound, SoundSystemAccessor soundSystem) {
float categoryVolume = soundSystem.invokeGetSoundVolume(sound.getCategory());
float adjustment = volume * categoryVolume;
public Float getAdjustedVolume(SoundInstance sound) {
float baseCategoryVolume = MinecraftClient.getInstance().options.getSoundVolume(sound.getCategory());
float adjustment = volume * baseCategoryVolume;

return Math.max(adjustment * sound.getVolume(), 0.0F);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.bvengo.soundcontroller.config;

import com.bvengo.soundcontroller.VolumeData;
import com.bvengo.soundcontroller.mixin.SoundSystemAccessor;
import net.minecraft.client.sound.SoundInstance;
import net.minecraft.registry.Registries;
import net.minecraft.sound.SoundEvent;
Expand Down Expand Up @@ -54,9 +53,9 @@ public VolumeData getVolumeData(Identifier soundId) {
return soundVolumes.getOrDefault(soundId, new VolumeData(soundId));
}

public float getAdjustedVolume(SoundInstance sound, SoundSystemAccessor soundSystem) {
public float getAdjustedVolume(SoundInstance sound) {
VolumeData volumeData = getVolumeData(sound.getId());
return volumeData.getAdjustedVolume(sound, soundSystem);
return volumeData.getAdjustedVolume(sound);
}

public boolean areSubtitlesEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void addDoneButton() {
}

private void loadOptions() {
this.volumeListWidget.children().clear();
this.volumeListWidget.clearEntriesPublic();
this.volumeListWidget.setScrollY(0);

String search = this.searchField.getText().toLowerCase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ public void addWidgetEntry(VolumeWidgetEntry widget) {
public int getRowWidth() {
return rowWidth;
}

public void clearEntriesPublic() {
this.clearEntries();
}
}

28 changes: 14 additions & 14 deletions src/main/java/com/bvengo/soundcontroller/gui/VolumeWidgetEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,6 @@ private void init() {
addResetButton();
}

@Override
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
int leftSide = (this.screen.width - totalWidth) / 2;

this.volumeSlider.setPosition(leftSide, y);
this.volumeSlider.render(context, mouseX, mouseY, tickDelta);

this.playSoundButton.setPosition(volumeSlider.getRight() + paddingAfterSearch, y);
this.playSoundButton.render(context, mouseX, mouseY, tickDelta);

this.resetButton.setPosition(playSoundButton.getRight() + paddingBetweenButtons, y);
this.resetButton.render(context, mouseX, mouseY, tickDelta);
}

@Override
public List<? extends Element> children() {
return List.of(volumeSlider, playSoundButton, resetButton);
Expand All @@ -144,4 +130,18 @@ public List<? extends Element> children() {
public List<? extends Selectable> selectableChildren() {
return List.of(volumeSlider, playSoundButton, resetButton);
}

@Override
public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float tickDelta) {
int leftSide = (this.screen.width - totalWidth) / 2;

this.volumeSlider.setPosition(leftSide, getY());
this.volumeSlider.render(context, mouseX, mouseY, tickDelta);

this.playSoundButton.setPosition(volumeSlider.getRight() + paddingAfterSearch, getY());
this.playSoundButton.render(context, mouseX, mouseY, tickDelta);

this.resetButton.setPosition(playSoundButton.getRight() + paddingBetweenButtons, getY());
this.resetButton.render(context, mouseX, mouseY, tickDelta);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.input.AbstractInput;

/**
* Custom button widget that is used as a trigger rather than a toggle.
Expand All @@ -16,7 +17,7 @@ public ToggleButtonWidget(String buttonId, int x, int y, int width, int height,
}

@Override
public void onPress() {
public void onPress(AbstractInput input) {
// Natural toggle when button is pressed
this.onPress.onPress(this);
isPressed = !isPressed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.Click;
import net.minecraft.client.input.AbstractInput;

/**
* Custom button widget that is used as a trigger rather than a toggle.
Expand All @@ -15,12 +17,12 @@ public TriggerButtonWidget(String buttonId, int x, int y, int width, int height,
}

@Override
public void onPress() {
public void onPress(AbstractInput input) {
isPressed = true;
}

@Override
public void onRelease(double mouseX, double mouseY) {
public void onRelease(Click click) {
// Release toggle texture on release, and perform press action.
// Only perform press action if button remains hovered.
if(hovered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
@Mixin(SoundSystem.class)
public interface SoundSystemAccessor {
@Invoker("updateSoundVolume")
void invokeUpdateSoundVolume(SoundCategory category, float volume);

@Invoker("method_72233")
float invokeGetSoundVolume(SoundCategory category);
void invokeUpdateSoundVolume(SoundCategory category);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public class SoundSystemMixin {
@WrapOperation(method = "play(Lnet/minecraft/client/sound/SoundInstance;)Lnet/minecraft/client/sound/SoundSystem$PlayResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundSystem;getAdjustedVolume(FLnet/minecraft/sound/SoundCategory;)F"))
private float modifyH(SoundSystem instance, float volume, SoundCategory category, Operation<Float> original, SoundInstance sound) {
// h comes from getAdjustedVolume(float volume, Category category) - we can't inject there, because no ID is available
return SoundController.CONFIG.getAdjustedVolume(sound, (SoundSystemAccessor) this);
return SoundController.CONFIG.getAdjustedVolume(sound);
}

@Inject(method = "getAdjustedVolume(Lnet/minecraft/client/sound/SoundInstance;)F", at = @At("HEAD"), cancellable = true)
private void modifyGetAdjustedVolume(SoundInstance sound, CallbackInfoReturnable<Float> ci) {
float volume = SoundController.CONFIG.getAdjustedVolume(sound, (SoundSystemAccessor) this);
float volume = SoundController.CONFIG.getAdjustedVolume(sound);
ci.setReturnValue(volume);
ci.cancel();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"depends": {
"fabricloader": ">=0.16.0",
"minecraft": ">=1.21.6",
"minecraft": ">=1.21.9",
"java": ">=21",
"fabric-api": "*"
},
Expand Down