diff --git a/library/gui/key_binds/build.gradle b/library/gui/key_binds/build.gradle
index 4b0acdb0c1..6ca3a5bd58 100644
--- a/library/gui/key_binds/build.gradle
+++ b/library/gui/key_binds/build.gradle
@@ -7,14 +7,14 @@ qslModule {
moduleName = "key_binds"
id = "quilt_key_binds"
description = "Key binds registration and utilities."
- library = "gui"
moduleDependencies {
core {
api("resource_loader")
- impl("qsl_base")
+ api("qsl_base")
testmodOnly("lifecycle_events")
}
}
+ clientOnly()
injectedInterface("net/minecraft/class_304") {
values = [
"org/quiltmc/qsl/key/binds/api/ChordedKeyBind",
@@ -22,5 +22,4 @@ qslModule {
"org/quiltmc/qsl/key/binds/api/ToggleableKeyBind"
]
}
- clientOnly()
}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ChordedKeyBind.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ChordedKeyBind.java
index 6077800164..90b8b12779 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ChordedKeyBind.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ChordedKeyBind.java
@@ -16,13 +16,11 @@
package org.quiltmc.qsl.key.binds.api;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-
import com.mojang.blaze3d.platform.InputUtil;
import net.minecraft.client.option.KeyBind;
+import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.base.api.util.InjectedInterface;
import org.quiltmc.qsl.key.binds.impl.chords.KeyChord;
@@ -30,7 +28,7 @@
/**
* An interface that adds key chord support to key binds.
*/
-@Environment(EnvType.CLIENT)
+@ClientOnly
@InjectedInterface(KeyBind.class)
public interface ChordedKeyBind {
/**
@@ -39,24 +37,24 @@ public interface ChordedKeyBind {
* @return the key bind's bound key chord.
*/
default KeyChord getBoundChord() {
- throw new UnsupportedOperationException();
+ throw new IllegalStateException("Mixin injection failed.");
}
/**
* Sets the bound key chord of the key bind.
*/
- default void setBoundChord(KeyChord chord) { }
+ default void setBoundChord(KeyChord chord) {}
// TODO - This is a temporary measure until Chasm arrives. Replace it with a proper constructor or builder
/**
* Specifies the default key chord for the key bind.
- *
- *
This method is to be used only on creating a key bind instance.
+ *
+ * This method is to be used only on creating a key bind instance.
*
* @param keys the keys of the default key chord
* @return the original key bind instance
*/
default KeyBind withChord(InputUtil.Key... keys) {
- throw new UnsupportedOperationException();
+ throw new IllegalStateException("Mixin injection failed.");
}
}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/KeyBindRegistry.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/KeyBindRegistry.java
index fedfa6133f..9ff62342ce 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/KeyBindRegistry.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/KeyBindRegistry.java
@@ -23,6 +23,7 @@
import net.minecraft.client.option.KeyBind;
+import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.key.binds.impl.KeyBindRegistryImpl;
// TODO - This isn't a registry anymore; What the heck should it be named?
@@ -32,7 +33,7 @@
*
*
This class also allows for getting key binds registered by other mods.
*/
-@Environment(EnvType.CLIENT)
+@ClientOnly
public class KeyBindRegistry {
// TODO - Shouldn't we use Vanilla's Map for getAllKeyBinds instead? Two birds, one stone, zero thoughts, head empty
/**
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/QuiltKeyBind.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/QuiltKeyBind.java
index b7df79152d..a967671a65 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/QuiltKeyBind.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/QuiltKeyBind.java
@@ -18,9 +18,16 @@
import com.mojang.blaze3d.platform.InputUtil;
+import net.minecraft.client.option.KeyBind;
+
+import org.quiltmc.loader.api.minecraft.ClientOnly;
+import org.quiltmc.qsl.base.api.util.InjectedInterface;
+
/**
* An injected interface for KeyBind that adds few Quilt-relevant utility methods.
*/
+@ClientOnly
+@InjectedInterface(KeyBind.class)
public interface QuiltKeyBind {
/**
* Gets whenever the key bind is from Vanilla or not.
@@ -29,7 +36,7 @@ public interface QuiltKeyBind {
* @return {@code true} if the key bind is from Vanilla, or {@code false} otherwise
*/
default boolean isVanilla() {
- return false;
+ throw new IllegalStateException("Mixin injection failed.");
}
/**
@@ -41,6 +48,6 @@ default boolean isVanilla() {
* @return the key bind's bound key
*/
default InputUtil.Key getBoundKey() {
- throw new UnsupportedOperationException();
+ throw new IllegalStateException("Mixin injection failed.");
}
}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ToggleableKeyBind.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ToggleableKeyBind.java
index d4dc00f0ab..5d85a9e4b6 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ToggleableKeyBind.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/api/ToggleableKeyBind.java
@@ -21,13 +21,14 @@
import net.minecraft.client.option.KeyBind;
+import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.base.api.util.InjectedInterface;
// TODO - Add Javadocs; You can nab the ones from KeyBindRegistry
/**
* An interface for adding toggling capabilities to key binds.
*/
-@Environment(EnvType.CLIENT)
+@ClientOnly
@InjectedInterface(KeyBind.class)
public interface ToggleableKeyBind {
/**
@@ -36,7 +37,7 @@ public interface ToggleableKeyBind {
* @return {@code true} if the key bind is enabled, {@code false} otherwise
*/
default boolean isEnabled() {
- return true;
+ throw new IllegalStateException("Mixin injection failed.");
}
/**
@@ -45,7 +46,7 @@ default boolean isEnabled() {
* @return {@code true} if the key bind is disabled, {@code false} otherwise
*/
default boolean isDisabled() {
- return false;
+ throw new IllegalStateException("Mixin injection failed.");
}
/**
@@ -54,27 +55,31 @@ default boolean isDisabled() {
* @return {@code true} if the key bind can be disabled, {@code false} otherwise
*/
default boolean canDisable() {
- return false;
+ throw new IllegalStateException("Mixin injection failed.");
}
/**
* Enables the key bind.
- *
- *
If the key bind has been disabled more than once, this method will only
+ *
+ * If the key bind has been disabled more than once, this method will only
* decrement its internal counter instead of enabling the key bind.
*/
- default void enable() { }
+ default void enable() {
+ throw new IllegalStateException("Mixin injection failed.");
+ }
/**
* Disables the key bind.
- *
- *
When a key bind is disabled, it is effectively hidden from the game,
+ *
+ * When a key bind is disabled, it is effectively hidden from the game,
* being non-existent to it. config/quilt/key_binds.json, however, will
* still remember the key bind's bound keys, similar to non-existent key binds.
- *
- *
If the key bind is disabled while already disabled, it will be increment
+ *
+ * If the key bind is disabled while already disabled, it will be increment
* an internal counter, making the next enable only decrement it instead of
* enabling the key bind.
*/
- default void disable() { }
+ default void disable() {
+ throw new IllegalStateException("Mixin injection failed.");
+ }
}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindManager.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindManager.java
index d8dbe6502c..567ee1818d 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindManager.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindManager.java
@@ -17,15 +17,14 @@
package org.quiltmc.qsl.key.binds.impl;
import org.jetbrains.annotations.ApiStatus;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.KeyBind;
+import org.quiltmc.loader.api.minecraft.ClientOnly;
import org.quiltmc.qsl.key.binds.mixin.client.GameOptionsAccessor;
-@Environment(EnvType.CLIENT)
+@ClientOnly
@ApiStatus.Internal
public class KeyBindManager {
private final GameOptions options;
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindRegistryImpl.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindRegistryImpl.java
index 2ba8615abe..26832509d9 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindRegistryImpl.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindRegistryImpl.java
@@ -20,12 +20,12 @@
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
import org.jetbrains.annotations.ApiStatus;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
import net.minecraft.client.option.KeyBind;
-@Environment(EnvType.CLIENT)
+import org.quiltmc.loader.api.minecraft.ClientOnly;
+
+@ClientOnly
@ApiStatus.Internal
public class KeyBindRegistryImpl {
private static final List ALL_KEY_BINDS = new ReferenceArrayList<>();
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindTooltipHolder.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindTooltipHolder.java
deleted file mode 100644
index 6475d89e90..0000000000
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/KeyBindTooltipHolder.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2021-2022 QuiltMC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.quiltmc.qsl.key.binds.impl;
-
-import java.util.List;
-
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-import org.jetbrains.annotations.ApiStatus;
-
-import net.minecraft.text.Text;
-
-@Environment(EnvType.CLIENT)
-@ApiStatus.Internal
-public interface KeyBindTooltipHolder {
- List getKeyBindTooltips();
-}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/chords/KeyChord.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/chords/KeyChord.java
index 62eccf53de..9eded8a441 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/chords/KeyChord.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/impl/chords/KeyChord.java
@@ -22,6 +22,9 @@
import com.mojang.blaze3d.platform.InputUtil;
+import org.quiltmc.loader.api.minecraft.ClientOnly;
+
+@ClientOnly
public class KeyChord {
// TODO - Private this, add methods for getting/modifying it
public SortedMap keys = new Object2BooleanAVLTreeMap<>();
@@ -30,13 +33,13 @@ public KeyChord(SortedMap keys) {
this.keys = keys;
}
- public KeyChord() { }
+ public KeyChord() {}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
- } else if (o != null && o instanceof KeyChord keyChord) {
+ } else if (o instanceof KeyChord keyChord) {
return this.keys.keySet().equals(keyChord.keys.keySet());
} else {
return false;
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/EntryListWidgetAccessor.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/EntryListWidgetAccessor.java
deleted file mode 100644
index 266398360a..0000000000
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/EntryListWidgetAccessor.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2021-2022 QuiltMC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.quiltmc.qsl.key.binds.mixin.client;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.gen.Invoker;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-
-import net.minecraft.client.gui.widget.EntryListWidget;
-
-@Environment(EnvType.CLIENT)
-@Mixin(EntryListWidget.class)
-public interface EntryListWidgetAccessor> {
- @Invoker
- E invokeGetHoveredEntry();
-}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/KeyBindEntryMixin.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/KeyBindEntryMixin.java
deleted file mode 100644
index 26c5ee6205..0000000000
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/KeyBindEntryMixin.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright 2022 QuiltMC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.quiltmc.qsl.key.binds.mixin.client;
-
-import java.util.List;
-
-import org.objectweb.asm.Opcodes;
-import org.spongepowered.asm.mixin.Final;
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.Unique;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.ModifyArg;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
-import it.unimi.dsi.fastutil.objects.ObjectArrayList;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-
-import com.mojang.blaze3d.platform.InputUtil;
-
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.widget.ButtonWidget;
-import net.minecraft.client.gui.widget.option.KeyBindListWidget;
-import net.minecraft.client.gui.widget.option.KeyBindListWidget.KeyBindEntry;
-import net.minecraft.client.option.KeyBind;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.text.Text;
-import net.minecraft.util.Formatting;
-
-import org.quiltmc.qsl.key.binds.impl.KeyBindTooltipHolder;
-import org.quiltmc.qsl.key.binds.impl.KeyBindRegistryImpl;
-import org.quiltmc.qsl.key.binds.impl.chords.KeyChord;
-
-@Environment(EnvType.CLIENT)
-@Mixin(KeyBindEntry.class)
-public abstract class KeyBindEntryMixin extends KeyBindListWidget.Entry implements KeyBindTooltipHolder {
- @Shadow
- @Final
- private KeyBind key;
-
- @Shadow
- @Final
- private ButtonWidget bindButton;
-
- @Unique
- private List quilt$conflictTooltips = new ObjectArrayList<>();
-
- @Unique
- private List quilt$previousProtoChord;
-
- @Unique
- private static List quilt$changedProtoChord;
-
- @Unique
- private boolean quilt$addKeyNameToTooltip;
-
- @Shadow(aliases = "field_2742", remap = false)
- @Final
- KeyBindListWidget field_2742;
-
- @Inject(method = "", at = @At("TAIL"))
- private void initPreviousBoundKey(KeyBindListWidget list, KeyBind key, Text text, CallbackInfo ci) {
- this.quilt$previousProtoChord = null;
- quilt$changedProtoChord = null;
- this.quilt$addKeyNameToTooltip = false;
- }
-
- @Inject(
- method = "render",
- at = @At(
- value = "INVOKE",
- target = "Lnet/minecraft/client/option/KeyBind;isUnbound()Z"
- ),
- locals = LocalCapture.CAPTURE_FAILHARD
- )
- private void collectConflictTooltips(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta, CallbackInfo ci, boolean bl, boolean bl2) {
- InputUtil.Key boundKey = this.key.getBoundKey();
- KeyChord boundChord = this.key.getBoundChord();
- List boundProtoChord;
-
- if (boundChord == null) {
- boundProtoChord = List.of(boundKey);
- } else {
- boundProtoChord = List.copyOf(boundChord.keys.keySet());
- }
-
- if (!boundProtoChord.equals(this.quilt$previousProtoChord) || quilt$changedProtoChord != null) {
- this.quilt$conflictTooltips.clear();
- if (quilt$changedProtoChord != null && quilt$changedProtoChord.equals(boundProtoChord)) {
- quilt$changedProtoChord = null;
- } else {
- quilt$changedProtoChord = boundProtoChord;
- }
-
- this.quilt$addKeyNameToTooltip = true;
-
- if (!this.key.isUnbound()) {
- for (KeyBind otherKey : KeyBindRegistryImpl.getKeyBinds()) {
- if (otherKey != this.key && this.key.keyEquals(otherKey)) {
- if (this.quilt$conflictTooltips.isEmpty()) {
- this.quilt$conflictTooltips.add(Text.translatable("key.qsl.key_conflict.tooltip").formatted(Formatting.RED));
- }
-
- this.quilt$conflictTooltips.add(Text.translatable("key.qsl.key_conflict.tooltip.entry", Text.translatable(otherKey.getTranslationKey())).formatted(Formatting.RED));
- }
- }
- }
- }
-
- this.quilt$previousProtoChord = boundProtoChord;
- }
-
- @Inject(
- method = "render",
- at = @At(
- value = "JUMP",
- opcode = Opcodes.IFEQ,
- ordinal = 1,
- shift = At.Shift.BEFORE
- ),
- locals = LocalCapture.CAPTURE_FAILHARD
- )
- private void shortenText(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta, CallbackInfo ci, boolean bl, boolean bl2) {
- // TODO - Get client from the parent screen instead
- MinecraftClient client = MinecraftClient.getInstance();
- Text text = this.bindButton.getMessage();
- int targetWidth = bl || bl2 ? 50 - 10 : 75 - 10;
- if (client.textRenderer.getWidth(text) > targetWidth) {
- String protoText = text.getString();
- if (this.key.getBoundChord() != null) {
- protoText = "";
- KeyChord chord = this.key.getBoundChord();
-
- for (InputUtil.Key key : chord.keys.keySet()) {
- if (!protoText.isEmpty()) {
- protoText += " + ";
- }
-
- String keyString = key.getDisplayText().getString();
-
- if (keyString.length() > 3) {
- String[] keySegments = keyString.split(" ");
- keyString = "";
- for (String keySegment : keySegments) {
- keyString += keySegment.substring(0, 1);
- }
- }
-
- protoText += keyString;
- }
- }
-
- if (client.textRenderer.getWidth(protoText) > targetWidth) {
- if (this.quilt$addKeyNameToTooltip) {
- this.quilt$conflictTooltips.add(0, this.key.getKeyName());
- this.quilt$addKeyNameToTooltip = false;
- }
-
- protoText = client.textRenderer.trimToWidth(protoText, targetWidth);
- protoText += "...";
- }
-
- this.bindButton.setMessage(Text.literal(protoText));
- }
- }
-
- @ModifyArg(
- method = "render",
- at = @At(
- value = "INVOKE",
- target = "Lnet/minecraft/client/gui/widget/ButtonWidget;setMessage(Lnet/minecraft/text/Text;)V",
- ordinal = 2
- )
- )
- private Text addConflictIndicator(Text originalText) {
- return Text.translatable("key.qsl.key_conflict.indicator", originalText).formatted(Formatting.RED);
- }
-
- @Override
- public List getKeyBindTooltips() {
- return this.quilt$conflictTooltips;
- }
-}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/KeyBindsScreenMixin.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/KeyBindsScreenMixin.java
deleted file mode 100644
index eb6d07adc0..0000000000
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/KeyBindsScreenMixin.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2021-2022 QuiltMC
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.quiltmc.qsl.key.binds.mixin.client;
-
-import java.util.List;
-
-import org.spongepowered.asm.mixin.Mixin;
-import org.spongepowered.asm.mixin.Shadow;
-import org.spongepowered.asm.mixin.injection.At;
-import org.spongepowered.asm.mixin.injection.Inject;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.api.Environment;
-
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.client.gui.screen.option.GameOptionsScreen;
-import net.minecraft.client.gui.screen.option.KeyBindsScreen;
-import net.minecraft.client.gui.widget.option.KeyBindListWidget;
-import net.minecraft.client.gui.widget.option.KeyBindListWidget.KeyBindEntry;
-import net.minecraft.client.option.GameOptions;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.text.Text;
-
-import org.quiltmc.qsl.key.binds.impl.KeyBindTooltipHolder;
-
-@Environment(EnvType.CLIENT)
-@Mixin(KeyBindsScreen.class)
-public abstract class KeyBindsScreenMixin extends GameOptionsScreen {
- @Shadow
- private KeyBindListWidget keyBindList;
-
- private KeyBindsScreenMixin(Screen screen, GameOptions gameOptions, Text text) {
- super(screen, gameOptions, text);
- }
-
- @SuppressWarnings("unchecked")
- @Inject(method = "render", at = @At("TAIL"))
- private void renderConflictTooltips(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo ci) {
- // TODO - Somehow extend the hover area to include the label too
- KeyBindListWidget.Entry entry = ((EntryListWidgetAccessor) this.keyBindList).invokeGetHoveredEntry();
- if (entry != null && entry instanceof KeyBindEntry keyBindEntry) {
- List tooltipLines = ((KeyBindTooltipHolder) keyBindEntry).getKeyBindTooltips();
-
- if (tooltipLines != null) {
- // TODO - With key names, it's getting too big! Add a maximum width
- this.renderTooltip(matrices, tooltipLines, mouseX, mouseY);
- }
- }
- }
-}
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/chords/KeyBindsScreenMixin.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/chords/KeyBindsScreenMixin.java
index e5c70d484c..efca89912a 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/chords/KeyBindsScreenMixin.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/chords/KeyBindsScreenMixin.java
@@ -35,6 +35,7 @@
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.screen.option.KeyBindsScreen;
+import net.minecraft.client.gui.widget.option.KeyBindListWidget;
import net.minecraft.client.option.GameOptions;
import net.minecraft.client.option.KeyBind;
import net.minecraft.text.Text;
@@ -51,6 +52,8 @@ public abstract class KeyBindsScreenMixin extends GameOptionsScreen {
@Shadow
public long time;
+ @Shadow
+ private KeyBindListWidget keyBindList;
@Unique
private List quilt$focusedProtoChord;
@@ -100,7 +103,7 @@ private void excludeFirstMouseClick(double mouseX, double mouseY, int button, Ca
cancellable = true
)
private void modifyKeyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable cir) {
- InputUtil.Key key = InputUtil.fromKeyCode(keyCode, scanCode);
+ var key = InputUtil.fromKeyCode(keyCode, scanCode);
if (!this.quilt$focusedProtoChord.contains(key)) {
this.quilt$focusedProtoChord.add(key);
}
@@ -115,8 +118,8 @@ public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
this.gameOptions.setKeyCode(this.focusedKey, this.quilt$focusedProtoChord.get(0));
} else if (this.quilt$focusedProtoChord.size() > 1) {
SortedMap map = new Object2BooleanAVLTreeMap<>();
- for (int i = 0; i < this.quilt$focusedProtoChord.size(); i++) {
- map.put(this.quilt$focusedProtoChord.get(i), false);
+ for (InputUtil.Key key : this.quilt$focusedProtoChord) {
+ map.put(key, false);
}
this.focusedKey.setBoundChord(new KeyChord(map));
@@ -126,7 +129,8 @@ public boolean keyReleased(int keyCode, int scanCode, int modifiers) {
this.quilt$focusedProtoChord.clear();
this.focusedKey = null;
this.time = Util.getMeasuringTimeMs();
- KeyBind.updateBoundKeys();
+ this.keyBindList.update();
+
return true;
} else {
return super.keyReleased(keyCode, scanCode, modifiers);
@@ -141,8 +145,8 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {
this.gameOptions.setKeyCode(this.focusedKey, this.quilt$focusedProtoChord.get(0));
} else if (this.quilt$focusedProtoChord.size() > 1) {
SortedMap map = new Object2BooleanAVLTreeMap<>();
- for (int i = 0; i < this.quilt$focusedProtoChord.size(); i++) {
- map.put(this.quilt$focusedProtoChord.get(i), false);
+ for (InputUtil.Key key : this.quilt$focusedProtoChord) {
+ map.put(key, false);
}
this.focusedKey.setBoundChord(new KeyChord(map));
@@ -152,7 +156,8 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {
this.quilt$focusedProtoChord.clear();
this.focusedKey = null;
this.time = Util.getMeasuringTimeMs();
- KeyBind.updateBoundKeys();
+ this.keyBindList.update();
+
return true;
} else {
this.quilt$initialMouseRelease = false;
diff --git a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/toggle/KeyBindMixin.java b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/toggle/KeyBindMixin.java
index 7ddea650af..481118de13 100644
--- a/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/toggle/KeyBindMixin.java
+++ b/library/gui/key_binds/src/main/java/org/quiltmc/qsl/key/binds/mixin/client/toggle/KeyBindMixin.java
@@ -51,11 +51,11 @@ public abstract class KeyBindMixin implements ToggleableKeyBind {
public abstract String getTranslationKey();
@Shadow
- abstract void reset();
+ protected abstract void reset();
@Inject(method = "(Ljava/lang/String;Lcom/mojang/blaze3d/platform/InputUtil$Type;ILjava/lang/String;)V", at = @At("RETURN"))
private void initializeToggleFields(String string, InputUtil.Type type, int i, String string2, CallbackInfo ci) {
- for (KeyBind otherKey : QUILT$ALL_KEY_BINDS) {
+ for (var otherKey : QUILT$ALL_KEY_BINDS) {
if (this.equals(otherKey)) {
throw new IllegalArgumentException(String.format("%s has already been registered!", this.getTranslationKey()));
} else if (this.getTranslationKey().equals(otherKey.getTranslationKey())) {
diff --git a/library/gui/key_binds/src/main/resources/assets/quilt_key_binds/icon.png b/library/gui/key_binds/src/main/resources/assets/quilt_key_binds/icon.png
index 8d54ad0021..c2e0d4364c 100644
Binary files a/library/gui/key_binds/src/main/resources/assets/quilt_key_binds/icon.png and b/library/gui/key_binds/src/main/resources/assets/quilt_key_binds/icon.png differ
diff --git a/library/gui/key_binds/src/main/resources/quilt_key_binds.mixins.json b/library/gui/key_binds/src/main/resources/quilt_key_binds.mixins.json
index 2b5e8fde51..22270bbd8f 100644
--- a/library/gui/key_binds/src/main/resources/quilt_key_binds.mixins.json
+++ b/library/gui/key_binds/src/main/resources/quilt_key_binds.mixins.json
@@ -10,13 +10,10 @@
"client.config.GameOptionsMixin",
"client.config.MinecraftClientMixin",
"client.toggle.KeyBindMixin",
- "client.EntryListWidgetAccessor",
"client.GameOptionsAccessor",
"client.GameOptionsMixin",
"client.KeyBindAccessor",
- "client.KeyBindEntryMixin",
- "client.KeyBindMixin",
- "client.KeyBindsScreenMixin"
+ "client.KeyBindMixin"
],
"injectors": {
"defaultRequire": 1