diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java index c5b1b8a..7d0b116 100644 --- a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java @@ -44,7 +44,12 @@ public class BindButton @Override public void mouseClicked(int mouseX, int mouseY, int mouseButton) { super.mouseClicked(mouseX, mouseY, mouseButton); - if (this.isHovering(mouseX, mouseY)) { + if (this.isListening) { + if (mouseButton != 0 && mouseButton != 1) { + this.setting.setValue(new Bind(-mouseButton - 2)); + this.onMouseClick(); + } + } else if (this.isHovering(mouseX, mouseY)) { mc.getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1f)); } } diff --git a/src/main/java/me/alpha432/oyvey/features/settings/Bind.java b/src/main/java/me/alpha432/oyvey/features/settings/Bind.java index 166502a..05d2825 100644 --- a/src/main/java/me/alpha432/oyvey/features/settings/Bind.java +++ b/src/main/java/me/alpha432/oyvey/features/settings/Bind.java @@ -28,17 +28,19 @@ public class Bind implements Util { } public boolean isEmpty() { - return this.key < 0; + return this.key == -1; } public String toString() { - return this.isEmpty() ? "None" : (this.key < 0 - ? "None" - : this.capitalise(InputConstants.getKey(new KeyEvent(this.key, 0, 0)).getName())); + if (this.isEmpty()) return "None"; + if (this.key < -1) return "Mouse " + (-this.key - 1); + return this.capitalise(InputConstants.getKey(new KeyEvent(this.key, 0, 0)).getName()); } public boolean isDown() { - return !this.isEmpty() && GLFW.glfwGetKey(mc.getWindow().handle(), this.getKey()) == 1; + if (this.isEmpty()) return false; + if (this.key < -1) return GLFW.glfwGetMouseButton(mc.getWindow().handle(), -this.key - 2) == 1; + return GLFW.glfwGetKey(mc.getWindow().handle(), this.getKey()) == 1; } private String capitalise(String str) { @@ -56,18 +58,19 @@ public class Bind implements Util { public Bind doBackward(JsonElement jsonElement) { String s = jsonElement.getAsString(); - if (s.equalsIgnoreCase("None")) { - return Bind.none(); + if (s.equalsIgnoreCase("None")) return Bind.none(); + if (s.toLowerCase().startsWith("mouse ")) { + try { + return new Bind(-Integer.parseInt(s.substring(6)) - 1); + } catch (Exception e) { + } } int key = -1; try { key = InputConstants.getKey(s.toUpperCase()).getValue(); - } catch (Exception exception) { - // empty catch block - } - if (key == 0) { - return Bind.none(); + } catch (Exception e) { } + if (key == 0) return Bind.none(); return new Bind(key); } } diff --git a/src/main/java/me/alpha432/oyvey/manager/EventManager.java b/src/main/java/me/alpha432/oyvey/manager/EventManager.java index c36fb85..7c11b44 100644 --- a/src/main/java/me/alpha432/oyvey/manager/EventManager.java +++ b/src/main/java/me/alpha432/oyvey/manager/EventManager.java @@ -6,6 +6,7 @@ import me.alpha432.oyvey.event.impl.entity.DeathEvent; import me.alpha432.oyvey.event.impl.entity.player.TickEvent; import me.alpha432.oyvey.event.impl.entity.player.UpdateWalkingPlayerEvent; import me.alpha432.oyvey.event.impl.input.KeyInputEvent; +import me.alpha432.oyvey.event.impl.input.MouseInputEvent; import me.alpha432.oyvey.event.impl.network.ChatEvent; import me.alpha432.oyvey.event.impl.network.PacketEvent; import me.alpha432.oyvey.event.impl.render.Render2DEvent; @@ -80,6 +81,13 @@ public class EventManager extends Feature { OyVey.moduleManager.onKeyPressed(event.getKey()); } + @Subscribe + public void onMouseInput(MouseInputEvent event) { + if (event.getAction() == 1) { + OyVey.moduleManager.onMouseClicked(event.getButton()); + } + } + @Subscribe public void onChatSent(ChatEvent event) { String message = event.getMessage(); diff --git a/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java b/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java index 01c5811..66a5949 100644 --- a/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java +++ b/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java @@ -122,6 +122,12 @@ public class ModuleManager implements Jsonable, Util { stream().filter(module -> module.getBind().getKey() == key).forEach(Module::toggle); } + public void onMouseClicked(int button) { + if (mc.screen != null) return; + int key = -button - 2; + stream().filter(module -> module.getBind().getKey() == key).forEach(Module::toggle); + } + @Override public JsonElement toJson() { JsonObject object = new JsonObject();