Create/src/main/java/com/simibubi/create/AllKeys.java

79 lines
1.6 KiB
Java
Raw Normal View History

package com.simibubi.create;
import org.lwjgl.glfw.GLFW;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.client.registry.ClientRegistry;
public enum AllKeys {
TOOL_MENU("toolmenu", GLFW.GLFW_KEY_LEFT_ALT),
ACTIVATE_TOOL("", GLFW.GLFW_KEY_LEFT_CONTROL),
2021-09-16 04:10:34 +02:00
TOOLBELT("toolbelt", GLFW.GLFW_KEY_LEFT_ALT),
;
private KeyBinding keybind;
private String description;
private int key;
private boolean modifiable;
private AllKeys(String description, int defaultKey) {
this.description = Create.ID + ".keyinfo." + description;
this.key = defaultKey;
this.modifiable = !description.isEmpty();
}
public static void register() {
for (AllKeys key : values()) {
key.keybind = new KeyBinding(key.description, key.key, Create.NAME);
if (!key.modifiable)
continue;
ClientRegistry.registerKeyBinding(key.keybind);
}
}
public KeyBinding getKeybind() {
return keybind;
}
public boolean isPressed() {
if (!modifiable)
return isKeyDown(key);
2021-07-15 11:32:03 +02:00
return keybind.isDown();
}
public String getBoundKey() {
2021-07-15 11:32:03 +02:00
return keybind.getTranslatedKeyMessage()
.getString()
.toUpperCase();
}
public int getBoundCode() {
return keybind.getKey()
2021-07-15 11:32:03 +02:00
.getValue();
}
public static boolean isKeyDown(int key) {
return GLFW.glfwGetKey(Minecraft.getInstance()
.getWindow()
2021-07-15 11:32:03 +02:00
.getWindow(), key) != 0;
}
public static boolean ctrlDown() {
return Screen.hasControlDown();
}
public static boolean shiftDown() {
return Screen.hasShiftDown();
}
public static boolean altDown() {
return Screen.hasAltDown();
}
}