Skip to content

Commit

Permalink
Hopefully fix crashes when rare mouse buttons are pressed (Fixes fr1k…
Browse files Browse the repository at this point in the history
  • Loading branch information
fr1kin committed Jan 31, 2021
1 parent 361ee0d commit cc28381
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/main/java/dev/fiki/forgehax/api/key/KeyInputs.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,36 @@ public interface KeyInputs {
.code(GLFW.GLFW_MOUSE_BUTTON_MIDDLE)
.build();

KeyInput MOUSE_4 = KeyInput.builder()
.type(Type.MOUSE)
.name("key.mouse.4")
.code(GLFW.GLFW_MOUSE_BUTTON_4)
.build();

KeyInput MOUSE_5 = KeyInput.builder()
.type(Type.MOUSE)
.name("key.mouse.5")
.code(GLFW.GLFW_MOUSE_BUTTON_5)
.build();

KeyInput MOUSE_6 = KeyInput.builder()
.type(Type.MOUSE)
.name("key.mouse.6")
.code(GLFW.GLFW_MOUSE_BUTTON_6)
.build();

KeyInput MOUSE_7 = KeyInput.builder()
.type(Type.MOUSE)
.name("key.mouse.7")
.code(GLFW.GLFW_MOUSE_BUTTON_7)
.build();

KeyInput MOUSE_8 = KeyInput.builder()
.type(Type.MOUSE)
.name("key.mouse.8")
.code(GLFW.GLFW_MOUSE_BUTTON_8)
.build();

KeyInput KEY_0 = KeyInput.builder()
.type(Type.KEYSYM)
.name("key.keyboard.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.fiki.forgehax.api.events.render.GuiChangedEvent;
import dev.fiki.forgehax.api.key.BindingHelper;
import dev.fiki.forgehax.api.key.KeyBindingEx;
import dev.fiki.forgehax.api.key.KeyInput;
import dev.fiki.forgehax.api.mod.ServiceMod;
import dev.fiki.forgehax.api.modloader.RegisterMod;
import dev.fiki.forgehax.asm.events.packet.PacketOutboundEvent;
Expand Down Expand Up @@ -45,7 +46,10 @@ private void updateBindings(KeyBindingSetting setting, int keyAction) {
@SubscribeListener
public void onKeyboardEvent(KeyInputEvent event) {
for (KeyBindingSetting setting : getRegistry()) {
if (InputMappings.Type.KEYSYM.equals(setting.getKeyInput().getType())
KeyInput input = setting.getKeyInput();
if (input != null
&& input.getType() != null
&& InputMappings.Type.KEYSYM.equals(input.getType())
&& setting.getKeyBinding().matchesKey(event.getKey(), event.getScanCode())
&& setting.getKeyBinding().checkConflicts()) {
updateBindings(setting, event.getAction());
Expand All @@ -56,7 +60,10 @@ public void onKeyboardEvent(KeyInputEvent event) {
@SubscribeListener
public void onMouseEvent(MouseInputEvent event) {
for (KeyBindingSetting setting : getRegistry()) {
if (InputMappings.Type.MOUSE.equals(setting.getKeyInput().getType())
KeyInput input = setting.getKeyInput();
if (input != null
&& input.getType() != null
&& InputMappings.Type.MOUSE.equals(input.getType())
&& setting.getKeyCode() == event.getButton()
&& setting.getKeyBinding().checkConflicts()) {
updateBindings(setting, event.getAction());
Expand Down

0 comments on commit cc28381

Please sign in to comment.