* Fix 

* Fix import order

* Update fabric-key-binding-api-v1/src/main/java/net/fabricmc/fabric/impl/client/keybinding/KeyBindingRegistryImpl.java

Co-authored-by: Player <sfPlayer1@users.noreply.github.com>

* Fix checkstyle

Co-authored-by: modmuss50 <modmuss50@gmail.com>
Co-authored-by: Player <sfPlayer1@users.noreply.github.com>
This commit is contained in:
Stuff-Stuffs 2021-11-23 18:27:03 +00:00 committed by modmuss50
parent 7de09f55c6
commit c8aba2f392
3 changed files with 9 additions and 2 deletions
fabric-key-binding-api-v1/src
main/java/net/fabricmc/fabric/impl/client/keybinding
testmod
java/net/fabricmc/fabric/test/client/keybinding
resources/assets/fabric-keybindings-v1-testmod/lang

View file

@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Optional;
import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.objects.ReferenceArrayList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -31,7 +32,7 @@ import net.fabricmc.fabric.mixin.client.keybinding.KeyBindingAccessor;
public final class KeyBindingRegistryImpl {
private static final Logger LOGGER = LogManager.getLogger();
private static final List<KeyBinding> moddedKeyBindings = Lists.newArrayList();
private static final List<KeyBinding> moddedKeyBindings = new ReferenceArrayList<>(); // ArrayList with identity based comparisons for contains/remove/indexOf etc., required for correctly handling duplicate keybinds
private KeyBindingRegistryImpl() {
}

View file

@ -33,6 +33,7 @@ public class KeyBindingsTest implements ClientModInitializer {
KeyBinding binding1 = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabric-key-binding-api-v1-testmod.test_keybinding_1", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_P, "key.category.first.test"));
KeyBinding binding2 = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabric-key-binding-api-v1-testmod.test_keybinding_2", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_U, "key.category.second.test"));
KeyBinding stickyBinding = KeyBindingHelper.registerKeyBinding(new StickyKeyBinding("key.fabric-key-binding-api-v1-testmod.test_keybinding_sticky", GLFW.GLFW_KEY_R, "key.category.first.test", () -> true));
KeyBinding duplicateBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabric-key-binding-api-v1-testmod.test_keybinding_duplicate", GLFW.GLFW_KEY_LEFT_SHIFT, "key.category.first.test"));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (binding1.wasPressed()) {
@ -46,6 +47,10 @@ public class KeyBindingsTest implements ClientModInitializer {
if (stickyBinding.isPressed()) {
client.player.sendMessage(new LiteralText("Sticky Key was pressed!"), false);
}
while (duplicateBinding.wasPressed()) {
client.player.sendMessage(new LiteralText("Duplicate Key was pressed!"), false);
}
});
}
}

View file

@ -3,5 +3,6 @@
"key.category.second.test": "Second Test Category",
"key.fabric-key-binding-api-v1-testmod.test_keybinding_1": "Test 1",
"key.fabric-key-binding-api-v1-testmod.test_keybinding_2": "Test 2",
"key.fabric-key-binding-api-v1-testmod.test_keybinding_sticky": "Sticky Test"
"key.fabric-key-binding-api-v1-testmod.test_keybinding_sticky": "Sticky Test",
"key.fabric-key-binding-api-v1-testmod.test_keybinding_duplicate": "Duplicate Test"
}