2019-09-03 08:34:02 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
|
|
|
import org.lwjgl.glfw.GLFW;
|
|
|
|
|
2021-11-02 06:18:30 +01:00
|
|
|
import net.minecraft.client.KeyMapping;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2021-11-02 00:08:20 +01:00
|
|
|
import net.minecraft.client.gui.screens.Screen;
|
2021-11-02 06:18:30 +01:00
|
|
|
import net.minecraftforge.fmlclient.registry.ClientRegistry;
|
2019-09-03 08:34:02 +02:00
|
|
|
|
|
|
|
public enum AllKeys {
|
|
|
|
|
2021-05-23 03:00:10 +02:00
|
|
|
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),
|
2019-09-03 08:34:02 +02:00
|
|
|
|
|
|
|
;
|
|
|
|
|
2021-11-02 00:08:20 +01:00
|
|
|
private KeyMapping keybind;
|
2019-09-03 08:34:02 +02:00
|
|
|
private String description;
|
|
|
|
private int key;
|
|
|
|
private boolean modifiable;
|
|
|
|
|
|
|
|
private AllKeys(String description, int defaultKey) {
|
2019-09-14 18:21:30 +02:00
|
|
|
this.description = Create.ID + ".keyinfo." + description;
|
2019-09-03 08:34:02 +02:00
|
|
|
this.key = defaultKey;
|
|
|
|
this.modifiable = !description.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void register() {
|
|
|
|
for (AllKeys key : values()) {
|
2021-11-02 00:08:20 +01:00
|
|
|
key.keybind = new KeyMapping(key.description, key.key, Create.NAME);
|
2019-09-03 08:34:02 +02:00
|
|
|
if (!key.modifiable)
|
|
|
|
continue;
|
2019-10-05 19:00:43 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
ClientRegistry.registerKeyBinding(key.keybind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-02 00:08:20 +01:00
|
|
|
public KeyMapping getKeybind() {
|
2019-09-03 08:34:02 +02:00
|
|
|
return keybind;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPressed() {
|
|
|
|
if (!modifiable)
|
|
|
|
return isKeyDown(key);
|
2021-07-15 11:32:03 +02:00
|
|
|
return keybind.isDown();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getBoundKey() {
|
2021-07-15 11:32:03 +02:00
|
|
|
return keybind.getTranslatedKeyMessage()
|
2021-04-08 19:22:11 +02:00
|
|
|
.getString()
|
|
|
|
.toUpperCase();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getBoundCode() {
|
2021-04-08 19:22:11 +02:00
|
|
|
return keybind.getKey()
|
2021-07-15 11:32:03 +02:00
|
|
|
.getValue();
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isKeyDown(int key) {
|
2021-04-08 19:22:11 +02:00
|
|
|
return GLFW.glfwGetKey(Minecraft.getInstance()
|
|
|
|
.getWindow()
|
2021-07-15 11:32:03 +02:00
|
|
|
.getWindow(), key) != 0;
|
2019-09-03 08:34:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean ctrlDown() {
|
|
|
|
return Screen.hasControlDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean shiftDown() {
|
|
|
|
return Screen.hasShiftDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean altDown() {
|
|
|
|
return Screen.hasAltDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|