mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-12-24 12:38:25 +01:00
Compare commits
3 Commits
cbf5adb4a7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
1c7c5402ad
|
|||
|
cdb9dadaec
|
|||
|
76afa6bc40
|
@@ -3,15 +3,15 @@ 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.2
|
modVersion=1.6.3
|
||||||
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.9
|
minecraftVersion=1.21.11
|
||||||
neoForgeVersion=21.9.2-beta
|
neoForgeVersion=21.11.12-beta
|
||||||
neoModDevVersion=2.0.110
|
neoModDevVersion=2.0.110
|
||||||
fabricVersion=0.17.2
|
fabricVersion=0.17.2
|
||||||
loomVersion=1.10
|
loomVersion=1.10
|
||||||
@@ -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.9
|
minimumMinecraftVersion=1.21.11
|
||||||
minimumNeoForgeVersion=21.9.0-beta
|
minimumNeoForgeVersion=21.11.0-beta
|
||||||
minimumFabricVersion=0.15.0
|
minimumFabricVersion=0.15.0
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
|
|||||||
@@ -98,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();
|
||||||
|
|
||||||
@@ -213,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())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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.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;
|
||||||
@@ -14,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;
|
||||||
|
|
||||||
@@ -43,7 +44,9 @@ 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
|
||||||
@@ -69,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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ 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.ResourceLocation;
|
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 Category CATEGORY = new Category(ResourceLocation.fromNamespaceAndPath("bettercontrols", "all"));
|
@SuppressWarnings("SpellCheckingInspection")
|
||||||
|
public static final Category CATEGORY = new Category(Identifier.fromNamespaceAndPath("bettercontrols", "all"));
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ModifierKey modifier;
|
private ModifierKey modifier;
|
||||||
|
|||||||
@@ -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