Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
import net.minecraft.client.gui.screens.worldselection.SelectWorldScreen;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

/**
* ClickCrystals main
Expand Down Expand Up @@ -98,7 +98,7 @@ public final class ClickCrystals implements ModInitializer, Global {
@SuppressWarnings("unused")
public static final Keybind openModuleKeybind = Keybind.create()
.id("open-clickcrystals-module-screen")
.defaultKey(GLFW.GLFW_KEY_APOSTROPHE)
.defaultKey(InputConstants.KEY_APOSTROPHE)
.condition((bind, screen) -> screen == null || screen instanceof TitleScreen || screen instanceof JoinMultiplayerScreen || screen instanceof SelectWorldScreen)
.onPress(bind -> UserInputListener.openPreviousScreen())
.onChange(config::saveKeybind)
Expand All @@ -107,7 +107,7 @@ public final class ClickCrystals implements ModInitializer, Global {
@SuppressWarnings("unused")
public static final Keybind openHudEditorKeybind = Keybind.create()
.id("open-hud-editor-screen")
.defaultKey(GLFW.GLFW_KEY_SEMICOLON)
.defaultKey(InputConstants.KEY_SEMICOLON)
.condition((bind, screen) -> screen == null)
.onPress(bind -> {
if (Module.isEnabled(InGameHuds.class)) {
Expand All @@ -122,7 +122,7 @@ public final class ClickCrystals implements ModInitializer, Global {
@SuppressWarnings("unused")
public static final Keybind commandPrefix = Keybind.create()
.id("command-prefix")
.defaultKey(GLFW.GLFW_KEY_COMMA)
.defaultKey(InputConstants.KEY_COMMA)
.condition((bind, screen) -> screen == null)
.onPress(bind -> mc.gui.setScreen(new ChatScreen("", false)))
.onChange(config::saveKeybind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import net.minecraft.client.input.MouseButtonEvent;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.network.chat.Component;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

import java.util.ArrayList;
import java.util.ConcurrentModificationException;
Expand Down Expand Up @@ -238,13 +238,13 @@ public boolean keyPressed(KeyEvent input) {
int scanCode = input.scancode();
int modifiers = input.modifiers();

if (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT) {
if (keyCode == InputConstants.KEY_LSHIFT || keyCode == InputConstants.KEY_RSHIFT) {
this.shiftKeyPressed = true;
}
else if (keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT) {
else if (keyCode == InputConstants.KEY_LALT || keyCode == InputConstants.KEY_RALT) {
this.altKeyPressed = true;
}
else if (keyCode == GLFW.GLFW_KEY_LEFT_CONTROL || keyCode == GLFW.GLFW_KEY_RIGHT_CONTROL) {
else if (keyCode == InputConstants.KEY_LCONTROL || keyCode == InputConstants.KEY_RCONTROL) {
this.ctrlKeyPressed = true;
}

Expand All @@ -265,13 +265,13 @@ public boolean keyReleased(KeyEvent input) {
int scanCode = input.scancode();
int modifiers = input.modifiers();

if (keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT) {
if (keyCode == InputConstants.KEY_LSHIFT || keyCode == InputConstants.KEY_RSHIFT) {
this.shiftKeyPressed = false;
}
else if (keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT) {
else if (keyCode == InputConstants.KEY_LALT || keyCode == InputConstants.KEY_RALT) {
this.altKeyPressed = false;
}
else if (keyCode == GLFW.GLFW_KEY_LEFT_CONTROL || keyCode == GLFW.GLFW_KEY_RIGHT_CONTROL) {
else if (keyCode == InputConstants.KEY_LCONTROL || keyCode == InputConstants.KEY_RCONTROL) {
this.ctrlKeyPressed = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@
import io.github.itzispyder.clickcrystals.modules.settings.KeybindSetting;
import io.github.itzispyder.clickcrystals.util.minecraft.render.RenderUtils;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

import java.util.function.Function;

public class KeybindSettingElement extends SettingElement<KeybindSetting> implements Typeable {

private final KeybindSetting setting;
private String display;
private int currentScanCode;

public KeybindSettingElement(KeybindSetting setting, int x, int y) {
super(setting, x, y);
this.setting = setting;
this.display = null;
this.currentScanCode = 42;
}

@Override
Expand Down Expand Up @@ -54,8 +52,7 @@ public void mouseClicked(double mouseX, double mouseY, int button) {
@Override
public boolean onKey(int key, int scanCode) {
if (mc.gui.screen() instanceof GuiScreen screen) {
setting.setKey(key == GLFW.GLFW_KEY_ESCAPE ? Keybind.NONE : key);
currentScanCode = scanCode;
setting.setKey(key == InputConstants.KEY_ESCAPE ? Keybind.NONE : key);
screen.selected = null;
}
return true;
Expand All @@ -72,7 +69,7 @@ public String getDisplay() {

public void updateDisplay() {
int key = setting.getKey();
String name = GLFW.glfwGetKeyName(key, currentScanCode);
String name = InputConstants.Type.KEYSYM.getOrCreate(key).getDisplayName().getString();

if (name == null || Keybind.EXTRAS.containsKey(key)) {
name = Keybind.EXTRAS.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.github.itzispyder.clickcrystals.Global;
import io.github.itzispyder.clickcrystals.gui.GuiScreen;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

import java.util.function.Function;

Expand All @@ -12,17 +12,17 @@ default boolean onKey(int key, int scan) {
if (!(mc.gui.screen() instanceof GuiScreen screen))
return false;

if (key == GLFW.GLFW_KEY_ESCAPE) {
if (key == InputConstants.KEY_ESCAPE) {
screen.selected = null;
return true;
}
else if (key == GLFW.GLFW_KEY_BACKSPACE) {
else if (key == InputConstants.KEY_BACKSPACE) {
onInput(input -> input.isEmpty()
? input
: input.substring(0, input.length() - 1));
return true;
}
else if (key == GLFW.GLFW_KEY_V && screen.ctrlKeyPressed) {
else if (key == InputConstants.KEY_V && screen.ctrlKeyPressed) {
onInput(input -> input.concat(mc.keyboardHandler.getClipboard()));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.FormattedText;
import net.minecraft.util.FormattedCharSequence;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

import java.awt.*;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -233,12 +233,12 @@ public boolean onKey(int key, int scan) {
if (keyInterceptor != null && keyInterceptor.apply(key)) return true;
boolean handled = handleKeyInner(key, screen);
// Only typing (character entry, backspace, delete) should surface autocomplete; copy/paste/navigation dismiss it.
if (handled) fireChanged(key == GLFW.GLFW_KEY_BACKSPACE || key == GLFW.GLFW_KEY_DELETE);
if (handled) fireChanged(key == InputConstants.KEY_BACKSPACE || key == InputConstants.KEY_DELETE);
return handled;
}

private boolean handleKeyInner(int key, GuiScreen screen) {
if (key == GLFW.GLFW_KEY_ESCAPE) {
if (key == InputConstants.KEY_ESCAPE) {
if (hasRange() || selectedAll) {
selectedAll = false;
selectionEnd = selectionStart;
Expand All @@ -251,17 +251,17 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
// Ctrl combos
if (screen.ctrlKeyPressed) {
switch (key) {
case GLFW.GLFW_KEY_A -> {
case InputConstants.KEY_A -> {
selectedAll = true;
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_C -> {
case InputConstants.KEY_C -> {
if (selectedAll) mc.keyboardHandler.setClipboard(content);
else if (hasRange()) mc.keyboardHandler.setClipboard(content.substring(selMin(), selMax()));
return true;
}
case GLFW.GLFW_KEY_X -> {
case InputConstants.KEY_X -> {
if (selectedAll) {
mc.keyboardHandler.setClipboard(content);
clear();
Expand All @@ -272,14 +272,14 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_V -> {
case InputConstants.KEY_V -> {
if (hasRange() || selectedAll) deleteRange();
onInput(input -> insertInput(mc.keyboardHandler.getClipboard()));
shiftRight();
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_Z -> {
case InputConstants.KEY_Z -> {
if (!undoStack.isEmpty()) {
redoStack.push(Pair.of(content, selectionStart));
Pair<String, Integer> state = undoStack.pop();
Expand All @@ -291,7 +291,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_Y -> {
case InputConstants.KEY_Y -> {
if (!redoStack.isEmpty()) {
undoStack.push(Pair.of(content, selectionStart));
Pair<String, Integer> state = redoStack.pop();
Expand All @@ -303,7 +303,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_D -> {
case InputConstants.KEY_D -> {
int ls = lineStart(selectionStart);
int le = lineEnd(selectionStart);
String line = content.substring(ls, le);
Expand All @@ -316,24 +316,24 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_SLASH -> {
case InputConstants.KEY_SLASH -> {
return toggleComment();
}
case GLFW.GLFW_KEY_LEFT -> {
case InputConstants.KEY_LEFT -> {
selectionStart = selectionEnd = prevWordBoundary(selectionStart);
selectedAll = false;
updateSelection();
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_RIGHT -> {
case InputConstants.KEY_RIGHT -> {
selectionStart = selectionEnd = nextWordBoundary(selectionStart);
selectedAll = false;
updateSelection();
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_BACKSPACE -> {
case InputConstants.KEY_BACKSPACE -> {
if (hasRange() || selectedAll) {
deleteRange();
preferredCol = -1;
Expand All @@ -355,7 +355,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) {

// Basic keys
switch (key) {
case GLFW.GLFW_KEY_BACKSPACE -> {
case InputConstants.KEY_BACKSPACE -> {
if (hasRange() || selectedAll) {
deleteRange();
preferredCol = -1;
Expand All @@ -381,7 +381,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_DELETE -> {
case InputConstants.KEY_DELETE -> {
if (hasRange() || selectedAll) {
deleteRange();
preferredCol = -1;
Expand All @@ -391,7 +391,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_ENTER -> {
case InputConstants.KEY_RETURN -> {
if (hasRange() || selectedAll) deleteRange();
int ls = lineStart(selectionStart);
String before = content.substring(ls, selectionStart);
Expand Down Expand Up @@ -420,14 +420,14 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_TAB -> {
case InputConstants.KEY_TAB -> {
if (hasRange() || selectedAll) deleteRange();
onInput(input -> insertInput(" "));
for (int i = 0; i < 4; i++) shiftRight();
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_LEFT -> {
case InputConstants.KEY_LEFT -> {
if (hasRange() || selectedAll) {
selectionStart = selectionEnd = selMin();
selectedAll = false;
Expand All @@ -436,7 +436,7 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_RIGHT -> {
case InputConstants.KEY_RIGHT -> {
if (hasRange() || selectedAll) {
selectionStart = selectionEnd = selMax();
selectedAll = false;
Expand All @@ -445,25 +445,25 @@ private boolean handleKeyInner(int key, GuiScreen screen) {
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_HOME -> {
case InputConstants.KEY_HOME -> {
selectionStart = selectionEnd = lineStart(selectionStart);
selectedAll = false;
updateSelection();
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_END -> {
case InputConstants.KEY_END -> {
selectionStart = selectionEnd = lineEnd(selectionStart);
selectedAll = false;
updateSelection();
preferredCol = -1;
return true;
}
case GLFW.GLFW_KEY_UP -> {
case InputConstants.KEY_UP -> {
navigateVertical(-1);
return true;
}
case GLFW.GLFW_KEY_DOWN -> {
case InputConstants.KEY_DOWN -> {
navigateVertical(1);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.input.KeyEvent;
import net.minecraft.client.input.MouseButtonEvent;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -113,7 +113,7 @@ public void resize(int width, int height) {
@Override
public boolean keyPressed(KeyEvent e) {
super.keyPressed(e);
if (e.input() == GLFW.GLFW_KEY_ENTER && this.selected == searchBar && !searchBar.getQuery().isEmpty()) {
if (e.input() == InputConstants.KEY_RETURN && this.selected == searchBar && !searchBar.getQuery().isEmpty()) {
mc.gui.setScreen(new SearchScreen() {{
this.searchbar.setQuery(HomeScreen.this.searchBar.getQuery());
this.filterByQuery(this.searchbar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.github.itzispyder.clickcrystals.util.minecraft.PlayerUtils;
import io.github.itzispyder.clickcrystals.util.minecraft.render.RenderUtils;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

import java.io.File;
import java.util.Comparator;
Expand Down Expand Up @@ -297,7 +297,7 @@ private static class ScriptCreateNew extends ModuleElement {

@Override
public boolean onKey(int key, int scancode) {
if (key != GLFW.GLFW_KEY_ENTER)
if (key != InputConstants.KEY_RETURN)
return super.onKey(key, scancode);
if (!(mc.gui.screen() instanceof GuiScreen screen))
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.github.itzispyder.clickcrystals.util.StringUtils;
import io.github.itzispyder.clickcrystals.util.minecraft.render.RenderUtils;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;

public class ProfilesScreen extends DefaultBase {

Expand Down Expand Up @@ -121,7 +121,7 @@ private static class ProfileCreateNew extends ModuleElement {

@Override
public boolean onKey(int key, int scancode) {
if (key != GLFW.GLFW_KEY_ENTER)
if (key != InputConstants.KEY_RETURN)
return super.onKey(key, scancode);
if (!(mc.gui.screen() instanceof GuiScreen screen))
return true;
Expand Down
Loading