mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-12-24 12:38:25 +01:00
Compare commits
2 Commits
cbf5adb4a7
...
cdb9dadaec
| Author | SHA1 | Date | |
|---|---|---|---|
|
cdb9dadaec
|
|||
|
76afa6bc40
|
@@ -10,8 +10,8 @@ modIssuesURL=https://github.com/chylex/Better-Controls/issues
|
||||
modSides=client
|
||||
|
||||
# Dependencies
|
||||
minecraftVersion=1.21.9
|
||||
neoForgeVersion=21.9.2-beta
|
||||
minecraftVersion=1.21.11
|
||||
neoForgeVersion=21.11.12-beta
|
||||
neoModDevVersion=2.0.110
|
||||
fabricVersion=0.17.2
|
||||
loomVersion=1.10
|
||||
@@ -24,8 +24,8 @@ mixinExtrasVersion=0.4.1
|
||||
# https://github.com/FabricMC/fabric-loom/releases
|
||||
|
||||
# Constraints
|
||||
minimumMinecraftVersion=1.21.9
|
||||
minimumNeoForgeVersion=21.9.0-beta
|
||||
minimumMinecraftVersion=1.21.11
|
||||
minimumNeoForgeVersion=21.11.0-beta
|
||||
minimumFabricVersion=0.15.0
|
||||
|
||||
# Gradle
|
||||
|
||||
@@ -98,6 +98,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
|
||||
return y;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "AutoBoxing", "AutoUnboxing" })
|
||||
private int generateFlightOptions(int y, List<GuiEventListener> elements) {
|
||||
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) {
|
||||
generateLeftSideText(y, elements, text);
|
||||
elements.add(CycleButton.onOffBuilder()
|
||||
elements.add(CycleButton.onOffBuilder(initialValue)
|
||||
.displayOnlyValue()
|
||||
.withInitialValue(Boolean.valueOf(initialValue))
|
||||
.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.gui.components.AbstractButton;
|
||||
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.MutableComponent;
|
||||
@@ -14,7 +15,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class KeyBindingWidget extends Button {
|
||||
public final class KeyBindingWidget extends Button.Plain {
|
||||
private final KeyMapping binding;
|
||||
private final Component bindingName;
|
||||
|
||||
@@ -43,7 +44,9 @@ public final class KeyBindingWidget extends Button {
|
||||
@NotNull
|
||||
@Override
|
||||
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
|
||||
@@ -69,24 +72,59 @@ public final class KeyBindingWidget extends Button {
|
||||
|
||||
public void updateKeyBindingText() {
|
||||
boolean hasConflict = false;
|
||||
MutableComponent conflictText = Component.empty();
|
||||
|
||||
if (!binding.isUnbound()) {
|
||||
for (KeyMapping other : Minecraft.getInstance().options.keyMappings) {
|
||||
if (binding != other && binding.same(other)) {
|
||||
if (hasConflict) {
|
||||
conflictText.append(", ");
|
||||
}
|
||||
|
||||
hasConflict = true;
|
||||
break;
|
||||
conflictText.append(Component.translatable(other.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
setMessage(Component.literal("> ").append(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.YELLOW)).append(" <").withStyle(ChatFormatting.YELLOW));
|
||||
}
|
||||
else if (hasConflict) {
|
||||
setMessage(binding.getTranslatedKeyMessage().copy().withStyle(ChatFormatting.RED));
|
||||
if (hasConflict) {
|
||||
setMessage(getMessageWithConflict(binding));
|
||||
setTooltip(Tooltip.create(Component.translatable("controls.keybinds.duplicateKeybinds", conflictText)));
|
||||
}
|
||||
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 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) {
|
||||
return CycleButton.<Option<T>>builder(Option::text)
|
||||
return CycleButton.builder(Option::text, find(options, initialValue))
|
||||
.displayOnlyValue()
|
||||
.withValues(options)
|
||||
.withInitialValue(find(options, initialValue))
|
||||
.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 net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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
|
||||
private ModifierKey modifier;
|
||||
|
||||
@@ -87,7 +87,7 @@ public final class PlayerTicker {
|
||||
}
|
||||
|
||||
SprintMode sprintMode = getConfig().sprintMode;
|
||||
boolean wasSprintToggled = Boolean.TRUE.equals(OPTIONS.toggleSprint().get());
|
||||
boolean wasSprintToggled = OPTIONS.toggleSprint().get().booleanValue();
|
||||
boolean isSprintToggled = toggleSprint.tick();
|
||||
|
||||
if (temporarySprintTimer > 0) {
|
||||
@@ -270,7 +270,7 @@ public final class PlayerTicker {
|
||||
if (!getConfig().sneakingMovesCameraSmoothly) {
|
||||
Camera camera = MINECRAFT.gameRenderer.getMainCamera();
|
||||
|
||||
if (camera.getEntity() == player) {
|
||||
if (camera.entity() == player) {
|
||||
Mixins.cameraFields(camera).setEyeHeight(player.getEyeHeight());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user