Added Keyboard, Mouse, and Display classes to the OpenGL Emulator

This commit is contained in:
PeytonPlayz595 2023-07-10 13:52:36 -04:00
parent 879a479353
commit a8694b7e30
7 changed files with 1156 additions and 3 deletions

View File

@ -0,0 +1,268 @@
package net.PeytonPlayz585.lwjgl;
import org.lwjgl.input.Keyboard;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class KeyboardConstants {
private static final String[] keyboardNames = new String[256];
private static final int[] keyboardGLFWToMinecraft = new int[384];
private static final int[] keyboardMinecraftToGLFW = new int[256];
private static final int[] keyboardBrowserToMinecraft = new int[384 * 4];
private static final int[] keyboardMinecraftToBrowser = new int[256];
private static final char[] keyboardChars = new char[256];
private static final int GLFW_KEY_SPACE = 32, GLFW_KEY_APOSTROPHE = 39, GLFW_KEY_COMMA = 44, GLFW_KEY_MINUS = 45,
GLFW_KEY_PERIOD = 46, GLFW_KEY_SLASH = 47, GLFW_KEY_0 = 48, GLFW_KEY_1 = 49, GLFW_KEY_2 = 50,
GLFW_KEY_3 = 51, GLFW_KEY_4 = 52, GLFW_KEY_5 = 53, GLFW_KEY_6 = 54, GLFW_KEY_7 = 55, GLFW_KEY_8 = 56,
GLFW_KEY_9 = 57, GLFW_KEY_SEMICOLON = 59, GLFW_KEY_EQUAL = 61, GLFW_KEY_A = 65, GLFW_KEY_B = 66,
GLFW_KEY_C = 67, GLFW_KEY_D = 68, GLFW_KEY_E = 69, GLFW_KEY_F = 70, GLFW_KEY_G = 71, GLFW_KEY_H = 72,
GLFW_KEY_I = 73, GLFW_KEY_J = 74, GLFW_KEY_K = 75, GLFW_KEY_L = 76, GLFW_KEY_M = 77, GLFW_KEY_N = 78,
GLFW_KEY_O = 79, GLFW_KEY_P = 80, GLFW_KEY_Q = 81, GLFW_KEY_R = 82, GLFW_KEY_S = 83, GLFW_KEY_T = 84,
GLFW_KEY_U = 85, GLFW_KEY_V = 86, GLFW_KEY_W = 87, GLFW_KEY_X = 88, GLFW_KEY_Y = 89, GLFW_KEY_Z = 90,
GLFW_KEY_LEFT_BRACKET = 91, GLFW_KEY_BACKSLASH = 92, GLFW_KEY_RIGHT_BRACKET = 93,
GLFW_KEY_GRAVE_ACCENT = 96, GLFW_KEY_WORLD_1 = 161, GLFW_KEY_WORLD_2 = 162;
private static final int GLFW_KEY_ESCAPE = 256, GLFW_KEY_ENTER = 257, GLFW_KEY_TAB = 258, GLFW_KEY_BACKSPACE = 259,
GLFW_KEY_INSERT = 260, GLFW_KEY_DELETE = 261, GLFW_KEY_RIGHT = 262, GLFW_KEY_LEFT = 263,
GLFW_KEY_DOWN = 264, GLFW_KEY_UP = 265, GLFW_KEY_PAGE_UP = 266, GLFW_KEY_PAGE_DOWN = 267,
GLFW_KEY_HOME = 268, GLFW_KEY_END = 269, GLFW_KEY_CAPS_LOCK = 280, GLFW_KEY_SCROLL_LOCK = 281,
GLFW_KEY_NUM_LOCK = 282, GLFW_KEY_PRINT_SCREEN = 283, GLFW_KEY_PAUSE = 284, GLFW_KEY_F1 = 290,
GLFW_KEY_F2 = 291, GLFW_KEY_F3 = 292, GLFW_KEY_F4 = 293, GLFW_KEY_F5 = 294, GLFW_KEY_F6 = 295,
GLFW_KEY_F7 = 296, GLFW_KEY_F8 = 297, GLFW_KEY_F9 = 298, GLFW_KEY_F10 = 299, GLFW_KEY_F11 = 300,
GLFW_KEY_F12 = 301, GLFW_KEY_F13 = 302, GLFW_KEY_F14 = 303, GLFW_KEY_F15 = 304, GLFW_KEY_F16 = 305,
GLFW_KEY_F17 = 306, GLFW_KEY_F18 = 307, GLFW_KEY_F19 = 308, GLFW_KEY_F20 = 309, GLFW_KEY_F21 = 310,
GLFW_KEY_F22 = 311, GLFW_KEY_F23 = 312, GLFW_KEY_F24 = 313, GLFW_KEY_F25 = 314, GLFW_KEY_KP_0 = 320,
GLFW_KEY_KP_1 = 321, GLFW_KEY_KP_2 = 322, GLFW_KEY_KP_3 = 323, GLFW_KEY_KP_4 = 324, GLFW_KEY_KP_5 = 325,
GLFW_KEY_KP_6 = 326, GLFW_KEY_KP_7 = 327, GLFW_KEY_KP_8 = 328, GLFW_KEY_KP_9 = 329,
GLFW_KEY_KP_DECIMAL = 330, GLFW_KEY_KP_DIVIDE = 331, GLFW_KEY_KP_MULTIPLY = 332, GLFW_KEY_KP_SUBTRACT = 333,
GLFW_KEY_KP_ADD = 334, GLFW_KEY_KP_ENTER = 335, GLFW_KEY_KP_EQUAL = 336, GLFW_KEY_LEFT_SHIFT = 340,
GLFW_KEY_LEFT_CONTROL = 341, GLFW_KEY_LEFT_ALT = 342, GLFW_KEY_LEFT_SUPER = 343, GLFW_KEY_RIGHT_SHIFT = 344,
GLFW_KEY_RIGHT_CONTROL = 345, GLFW_KEY_RIGHT_ALT = 346, GLFW_KEY_RIGHT_SUPER = 347, GLFW_KEY_MENU = 348,
GLFW_KEY_LAST = GLFW_KEY_MENU;
private static final int DOM_KEY_LOCATION_STANDARD = 0, DOM_KEY_LOCATION_LEFT = 1, DOM_KEY_LOCATION_RIGHT = 2,
DOM_KEY_LOCATION_NUMPAD = 3;
private static void register(int minecraftId, int glfwId, int browserId, int browserLocation, String name, char character) {
if(keyboardMinecraftToGLFW[minecraftId] != 0) throw new IllegalArgumentException("Duplicate keyboardMinecraftToGLFW entry: " + minecraftId + " -> " + glfwId);
keyboardMinecraftToGLFW[minecraftId] = glfwId;
if(keyboardGLFWToMinecraft[glfwId] != 0) throw new IllegalArgumentException("Duplicate keyboardGLFWToMinecraft entry: " + glfwId + " -> " + minecraftId);
keyboardGLFWToMinecraft[glfwId] = minecraftId;
if(browserLocation == 0) {
if(keyboardMinecraftToBrowser[minecraftId] != 0) throw new IllegalArgumentException("Duplicate keyboardMinecraftToBrowser entry: " + minecraftId + " -> " + browserId + "(0)");
keyboardMinecraftToBrowser[minecraftId] = browserId;
if(keyboardBrowserToMinecraft[browserId] != 0) throw new IllegalArgumentException("Duplicate keyboardBrowserToMinecraft entry: " + browserId + "(0) -> " + minecraftId);
keyboardBrowserToMinecraft[browserId] = minecraftId;
}else {
browserLocation *= 384;
if(keyboardMinecraftToBrowser[minecraftId] != 0) throw new IllegalArgumentException("Duplicate keyboardMinecraftToBrowser entry: " + minecraftId + " -> " + browserId + "(" + browserLocation + ")");
keyboardMinecraftToBrowser[minecraftId] = browserId + browserLocation;
if(keyboardBrowserToMinecraft[browserId + browserLocation] != 0) throw new IllegalArgumentException("Duplicate keyboardBrowserToMinecraft entry: " + browserId + "(" + browserLocation + ") -> " + minecraftId);
keyboardBrowserToMinecraft[browserId + browserLocation] = minecraftId;
}
if(keyboardNames[minecraftId] != null) throw new IllegalArgumentException("Duplicate keyboardNames entry: " + minecraftId + " -> " + name);
keyboardNames[minecraftId] = name;
if(keyboardChars[minecraftId] != '\0') throw new IllegalArgumentException("Duplicate keyboardChars entry: " + minecraftId + " -> " + character);
keyboardChars[minecraftId] = character;
}
private static void registerAlt(int minecraftId, int browserId, int browserLocation) {
if(browserLocation == 0) {
if(keyboardBrowserToMinecraft[browserId] != 0) throw new IllegalArgumentException("Duplicate (alt) keyboardBrowserToMinecraft entry: " + browserId + " -> " + minecraftId);
keyboardBrowserToMinecraft[browserId] = minecraftId;
}else {
browserLocation *= 384;
if(keyboardBrowserToMinecraft[browserId + browserLocation] != 0) throw new IllegalArgumentException("Duplicate (alt) keyboardBrowserToMinecraft entry: " + browserId + "(" + browserLocation + ") -> " + minecraftId);
keyboardBrowserToMinecraft[browserId + browserLocation] = minecraftId;
}
}
static {
register(Keyboard.KEY_SPACE, GLFW_KEY_SPACE, 32, DOM_KEY_LOCATION_STANDARD, "Space", ' ');
register(Keyboard.KEY_APOSTROPHE, GLFW_KEY_APOSTROPHE, 222, DOM_KEY_LOCATION_STANDARD, "Quote", '\'');
register(Keyboard.KEY_COMMA, GLFW_KEY_COMMA, 188, DOM_KEY_LOCATION_STANDARD, "Comma", ',');
register(Keyboard.KEY_MINUS, GLFW_KEY_MINUS, 189, DOM_KEY_LOCATION_STANDARD, "Minus", '-');
register(Keyboard.KEY_PERIOD, GLFW_KEY_PERIOD, 190, DOM_KEY_LOCATION_STANDARD, "Period", '.');
register(Keyboard.KEY_SLASH, GLFW_KEY_SLASH, 191, DOM_KEY_LOCATION_STANDARD, "Slash", '/');
register(Keyboard.KEY_0, GLFW_KEY_0, 48, DOM_KEY_LOCATION_STANDARD, "0", '0');
register(Keyboard.KEY_1, GLFW_KEY_1, 49, DOM_KEY_LOCATION_STANDARD, "1", '1');
register(Keyboard.KEY_2, GLFW_KEY_2, 50, DOM_KEY_LOCATION_STANDARD, "2", '2');
register(Keyboard.KEY_3, GLFW_KEY_3, 51, DOM_KEY_LOCATION_STANDARD, "3", '3');
register(Keyboard.KEY_4, GLFW_KEY_4, 52, DOM_KEY_LOCATION_STANDARD, "4", '4');
register(Keyboard.KEY_5, GLFW_KEY_5, 53, DOM_KEY_LOCATION_STANDARD, "5", '5');
register(Keyboard.KEY_6, GLFW_KEY_6, 54, DOM_KEY_LOCATION_STANDARD, "6", '6');
register(Keyboard.KEY_7, GLFW_KEY_7, 55, DOM_KEY_LOCATION_STANDARD, "7", '7');
register(Keyboard.KEY_8, GLFW_KEY_8, 56, DOM_KEY_LOCATION_STANDARD, "8", '8');
register(Keyboard.KEY_9, GLFW_KEY_9, 57, DOM_KEY_LOCATION_STANDARD, "9", '9');
register(Keyboard.KEY_SEMICOLON, GLFW_KEY_SEMICOLON, 186, DOM_KEY_LOCATION_STANDARD, "Semicolon", ';');
register(Keyboard.KEY_EQUALS, GLFW_KEY_EQUAL, 187, DOM_KEY_LOCATION_STANDARD, "Equals", '=');
register(Keyboard.KEY_A, GLFW_KEY_A, 65, DOM_KEY_LOCATION_STANDARD, "A", 'a');
register(Keyboard.KEY_B, GLFW_KEY_B, 66, DOM_KEY_LOCATION_STANDARD, "B", 'b');
register(Keyboard.KEY_C, GLFW_KEY_C, 67, DOM_KEY_LOCATION_STANDARD, "C", 'c');
register(Keyboard.KEY_D, GLFW_KEY_D, 68, DOM_KEY_LOCATION_STANDARD, "D", 'd');
register(Keyboard.KEY_E, GLFW_KEY_E, 69, DOM_KEY_LOCATION_STANDARD, "E", 'e');
register(Keyboard.KEY_F, GLFW_KEY_F, 70, DOM_KEY_LOCATION_STANDARD, "F", 'f');
register(Keyboard.KEY_G, GLFW_KEY_G, 71, DOM_KEY_LOCATION_STANDARD, "G", 'g');
register(Keyboard.KEY_H, GLFW_KEY_H, 72, DOM_KEY_LOCATION_STANDARD, "H", 'h');
register(Keyboard.KEY_I, GLFW_KEY_I, 73, DOM_KEY_LOCATION_STANDARD, "I", 'i');
register(Keyboard.KEY_J, GLFW_KEY_J, 74, DOM_KEY_LOCATION_STANDARD, "J", 'j');
register(Keyboard.KEY_K, GLFW_KEY_K, 75, DOM_KEY_LOCATION_STANDARD, "K", 'k');
register(Keyboard.KEY_L, GLFW_KEY_L, 76, DOM_KEY_LOCATION_STANDARD, "L", 'l');
register(Keyboard.KEY_M, GLFW_KEY_M, 77, DOM_KEY_LOCATION_STANDARD, "M", 'm');
register(Keyboard.KEY_N, GLFW_KEY_N, 78, DOM_KEY_LOCATION_STANDARD, "N", 'n');
register(Keyboard.KEY_O, GLFW_KEY_O, 79, DOM_KEY_LOCATION_STANDARD, "O", 'o');
register(Keyboard.KEY_P, GLFW_KEY_P, 80, DOM_KEY_LOCATION_STANDARD, "P", 'p');
register(Keyboard.KEY_Q, GLFW_KEY_Q, 81, DOM_KEY_LOCATION_STANDARD, "Q", 'q');
register(Keyboard.KEY_R, GLFW_KEY_R, 82, DOM_KEY_LOCATION_STANDARD, "R", 'r');
register(Keyboard.KEY_S, GLFW_KEY_S, 83, DOM_KEY_LOCATION_STANDARD, "S", 's');
register(Keyboard.KEY_T, GLFW_KEY_T, 84, DOM_KEY_LOCATION_STANDARD, "T", 't');
register(Keyboard.KEY_U, GLFW_KEY_U, 85, DOM_KEY_LOCATION_STANDARD, "U", 'u');
register(Keyboard.KEY_V, GLFW_KEY_V, 86, DOM_KEY_LOCATION_STANDARD, "V", 'v');
register(Keyboard.KEY_W, GLFW_KEY_W, 87, DOM_KEY_LOCATION_STANDARD, "W", 'w');
register(Keyboard.KEY_X, GLFW_KEY_X, 88, DOM_KEY_LOCATION_STANDARD, "X", 'x');
register(Keyboard.KEY_Y, GLFW_KEY_Y, 89, DOM_KEY_LOCATION_STANDARD, "Y", 'y');
register(Keyboard.KEY_Z, GLFW_KEY_Z, 90, DOM_KEY_LOCATION_STANDARD, "Z", 'z');
register(Keyboard.KEY_LBRACKET, GLFW_KEY_LEFT_BRACKET, 219, DOM_KEY_LOCATION_STANDARD, "L. Bracket", '[');
register(Keyboard.KEY_BACKSLASH, GLFW_KEY_BACKSLASH, 220, DOM_KEY_LOCATION_STANDARD, "Backslash", '\\');
register(Keyboard.KEY_RBRACKET, GLFW_KEY_RIGHT_BRACKET, 221, DOM_KEY_LOCATION_STANDARD, "R. Bracket", ']');
register(Keyboard.KEY_GRAVE, GLFW_KEY_GRAVE_ACCENT, 192, DOM_KEY_LOCATION_STANDARD, "Backtick", '`');
register(Keyboard.KEY_ESCAPE, GLFW_KEY_ESCAPE, 27, DOM_KEY_LOCATION_STANDARD, "Escape", '\0');
register(Keyboard.KEY_RETURN, GLFW_KEY_ENTER, 13, DOM_KEY_LOCATION_STANDARD, "Enter", '\n');
register(Keyboard.KEY_TAB, GLFW_KEY_TAB, 9, DOM_KEY_LOCATION_STANDARD, "Tab", '\t');
register(Keyboard.KEY_BACK, GLFW_KEY_BACKSPACE, 8, DOM_KEY_LOCATION_STANDARD, "Backspace", '\0');
register(Keyboard.KEY_INSERT, GLFW_KEY_INSERT, 45, DOM_KEY_LOCATION_STANDARD, "Insert", '\0');
register(Keyboard.KEY_DELETE, GLFW_KEY_DELETE, 46, DOM_KEY_LOCATION_STANDARD, "Delete", '\0');
register(Keyboard.KEY_RIGHT, GLFW_KEY_RIGHT, 39, DOM_KEY_LOCATION_STANDARD, "Right", '\0');
register(Keyboard.KEY_LEFT, GLFW_KEY_LEFT, 37, DOM_KEY_LOCATION_STANDARD, "Left", '\0');
register(Keyboard.KEY_DOWN, GLFW_KEY_DOWN, 40, DOM_KEY_LOCATION_STANDARD, "Down", '\0');
register(Keyboard.KEY_UP, GLFW_KEY_UP, 38, DOM_KEY_LOCATION_STANDARD, "Up", '\0');
register(Keyboard.KEY_PRIOR, GLFW_KEY_PAGE_UP, 33, DOM_KEY_LOCATION_STANDARD, "Page Up", '\0');
register(Keyboard.KEY_NEXT, GLFW_KEY_PAGE_DOWN, 34, DOM_KEY_LOCATION_STANDARD, "Page Down", '\0');
register(Keyboard.KEY_HOME, GLFW_KEY_HOME, 36, DOM_KEY_LOCATION_STANDARD, "Home", '\0');
register(Keyboard.KEY_END, GLFW_KEY_END, 35, DOM_KEY_LOCATION_STANDARD, "End", '\0');
register(Keyboard.KEY_CAPITAL, GLFW_KEY_CAPS_LOCK, 20, DOM_KEY_LOCATION_STANDARD, "Caps Lock", '\0');
register(Keyboard.KEY_SCROLL, GLFW_KEY_SCROLL_LOCK, 145, DOM_KEY_LOCATION_STANDARD, "Scroll Lock", '\0');
register(Keyboard.KEY_NUMLOCK, GLFW_KEY_NUM_LOCK, 144, DOM_KEY_LOCATION_STANDARD, "Num Lock", '\0');
register(Keyboard.KEY_PAUSE, GLFW_KEY_PAUSE, 19, DOM_KEY_LOCATION_STANDARD, "Pause", '\0');
register(Keyboard.KEY_F1, GLFW_KEY_F1, 112, DOM_KEY_LOCATION_STANDARD, "F1", '\0');
register(Keyboard.KEY_F2, GLFW_KEY_F2, 113, DOM_KEY_LOCATION_STANDARD, "F2", '\0');
register(Keyboard.KEY_F3, GLFW_KEY_F3, 114, DOM_KEY_LOCATION_STANDARD, "F3", '\0');
register(Keyboard.KEY_F4, GLFW_KEY_F4, 115, DOM_KEY_LOCATION_STANDARD, "F4", '\0');
register(Keyboard.KEY_F5, GLFW_KEY_F5, 116, DOM_KEY_LOCATION_STANDARD, "F5", '\0');
register(Keyboard.KEY_F6, GLFW_KEY_F6, 117, DOM_KEY_LOCATION_STANDARD, "F6", '\0');
register(Keyboard.KEY_F7, GLFW_KEY_F7, 118, DOM_KEY_LOCATION_STANDARD, "F7", '\0');
register(Keyboard.KEY_F8, GLFW_KEY_F8, 119, DOM_KEY_LOCATION_STANDARD, "F8", '\0');
register(Keyboard.KEY_F9, GLFW_KEY_F9, 120, DOM_KEY_LOCATION_STANDARD, "F9", '\0');
register(Keyboard.KEY_F10, GLFW_KEY_F10, 121, DOM_KEY_LOCATION_STANDARD, "F10", '\0');
register(Keyboard.KEY_F11, GLFW_KEY_F11, 122, DOM_KEY_LOCATION_STANDARD, "F11", '\0');
register(Keyboard.KEY_F12, GLFW_KEY_F12, 123, DOM_KEY_LOCATION_STANDARD, "F12", '\0');
register(Keyboard.KEY_NUMPAD0, GLFW_KEY_KP_0, 96, DOM_KEY_LOCATION_NUMPAD, "Keypad 0", '0');
register(Keyboard.KEY_NUMPAD1, GLFW_KEY_KP_1, 97, DOM_KEY_LOCATION_NUMPAD, "Keypad 1", '1');
register(Keyboard.KEY_NUMPAD2, GLFW_KEY_KP_2, 98, DOM_KEY_LOCATION_NUMPAD, "Keypad 2", '2');
register(Keyboard.KEY_NUMPAD3, GLFW_KEY_KP_3, 99, DOM_KEY_LOCATION_NUMPAD, "Keypad 3", '3');
register(Keyboard.KEY_NUMPAD4, GLFW_KEY_KP_4, 100, DOM_KEY_LOCATION_NUMPAD, "Keypad 4", '4');
register(Keyboard.KEY_NUMPAD5, GLFW_KEY_KP_5, 101, DOM_KEY_LOCATION_NUMPAD, "Keypad 5", '5');
register(Keyboard.KEY_NUMPAD6, GLFW_KEY_KP_6, 102, DOM_KEY_LOCATION_NUMPAD, "Keypad 6", '6');
register(Keyboard.KEY_NUMPAD7, GLFW_KEY_KP_7, 103, DOM_KEY_LOCATION_NUMPAD, "Keypad 7", '7');
register(Keyboard.KEY_NUMPAD8, GLFW_KEY_KP_8, 104, DOM_KEY_LOCATION_NUMPAD, "Keypad 8", '8');
register(Keyboard.KEY_NUMPAD9, GLFW_KEY_KP_9, 105, DOM_KEY_LOCATION_NUMPAD, "Keypad 9", '9');
register(Keyboard.KEY_DECIMAL, GLFW_KEY_KP_DECIMAL, 110, DOM_KEY_LOCATION_NUMPAD, "Decimal", '.');
register(Keyboard.KEY_DIVIDE, GLFW_KEY_KP_DIVIDE, 111, DOM_KEY_LOCATION_NUMPAD, "Divide", '/');
register(Keyboard.KEY_MULTIPLY, GLFW_KEY_KP_MULTIPLY, 106, DOM_KEY_LOCATION_NUMPAD, "Multiply", '*');
register(Keyboard.KEY_SUBTRACT, GLFW_KEY_KP_SUBTRACT, 109, DOM_KEY_LOCATION_NUMPAD, "Subtract", '-');
register(Keyboard.KEY_ADD, GLFW_KEY_KP_ADD, 107, DOM_KEY_LOCATION_NUMPAD, "Add", '+');
register(Keyboard.KEY_NUMPADENTER, GLFW_KEY_KP_ENTER, 13, DOM_KEY_LOCATION_NUMPAD, "Enter", '\n');
register(Keyboard.KEY_NUMPADEQUALS, GLFW_KEY_KP_EQUAL, 187, DOM_KEY_LOCATION_NUMPAD, "Equals", '=');
register(Keyboard.KEY_LSHIFT, GLFW_KEY_LEFT_SHIFT, 16, DOM_KEY_LOCATION_LEFT, "L. Shift", '\0');
register(Keyboard.KEY_LCONTROL, GLFW_KEY_LEFT_CONTROL, 17, DOM_KEY_LOCATION_LEFT, "L. Control", '\0');
register(Keyboard.KEY_LMENU, GLFW_KEY_LEFT_ALT, 18, DOM_KEY_LOCATION_LEFT, "L. Alt", '\0');
registerAlt(Keyboard.KEY_LSHIFT, 16, DOM_KEY_LOCATION_STANDARD);
registerAlt(Keyboard.KEY_LCONTROL, 17, DOM_KEY_LOCATION_STANDARD);
registerAlt(Keyboard.KEY_LMENU, 18, DOM_KEY_LOCATION_STANDARD);
register(Keyboard.KEY_RSHIFT, GLFW_KEY_RIGHT_SHIFT, 16, DOM_KEY_LOCATION_RIGHT, "R. Shift", '\0');
register(Keyboard.KEY_RCONTROL, GLFW_KEY_RIGHT_CONTROL, 17, DOM_KEY_LOCATION_RIGHT, "R. Control", '\0');
register(Keyboard.KEY_RMENU, GLFW_KEY_RIGHT_ALT, 18, DOM_KEY_LOCATION_RIGHT, "R. Alt", '\0');
}
public static String getKeyName(int key) {
if (key < 0 || key >= 256 || keyboardNames[key] == null) {
return "Unknown";
} else {
return keyboardNames[key];
}
}
public static int getMinecraftKeyFromGLFW(int key) {
if (key < 0 || key >= 384) {
return 0;
} else {
return keyboardGLFWToMinecraft[key];
}
}
public static int getGLFWKeyFromMinecraft(int key) {
if (key < 0 || key >= 256) {
return 0;
} else {
return keyboardMinecraftToGLFW[key];
}
}
public static int getMinecraftKeyFromBrowser(int key) {
return getMinecraftKeyFromBrowser(key, 0);
}
public static int getMinecraftKeyFromBrowser(int key, int location) {
if (key < 0 || key >= 384) {
return 0;
} else {
if(location <= 0 || location >= 4) {
return keyboardBrowserToMinecraft[key];
}else {
int i = keyboardBrowserToMinecraft[key + location * 384];
if(i == 0) {
i = keyboardBrowserToMinecraft[key];
}
return i;
}
}
}
public static int getBrowserKeyFromMinecraft(int key) {
if (key < 0 || key >= 256) {
return 0;
} else {
return keyboardMinecraftToBrowser[key] % 384;
}
}
public static int getBrowserLocationFromMinecraft(int key) {
if (key < 0 || key >= 384) {
return 0;
} else {
return keyboardMinecraftToBrowser[key] / 384;
}
}
public static char getKeyCharFromMinecraft(int key) {
if (key < 0 || key >= 256) {
return '\0';
} else {
return keyboardChars[key];
}
}
}

View File

@ -0,0 +1,507 @@
package net.PeytonPlayz585.lwjgl;
import java.util.LinkedList;
import java.util.List;
import org.lwjgl.input.Keyboard;
import org.teavm.jso.JSBody;
import org.teavm.jso.browser.TimerHandler;
import org.teavm.jso.browser.Window;
import org.teavm.jso.dom.events.EventListener;
import org.teavm.jso.dom.events.KeyboardEvent;
import org.teavm.jso.dom.events.MouseEvent;
import org.teavm.jso.dom.events.WheelEvent;
import org.teavm.jso.dom.html.HTMLCanvasElement;
import org.teavm.jso.webgl.WebGLFramebuffer;
import org.teavm.jso.webgl.WebGLRenderbuffer;
import net.PeytonPlayz585.main.MinecraftMain;
import net.PeytonPlayz585.teavm.WebGL2RenderingContext;
import static net.PeytonPlayz585.teavm.WebGL2RenderingContext.*;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class PlatformInput {
static WebGLFramebuffer mainFramebuffer = null;
static WebGLRenderbuffer mainColorRenderbuffer = null;
static WebGLRenderbuffer mainDepthRenderbuffer = null;
private static int framebufferWidth = -1;
private static int framebufferHeight = -1;
private static EventListener contextmenu = null;
private static EventListener mousedown = null;
private static EventListener mouseup = null;
private static EventListener mousemove = null;
private static EventListener mouseenter = null;
private static EventListener mouseleave = null;
private static EventListener keydown = null;
private static EventListener keyup = null;
private static EventListener keypress = null;
private static EventListener wheel = null;
private static EventListener pointerlock = null;
private static List<MouseEvent> mouseEvents = new LinkedList();
private static List<KeyboardEvent> keyEvents = new LinkedList();
private static int mouseX = 0;
private static int mouseY = 0;
private static double mouseDX = 0.0D;
private static double mouseDY = 0.0D;
private static double mouseDWheel = 0.0D;
private static int width = 0;
private static int height = 0;
private static boolean enableRepeatEvents = true;
private static boolean isWindowFocused = true;
private static boolean isMouseOverWindow = true;
static boolean unpressCTRL = false;
private static int windowWidth = -1;
private static int windowHeight = -1;
private static int lastWasResizedWindowWidth = -2;
private static int lastWasResizedWindowHeight = -2;
private static MouseEvent currentEvent = null;
private static KeyboardEvent currentEventK = null;
private static boolean[] buttonStates = new boolean[8];
private static boolean[] keyStates = new boolean[256];
private static int functionKeyModifier = Keyboard.KEY_F;
private static long mouseUngrabTimer = 0l;
private static long mouseGrabTimer = 0l;
private static int mouseUngrabTimeout = -1;
private static boolean pointerLockFlag = false;
@JSBody(params = { }, script = "window.onbeforeunload = () => {return false;};")
private static native void onBeforeCloseRegister();
public static void initHooks() {
MinecraftMain.win.addEventListener("contextmenu", contextmenu = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
evt.preventDefault();
evt.stopPropagation();
}
});
MinecraftMain.canvas.addEventListener("mousedown", mousedown = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
evt.preventDefault();
evt.stopPropagation();
int b = evt.getButton();
buttonStates[b == 1 ? 2 : (b == 2 ? 1 : b)] = true;
mouseEvents.add(evt);
}
});
MinecraftMain.canvas.addEventListener("mouseup", mouseup = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
evt.preventDefault();
evt.stopPropagation();
int b = evt.getButton();
buttonStates[b == 1 ? 2 : (b == 2 ? 1 : b)] = false;
mouseEvents.add(evt);
}
});
MinecraftMain.canvas.addEventListener("mousemove", mousemove = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
evt.preventDefault();
evt.stopPropagation();
mouseX = (int)(getOffsetX(evt) * MinecraftMain.win.getDevicePixelRatio());
mouseY = (int)((MinecraftMain.canvas.getClientHeight() - getOffsetY(evt)) * MinecraftMain.win.getDevicePixelRatio());
mouseDX += evt.getMovementX();
mouseDY += -evt.getMovementY();
if(hasBeenActive()) {
mouseEvents.add(evt);
}
}
});
MinecraftMain.canvas.addEventListener("mouseenter", mouseenter = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
isMouseOverWindow = true;
}
});
MinecraftMain.canvas.addEventListener("mouseleave", mouseleave = new EventListener<MouseEvent>() {
@Override
public void handleEvent(MouseEvent evt) {
isMouseOverWindow = false;
}
});
MinecraftMain.win.addEventListener("keydown", keydown = new EventListener<KeyboardEvent>() {
@Override
public void handleEvent(KeyboardEvent evt) {
int w = getWhich(evt);
if (w == 122) return; // F11
evt.preventDefault();
evt.stopPropagation();
if(!enableRepeatEvents && evt.isRepeat()) return;
w = processFunctionKeys(w);
keyStates[KeyboardConstants.getMinecraftKeyFromBrowser(w, evt.getLocation())] = true;
keyEvents.add(evt);
}
});
MinecraftMain.win.addEventListener("keyup", keyup = new EventListener<KeyboardEvent>() {
@Override
public void handleEvent(KeyboardEvent evt) {
int w = getWhich(evt);
if (w == 122) return; // F11
evt.preventDefault();
evt.stopPropagation();
if(!enableRepeatEvents && evt.isRepeat()) return;
w = processFunctionKeys(w);
keyStates[KeyboardConstants.getMinecraftKeyFromBrowser(w, evt.getLocation())] = false;
keyEvents.add(evt);
}
});
MinecraftMain.win.addEventListener("keypress", keypress = new EventListener<KeyboardEvent>() {
@Override
public void handleEvent(KeyboardEvent evt) {
evt.preventDefault();
evt.stopPropagation();
if(enableRepeatEvents && evt.isRepeat()) keyEvents.add(evt);
}
});
MinecraftMain.canvas.addEventListener("wheel", wheel = new EventListener<WheelEvent>() {
@Override
public void handleEvent(WheelEvent evt) {
evt.preventDefault();
evt.stopPropagation();
mouseEvents.add(evt);
mouseDWheel += evt.getDeltaY();
}
});
MinecraftMain.win.addEventListener("blur", new EventListener<WheelEvent>() {
@Override
public void handleEvent(WheelEvent evt) {
isWindowFocused = false;
for(int i = 0; i < buttonStates.length; ++i) {
buttonStates[i] = false;
}
for(int i = 0; i < keyStates.length; ++i) {
keyStates[i] = false;
}
}
});
MinecraftMain.win.addEventListener("focus", new EventListener<WheelEvent>() {
@Override
public void handleEvent(WheelEvent evt) {
isWindowFocused = true;
}
});
MinecraftMain.win.getDocument().addEventListener("pointerlockchange", pointerlock = new EventListener<WheelEvent>() {
@Override
public void handleEvent(WheelEvent evt) {
Window.setTimeout(new TimerHandler() {
@Override
public void onTimer() {
boolean grab = isPointerLocked();
if(!grab) {
if(pointerLockFlag) {
mouseUngrabTimer = System.currentTimeMillis();
}
}
pointerLockFlag = grab;
}
}, 60);
mouseDX = 0.0D;
mouseDY = 0.0D;
}
});
onBeforeCloseRegister();
}
@JSBody(params = { }, script = "if(window.navigator.userActivation){return window.navigator.userActivation.hasBeenActive;}else{return false;}")
public static native boolean hasBeenActive();
@JSBody(params = { "m" }, script = "return m.offsetX;")
private static native int getOffsetX(MouseEvent m);
@JSBody(params = { "m" }, script = "return m.offsetY;")
private static native int getOffsetY(MouseEvent m);
@JSBody(params = { "e" }, script = "return e.which;")
private static native int getWhich(KeyboardEvent e);
public static int getWindowWidth() {
return windowWidth;
}
public static int getWindowHeight() {
return windowHeight;
}
public static boolean getWindowFocused() {
return isWindowFocused || isPointerLocked();
}
public static boolean isCloseRequested() {
return false;
}
public static void update() {
double r = MinecraftMain.win.getDevicePixelRatio();
int w = MinecraftMain.parent.getClientWidth();
int h = MinecraftMain.parent.getClientHeight();
int w2 = windowWidth = (int)(w * r);
int h2 = windowHeight = (int)(h * r);
if(MinecraftMain.canvas.getWidth() != w2) {
MinecraftMain.canvas.setWidth(w2);
}
if(MinecraftMain.canvas.getHeight() != h2) {
MinecraftMain.canvas.setHeight(h2);
}
flipBuffer();
MinecraftMain.sleep(1l);
}
public static void initFramebuffer(WebGLFramebuffer fbo, int sw, int sh) {
mainFramebuffer = fbo;
framebufferWidth = windowWidth = sw;
framebufferHeight = windowHeight = sh;
MinecraftMain.webgl.bindFramebuffer(FRAMEBUFFER, fbo);
mainColorRenderbuffer = MinecraftMain.webgl.createRenderbuffer();
mainDepthRenderbuffer = MinecraftMain.webgl.createRenderbuffer();
MinecraftMain.webgl.bindRenderbuffer(RENDERBUFFER, mainColorRenderbuffer);
MinecraftMain.webgl.renderbufferStorage(RENDERBUFFER, RGBA8, sw, sh);
MinecraftMain.webgl.framebufferRenderbuffer(FRAMEBUFFER, COLOR_ATTACHMENT0, RENDERBUFFER, mainColorRenderbuffer);
MinecraftMain.webgl.bindRenderbuffer(RENDERBUFFER, mainDepthRenderbuffer);
MinecraftMain.webgl.renderbufferStorage(RENDERBUFFER, DEPTH_COMPONENT32F, sw, sh);
MinecraftMain.webgl.framebufferRenderbuffer(FRAMEBUFFER, DEPTH_ATTACHMENT, RENDERBUFFER, mainDepthRenderbuffer);
MinecraftMain.webgl.drawBuffers(new int[] { COLOR_ATTACHMENT0 });
}
private static void flipBuffer() {
MinecraftMain.webgl.bindFramebuffer(READ_FRAMEBUFFER, mainFramebuffer);
MinecraftMain.webgl.bindFramebuffer(DRAW_FRAMEBUFFER, null);
MinecraftMain.webgl.blitFramebuffer(0, 0, framebufferWidth, framebufferHeight, 0, 0, windowWidth, windowHeight, COLOR_BUFFER_BIT, NEAREST);
MinecraftMain.webgl.bindFramebuffer(FRAMEBUFFER, mainFramebuffer);
if(windowWidth != framebufferWidth || windowHeight != framebufferHeight) {
framebufferWidth = windowWidth;
framebufferHeight = windowHeight;
MinecraftMain.webgl.bindRenderbuffer(RENDERBUFFER, mainColorRenderbuffer);
MinecraftMain.webgl.renderbufferStorage(RENDERBUFFER, RGBA8, framebufferWidth, framebufferHeight);
MinecraftMain.webgl.bindRenderbuffer(RENDERBUFFER, mainDepthRenderbuffer);
MinecraftMain.webgl.renderbufferStorage(RENDERBUFFER, DEPTH_COMPONENT32F, framebufferWidth, framebufferHeight);
}
}
public static boolean wasResized() {
if(windowWidth != lastWasResizedWindowWidth || windowHeight != lastWasResizedWindowHeight) {
lastWasResizedWindowWidth = windowWidth;
lastWasResizedWindowHeight = windowHeight;
return true;
}else {
return false;
}
}
public static boolean keyboardNext() {
if(unpressCTRL) { //un-press ctrl after copy/paste permission
keyEvents.clear();
currentEventK = null;
keyStates[29] = false;
keyStates[157] = false;
keyStates[28] = false;
keyStates[219] = false;
keyStates[220] = false;
unpressCTRL = false;
return false;
}
currentEventK = null;
return !keyEvents.isEmpty() && (currentEventK = keyEvents.remove(0)) != null;
}
public static boolean keyboardGetEventKeyState() {
return currentEventK == null? false : !currentEventK.getType().equals("keyup");
}
public static int keyboardGetEventKey() {
int w = processFunctionKeys(getWhich(currentEventK));
return currentEventK == null ? -1 : KeyboardConstants.getMinecraftKeyFromBrowser(w, currentEventK.getLocation());
}
public static char keyboardGetEventCharacter() {
if(currentEventK == null) return '\0';
String s = currentEventK.getKey();
return currentEventK == null ? ' ' : (char) (s.length() > 1 ? '\0' : s.charAt(0));
}
public static boolean keyboardIsKeyDown(int key) {
if(unpressCTRL) { //un-press ctrl after copy/paste permission
keyStates[28] = false;
keyStates[29] = false;
keyStates[157] = false;
keyStates[219] = false;
keyStates[220] = false;
}
return key < 0 || key >= keyStates.length ? false : keyStates[key];
}
public static boolean keyboardIsRepeatEvent() {
return currentEventK == null ? false : currentEventK.isRepeat();
}
public static void keyboardEnableRepeatEvents(boolean b) {
enableRepeatEvents = b;
}
public static boolean mouseNext() {
currentEvent = null;
return !mouseEvents.isEmpty() && (currentEvent = mouseEvents.remove(0)) != null;
}
public static boolean mouseGetEventButtonState() {
return currentEvent == null ? false : currentEvent.getType().equals(MouseEvent.MOUSEDOWN);
}
public static int mouseGetEventButton() {
if(currentEvent == null || currentEvent.getType().equals(MouseEvent.MOUSEMOVE)) return -1;
int b = currentEvent.getButton();
return b == 1 ? 2 : (b == 2 ? 1 : b);
}
public static int mouseGetEventX() {
return currentEvent == null ? -1 : (int)(currentEvent.getClientX() * MinecraftMain.win.getDevicePixelRatio());
}
public static int mouseGetEventY() {
return currentEvent == null ? -1 : (int)((MinecraftMain.canvas.getClientHeight() - currentEvent.getClientY()) * MinecraftMain.win.getDevicePixelRatio());
}
public static int mouseGetEventDWheel() {
return ("wheel".equals(currentEvent.getType())) ? (((WheelEvent)currentEvent).getDeltaY() == 0.0D ? 0 : (((WheelEvent)currentEvent).getDeltaY() > 0.0D ? -1 : 1)) : 0;
}
public static int mouseGetX() {
return mouseX;
}
public static int mouseGetY() {
return mouseY;
}
public static boolean mouseIsButtonDown(int i) {
return buttonStates[i];
}
public static int mouseGetDWheel() {
int ret = (int)mouseDWheel;
mouseDWheel = 0.0D;
return ret;
}
public static void mouseSetGrabbed(boolean grab) {
long t = System.currentTimeMillis();
pointerLockFlag = grab;
mouseGrabTimer = t;
if(grab) {
MinecraftMain.canvas.requestPointerLock();
if(mouseUngrabTimeout != -1) Window.clearTimeout(mouseUngrabTimeout);
mouseUngrabTimeout = -1;
if(t - mouseUngrabTimer < 3000l) {
mouseUngrabTimeout = Window.setTimeout(new TimerHandler() {
@Override
public void onTimer() {
MinecraftMain.canvas.requestPointerLock();
}
}, 3100 - (int)(t - mouseUngrabTimer));
}
}else {
if(mouseUngrabTimeout != -1) Window.clearTimeout(mouseUngrabTimeout);
mouseUngrabTimeout = -1;
Window.current().getDocument().exitPointerLock();
}
mouseDX = 0.0D;
mouseDY = 0.0D;
}
public static boolean isMouseGrabbed() {
return pointerLockFlag;
}
@JSBody(params = { }, script = "return document.pointerLockElement != null;")
public static native boolean isPointerLocked();
public static int mouseGetDX() {
int ret = (int)mouseDX;
mouseDX = 0.0D;
return ret;
}
public static int mouseGetDY() {
int ret = (int)mouseDY;
mouseDY = 0.0D;
return ret;
}
public static void mouseSetCursorPosition(int x, int y) {
// obsolete
}
public static boolean mouseIsInsideWindow() {
return isMouseOverWindow;
}
private static int processFunctionKeys(int key) {
if(keyboardIsKeyDown(functionKeyModifier)) {
if(key >= 49 && key <= 57) {
key = key - 49 + 112;
}
}
return key;
}
public static void setFunctionKeyModifier(int key) {
functionKeyModifier = key;
}
public static void removeEventHandlers() {
MinecraftMain.win.removeEventListener("contextmenu", contextmenu);
MinecraftMain.canvas.removeEventListener("mousedown", mousedown);
MinecraftMain.canvas.removeEventListener("mouseup", mouseup);
MinecraftMain.canvas.removeEventListener("mousemove", mousemove);
MinecraftMain.canvas.removeEventListener("mouseenter", mouseenter);
MinecraftMain.canvas.removeEventListener("mouseleave", mouseleave);
MinecraftMain.win.removeEventListener("keydown", keydown);
MinecraftMain.win.removeEventListener("keyup", keyup);
MinecraftMain.win.removeEventListener("keypress", keypress);
MinecraftMain.canvas.removeEventListener("wheel", wheel);
MinecraftMain.win.getDocument().removeEventListener("pointerlockchange", pointerlock);
if(mouseUngrabTimeout != -1) {
Window.clearTimeout(mouseUngrabTimeout);
mouseUngrabTimeout = -1;
}
}
public static void clearEvenBuffers() {
mouseEvents.clear();
keyEvents.clear();
}
}

View File

@ -16,8 +16,10 @@ import org.teavm.jso.dom.html.HTMLDocument;
import org.teavm.jso.dom.html.HTMLElement;
import org.teavm.jso.typedarrays.ArrayBuffer;
import org.teavm.jso.typedarrays.Uint8Array;
import org.teavm.jso.webgl.WebGLFramebuffer;
import org.teavm.jso.webgl.WebGLRenderingContext;
import net.PeytonPlayz585.lwjgl.PlatformInput;
import net.PeytonPlayz585.minecraft.MinecraftClient;
import net.PeytonPlayz585.teavm.WebGL2RenderingContext;
@ -34,16 +36,21 @@ public class MinecraftMain {
public static HTMLCanvasElement imageLoadCanvas = null;
public static CanvasRenderingContext2D imageLoadContext = null;
private static byte[] loadedPackage = null;
static WebGLFramebuffer mainFramebuffer = null;
public static int width = 0;
public static int height = 0;
public static void main(String args[]) {
String[] element = getClassicConfig();
initContext(rootElement = Window.current().getDocument().getElementById(element[0]), element[1]);
try {
initContext(rootElement = Window.current().getDocument().getElementById(element[0]), element[1]);
} catch (Exception e) {
e.printStackTrace();
}
}
public final static void initContext(HTMLElement rootElement, String assetsURI) {
public final static void initContext(HTMLElement rootElement, String assetsURI) throws Exception {
parent = rootElement;
String s = parent.getAttribute("style");
parent.setAttribute("style", (s == null ? "" : s)+"overflow-x:hidden;overflow-y:hidden;");
@ -58,8 +65,28 @@ public class MinecraftMain {
canvas.setAttribute("id", "minecraftClassicBrowser");
rootElement.appendChild(canvas);
canvasBack = (HTMLCanvasElement)doc.createElement("canvas");
double r = win.getDevicePixelRatio();
int iw = parent.getClientWidth();
int ih = parent.getClientHeight();
int sw = (int)(r * iw);
int sh = (int)(r * ih);
canvasBack.setWidth(width);
canvasBack.setHeight(height);
try {
PlatformInput.initHooks();
}catch(Throwable t) {
throw new Exception("Exception while registering window event handlers");
}
try {
doc.exitPointerLock();
}catch(Throwable t) {
throw new Exception("Mouse cursor lock is not available on this device!");
}
webgl = (WebGL2RenderingContext) canvasBack.getContext("webgl2");
if(webgl == null) {
throw new RuntimeException("WebGL 2.0 is not supported in your browser, please get a new one!");
@ -67,6 +94,9 @@ public class MinecraftMain {
setCurrentContext(webgl);
GL11.initWebGL(webgl);
mainFramebuffer = webgl.createFramebuffer();
PlatformInput.initFramebuffer(mainFramebuffer, sw, sh);
webgl.getExtension("EXT_texture_filter_anisotropic");
downloadAssetPack(assetsURI);
@ -123,6 +153,13 @@ public class MinecraftMain {
return h;
}
public static void sleep(long millis) {
try {
Thread.sleep(millis);
}catch(InterruptedException ex) {
}
}
@JSBody(params = { "obj" }, script = "window.currentContext = obj;")
private static native int setCurrentContext(JSObject obj);

View File

@ -324,7 +324,7 @@ public class GlStateManager extends LWJGL {
public static final void glClear(int p1) {
_wglClear(p1);
}
public static final void glOrtho(double l, double r, double b, double t, double n, double f) {
Matrix4f res = getMatrix();
res.m00 = (float) (2.0f / (r - l));

View File

@ -0,0 +1,193 @@
package org.lwjgl.input;
import net.PeytonPlayz585.lwjgl.KeyboardConstants;
import net.PeytonPlayz585.lwjgl.PlatformInput;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class Keyboard {
public static final int KEY_NONE = 0x00;
public static final int KEY_ESCAPE = 0x01;
public static final int KEY_1 = 0x02;
public static final int KEY_2 = 0x03;
public static final int KEY_3 = 0x04;
public static final int KEY_4 = 0x05;
public static final int KEY_5 = 0x06;
public static final int KEY_6 = 0x07;
public static final int KEY_7 = 0x08;
public static final int KEY_8 = 0x09;
public static final int KEY_9 = 0x0A;
public static final int KEY_0 = 0x0B;
public static final int KEY_MINUS = 0x0C; /* - on main keyboard */
public static final int KEY_EQUALS = 0x0D;
public static final int KEY_BACK = 0x0E; /* backspace */
public static final int KEY_TAB = 0x0F;
public static final int KEY_Q = 0x10;
public static final int KEY_W = 0x11;
public static final int KEY_E = 0x12;
public static final int KEY_R = 0x13;
public static final int KEY_T = 0x14;
public static final int KEY_Y = 0x15;
public static final int KEY_U = 0x16;
public static final int KEY_I = 0x17;
public static final int KEY_O = 0x18;
public static final int KEY_P = 0x19;
public static final int KEY_LBRACKET = 0x1A;
public static final int KEY_RBRACKET = 0x1B;
public static final int KEY_RETURN = 0x1C; /* Enter on main keyboard */
public static final int KEY_LCONTROL = 0x1D;
public static final int KEY_A = 0x1E;
public static final int KEY_S = 0x1F;
public static final int KEY_D = 0x20;
public static final int KEY_F = 0x21;
public static final int KEY_G = 0x22;
public static final int KEY_H = 0x23;
public static final int KEY_J = 0x24;
public static final int KEY_K = 0x25;
public static final int KEY_L = 0x26;
public static final int KEY_SEMICOLON = 0x27;
public static final int KEY_APOSTROPHE = 0x28;
public static final int KEY_GRAVE = 0x29; /* accent grave */
public static final int KEY_LSHIFT = 0x2A;
public static final int KEY_BACKSLASH = 0x2B;
public static final int KEY_Z = 0x2C;
public static final int KEY_X = 0x2D;
public static final int KEY_C = 0x2E;
public static final int KEY_V = 0x2F;
public static final int KEY_B = 0x30;
public static final int KEY_N = 0x31;
public static final int KEY_M = 0x32;
public static final int KEY_COMMA = 0x33;
public static final int KEY_PERIOD = 0x34; /* . on main keyboard */
public static final int KEY_SLASH = 0x35; /* / on main keyboard */
public static final int KEY_RSHIFT = 0x36;
public static final int KEY_MULTIPLY = 0x37; /* * on numeric keypad */
public static final int KEY_LMENU = 0x38; /* left Alt */
public static final int KEY_SPACE = 0x39;
public static final int KEY_CAPITAL = 0x3A;
public static final int KEY_F1 = 0x3B;
public static final int KEY_F2 = 0x3C;
public static final int KEY_F3 = 0x3D;
public static final int KEY_F4 = 0x3E;
public static final int KEY_F5 = 0x3F;
public static final int KEY_F6 = 0x40;
public static final int KEY_F7 = 0x41;
public static final int KEY_F8 = 0x42;
public static final int KEY_F9 = 0x43;
public static final int KEY_F10 = 0x44;
public static final int KEY_NUMLOCK = 0x45;
public static final int KEY_SCROLL = 0x46; /* Scroll Lock */
public static final int KEY_NUMPAD7 = 0x47;
public static final int KEY_NUMPAD8 = 0x48;
public static final int KEY_NUMPAD9 = 0x49;
public static final int KEY_SUBTRACT = 0x4A; /* - on numeric keypad */
public static final int KEY_NUMPAD4 = 0x4B;
public static final int KEY_NUMPAD5 = 0x4C;
public static final int KEY_NUMPAD6 = 0x4D;
public static final int KEY_ADD = 0x4E; /* + on numeric keypad */
public static final int KEY_NUMPAD1 = 0x4F;
public static final int KEY_NUMPAD2 = 0x50;
public static final int KEY_NUMPAD3 = 0x51;
public static final int KEY_NUMPAD0 = 0x52;
public static final int KEY_DECIMAL = 0x53; /* . on numeric keypad */
public static final int KEY_F11 = 0x57;
public static final int KEY_F12 = 0x58;
public static final int KEY_F13 = 0x64; /* (NEC PC98) */
public static final int KEY_F14 = 0x65; /* (NEC PC98) */
public static final int KEY_F15 = 0x66; /* (NEC PC98) */
public static final int KEY_F16 = 0x67; /* Extended Function keys - (Mac) */
public static final int KEY_F17 = 0x68;
public static final int KEY_F18 = 0x69;
public static final int KEY_KANA = 0x70; /* (Japanese keyboard) */
public static final int KEY_F19 = 0x71; /* Extended Function keys - (Mac) */
public static final int KEY_CONVERT = 0x79; /* (Japanese keyboard) */
public static final int KEY_NOCONVERT = 0x7B; /* (Japanese keyboard) */
public static final int KEY_YEN = 0x7D; /* (Japanese keyboard) */
public static final int KEY_NUMPADEQUALS = 0x8D; /* = on numeric keypad (NEC PC98) */
public static final int KEY_CIRCUMFLEX = 0x90; /* (Japanese keyboard) */
public static final int KEY_AT = 0x91; /* (NEC PC98) */
public static final int KEY_COLON = 0x92; /* (NEC PC98) */
public static final int KEY_UNDERLINE = 0x93; /* (NEC PC98) */
public static final int KEY_KANJI = 0x94; /* (Japanese keyboard) */
public static final int KEY_STOP = 0x95; /* (NEC PC98) */
public static final int KEY_AX = 0x96; /* (Japan AX) */
public static final int KEY_UNLABELED = 0x97; /* (J3100) */
public static final int KEY_NUMPADENTER = 0x9C; /* Enter on numeric keypad */
public static final int KEY_RCONTROL = 0x9D;
public static final int KEY_SECTION = 0xA7; /* Section symbol (Mac) */
public static final int KEY_NUMPADCOMMA = 0xB3; /* , on numeric keypad (NEC PC98) */
public static final int KEY_DIVIDE = 0xB5; /* / on numeric keypad */
public static final int KEY_SYSRQ = 0xB7;
public static final int KEY_RMENU = 0xB8; /* right Alt */
public static final int KEY_FUNCTION = 0xC4; /* Function (Mac) */
public static final int KEY_PAUSE = 0xC5; /* Pause */
public static final int KEY_HOME = 0xC7; /* Home on arrow keypad */
public static final int KEY_UP = 0xC8; /* UpArrow on arrow keypad */
public static final int KEY_PRIOR = 0xC9; /* PgUp on arrow keypad */
public static final int KEY_LEFT = 0xCB; /* LeftArrow on arrow keypad */
public static final int KEY_RIGHT = 0xCD; /* RightArrow on arrow keypad */
public static final int KEY_END = 0xCF; /* End on arrow keypad */
public static final int KEY_DOWN = 0xD0; /* DownArrow on arrow keypad */
public static final int KEY_NEXT = 0xD1; /* PgDn on arrow keypad */
public static final int KEY_INSERT = 0xD2; /* Insert on arrow keypad */
public static final int KEY_DELETE = 0xD3; /* Delete on arrow keypad */
public static final int KEY_CLEAR = 0xDA; /* Clear key (Mac) */
public static final int KEY_LMETA = 0xDB; /* Left Windows/Option key */
public static final int KEY_RMETA = 0xDC; /* Right Windows/Option key */
public static final int KEY_APPS = 0xDD; /* AppMenu key */
public static final int KEY_POWER = 0xDE;
public static final int KEY_SLEEP = 0xDF;
public static void enableRepeatEvents(boolean b) {
PlatformInput.keyboardEnableRepeatEvents(b);
}
public static boolean isCreated() {
return true;
}
public static boolean next() {
return PlatformInput.keyboardNext();
}
public static boolean getEventKeyState() {
return PlatformInput.keyboardGetEventKeyState();
}
public static char getEventCharacter() {
return PlatformInput.keyboardGetEventCharacter();
}
public static int getEventKey() {
return PlatformInput.keyboardGetEventKey();
}
public static void setFunctionKeyModifier(int key) {
PlatformInput.setFunctionKeyModifier(key);
}
public static boolean isKeyDown(int key) {
return PlatformInput.keyboardIsKeyDown(key);
}
public static String getKeyName(int key) {
return KeyboardConstants.getKeyName(key);
}
public static boolean isRepeatEvent() {
return PlatformInput.keyboardIsRepeatEvent();
}
}

View File

@ -0,0 +1,92 @@
package org.lwjgl.input;
import net.PeytonPlayz585.lwjgl.PlatformInput;
/**
* Copyright (c) 2022 LAX1DUDE. All Rights Reserved.
*
* WITH THE EXCEPTION OF PATCH FILES, MINIFIED JAVASCRIPT, AND ALL FILES
* NORMALLY FOUND IN AN UNMODIFIED MINECRAFT RESOURCE PACK, YOU ARE NOT ALLOWED
* TO SHARE, DISTRIBUTE, OR REPURPOSE ANY FILE USED BY OR PRODUCED BY THE
* SOFTWARE IN THIS REPOSITORY WITHOUT PRIOR PERMISSION FROM THE PROJECT AUTHOR.
*
* NOT FOR COMMERCIAL OR MALICIOUS USE
*
* (please read the 'LICENSE' file this repo's root directory for more info)
*
*/
public class Mouse {
public static int getEventDWheel() {
return PlatformInput.mouseGetEventDWheel();
}
public static int getX() {
return PlatformInput.mouseGetX();
}
public static int getY() {
return PlatformInput.mouseGetY();
}
public static boolean getEventButtonState() {
return PlatformInput.mouseGetEventButtonState();
}
public static boolean isCreated() {
return true;
}
public static boolean next() {
return PlatformInput.mouseNext();
}
public static int getEventX() {
return PlatformInput.mouseGetEventX();
}
public static int getEventY() {
return PlatformInput.mouseGetEventY();
}
public static int getEventButton() {
return PlatformInput.mouseGetEventButton();
}
public static boolean isButtonDown(int i) {
return PlatformInput.mouseIsButtonDown(i);
}
public static int getDWheel() {
return PlatformInput.mouseGetDWheel();
}
public static void setGrabbed(boolean grab) {
PlatformInput.mouseSetGrabbed(grab);
}
public static int getDX() {
return PlatformInput.mouseGetDX();
}
public static int getDY() {
return PlatformInput.mouseGetDY();
}
public static void setCursorPosition(int x, int y) {
PlatformInput.mouseSetCursorPosition(x, y);
}
public static boolean isInsideWindow() {
return PlatformInput.mouseIsInsideWindow();
}
public static boolean isActuallyGrabbed() {
return PlatformInput.isPointerLocked();
}
public static boolean isMouseGrabbed() {
return PlatformInput.isMouseGrabbed();
}
}

View File

@ -0,0 +1,56 @@
package org.lwjgl.opengl;
import net.PeytonPlayz585.lwjgl.PlatformInput;
import net.PeytonPlayz585.main.MinecraftMain;
public class Display {
private static long lastSwap = 0l;
public static int getWidth() {
return PlatformInput.getWindowWidth();
}
public static int getHeight() {
return PlatformInput.getWindowHeight();
}
public static boolean isActive() {
return PlatformInput.getWindowFocused();
}
public static void create() {
}
public static void setTitle(String string) {
}
public static boolean isCloseRequested() {
return PlatformInput.isCloseRequested();
}
public static void update() {
PlatformInput.update();
}
public static void sync(int limitFramerate) {
boolean limitFPS = limitFramerate > 0 && limitFramerate < 1000;
if(limitFPS) {
long millis = System.currentTimeMillis();
long frameMillis = (1000l / limitFramerate) - (millis - lastSwap);
if(frameMillis > 0l) {
MinecraftMain.sleep(frameMillis);
}
}
lastSwap = System.currentTimeMillis();
}
public static boolean wasResized() {
return PlatformInput.wasResized();
}
}