mirror of
https://github.com/chylex/Better-Controls.git
synced 2026-02-14 12:06:12 +01:00
Compare commits
11 Commits
6b574f8568
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
a8cc4e115b
|
|||
|
13fc85ff1c
|
|||
|
1c7c5402ad
|
|||
|
cdb9dadaec
|
|||
|
76afa6bc40
|
|||
|
cbf5adb4a7
|
|||
|
5a67786d0b
|
|||
|
2e19fffe44
|
|||
|
32f6a6e7fe
|
|||
|
dfefab3482
|
|||
|
ffd56a4407
|
@@ -15,7 +15,7 @@ import javax.annotation.Nullable;
|
|||||||
@Mod("bettercontrols")
|
@Mod("bettercontrols")
|
||||||
public final class BetterControlsMod {
|
public final class BetterControlsMod {
|
||||||
public BetterControlsMod() {
|
public BetterControlsMod() {
|
||||||
if (FMLEnvironment.dist == Dist.CLIENT) {
|
if (FMLEnvironment.getDist() == Dist.CLIENT) {
|
||||||
BetterControlsCommon.setConfig(BetterControlsConfig.load(FMLPaths.CONFIGDIR.get().resolve("BetterControls.json")));
|
BetterControlsCommon.setConfig(BetterControlsConfig.load(FMLPaths.CONFIGDIR.get().resolve("BetterControls.json")));
|
||||||
ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> BetterControlsMod::createOptionsScreen);
|
ModLoadingContext.get().registerExtensionPoint(IConfigScreenFactory.class, () -> BetterControlsMod::createOptionsScreen);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.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
|
||||||
modSides=client
|
modSides=client
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
minecraftVersion=1.21.5
|
minecraftVersion=1.21.11
|
||||||
neoForgeVersion=21.5.0-beta
|
neoForgeVersion=21.11.12-beta
|
||||||
neoModDevVersion=2.0.88
|
neoModDevVersion=2.0.110
|
||||||
fabricVersion=0.16.14
|
fabricVersion=0.17.2
|
||||||
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.5
|
minimumMinecraftVersion=1.21.11
|
||||||
minimumNeoForgeVersion=21.5.0-beta
|
minimumNeoForgeVersion=21.11.0-beta
|
||||||
minimumFabricVersion=0.15.0
|
minimumFabricVersion=0.15.0
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ import net.minecraft.client.gui.components.CycleButton;
|
|||||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
|
import net.minecraft.client.gui.screens.options.OptionsSubScreen;
|
||||||
|
import net.minecraft.client.input.KeyEvent;
|
||||||
|
import net.minecraft.client.input.MouseButtonEvent;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -95,6 +98,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "AutoBoxing", "AutoUnboxing" })
|
||||||
private int generateFlightOptions(int y, List<GuiEventListener> elements) {
|
private int generateFlightOptions(int y, List<GuiEventListener> elements) {
|
||||||
BetterControlsConfig cfg = BetterControlsCommon.getConfig();
|
BetterControlsConfig cfg = BetterControlsCommon.getConfig();
|
||||||
|
|
||||||
@@ -210,9 +214,8 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
|
|
||||||
private static void generateBooleanOptionRow(int y, List<GuiEventListener> elements, Component text, boolean initialValue, BooleanConsumer onValueChanged) {
|
private static void generateBooleanOptionRow(int y, List<GuiEventListener> elements, Component text, boolean initialValue, BooleanConsumer onValueChanged) {
|
||||||
generateLeftSideText(y, elements, text);
|
generateLeftSideText(y, elements, text);
|
||||||
elements.add(CycleButton.onOffBuilder()
|
elements.add(CycleButton.onOffBuilder(initialValue)
|
||||||
.displayOnlyValue()
|
.displayOnlyValue()
|
||||||
.withInitialValue(Boolean.valueOf(initialValue))
|
|
||||||
.create(col2(1), y, COL2_W, 20, text, (btn, newValue) -> onValueChanged.accept(newValue.booleanValue())));
|
.create(col2(1), y, COL2_W, 20, text, (btn, newValue) -> onValueChanged.accept(newValue.booleanValue())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,32 +285,32 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
public boolean mouseClicked(@NotNull MouseButtonEvent event, boolean isDoubleClick) {
|
||||||
if (editingKeyBinding != null) {
|
if (editingKeyBinding != null) {
|
||||||
editingKeyBinding.bindAndStopEditing(InputConstants.Type.MOUSE.getOrCreate(button));
|
editingKeyBinding.bindAndStopEditing(InputConstants.Type.MOUSE.getOrCreate(event.button()));
|
||||||
onKeyBindingEditingFinished();
|
onKeyBindingEditingFinished();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return super.mouseClicked(mouseX, mouseY, button);
|
return super.mouseClicked(event, isDoubleClick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
public boolean keyPressed(@NotNull KeyEvent event) {
|
||||||
if (editingKeyBinding != null) {
|
if (editingKeyBinding != null) {
|
||||||
if (keyCode == GLFW.GLFW_KEY_ESCAPE) {
|
if (event.key() == GLFW.GLFW_KEY_ESCAPE) {
|
||||||
editingKeyBinding.bindAndStopEditing(InputConstants.UNKNOWN);
|
editingKeyBinding.bindAndStopEditing(InputConstants.UNKNOWN);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
editingKeyBinding.bindAndStopEditing(InputConstants.getKey(keyCode, scanCode));
|
editingKeyBinding.bindAndStopEditing(InputConstants.getKey(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyBindingEditingFinished();
|
onKeyBindingEditingFinished();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
return super.keyPressed(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void ensureVisible(@NotNull Entry entry) {
|
protected void scrollToEntry(@NotNull Entry entry) {
|
||||||
// Scrolling to focused item is implemented in Entry.
|
// Scrolling to focused item is implemented in Entry.
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,17 +126,17 @@ public final class OptionListWidget extends ContainerObjectSelectionList<Entry>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(@NotNull GuiGraphics graphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
public void renderContent(@NotNull GuiGraphics graphics, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
||||||
for (GuiEventListener element : elements) {
|
for (GuiEventListener element : elements) {
|
||||||
Offset offset = offsets.get(element);
|
Offset offset = offsets.get(element);
|
||||||
|
|
||||||
if (element instanceof AbstractWidget widget) {
|
if (element instanceof AbstractWidget widget) {
|
||||||
widget.setX(x + offset.x);
|
widget.setX(getX() + offset.x);
|
||||||
widget.setY(y + offset.y);
|
widget.setY(getY() + offset.y);
|
||||||
}
|
}
|
||||||
else if (element instanceof OptionWidget widget) {
|
else if (element instanceof OptionWidget widget) {
|
||||||
widget.setX(x + offset.x);
|
widget.setX(getX() + offset.x);
|
||||||
widget.setY(y + offset.y);
|
widget.setY(getY() + offset.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof Renderable renderable) {
|
if (element instanceof Renderable renderable) {
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ 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.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 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 {
|
||||||
@@ -33,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
|
||||||
@@ -42,13 +40,13 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
public boolean keyPressed(KeyEvent keyEvent) {
|
||||||
if (CommonInputs.selected(keyCode)) {
|
if (keyEvent.isSelection()) {
|
||||||
return super.keyPressed(keyCode, scanCode, modifiers);
|
return super.keyPressed(keyEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyCode == GLFW.GLFW_KEY_LEFT || keyCode == GLFW.GLFW_KEY_RIGHT) {
|
if (keyEvent.isLeft() || keyEvent.isRight()) {
|
||||||
int newOptionIndex = keyCode == GLFW.GLFW_KEY_LEFT
|
int newOptionIndex = keyEvent.isLeft()
|
||||||
? getSelectedOptionIndex() - 1
|
? getSelectedOptionIndex() - 1
|
||||||
: getSelectedOptionIndex() + 1;
|
: getSelectedOptionIndex() + 1;
|
||||||
|
|
||||||
@@ -80,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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import net.minecraft.client.KeyMapping;
|
|||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.components.AbstractButton;
|
import net.minecraft.client.gui.components.AbstractButton;
|
||||||
import net.minecraft.client.gui.components.Button;
|
import net.minecraft.client.gui.components.Button;
|
||||||
|
import net.minecraft.client.gui.components.Tooltip;
|
||||||
|
import net.minecraft.client.input.InputWithModifiers;
|
||||||
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 org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -13,7 +15,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public final class KeyBindingWidget extends Button {
|
public final class KeyBindingWidget extends Button.Plain {
|
||||||
private final KeyMapping binding;
|
private final KeyMapping binding;
|
||||||
private final Component bindingName;
|
private final Component bindingName;
|
||||||
|
|
||||||
@@ -42,11 +44,13 @@ public final class KeyBindingWidget extends Button {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected MutableComponent createNarrationMessage() {
|
protected MutableComponent createNarrationMessage() {
|
||||||
return binding.isUnbound() ? Component.translatable("narrator.controls.unbound", bindingName) : Component.translatable("narrator.controls.bound", bindingName, super.createNarrationMessage());
|
return binding.isUnbound()
|
||||||
|
? Component.translatable("narrator.controls.unbound", bindingName)
|
||||||
|
: Component.translatable("narrator.controls.bound", bindingName, super.createNarrationMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPress() {
|
public void onPress(@NotNull InputWithModifiers input) {
|
||||||
isEditing = true;
|
isEditing = true;
|
||||||
onEditingStarted.accept(this);
|
onEditingStarted.accept(this);
|
||||||
updateKeyBindingText();
|
updateKeyBindingText();
|
||||||
@@ -68,24 +72,59 @@ public final class KeyBindingWidget extends Button {
|
|||||||
|
|
||||||
public void updateKeyBindingText() {
|
public void updateKeyBindingText() {
|
||||||
boolean hasConflict = false;
|
boolean hasConflict = false;
|
||||||
|
MutableComponent conflictText = Component.empty();
|
||||||
|
|
||||||
if (!binding.isUnbound()) {
|
if (!binding.isUnbound()) {
|
||||||
for (KeyMapping other : Minecraft.getInstance().options.keyMappings) {
|
for (KeyMapping other : Minecraft.getInstance().options.keyMappings) {
|
||||||
if (binding != other && binding.same(other)) {
|
if (binding != other && binding.same(other)) {
|
||||||
|
if (hasConflict) {
|
||||||
|
conflictText.append(", ");
|
||||||
|
}
|
||||||
|
|
||||||
hasConflict = true;
|
hasConflict = true;
|
||||||
break;
|
conflictText.append(Component.translatable(other.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEditing) {
|
if (hasConflict) {
|
||||||
setMessage(Component.literal("> ").append(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.YELLOW)).append(" <").withStyle(ChatFormatting.YELLOW));
|
setMessage(getMessageWithConflict(binding));
|
||||||
}
|
setTooltip(Tooltip.create(Component.translatable("controls.keybinds.duplicateKeybinds", conflictText)));
|
||||||
else if (hasConflict) {
|
|
||||||
setMessage(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.RED));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setMessage(binding.isUnbound() ? Component.literal("(No Binding)") : binding.getTranslatedKeyMessage());
|
setMessage(getMessageWithoutConflict(binding));
|
||||||
|
setTooltip(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEditing) {
|
||||||
|
setMessage(getEditingMessage(getMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MutableComponent getMessageWithConflict(KeyMapping binding) {
|
||||||
|
return Component
|
||||||
|
.literal("[ ")
|
||||||
|
.append(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.WHITE))
|
||||||
|
.append(" ]")
|
||||||
|
.withStyle(ChatFormatting.YELLOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Component getMessageWithoutConflict(KeyMapping binding) {
|
||||||
|
if (binding.isUnbound()) {
|
||||||
|
return Component
|
||||||
|
.literal("(")
|
||||||
|
.append(Component.translatable("key.keyboard.unknown"))
|
||||||
|
.append(")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return binding.getTranslatedKeyMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MutableComponent getEditingMessage(Component originalMessage) {
|
||||||
|
return Component
|
||||||
|
.literal("> ")
|
||||||
|
.append(originalMessage.copy().withStyle(ChatFormatting.WHITE, ChatFormatting.UNDERLINE))
|
||||||
|
.append(" <")
|
||||||
|
.withStyle(ChatFormatting.YELLOW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public record Option<T>(T value, Component text) {
|
public record Option<T>(T value, Component text) {
|
||||||
public static <T> Option<T> find(List<Option<T>> options, T value) {
|
public static <T> Option<T> find(List<Option<T>> options, T value) {
|
||||||
return options.stream().filter(it -> Objects.equals(it.value, value)).findFirst().orElseGet(() -> options.get(0));
|
return options.stream().filter(it -> Objects.equals(it.value, value)).findFirst().orElseGet(options::getFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> CycleButton<Option<T>> button(int x, int y, int width, Component text, List<Option<T>> options, T initialValue, Consumer<T> onValueChanged) {
|
public static <T> CycleButton<Option<T>> button(int x, int y, int width, Component text, List<Option<T>> options, T initialValue, Consumer<T> onValueChanged) {
|
||||||
return CycleButton.<Option<T>>builder(Option::text)
|
return CycleButton.builder(Option::text, find(options, initialValue))
|
||||||
.displayOnlyValue()
|
.displayOnlyValue()
|
||||||
.withValues(options)
|
.withValues(options)
|
||||||
.withInitialValue(find(options, initialValue))
|
|
||||||
.create(x, y, width, 20, text, (btn, newValue) -> onValueChanged.accept(newValue.value()));
|
.create(x, y, width, 20, text, (btn, newValue) -> onValueChanged.accept(newValue.value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package chylex.bettercontrols.input;
|
|||||||
|
|
||||||
import com.mojang.blaze3d.platform.InputConstants.Type;
|
import com.mojang.blaze3d.platform.InputConstants.Type;
|
||||||
import net.minecraft.client.KeyMapping;
|
import net.minecraft.client.KeyMapping;
|
||||||
|
import net.minecraft.resources.Identifier;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class KeyBindingWithModifier extends KeyMapping {
|
public class KeyBindingWithModifier extends KeyMapping {
|
||||||
public static final String CATEGORY = "key.categories.bettercontrols";
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public static final Category CATEGORY = new Category(Identifier.fromNamespaceAndPath("bettercontrols", "all"));
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ModifierKey modifier = null;
|
private ModifierKey modifier;
|
||||||
|
|
||||||
public KeyBindingWithModifier(String translationKey) {
|
public KeyBindingWithModifier(String translationKey) {
|
||||||
super(translationKey, Type.KEYSYM, -1, CATEGORY);
|
super(translationKey, Type.KEYSYM, -1, CATEGORY);
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
package chylex.bettercontrols.input;
|
package chylex.bettercontrols.input;
|
||||||
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
public enum ModifierKey {
|
public enum ModifierKey {
|
||||||
CONTROL(0) {
|
CONTROL(0) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isPressed() {
|
public boolean isPressed() {
|
||||||
return Screen.hasControlDown();
|
return Minecraft.getInstance().hasControlDown();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
SHIFT(1) {
|
SHIFT(1) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isPressed() {
|
public boolean isPressed() {
|
||||||
return Screen.hasShiftDown();
|
return Minecraft.getInstance().hasShiftDown();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
ALT(2) {
|
ALT(2) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isPressed() {
|
public boolean isPressed() {
|
||||||
return Screen.hasAltDown();
|
return Minecraft.getInstance().hasAltDown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,10 @@ package chylex.bettercontrols.mixin;
|
|||||||
import net.minecraft.client.KeyMapping;
|
import net.minecraft.client.KeyMapping;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Mixin(KeyMapping.class)
|
@Mixin(KeyMapping.class)
|
||||||
@SuppressWarnings("StaticMethodOnlyUsedInOneClass")
|
@SuppressWarnings("StaticMethodOnlyUsedInOneClass")
|
||||||
public interface AccessKeyMappingFields {
|
public interface AccessKeyMappingFields {
|
||||||
@Accessor("CATEGORY_SORT_ORDER")
|
|
||||||
static Map<String, Integer> getCategoryOrderMap() {
|
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Accessor("isDown")
|
@Accessor("isDown")
|
||||||
boolean isPressedField();
|
boolean isPressedField();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package chylex.bettercontrols.mixin;
|
|||||||
|
|
||||||
import chylex.bettercontrols.BetterControlsCommon;
|
import chylex.bettercontrols.BetterControlsCommon;
|
||||||
import chylex.bettercontrols.config.BetterControlsConfig;
|
import chylex.bettercontrols.config.BetterControlsConfig;
|
||||||
import chylex.bettercontrols.input.KeyBindingWithModifier;
|
|
||||||
import net.minecraft.client.KeyMapping;
|
import net.minecraft.client.KeyMapping;
|
||||||
import net.minecraft.client.Options;
|
import net.minecraft.client.Options;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
@@ -38,6 +37,5 @@ public abstract class HookLoadGameOptions {
|
|||||||
|
|
||||||
hasLoaded = true;
|
hasLoaded = true;
|
||||||
keyMappings = ArrayUtils.addAll(keyMappings, config.getAllKeyBindings());
|
keyMappings = ArrayUtils.addAll(keyMappings, config.getAllKeyBindings());
|
||||||
AccessKeyMappingFields.getCategoryOrderMap().put(KeyBindingWithModifier.CATEGORY, Integer.valueOf(Integer.MAX_VALUE));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public abstract class HookStickyKeyBindingState extends KeyMapping {
|
|||||||
@Final
|
@Final
|
||||||
private BooleanSupplier needsToggle;
|
private BooleanSupplier needsToggle;
|
||||||
|
|
||||||
public HookStickyKeyBindingState(String translationKey, int code, String category) {
|
public HookStickyKeyBindingState(String translationKey, int code, KeyMapping.Category category) {
|
||||||
super(translationKey, code, category);
|
super(translationKey, code, category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public final class PlayerTicker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SprintMode sprintMode = getConfig().sprintMode;
|
SprintMode sprintMode = getConfig().sprintMode;
|
||||||
boolean wasSprintToggled = Boolean.TRUE.equals(OPTIONS.toggleSprint().get());
|
boolean wasSprintToggled = OPTIONS.toggleSprint().get().booleanValue();
|
||||||
boolean isSprintToggled = toggleSprint.tick();
|
boolean isSprintToggled = toggleSprint.tick();
|
||||||
|
|
||||||
if (temporarySprintTimer > 0) {
|
if (temporarySprintTimer > 0) {
|
||||||
@@ -270,7 +270,7 @@ public final class PlayerTicker {
|
|||||||
if (!getConfig().sneakingMovesCameraSmoothly) {
|
if (!getConfig().sneakingMovesCameraSmoothly) {
|
||||||
Camera camera = MINECRAFT.gameRenderer.getMainCamera();
|
Camera camera = MINECRAFT.gameRenderer.getMainCamera();
|
||||||
|
|
||||||
if (camera.getEntity() == player) {
|
if (camera.entity() == player) {
|
||||||
Mixins.cameraFields(camera).setEyeHeight(player.getEyeHeight());
|
Mixins.cameraFields(camera).setEyeHeight(player.getEyeHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user