mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-09-17 23:24:52 +02:00
Compare commits
8 Commits
5111ac5f7e
...
main
Author | SHA1 | Date | |
---|---|---|---|
2e19fffe44
|
|||
32f6a6e7fe
|
|||
dfefab3482
|
|||
ffd56a4407
|
|||
6b574f8568
|
|||
76a1353dbf
|
|||
0757d30f12
|
|||
64c4b51f0e
|
@@ -33,7 +33,7 @@ You can also bind a key that resets all **Toggle Keybinds** at once. That makes
|
|||||||
#### Flying
|
#### Flying
|
||||||
|
|
||||||
* **Double Tap 'Jump' To Fly** can be turned off.
|
* **Double Tap 'Jump' To Fly** can be turned off.
|
||||||
* **Disable Flight Inertia** stops you instantly when you stop holding movement keys.
|
* **Flight Inertia Multiplier** changes how quickly you stop moving in the air when you stop holding movement keys.
|
||||||
* **Disable Field Of View Changing** prevents sprinting, potions, and other factors from changing the FOV while flying in creative and spectator mode.
|
* **Disable Field Of View Changing** prevents sprinting, potions, and other factors from changing the FOV while flying in creative and spectator mode.
|
||||||
* **Fly On Ground** lets you fly while touching the ground in creative mode. Stop flying by tapping Sneak while touching the ground.
|
* **Fly On Ground** lets you fly while touching the ground in creative mode. Stop flying by tapping Sneak while touching the ground.
|
||||||
* **Flight Speed Multiplier** (0.25x - 8x) changes flight speed in creative and spectator mode.
|
* **Flight Speed Multiplier** (0.25x - 8x) changes flight speed in creative and spectator mode.
|
||||||
|
@@ -28,7 +28,7 @@ You can also bind a key that resets all **Toggle Keybinds** at once. That makes
|
|||||||
#### Flying
|
#### Flying
|
||||||
|
|
||||||
* **Double Tap 'Jump' To Fly** can be turned off.
|
* **Double Tap 'Jump' To Fly** can be turned off.
|
||||||
* **Disable Flight Inertia** stops you instantly when you stop holding movement keys.
|
* **Flight Inertia Multiplier** changes how quickly you stop moving in the air when you stop holding movement keys.
|
||||||
* **Disable Field Of View Changing** prevents sprinting, potions, and other factors from changing the FOV while flying in creative and spectator mode.
|
* **Disable Field Of View Changing** prevents sprinting, potions, and other factors from changing the FOV while flying in creative and spectator mode.
|
||||||
* **Fly On Ground** lets you fly while touching the ground in creative mode. Stop flying by tapping Sneak while touching the ground.
|
* **Fly On Ground** lets you fly while touching the ground in creative mode. Stop flying by tapping Sneak while touching the ground.
|
||||||
* **Flight Speed Multiplier** (0.25x - 8x) changes flight speed in creative and spectator mode.
|
* **Flight Speed Multiplier** (0.25x - 8x) changes flight speed in creative and spectator mode.
|
@@ -28,7 +28,7 @@ You can also bind a key that resets all **Toggle Keybinds** at once. That makes
|
|||||||
#### Flying
|
#### Flying
|
||||||
|
|
||||||
* **Double Tap 'Jump' To Fly** can be turned off.
|
* **Double Tap 'Jump' To Fly** can be turned off.
|
||||||
* **Disable Flight Inertia** stops you instantly when you stop holding movement keys.
|
* **Flight Inertia Multiplier** changes how quickly you stop moving in the air when you stop holding movement keys.
|
||||||
* **Disable Field Of View Changing** prevents sprinting, potions, and other factors from changing the FOV while flying in creative and spectator mode.
|
* **Disable Field Of View Changing** prevents sprinting, potions, and other factors from changing the FOV while flying in creative and spectator mode.
|
||||||
* **Fly On Ground** lets you fly while touching the ground in creative mode. Stop flying by tapping Sneak while touching the ground.
|
* **Fly On Ground** lets you fly while touching the ground in creative mode. Stop flying by tapping Sneak while touching the ground.
|
||||||
* **Flight Speed Multiplier** (0.25x - 8x) changes flight speed in creative and spectator mode.
|
* **Flight Speed Multiplier** (0.25x - 8x) changes flight speed in creative and spectator mode.
|
||||||
|
@@ -3,18 +3,18 @@ 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.5.0
|
modVersion=1.6.1
|
||||||
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
|
||||||
modSides=client
|
modSides=client
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
minecraftVersion=1.21.4
|
minecraftVersion=1.21.6
|
||||||
neoForgeVersion=21.4.77-beta
|
neoForgeVersion=21.6.20-beta
|
||||||
neoModDevVersion=2.0.76
|
neoModDevVersion=2.0.103
|
||||||
fabricVersion=0.16.10
|
fabricVersion=0.16.14
|
||||||
loomVersion=1.9
|
loomVersion=1.10
|
||||||
mixinVersion=0.12.5+mixin.0.8.5
|
mixinVersion=0.12.5+mixin.0.8.5
|
||||||
mixinExtrasVersion=0.4.1
|
mixinExtrasVersion=0.4.1
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ mixinExtrasVersion=0.4.1
|
|||||||
# https://github.com/FabricMC/fabric-loom/releases
|
# https://github.com/FabricMC/fabric-loom/releases
|
||||||
|
|
||||||
# Constraints
|
# Constraints
|
||||||
minimumMinecraftVersion=1.21.4
|
minimumMinecraftVersion=1.21.6
|
||||||
minimumNeoForgeVersion=21.4.0-beta
|
minimumNeoForgeVersion=21.6.0-beta
|
||||||
minimumFabricVersion=0.15.0
|
minimumFabricVersion=0.15.0
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
|
@@ -32,7 +32,7 @@ public final class BetterControlsConfig {
|
|||||||
|
|
||||||
public final KeyBindingWithModifier keyToggleFlight = new KeyBindingWithModifier("key.bettercontrols.toggle_flight");
|
public final KeyBindingWithModifier keyToggleFlight = new KeyBindingWithModifier("key.bettercontrols.toggle_flight");
|
||||||
public boolean doubleTapJumpToToggleFlight = true;
|
public boolean doubleTapJumpToToggleFlight = true;
|
||||||
public boolean disableFlightInertia = false;
|
public float flightInertiaMultiplier = 1F;
|
||||||
public boolean disableChangingFovWhileFlying = false;
|
public boolean disableChangingFovWhileFlying = false;
|
||||||
public boolean flyOnGroundInCreative = false;
|
public boolean flyOnGroundInCreative = false;
|
||||||
public float flightHorizontalSpeedMpCreativeDefault = 1F;
|
public float flightHorizontalSpeedMpCreativeDefault = 1F;
|
||||||
|
@@ -46,7 +46,7 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
|
|||||||
|
|
||||||
Json.writeKeyBinding(obj, "Flight.KeyToggle.Creative", cfg.keyToggleFlight);
|
Json.writeKeyBinding(obj, "Flight.KeyToggle.Creative", cfg.keyToggleFlight);
|
||||||
Json.setBool(obj, "Flight.DoubleTapJump", cfg.doubleTapJumpToToggleFlight);
|
Json.setBool(obj, "Flight.DoubleTapJump", cfg.doubleTapJumpToToggleFlight);
|
||||||
Json.setBool(obj, "Flight.DisableInertia", cfg.disableFlightInertia);
|
Json.setFloat(obj, "Flight.InertiaMultiplier", cfg.flightInertiaMultiplier);
|
||||||
Json.setBool(obj, "Flight.DisableChangingFOV", cfg.disableChangingFovWhileFlying);
|
Json.setBool(obj, "Flight.DisableChangingFOV", cfg.disableChangingFovWhileFlying);
|
||||||
Json.setBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
Json.setBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
||||||
Json.setFloat(obj, "Flight.SpeedMp.Creative.Default", cfg.flightHorizontalSpeedMpCreativeDefault);
|
Json.setFloat(obj, "Flight.SpeedMp.Creative.Default", cfg.flightHorizontalSpeedMpCreativeDefault);
|
||||||
@@ -75,6 +75,10 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
|
|||||||
cfg.sprintMode = SprintMode.TAP_TO_TOGGLE;
|
cfg.sprintMode = SprintMode.TAP_TO_TOGGLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj.has("Flight.DisableInertia") && obj.get("Flight.DisableInertia").getAsBoolean()) {
|
||||||
|
cfg.flightInertiaMultiplier = 0F;
|
||||||
|
}
|
||||||
|
|
||||||
Json.readKeyBinding(obj, "Sprint.KeyToggle", cfg.keyToggleSprint);
|
Json.readKeyBinding(obj, "Sprint.KeyToggle", cfg.keyToggleSprint);
|
||||||
cfg.sprintMode = Json.getEnum(obj, "Sprint.Mode", cfg.sprintMode, SprintMode.class);
|
cfg.sprintMode = Json.getEnum(obj, "Sprint.Mode", cfg.sprintMode, SprintMode.class);
|
||||||
cfg.doubleTapForwardToSprint = Json.getBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
|
cfg.doubleTapForwardToSprint = Json.getBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
|
||||||
@@ -88,7 +92,7 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
|
|||||||
|
|
||||||
Json.readKeyBinding(obj, "Flight.KeyToggle.Creative", cfg.keyToggleFlight);
|
Json.readKeyBinding(obj, "Flight.KeyToggle.Creative", cfg.keyToggleFlight);
|
||||||
cfg.doubleTapJumpToToggleFlight = Json.getBool(obj, "Flight.DoubleTapJump", cfg.doubleTapJumpToToggleFlight);
|
cfg.doubleTapJumpToToggleFlight = Json.getBool(obj, "Flight.DoubleTapJump", cfg.doubleTapJumpToToggleFlight);
|
||||||
cfg.disableFlightInertia = Json.getBool(obj, "Flight.DisableInertia", cfg.disableFlightInertia);
|
cfg.flightInertiaMultiplier = Json.getFloat(obj, "Flight.InertiaMultiplier", cfg.flightInertiaMultiplier, 0F, 1F);
|
||||||
cfg.disableChangingFovWhileFlying = Json.getBool(obj, "Flight.DisableChangingFOV", cfg.disableChangingFovWhileFlying);
|
cfg.disableChangingFovWhileFlying = Json.getBool(obj, "Flight.DisableChangingFOV", cfg.disableChangingFovWhileFlying);
|
||||||
cfg.flyOnGroundInCreative = Json.getBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
cfg.flyOnGroundInCreative = Json.getBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
||||||
cfg.flightHorizontalSpeedMpCreativeDefault = readHorizontalSpeedMultiplier(obj, "Flight.SpeedMp.Creative.Default", cfg.flightHorizontalSpeedMpCreativeDefault);
|
cfg.flightHorizontalSpeedMpCreativeDefault = readHorizontalSpeedMultiplier(obj, "Flight.SpeedMp.Creative.Default", cfg.flightHorizontalSpeedMpCreativeDefault);
|
||||||
|
@@ -98,6 +98,14 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
private int generateFlightOptions(int y, List<GuiEventListener> elements) {
|
private int generateFlightOptions(int y, List<GuiEventListener> elements) {
|
||||||
BetterControlsConfig cfg = BetterControlsCommon.getConfig();
|
BetterControlsConfig cfg = BetterControlsCommon.getConfig();
|
||||||
|
|
||||||
|
ImmutableList<Option<Float>> flightInertiaOptions = ImmutableList.of(
|
||||||
|
new Option<>(Float.valueOf(0.00F), text("0x")),
|
||||||
|
new Option<>(Float.valueOf(0.25F), text("0.25x")),
|
||||||
|
new Option<>(Float.valueOf(0.50F), text("0.5x")),
|
||||||
|
new Option<>(Float.valueOf(0.75F), text("0.75x")),
|
||||||
|
new Option<>(Float.valueOf(1.00F), text("1x"))
|
||||||
|
);
|
||||||
|
|
||||||
ImmutableList<Option<Float>> flightSpeedOptions = ImmutableList.of(
|
ImmutableList<Option<Float>> flightSpeedOptions = ImmutableList.of(
|
||||||
new Option<>(Float.valueOf(0.25F), text("0.25x")),
|
new Option<>(Float.valueOf(0.25F), text("0.25x")),
|
||||||
new Option<>(Float.valueOf(0.50F), text("0.5x")),
|
new Option<>(Float.valueOf(0.50F), text("0.5x")),
|
||||||
@@ -119,7 +127,8 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
generateBooleanOptionRow(y, elements, text("Double Tap 'Jump' To Fly (Creative)"), cfg.doubleTapJumpToToggleFlight, value -> cfg.doubleTapJumpToToggleFlight = value);
|
generateBooleanOptionRow(y, elements, text("Double Tap 'Jump' To Fly (Creative)"), cfg.doubleTapJumpToToggleFlight, value -> cfg.doubleTapJumpToToggleFlight = value);
|
||||||
y += ROW_HEIGHT;
|
y += ROW_HEIGHT;
|
||||||
|
|
||||||
generateBooleanOptionRow(y, elements, text("Disable Flight Inertia"), cfg.disableFlightInertia, value -> cfg.disableFlightInertia = value);
|
generateLeftSideText(y, elements, text("Flight Inertia Multiplier"));
|
||||||
|
elements.add(new DiscreteValueSliderWidget<>(col2(1), y, COL2_W, text("Flight Inertia Multiplier"), flightInertiaOptions, cfg.flightInertiaMultiplier, value -> cfg.flightInertiaMultiplier = value));
|
||||||
y += ROW_HEIGHT;
|
y += ROW_HEIGHT;
|
||||||
|
|
||||||
generateBooleanOptionRow(y, elements, text("Disable Field Of View Changing"), cfg.disableChangingFovWhileFlying, value -> cfg.disableChangingFovWhileFlying = value);
|
generateBooleanOptionRow(y, elements, text("Disable Field Of View Changing"), cfg.disableChangingFovWhileFlying, value -> cfg.disableChangingFovWhileFlying = value);
|
||||||
|
@@ -9,12 +9,11 @@ import net.minecraft.client.gui.components.Renderable;
|
|||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import java.util.ArrayList;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import static java.util.stream.Collectors.toMap;
|
||||||
|
|
||||||
public final class OptionListWidget extends ContainerObjectSelectionList<Entry> {
|
public final class OptionListWidget extends ContainerObjectSelectionList<Entry> {
|
||||||
public static final int ROW_WIDTH = 408;
|
public static final int ROW_WIDTH = 408;
|
||||||
@@ -35,28 +34,32 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
|
|
||||||
private static Offset getElementOffset(GuiEventListener element) {
|
private static Offset getElementOffset(GuiEventListener element) {
|
||||||
if (element instanceof OptionWidget widget) {
|
if (element instanceof OptionWidget widget) {
|
||||||
return new Offset(widget.getX(), widget.getY());
|
return new Offset(widget.getX(), widget.getY(), widget.getHeight());
|
||||||
}
|
}
|
||||||
else if (element instanceof AbstractWidget widget) {
|
else if (element instanceof AbstractWidget widget) {
|
||||||
return new Offset(widget.getX(), widget.getY());
|
return new Offset(widget.getX(), widget.getY(), widget.getHeight());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new Offset(0, 0);
|
return new Offset(0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OptionWidget extends GuiEventListener, Renderable {
|
public interface OptionWidget extends GuiEventListener, Renderable {
|
||||||
int getX();
|
|
||||||
int getY();
|
|
||||||
void setX(int x);
|
void setX(int x);
|
||||||
|
int getX();
|
||||||
|
|
||||||
void setY(int y);
|
void setY(int y);
|
||||||
|
int getY();
|
||||||
|
|
||||||
|
int getHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
private record Offset(int x, int y) {}
|
private record Offset(int x, int y, int height) {}
|
||||||
|
|
||||||
|
@SuppressWarnings("ThisEscapedInObjectConstruction")
|
||||||
public OptionListWidget(int width, int height, int top, int innerHeight, List<GuiEventListener> widgets) {
|
public OptionListWidget(int width, int height, int top, int innerHeight, List<GuiEventListener> widgets) {
|
||||||
super(Minecraft.getInstance(), width, height, top, innerHeight);
|
super(Minecraft.getInstance(), width, height, top, innerHeight);
|
||||||
addEntry(new Entry(widgets));
|
addEntry(new Entry(this, widgets));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -80,27 +83,46 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void ensureVisible(@NotNull Entry entry) {
|
||||||
|
// Scrolling to focused item is implemented in Entry.
|
||||||
|
}
|
||||||
|
|
||||||
protected static final class Entry extends ContainerObjectSelectionList.Entry<Entry> {
|
protected static final class Entry extends ContainerObjectSelectionList.Entry<Entry> {
|
||||||
|
private final OptionListWidget parentWidget;
|
||||||
private final List<GuiEventListener> elements;
|
private final List<GuiEventListener> elements;
|
||||||
private final List<NarratableEntry> narratables;
|
private final List<NarratableEntry> narratables;
|
||||||
private final Map<GuiEventListener, Offset> offsets;
|
private final Map<GuiEventListener, Offset> offsets;
|
||||||
|
|
||||||
public Entry(List<GuiEventListener> elements) {
|
public Entry(OptionListWidget parentWidget, List<GuiEventListener> elements) {
|
||||||
this.elements = new ArrayList<>(elements);
|
this.parentWidget = parentWidget;
|
||||||
this.narratables = elements.stream().filter(e -> e instanceof NarratableEntry).map(e -> (NarratableEntry)e).collect(Collectors.toList());
|
this.elements = List.copyOf(elements);
|
||||||
this.offsets = elements.stream().collect(Collectors.toMap(Function.identity(), OptionListWidget::getElementOffset));
|
this.narratables = elements.stream().filter(e -> e instanceof NarratableEntry).map(e -> (NarratableEntry)e).toList();
|
||||||
|
this.offsets = elements.stream().collect(toMap(Function.identity(), OptionListWidget::getElementOffset));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFocused(@Nullable GuiEventListener element) {
|
||||||
|
super.setFocused(element);
|
||||||
|
|
||||||
|
if (Minecraft.getInstance().getLastInputType().isKeyboard()) {
|
||||||
|
Offset offset = offsets.get(element);
|
||||||
|
if (offset != null) {
|
||||||
|
parentWidget.setScrollAmount(offset.y + (offset.height * 0.5F) - (parentWidget.getHeight() * 0.5F) + 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<? extends GuiEventListener> children() {
|
public List<? extends GuiEventListener> children() {
|
||||||
return Collections.unmodifiableList(elements);
|
return elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<? extends NarratableEntry> narratables() {
|
public List<? extends NarratableEntry> narratables() {
|
||||||
return Collections.unmodifiableList(narratables);
|
return narratables;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -2,10 +2,12 @@ package chylex.bettercontrols.gui.elements;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.minecraft.client.gui.components.AbstractSliderButton;
|
import net.minecraft.client.gui.components.AbstractSliderButton;
|
||||||
|
import net.minecraft.client.gui.navigation.CommonInputs;
|
||||||
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 net.minecraft.util.Mth;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
||||||
@@ -15,7 +17,7 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
|||||||
private T selectedValue;
|
private T selectedValue;
|
||||||
|
|
||||||
public DiscreteValueSliderWidget(int x, int y, int width, int height, Component narration, ImmutableList<Option<T>> options, T selectedValue, Consumer<T> onChanged) {
|
public DiscreteValueSliderWidget(int x, int y, int width, int height, Component narration, ImmutableList<Option<T>> options, T selectedValue, Consumer<T> onChanged) {
|
||||||
super(x, y, width, height, Option.find(options, selectedValue).text(), options.indexOf(Option.find(options, selectedValue)) / (options.size() - 1.0));
|
super(x, y, width, height, Option.find(options, selectedValue).text(), getOptionValue(options, options.indexOf(Option.find(options, selectedValue))));
|
||||||
this.narration = narration;
|
this.narration = narration;
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.selectedValue = selectedValue;
|
this.selectedValue = selectedValue;
|
||||||
@@ -27,7 +29,11 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Option<T> getSelectedOption() {
|
public Option<T> getSelectedOption() {
|
||||||
return options.get(Mth.floor(Mth.clampedLerp(0.0, options.size() - 1.0, value)));
|
return options.get(getSelectedOptionIndex());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getSelectedOptionIndex() {
|
||||||
|
return Mth.floor(Mth.clampedLerp(0.0, options.size() - 1.0, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,6 +41,29 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
|||||||
setMessage(getSelectedOption().text());
|
setMessage(getSelectedOption().text());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||||
|
if (CommonInputs.selected(keyCode)) {
|
||||||
|
return super.keyPressed(keyCode, scanCode, modifiers);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyCode == GLFW.GLFW_KEY_LEFT || keyCode == GLFW.GLFW_KEY_RIGHT) {
|
||||||
|
int newOptionIndex = keyCode == GLFW.GLFW_KEY_LEFT
|
||||||
|
? getSelectedOptionIndex() - 1
|
||||||
|
: getSelectedOptionIndex() + 1;
|
||||||
|
|
||||||
|
if (newOptionIndex >= 0 && newOptionIndex < options.size()) {
|
||||||
|
value = getOptionValue(options, newOptionIndex);
|
||||||
|
applyValue();
|
||||||
|
updateMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void applyValue() {
|
protected void applyValue() {
|
||||||
T newSelectedValue = getSelectedOption().value();
|
T newSelectedValue = getSelectedOption().value();
|
||||||
@@ -50,4 +79,8 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
|||||||
protected MutableComponent createNarrationMessage() {
|
protected MutableComponent createNarrationMessage() {
|
||||||
return Component.translatable("gui.narrate.slider", narration.plainCopy().append(" ").append(getMessage()));
|
return Component.translatable("gui.narrate.slider", narration.plainCopy().append(" ").append(getMessage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> double getOptionValue(ImmutableList<Option<T>> options, int optionIndex) {
|
||||||
|
return optionIndex / (options.size() - 1.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,7 @@ public final class TextWidget implements OptionWidget {
|
|||||||
public static final int LEFT = 0;
|
public static final int LEFT = 0;
|
||||||
public static final int CENTER = 1;
|
public static final int CENTER = 1;
|
||||||
|
|
||||||
public static final int WHITE = 0xFF_FF_FF;
|
public static final int WHITE = 0xFF_FF_FF_FF;
|
||||||
|
|
||||||
private final Component text;
|
private final Component text;
|
||||||
private int x;
|
private int x;
|
||||||
@@ -39,24 +39,29 @@ public final class TextWidget implements OptionWidget {
|
|||||||
this(x, y, width, 20, text, LEFT);
|
this(x, y, width, 20, text, LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setY(int y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getY() {
|
public int getY() {
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setX(int x) {
|
public int getHeight() {
|
||||||
this.x = x;
|
return height;
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setY(int y) {
|
|
||||||
this.y = y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -223,15 +223,21 @@ public final class PlayerTicker {
|
|||||||
holdingSneakWhileTouchingGround = false;
|
holdingSneakWhileTouchingGround = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FlightHelper.isFlyingCreativeOrSpectator(player) && getConfig().disableFlightInertia) {
|
if (FlightHelper.isFlyingCreativeOrSpectator(player)) {
|
||||||
ClientInput input = player.input;
|
float inertiaMultiplier = getConfig().flightInertiaMultiplier;
|
||||||
|
|
||||||
if (input.forwardImpulse == 0F && input.leftImpulse == 0F) {
|
if (inertiaMultiplier < 1F) {
|
||||||
player.setDeltaMovement(player.getDeltaMovement().multiply(0.0, 1.0, 0.0));
|
ClientInput input = player.input;
|
||||||
|
Input keyPresses = input.keyPresses;
|
||||||
|
double inertiaMultiplierSqrt = Math.sqrt(inertiaMultiplier);
|
||||||
|
|
||||||
|
if (!keyPresses.forward() && !keyPresses.backward() && !keyPresses.left() && !keyPresses.right()) {
|
||||||
|
player.setDeltaMovement(player.getDeltaMovement().multiply(inertiaMultiplierSqrt, 1.0, inertiaMultiplierSqrt));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input.keyPresses.jump() && !input.keyPresses.shift()) {
|
if (!keyPresses.jump() && !keyPresses.shift()) {
|
||||||
player.setDeltaMovement(player.getDeltaMovement().multiply(1.0, 0.0, 1.0));
|
player.setDeltaMovement(player.getDeltaMovement().multiply(1.0, inertiaMultiplierSqrt, 1.0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user