-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
KeyBindings.java
84 lines (65 loc) · 2.37 KB
/
KeyBindings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.tom.cpm.client;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Keyboard;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.client.settings.IKeyConflictContext;
import net.minecraftforge.client.settings.KeyConflictContext;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import com.tom.cpl.gui.IKeybind;
import com.tom.cpl.gui.KeyboardEvent;
public class KeyBindings implements IKeybind {
private static KeyConflictCtx conflictCtx = new KeyConflictCtx();
public static KeyBinding gestureMenuBinding, renderToggleBinding;
public static IKeybind[] quickAccess = new IKeybind[IKeybind.QUICK_ACCESS_KEYBINDS_COUNT];
public static void init() {
gestureMenuBinding = new KeyBinding("key.cpm.gestureMenu", KeyConflictContext.IN_GAME, Keyboard.KEY_G, "key.cpm.category");
kbs.add(new KeyBindings(gestureMenuBinding, "gestureMenu"));
renderToggleBinding = new KeyBinding("key.cpm.renderToggle", KeyConflictContext.IN_GAME, 0, "key.cpm.category");
kbs.add(new KeyBindings(renderToggleBinding, "renderToggle"));
for(int i = 1;i<=IKeybind.QUICK_ACCESS_KEYBINDS_COUNT;i++)
createQA(i);
}
private static class KeyConflictCtx implements IKeyConflictContext {
@Override
public boolean isActive() {
Minecraft mc = Minecraft.getMinecraft();
return mc.currentScreen instanceof GuiImpl || (!KeyConflictContext.GUI.isActive() && mc.player != null);
}
@Override
public boolean conflicts(IKeyConflictContext other) {
return other == this || other == KeyConflictContext.IN_GAME;
}
}
private static void createQA(int id) {
KeyBinding kb = new KeyBinding("key.cpm.qa_" + id, conflictCtx, 0, "key.cpm.category");
KeyBindings kbs = new KeyBindings(kb, "qa_" + id);
KeyBindings.kbs.add(kbs);
quickAccess[id - 1] = kbs;
}
public static List<IKeybind> kbs = new ArrayList<>();
private final KeyBinding kb;
private final String name;
private KeyBindings(KeyBinding kb, String name) {
this.kb = kb;
this.name = name;
ClientRegistry.registerKeyBinding(kb);
}
@Override
public boolean isPressed(KeyboardEvent evt) {
return kb.isActiveAndMatches(evt.keyCode);
}
@Override
public String getBoundKey() {
return kb.getDisplayName();
}
@Override
public String getName() {
return name;
}
@Override
public boolean isPressed() {
return kb.isKeyDown();
}
}