|
2 | 2 |
|
3 | 3 | import net.minecraft.client.KeyMapping; |
4 | 4 | import net.minecraft.client.Minecraft; |
5 | | -import org.apache.commons.lang3.ArrayUtils; |
| 5 | +import org.lwjgl.glfw.GLFW; |
6 | 6 | import org.vivecraft.client_vr.gameplay.screenhandlers.GuiHandler; |
7 | 7 | import org.vivecraft.client_vr.provider.HandedKeyBinding; |
8 | 8 |
|
9 | | -import java.util.*; |
| 9 | +import java.util.Arrays; |
| 10 | +import java.util.LinkedHashSet; |
| 11 | +import java.util.Set; |
| 12 | +import java.util.stream.Collectors; |
| 13 | +import java.util.stream.Stream; |
10 | 14 |
|
11 | 15 | public class VivecraftVRMod { |
12 | 16 |
|
13 | | - public static final boolean compiledWithForge = true; |
14 | | - |
15 | | - private static final Minecraft mc = Minecraft.getInstance(); |
16 | | - |
17 | | - public static VivecraftVRMod INSTANCE = new VivecraftVRMod(); |
18 | | - |
19 | | - Set<KeyMapping> allKeyBindingSet; |
20 | | - |
21 | | - // key binds that are settable by the user |
22 | | - Set<KeyMapping> userKeyBindingSet; |
23 | | - |
24 | | - // key binds that are needed internally, but are not required to be set by the user |
25 | | - Set<KeyMapping> hiddenKeyBindingSet; |
26 | | - |
27 | | - protected Set<KeyMapping> vanillaBindingSet; |
28 | | - |
29 | | - public final HandedKeyBinding keyClimbeyGrab = new HandedKeyBinding("vivecraft.key.climbeyGrab", -1, "vivecraft.key.category.climbey"); |
30 | | - public final HandedKeyBinding keyClimbeyJump = new HandedKeyBinding("vivecraft.key.climbeyJump", -1, "vivecraft.key.category.climbey"); |
31 | | - public final KeyMapping keyExportWorld = new KeyMapping("vivecraft.key.exportWorld", -1, "key.categories.misc"); |
32 | | - public final KeyMapping keyFreeMoveRotate = new KeyMapping("vivecraft.key.freeMoveRotate", -1, "key.categories.movement"); |
33 | | - public final KeyMapping keyFreeMoveStrafe = new KeyMapping("vivecraft.key.freeMoveStrafe", -1, "key.categories.movement"); |
34 | | - public final KeyMapping keyHotbarNext = new KeyMapping("vivecraft.key.hotbarNext", -1, "key.categories.inventory"); |
35 | | - public final KeyMapping keyHotbarPrev = new KeyMapping("vivecraft.key.hotbarPrev", -1, "key.categories.inventory"); |
36 | | - public final KeyMapping keyHotbarScroll = new KeyMapping("vivecraft.key.hotbarScroll", -1, "key.categories.inventory"); |
37 | | - public final KeyMapping keyHotbarSwipeX = new KeyMapping("vivecraft.key.hotbarSwipeX", -1, "key.categories.inventory"); |
38 | | - public final KeyMapping keyHotbarSwipeY = new KeyMapping("vivecraft.key.hotbarSwipeY", -1, "key.categories.inventory"); |
39 | | - public final KeyMapping keyMenuButton = new KeyMapping("vivecraft.key.ingameMenuButton", -1, "key.categories.ui"); |
40 | | - public final KeyMapping keyMoveThirdPersonCam = new KeyMapping("vivecraft.key.moveThirdPersonCam", -1, "key.categories.misc"); |
41 | | - public final KeyMapping keyQuickHandheldCam = new KeyMapping("vivecraft.key.quickHandheldCam", -1, "key.categories.misc"); |
42 | | - public final KeyMapping keyQuickTorch = new KeyMapping("vivecraft.key.quickTorch", -1, "key.categories.gameplay"); |
43 | | - public final KeyMapping keyRadialMenu = new KeyMapping("vivecraft.key.radialMenu", -1, "key.categories.ui"); |
44 | | - public final KeyMapping keyRotateAxis = new KeyMapping("vivecraft.key.rotateAxis", -1, "key.categories.movement"); |
45 | | - public final KeyMapping keyRotateFree = new KeyMapping("vivecraft.key.rotateFree", -1, "key.categories.movement"); |
46 | | - public final KeyMapping keyRotateLeft = new KeyMapping("vivecraft.key.rotateLeft", -1, "key.categories.movement"); |
47 | | - public final KeyMapping keyRotateRight = new KeyMapping("vivecraft.key.rotateRight", -1, "key.categories.movement"); |
48 | | - public final KeyMapping keySwapMirrorView = new KeyMapping("vivecraft.key.swapMirrorView", -1, "key.categories.misc"); |
49 | | - public final KeyMapping keyTeleport = new KeyMapping("vivecraft.key.teleport", -1, "key.categories.movement"); |
50 | | - public final KeyMapping keyTeleportFallback = new KeyMapping("vivecraft.key.teleportFallback", -1, "key.categories.movement"); |
51 | | - public final KeyMapping keyToggleHandheldCam = new KeyMapping("vivecraft.key.toggleHandheldCam", -1, "key.categories.misc"); |
52 | | - public final KeyMapping keyToggleKeyboard = new KeyMapping("vivecraft.key.toggleKeyboard", -1, "key.categories.ui"); |
53 | | - public final KeyMapping keyToggleMovement = new KeyMapping("vivecraft.key.toggleMovement", -1, "key.categories.movement"); |
54 | | - public final KeyMapping keyTogglePlayerList = new KeyMapping("vivecraft.key.togglePlayerList", -1, "key.categories.multiplayer"); |
55 | | - public final HandedKeyBinding keyTrackpadTouch = new HandedKeyBinding("vivecraft.key.trackpadTouch", -1, "key.categories.misc"); |
56 | | - public final HandedKeyBinding keyVRInteract = new HandedKeyBinding("vivecraft.key.vrInteract", -1, "key.categories.gameplay"); |
57 | | - public final KeyMapping keyWalkabout = new KeyMapping("vivecraft.key.walkabout", -1, "key.categories.movement"); |
58 | | - |
59 | | - private void setupKeybindingSets() { |
60 | | - if (this.userKeyBindingSet == null || hiddenKeyBindingSet == null) { |
61 | | - this.userKeyBindingSet = new LinkedHashSet<>(); |
62 | | - this.hiddenKeyBindingSet = new LinkedHashSet<>(); |
63 | | - this.allKeyBindingSet = new LinkedHashSet<>(); |
64 | | - |
65 | | - this.userKeyBindingSet.add(this.keyRotateLeft); |
66 | | - this.userKeyBindingSet.add(this.keyRotateRight); |
67 | | - this.userKeyBindingSet.add(this.keyTeleport); |
68 | | - this.userKeyBindingSet.add(this.keyTeleportFallback); |
69 | | - this.userKeyBindingSet.add(this.keyToggleMovement); |
70 | | - this.userKeyBindingSet.add(this.keyQuickTorch); |
71 | | - this.userKeyBindingSet.add(this.keySwapMirrorView); |
72 | | - this.userKeyBindingSet.add(this.keyExportWorld); |
73 | | - this.userKeyBindingSet.add(this.keyMoveThirdPersonCam); |
74 | | - this.userKeyBindingSet.add(this.keyTogglePlayerList); |
75 | | - this.userKeyBindingSet.add(this.keyToggleHandheldCam); |
76 | | - this.userKeyBindingSet.add(this.keyQuickHandheldCam); |
77 | | - |
78 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyLeftClick); |
79 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyRightClick); |
80 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyMiddleClick); |
81 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyShift); |
82 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyCtrl); |
83 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyAlt); |
84 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyScrollUp); |
85 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyScrollDown); |
86 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyScrollAxis); |
87 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyKeyboardClick); |
88 | | - this.hiddenKeyBindingSet.add(GuiHandler.keyKeyboardShift); |
89 | | - this.hiddenKeyBindingSet.add(this.keyClimbeyGrab); |
90 | | - this.hiddenKeyBindingSet.add(this.keyClimbeyJump); |
91 | | - this.hiddenKeyBindingSet.add(this.keyMenuButton); |
92 | | - this.hiddenKeyBindingSet.add(this.keyRadialMenu); |
93 | | - this.hiddenKeyBindingSet.add(this.keyToggleKeyboard); |
94 | | - this.hiddenKeyBindingSet.add(this.keyHotbarSwipeX); |
95 | | - this.hiddenKeyBindingSet.add(this.keyHotbarSwipeY); |
96 | | - this.hiddenKeyBindingSet.add(this.keyTrackpadTouch); |
97 | | - |
98 | | - this.hiddenKeyBindingSet.add(this.keyRotateAxis); |
99 | | - this.hiddenKeyBindingSet.add(this.keyRotateFree); |
100 | | - this.hiddenKeyBindingSet.add(this.keyFreeMoveRotate); |
101 | | - this.hiddenKeyBindingSet.add(this.keyFreeMoveStrafe); |
102 | | - this.hiddenKeyBindingSet.add(this.keyHotbarNext); |
103 | | - this.hiddenKeyBindingSet.add(this.keyHotbarPrev); |
104 | | - this.hiddenKeyBindingSet.add(this.keyHotbarScroll); |
105 | | - this.hiddenKeyBindingSet.add(this.keyVRInteract); |
106 | | - this.hiddenKeyBindingSet.add(this.keyWalkabout); |
107 | | - |
108 | | - allKeyBindingSet.addAll(userKeyBindingSet); |
109 | | - allKeyBindingSet.addAll(hiddenKeyBindingSet); |
110 | | - } |
111 | | - } |
112 | | - |
113 | | - public Set<KeyMapping> getUserKeyBindings() { |
114 | | - setupKeybindingSets(); |
115 | | - return this.userKeyBindingSet; |
116 | | - } |
117 | | - |
118 | | - public Set<KeyMapping> getHiddenKeyBindings() { |
119 | | - setupKeybindingSets(); |
120 | | - return hiddenKeyBindingSet; |
121 | | - } |
122 | | - |
123 | | - public Set<KeyMapping> getAllKeyBindings() { |
124 | | - setupKeybindingSets(); |
125 | | - return allKeyBindingSet; |
126 | | - } |
127 | | - |
128 | | - public KeyMapping[] initializeBindings(KeyMapping[] keyBindings) { |
129 | | - for (KeyMapping keymapping : this.getUserKeyBindings()) { |
130 | | - keyBindings = ArrayUtils.add(keyBindings, keymapping); |
131 | | - } |
132 | | - |
133 | | - this.setVanillaBindings(keyBindings); |
134 | | - Map<String, Integer> map = KeyMapping.CATEGORY_SORT_ORDER; |
135 | | - map.put("vivecraft.key.category.gui", 8); |
136 | | - map.put("vivecraft.key.category.climbey", 9); |
137 | | - map.put("vivecraft.key.category.keyboard", 10); |
138 | | - return keyBindings; |
139 | | - } |
140 | | - |
141 | | - public void setVanillaBindings(KeyMapping[] bindings) { |
142 | | - this.vanillaBindingSet = new HashSet<>(Arrays.asList(bindings)); |
143 | | - // add hidden keys, since those are not in there |
144 | | - vanillaBindingSet.addAll(hiddenKeyBindingSet); |
145 | | - } |
146 | | - |
147 | | - public boolean isSafeBinding(KeyMapping kb) { |
148 | | - return this.getAllKeyBindings().contains(kb) || kb == mc.options.keyChat || kb == mc.options.keyInventory; |
| 17 | + public static final HandedKeyBinding keyClimbeyGrab = new HandedKeyBinding("vivecraft.key.climbeyGrab", GLFW.GLFW_KEY_UNKNOWN, "vivecraft.key.category.climbey"); |
| 18 | + public static final HandedKeyBinding keyClimbeyJump = new HandedKeyBinding("vivecraft.key.climbeyJump", GLFW.GLFW_KEY_UNKNOWN, "vivecraft.key.category.climbey"); |
| 19 | + public static final KeyMapping keyExportWorld = new KeyMapping("vivecraft.key.exportWorld", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc"); |
| 20 | + public static final KeyMapping keyFreeMoveRotate = new KeyMapping("vivecraft.key.freeMoveRotate", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 21 | + public static final KeyMapping keyFreeMoveStrafe = new KeyMapping("vivecraft.key.freeMoveStrafe", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 22 | + public static final KeyMapping keyHotbarNext = new KeyMapping("vivecraft.key.hotbarNext", GLFW.GLFW_KEY_UNKNOWN, "key.categories.inventory"); |
| 23 | + public static final KeyMapping keyHotbarPrev = new KeyMapping("vivecraft.key.hotbarPrev", GLFW.GLFW_KEY_UNKNOWN, "key.categories.inventory"); |
| 24 | + public static final KeyMapping keyHotbarScroll = new KeyMapping("vivecraft.key.hotbarScroll", GLFW.GLFW_KEY_UNKNOWN, "key.categories.inventory"); |
| 25 | + public static final KeyMapping keyHotbarSwipeX = new KeyMapping("vivecraft.key.hotbarSwipeX", GLFW.GLFW_KEY_UNKNOWN, "key.categories.inventory"); |
| 26 | + public static final KeyMapping keyHotbarSwipeY = new KeyMapping("vivecraft.key.hotbarSwipeY", GLFW.GLFW_KEY_UNKNOWN, "key.categories.inventory"); |
| 27 | + public static final KeyMapping keyMenuButton = new KeyMapping("vivecraft.key.ingameMenuButton", GLFW.GLFW_KEY_UNKNOWN, "key.categories.ui"); |
| 28 | + public static final KeyMapping keyMoveThirdPersonCam = new KeyMapping("vivecraft.key.moveThirdPersonCam", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc"); |
| 29 | + public static final KeyMapping keyQuickHandheldCam = new KeyMapping("vivecraft.key.quickHandheldCam", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc"); |
| 30 | + public static final KeyMapping keyQuickTorch = new KeyMapping("vivecraft.key.quickTorch", GLFW.GLFW_KEY_UNKNOWN, "key.categories.gameplay"); |
| 31 | + public static final KeyMapping keyRadialMenu = new KeyMapping("vivecraft.key.radialMenu", GLFW.GLFW_KEY_UNKNOWN, "key.categories.ui"); |
| 32 | + public static final KeyMapping keyRotateAxis = new KeyMapping("vivecraft.key.rotateAxis", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 33 | + public static final KeyMapping keyRotateFree = new KeyMapping("vivecraft.key.rotateFree", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 34 | + public static final KeyMapping keyRotateLeft = new KeyMapping("vivecraft.key.rotateLeft", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 35 | + public static final KeyMapping keyRotateRight = new KeyMapping("vivecraft.key.rotateRight", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 36 | + public static final KeyMapping keySwapMirrorView = new KeyMapping("vivecraft.key.swapMirrorView", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc"); |
| 37 | + public static final KeyMapping keyTeleport = new KeyMapping("vivecraft.key.teleport", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 38 | + public static final KeyMapping keyTeleportFallback = new KeyMapping("vivecraft.key.teleportFallback", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 39 | + public static final KeyMapping keyToggleHandheldCam = new KeyMapping("vivecraft.key.toggleHandheldCam", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc"); |
| 40 | + public static final KeyMapping keyToggleKeyboard = new KeyMapping("vivecraft.key.toggleKeyboard", GLFW.GLFW_KEY_UNKNOWN, "key.categories.ui"); |
| 41 | + public static final KeyMapping keyToggleMovement = new KeyMapping("vivecraft.key.toggleMovement", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 42 | + public static final KeyMapping keyTogglePlayerList = new KeyMapping("vivecraft.key.togglePlayerList", GLFW.GLFW_KEY_UNKNOWN, "key.categories.multiplayer"); |
| 43 | + public static final HandedKeyBinding keyTrackpadTouch = new HandedKeyBinding("vivecraft.key.trackpadTouch", GLFW.GLFW_KEY_UNKNOWN, "key.categories.misc"); |
| 44 | + public static final HandedKeyBinding keyVRInteract = new HandedKeyBinding("vivecraft.key.vrInteract", GLFW.GLFW_KEY_UNKNOWN, "key.categories.gameplay"); |
| 45 | + public static final KeyMapping keyWalkabout = new KeyMapping("vivecraft.key.walkabout", GLFW.GLFW_KEY_UNKNOWN, "key.categories.movement"); |
| 46 | + |
| 47 | + /** Key binds provided by vivecraft, which the player may bind. */ |
| 48 | + public static final Set<KeyMapping> userKeyBindingSet = new LinkedHashSet<>(Arrays.asList( |
| 49 | + keyRotateLeft, |
| 50 | + keyRotateRight, |
| 51 | + keyTeleport, |
| 52 | + keyTeleportFallback, |
| 53 | + keyToggleMovement, |
| 54 | + keyQuickTorch, |
| 55 | + keySwapMirrorView, |
| 56 | + keyExportWorld, |
| 57 | + keyMoveThirdPersonCam, |
| 58 | + keyTogglePlayerList, |
| 59 | + keyToggleHandheldCam, |
| 60 | + keyQuickHandheldCam |
| 61 | + )); |
| 62 | + |
| 63 | + /** Key binds internal to vivecraft, which the player may <u>not</u> bind. */ |
| 64 | + public static final Set<KeyMapping> hiddenKeyBindingSet = new LinkedHashSet<>(Arrays.asList( |
| 65 | + GuiHandler.keyLeftClick, |
| 66 | + GuiHandler.keyRightClick, |
| 67 | + GuiHandler.keyMiddleClick, |
| 68 | + GuiHandler.keyShift, |
| 69 | + GuiHandler.keyCtrl, |
| 70 | + GuiHandler.keyAlt, |
| 71 | + GuiHandler.keyScrollUp, |
| 72 | + GuiHandler.keyScrollDown, |
| 73 | + GuiHandler.keyScrollAxis, |
| 74 | + GuiHandler.keyKeyboardClick, |
| 75 | + GuiHandler.keyKeyboardShift, |
| 76 | + keyClimbeyGrab, |
| 77 | + keyClimbeyJump, |
| 78 | + keyMenuButton, |
| 79 | + keyRadialMenu, |
| 80 | + keyToggleKeyboard, |
| 81 | + keyHotbarSwipeX, |
| 82 | + keyHotbarSwipeY, |
| 83 | + keyTrackpadTouch, |
| 84 | + keyRotateAxis, |
| 85 | + keyRotateFree, |
| 86 | + keyFreeMoveRotate, |
| 87 | + keyFreeMoveStrafe, |
| 88 | + keyHotbarNext, |
| 89 | + keyHotbarPrev, |
| 90 | + keyHotbarScroll, |
| 91 | + keyVRInteract, |
| 92 | + keyWalkabout |
| 93 | + )); |
| 94 | + |
| 95 | + /** Key binds provided by vanilla. */ |
| 96 | + public static final Set<KeyMapping> vanillaBindingSet = new LinkedHashSet<>(); |
| 97 | + |
| 98 | + /** Key binds provided to the player. */ |
| 99 | + public static final Set<KeyMapping> allKeyBindingSet = Stream.concat( |
| 100 | + userKeyBindingSet.stream(), |
| 101 | + hiddenKeyBindingSet.stream() |
| 102 | + ).collect(Collectors.toSet()); |
| 103 | + |
| 104 | + public static boolean isSafeBinding(KeyMapping kb) { |
| 105 | + return allKeyBindingSet.contains(kb) || kb == Minecraft.getInstance().options.keyChat || kb == Minecraft.getInstance().options.keyInventory; |
149 | 106 | } |
150 | 107 |
|
151 | | - public boolean isModBinding(KeyMapping kb) { |
152 | | - return !this.vanillaBindingSet.contains(kb); |
| 108 | + /** checks if a key bind is NOT provided by vanilla NOR internal to vivecraft */ |
| 109 | + public static boolean isModBinding(final KeyMapping kb) { |
| 110 | + return !hiddenKeyBindingSet.contains(kb) && !vanillaBindingSet.contains(kb); |
153 | 111 | } |
154 | 112 | } |
0 commit comments