]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/keyboard/KeyListener.java
Downgrade to 1.12.2
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / keyboard / KeyListener.java
index a680d7c74736a87c4fbd00e8e0455463a115bcb9..3d52bbb8fd2ab727145a7f1dd1c1ffc62e1789d1 100644 (file)
@@ -1,55 +1,36 @@
 package com.irtimaled.bbor.client.keyboard;
 
-import net.minecraft.client.Minecraft;
 import net.minecraft.client.settings.KeyBinding;
-import net.minecraft.client.util.InputMappings;
-import org.lwjgl.glfw.GLFW;
 
 import java.util.HashSet;
 import java.util.Set;
 
 public class KeyListener {
-    private static final Minecraft minecraft = Minecraft.getInstance();
-    private static long mainWindowHandle;
     private static Set<Key> keys = new HashSet<>();
 
-    public static void init() {
-        mainWindowHandle = minecraft.mainWindow.getHandle();
-        GLFW.glfwSetKeyCallback(mainWindowHandle, KeyListener::onKeyEvent);
-    }
-
     public static Key register(String description, int keyCode, String category) {
         Key key = new Key(description, keyCode, category);
         keys.add(key);
         return key;
     }
 
-    private static void onKeyEvent(long windowHandle, int keyCode, int scanCode, int action, int modifiers) {
-        if (windowHandle == mainWindowHandle && minecraft.currentScreen == null && keyCode != -1 && !InputMappings.isKeyDown(292)) {
-            InputMappings.Input input = InputMappings.getInputByCode(keyCode, scanCode);
-            for (Key key : keys) {
-                if (key.getInput() == input) {
-                    switch (action) {
-                        case GLFW.GLFW_PRESS:
-                            key.press();
-                            break;
-                        case GLFW.GLFW_REPEAT:
-                            key.repeat();
-                            break;
-                        case GLFW.GLFW_RELEASE:
-                            key.release();
-                            return;
-                    }
-                    if (minecraft.currentScreen != null)
-                        key.release();
-                    return;
+    public static KeyBinding[] keyBindings() {
+        return keys.toArray(new KeyBinding[0]);
+    }
+
+    public static boolean setKeyBindState(int keyCode, boolean pressed) {
+        for (Key key : keys) {
+            if (key.getKeyCode() == keyCode) {
+                if (!pressed) {
+                    key.release();
+                } else if (key.isPressed()) {
+                    key.repeat();
+                } else {
+                    key.press();
                 }
+                return true;
             }
         }
-        minecraft.keyboardListener.onKeyEvent(windowHandle, keyCode, scanCode, action, modifiers);
-    }
-
-    public static KeyBinding[] keyBindings() {
-        return keys.stream().toArray(KeyBinding[]::new);
+        return false;
     }
 }