1
0
mirror of https://github.com/chylex/Better-Controls.git synced 2026-02-14 03:06:13 +01:00

2 Commits

Author SHA1 Message Date
a8cc4e115b Release v1.6.4 for Minecraft 1.21.11+ 2026-01-16 05:19:35 +01:00
13fc85ff1c Fix broken slider options
Closes #48
2026-01-16 05:15:21 +01:00
2 changed files with 14 additions and 3 deletions

View File

@@ -3,7 +3,7 @@ modId=bettercontrols
modName=Better Controls modName=Better Controls
modDescription=Adds many powerful key bindings and options to control your movement.\\n\\nThe features complement vanilla mechanics without giving unfair advantages, so server use should be fine. modDescription=Adds many powerful key bindings and options to control your movement.\\n\\nThe features complement vanilla mechanics without giving unfair advantages, so server use should be fine.
modAuthor=chylex modAuthor=chylex
modVersion=1.6.3 modVersion=1.6.4
modLicense=MPL-2.0 modLicense=MPL-2.0
modSourcesURL=https://github.com/chylex/Better-Controls modSourcesURL=https://github.com/chylex/Better-Controls
modIssuesURL=https://github.com/chylex/Better-Controls/issues modIssuesURL=https://github.com/chylex/Better-Controls/issues

View File

@@ -5,7 +5,6 @@ import net.minecraft.client.gui.components.AbstractSliderButton;
import net.minecraft.client.input.KeyEvent; import net.minecraft.client.input.KeyEvent;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@@ -32,7 +31,7 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
} }
private int getSelectedOptionIndex() { private int getSelectedOptionIndex() {
return Mth.floor(Mth.clampedLerp(0.0, options.size() - 1.0, value)); return getOptionIndex(value, options.size());
} }
@Override @Override
@@ -79,6 +78,18 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
return Component.translatable("gui.narrate.slider", narration.plainCopy().append(" ").append(getMessage())); return Component.translatable("gui.narrate.slider", narration.plainCopy().append(" ").append(getMessage()));
} }
public static int getOptionIndex(double value, int optionCount) {
if (value < 0.0) {
return 0;
}
else if (value > 1.0) {
return optionCount - 1;
}
else {
return (int) (value * (optionCount - 1));
}
}
private static <T> double getOptionValue(ImmutableList<Option<T>> options, int optionIndex) { private static <T> double getOptionValue(ImmutableList<Option<T>> options, int optionIndex) {
return optionIndex / (options.size() - 1.0); return optionIndex / (options.size() - 1.0);
} }