From a8eddc718a8b32d9dc62622b04086546d7bdb460 Mon Sep 17 00:00:00 2001 From: Colton Date: Thu, 27 Jun 2024 20:50:13 -0400 Subject: [PATCH] Replaced mouse click events, fixed trajectories module, added Barrels to ChestESP Mouse click events are now handled by a single event containing information about the click (Left or right, button up or down, etc...) Fixed Trajectories module. Added barrels to the ChestESP module. --- .../aoba/event/events/LeftMouseDownEvent.java | 58 --------- .../aoba/event/events/LeftMouseUpEvent.java | 58 --------- .../aoba/event/events/MouseClickEvent.java | 39 ++++++ .../event/events/RightMouseDownEvent.java | 59 --------- .../aoba/event/events/RightMouseUpEvent.java | 59 --------- .../listeners/LeftMouseDownListener.java | 25 ---- .../event/listeners/LeftMouseUpListener.java | 25 ---- .../event/listeners/MouseClickListener.java | 7 ++ .../listeners/RightMouseDownListener.java | 25 ---- .../event/listeners/RightMouseUpListener.java | 25 ---- src/main/java/net/aoba/gui/AbstractGui.java | 40 +++--- src/main/java/net/aoba/gui/GuiManager.java | 30 +++-- src/main/java/net/aoba/gui/NavigationBar.java | 44 ++++--- .../java/net/aoba/gui/tabs/ClickGuiTab.java | 55 ++++---- .../net/aoba/gui/tabs/ModuleSettingsTab.java | 38 +++--- .../gui/tabs/components/BlocksComponent.java | 67 +++++----- .../gui/tabs/components/ButtonComponent.java | 33 +++-- .../tabs/components/CheckboxComponent.java | 36 +++--- .../tabs/components/ColorPickerComponent.java | 63 +++++----- .../gui/tabs/components/HudComponent.java | 30 +++-- .../gui/tabs/components/KeybindComponent.java | 30 +++-- .../gui/tabs/components/ListComponent.java | 42 ++++--- .../gui/tabs/components/ModuleComponent.java | 57 +++++---- .../gui/tabs/components/SliderComponent.java | 36 +++--- .../aoba/mixin/ClientPlayerEntityMixin.java | 4 + src/main/java/net/aoba/mixin/MouseMixin.java | 49 +++----- .../java/net/aoba/module/ModuleManager.java | 3 - .../aoba/module/modules/movement/ClickTP.java | 63 +++++----- .../aoba/module/modules/movement/Noclip.java | 55 +++++--- .../aoba/module/modules/render/ChestESP.java | 3 +- .../aoba/module/modules/render/Tracer.java | 1 + .../module/modules/render/Trajectory.java | 119 +++++++++++++----- .../net/aoba/utils/types/MouseAction.java | 5 + .../net/aoba/utils/types/MouseButton.java | 5 + 34 files changed, 564 insertions(+), 724 deletions(-) delete mode 100644 src/main/java/net/aoba/event/events/LeftMouseDownEvent.java delete mode 100644 src/main/java/net/aoba/event/events/LeftMouseUpEvent.java create mode 100644 src/main/java/net/aoba/event/events/MouseClickEvent.java delete mode 100644 src/main/java/net/aoba/event/events/RightMouseDownEvent.java delete mode 100644 src/main/java/net/aoba/event/events/RightMouseUpEvent.java delete mode 100644 src/main/java/net/aoba/event/listeners/LeftMouseDownListener.java delete mode 100644 src/main/java/net/aoba/event/listeners/LeftMouseUpListener.java create mode 100644 src/main/java/net/aoba/event/listeners/MouseClickListener.java delete mode 100644 src/main/java/net/aoba/event/listeners/RightMouseDownListener.java delete mode 100644 src/main/java/net/aoba/event/listeners/RightMouseUpListener.java create mode 100644 src/main/java/net/aoba/utils/types/MouseAction.java create mode 100644 src/main/java/net/aoba/utils/types/MouseButton.java diff --git a/src/main/java/net/aoba/event/events/LeftMouseDownEvent.java b/src/main/java/net/aoba/event/events/LeftMouseDownEvent.java deleted file mode 100644 index bab0bb3..0000000 --- a/src/main/java/net/aoba/event/events/LeftMouseDownEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.events; - -import java.util.ArrayList; -import java.util.List; -import net.aoba.event.listeners.AbstractListener; -import net.aoba.event.listeners.LeftMouseDownListener; - -public class LeftMouseDownEvent extends AbstractEvent{ - - double mouseX; - double mouseY; - - public LeftMouseDownEvent(double mouseX2, double mouseY2) { - super(); - this.mouseX = mouseX2; - this.mouseY = mouseY2; - } - - public double GetMouseX() { - return mouseX; - } - - public double GetMouseY() { - return mouseY; - } - - @Override - public void Fire(ArrayList listeners) { - for(AbstractListener listener : List.copyOf(listeners)) { - LeftMouseDownListener mouseLeftClickListener = (LeftMouseDownListener) listener; - mouseLeftClickListener.OnLeftMouseDown(this); - } - } - - @SuppressWarnings("unchecked") - @Override - public Class GetListenerClassType() { - return LeftMouseDownListener.class; - } -} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/events/LeftMouseUpEvent.java b/src/main/java/net/aoba/event/events/LeftMouseUpEvent.java deleted file mode 100644 index 54a3a52..0000000 --- a/src/main/java/net/aoba/event/events/LeftMouseUpEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.events; - -import java.util.ArrayList; -import java.util.List; -import net.aoba.event.listeners.AbstractListener; -import net.aoba.event.listeners.LeftMouseUpListener; - -public class LeftMouseUpEvent extends AbstractEvent{ - - double mouseX; - double mouseY; - - public LeftMouseUpEvent(double mouseX2, double mouseY2) { - super(); - this.mouseX = mouseX2; - this.mouseY = mouseY2; - } - - public double GetMouseX() { - return mouseX; - } - - public double GetMouseY() { - return mouseY; - } - - @Override - public void Fire(ArrayList listeners) { - for(AbstractListener listener : List.copyOf(listeners)) { - LeftMouseUpListener mouseLeftClickListener = (LeftMouseUpListener) listener; - mouseLeftClickListener.OnLeftMouseUp(this); - } - } - - @SuppressWarnings("unchecked") - @Override - public Class GetListenerClassType() { - return LeftMouseUpListener.class; - } -} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/events/MouseClickEvent.java b/src/main/java/net/aoba/event/events/MouseClickEvent.java new file mode 100644 index 0000000..43fbba0 --- /dev/null +++ b/src/main/java/net/aoba/event/events/MouseClickEvent.java @@ -0,0 +1,39 @@ +package net.aoba.event.events; + +import java.util.ArrayList; +import java.util.List; +import net.aoba.event.listeners.AbstractListener; +import net.aoba.event.listeners.MouseClickListener; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; + +public class MouseClickEvent extends AbstractEvent{ + + public final double mouseX; + public final double mouseY; + public final MouseButton button; + public final MouseAction action; + + public MouseClickEvent(double mouseX, double mouseY, MouseButton button, MouseAction action) { + super(); + this.mouseX = mouseX; + this.mouseY = mouseY; + this.button = button; + this.action = action; + } + + + @Override + public void Fire(ArrayList listeners) { + for(AbstractListener listener : List.copyOf(listeners)) { + MouseClickListener mouseClickListener = (MouseClickListener) listener; + mouseClickListener.OnMouseClick(this); + } + } + + @SuppressWarnings("unchecked") + @Override + public Class GetListenerClassType() { + return MouseClickListener.class; + } +} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/events/RightMouseDownEvent.java b/src/main/java/net/aoba/event/events/RightMouseDownEvent.java deleted file mode 100644 index c27ac83..0000000 --- a/src/main/java/net/aoba/event/events/RightMouseDownEvent.java +++ /dev/null @@ -1,59 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.events; - -import java.util.ArrayList; -import java.util.List; -import net.aoba.event.listeners.AbstractListener; -import net.aoba.event.listeners.LeftMouseDownListener; -import net.aoba.event.listeners.RightMouseDownListener; - -public class RightMouseDownEvent extends AbstractEvent{ - - double mouseX; - double mouseY; - - public RightMouseDownEvent(double mouseX2, double mouseY2) { - super(); - this.mouseX = mouseX2; - this.mouseY = mouseY2; - } - - public double GetMouseX() { - return mouseX; - } - - public double GetMouseY() { - return mouseY; - } - - @Override - public void Fire(ArrayList listeners) { - for(AbstractListener listener : List.copyOf(listeners)) { - RightMouseDownListener mouseRightClickListener = (RightMouseDownListener) listener; - mouseRightClickListener.OnRightMouseDown(this); - } - } - - @SuppressWarnings("unchecked") - @Override - public Class GetListenerClassType() { - return RightMouseDownListener.class; - } -} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/events/RightMouseUpEvent.java b/src/main/java/net/aoba/event/events/RightMouseUpEvent.java deleted file mode 100644 index a187f5f..0000000 --- a/src/main/java/net/aoba/event/events/RightMouseUpEvent.java +++ /dev/null @@ -1,59 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.events; - -import java.util.ArrayList; -import java.util.List; -import net.aoba.event.listeners.AbstractListener; -import net.aoba.event.listeners.LeftMouseUpListener; -import net.aoba.event.listeners.RightMouseUpListener; - -public class RightMouseUpEvent extends AbstractEvent{ - - double mouseX; - double mouseY; - - public RightMouseUpEvent(double mouseX2, double mouseY2) { - super(); - this.mouseX = mouseX2; - this.mouseY = mouseY2; - } - - public double GetMouseX() { - return mouseX; - } - - public double GetMouseY() { - return mouseY; - } - - @Override - public void Fire(ArrayList listeners) { - for(AbstractListener listener : List.copyOf(listeners)) { - RightMouseUpListener mouseRightClickListener = (RightMouseUpListener) listener; - mouseRightClickListener.OnRightMouseUp(this); - } - } - - @SuppressWarnings("unchecked") - @Override - public Class GetListenerClassType() { - return RightMouseUpListener.class; - } -} \ No newline at end of file diff --git a/src/main/java/net/aoba/event/listeners/LeftMouseDownListener.java b/src/main/java/net/aoba/event/listeners/LeftMouseDownListener.java deleted file mode 100644 index 03b1d94..0000000 --- a/src/main/java/net/aoba/event/listeners/LeftMouseDownListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.listeners; - -import net.aoba.event.events.LeftMouseDownEvent; - -public interface LeftMouseDownListener extends AbstractListener { - public abstract void OnLeftMouseDown(LeftMouseDownEvent event); -} diff --git a/src/main/java/net/aoba/event/listeners/LeftMouseUpListener.java b/src/main/java/net/aoba/event/listeners/LeftMouseUpListener.java deleted file mode 100644 index 24a668d..0000000 --- a/src/main/java/net/aoba/event/listeners/LeftMouseUpListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.listeners; - -import net.aoba.event.events.LeftMouseUpEvent; - -public interface LeftMouseUpListener extends AbstractListener { - public abstract void OnLeftMouseUp(LeftMouseUpEvent event); -} diff --git a/src/main/java/net/aoba/event/listeners/MouseClickListener.java b/src/main/java/net/aoba/event/listeners/MouseClickListener.java new file mode 100644 index 0000000..e6526e1 --- /dev/null +++ b/src/main/java/net/aoba/event/listeners/MouseClickListener.java @@ -0,0 +1,7 @@ +package net.aoba.event.listeners; + +import net.aoba.event.events.MouseClickEvent; + +public interface MouseClickListener extends AbstractListener { + public abstract void OnMouseClick(MouseClickEvent mouseClickEvent); +} diff --git a/src/main/java/net/aoba/event/listeners/RightMouseDownListener.java b/src/main/java/net/aoba/event/listeners/RightMouseDownListener.java deleted file mode 100644 index 19aab81..0000000 --- a/src/main/java/net/aoba/event/listeners/RightMouseDownListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.listeners; - -import net.aoba.event.events.RightMouseDownEvent; - -public interface RightMouseDownListener extends AbstractListener { - public abstract void OnRightMouseDown(RightMouseDownEvent event); -} diff --git a/src/main/java/net/aoba/event/listeners/RightMouseUpListener.java b/src/main/java/net/aoba/event/listeners/RightMouseUpListener.java deleted file mode 100644 index 8fefe03..0000000 --- a/src/main/java/net/aoba/event/listeners/RightMouseUpListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/* -* Aoba Hacked Client -* Copyright (C) 2019-2024 coltonk9043 -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*/ - -package net.aoba.event.listeners; - -import net.aoba.event.events.RightMouseUpEvent; - -public interface RightMouseUpListener extends AbstractListener { - public abstract void OnRightMouseUp(RightMouseUpEvent event); -} diff --git a/src/main/java/net/aoba/gui/AbstractGui.java b/src/main/java/net/aoba/gui/AbstractGui.java index b731837..88edf7c 100644 --- a/src/main/java/net/aoba/gui/AbstractGui.java +++ b/src/main/java/net/aoba/gui/AbstractGui.java @@ -20,18 +20,20 @@ import java.util.ArrayList; import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; +import net.aoba.event.events.MouseClickEvent; import net.aoba.event.events.MouseMoveEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.event.listeners.MouseMoveListener; import net.aoba.gui.tabs.components.Component; import net.aoba.settings.SettingManager; import net.aoba.settings.types.Vector2Setting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.aoba.utils.types.Vector2; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; -public abstract class AbstractGui implements IGuiElement, LeftMouseDownListener, MouseMoveListener { +public abstract class AbstractGui implements IGuiElement, MouseClickListener, MouseMoveListener { protected static MinecraftClient mc = MinecraftClient.getInstance(); protected String ID; @@ -145,10 +147,10 @@ public void setVisible(boolean state) { // Binds/Unbinds respective listeners depending on whether it is visible. if(state) { - Aoba.instance.eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.instance.eventManager.AddListener(MouseClickListener.class, this); Aoba.instance.eventManager.AddListener(MouseMoveListener.class, this); }else { - Aoba.instance.eventManager.RemoveListener(LeftMouseDownListener.class, this); + Aoba.instance.eventManager.RemoveListener(MouseClickListener.class, this); Aoba.instance.eventManager.RemoveListener(MouseMoveListener.class, this); } } @@ -166,19 +168,21 @@ public void setAlwaysVisible(boolean state) { public abstract void draw(DrawContext drawContext, float partialTicks); @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - double mouseX = event.GetMouseX(); - double mouseY = event.GetMouseY(); - - Vector2 pos = position.getValue(); - - if (Aoba.getInstance().hudManager.isClickGuiOpen()) { - if (GuiManager.currentGrabbed == null) { - if (mouseX >= pos.x && mouseX <= (pos.x + width)) { - if (mouseY >= pos.y && mouseY <= (pos.y + height)) { - GuiManager.currentGrabbed = this; - this.lastClickOffsetX = mouseX - pos.x; - this.lastClickOffsetY = mouseY - pos.y; + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + double mouseX = event.mouseX; + double mouseY = event.mouseY; + + Vector2 pos = position.getValue(); + + if (Aoba.getInstance().hudManager.isClickGuiOpen()) { + if (GuiManager.currentGrabbed == null) { + if (mouseX >= pos.x && mouseX <= (pos.x + width)) { + if (mouseY >= pos.y && mouseY <= (pos.y + height)) { + GuiManager.currentGrabbed = this; + this.lastClickOffsetX = mouseX - pos.x; + this.lastClickOffsetY = mouseY - pos.y; + } } } } diff --git a/src/main/java/net/aoba/gui/GuiManager.java b/src/main/java/net/aoba/gui/GuiManager.java index 2395435..a263f0f 100644 --- a/src/main/java/net/aoba/gui/GuiManager.java +++ b/src/main/java/net/aoba/gui/GuiManager.java @@ -20,11 +20,9 @@ import java.util.HashMap; import net.aoba.event.events.KeyDownEvent; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.events.LeftMouseUpEvent; +import net.aoba.event.events.MouseClickEvent; import net.aoba.event.events.TickEvent; -import net.aoba.event.listeners.LeftMouseDownListener; -import net.aoba.event.listeners.LeftMouseUpListener; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.event.listeners.TickListener; import net.aoba.event.listeners.KeyDownListener; import org.joml.Matrix4f; @@ -51,6 +49,8 @@ import net.aoba.settings.types.ColorSetting; import net.aoba.settings.types.FloatSetting; import net.aoba.settings.types.KeybindSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.option.KeyBinding; @@ -58,7 +58,7 @@ import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; -public class GuiManager implements LeftMouseDownListener, LeftMouseUpListener, KeyDownListener, TickListener { +public class GuiManager implements MouseClickListener, KeyDownListener, TickListener { protected MinecraftClient mc = MinecraftClient.getInstance(); public KeybindSetting clickGuiButton = new KeybindSetting("key.clickgui", "ClickGUI Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_GRAVE_ACCENT, 0)); @@ -147,9 +147,8 @@ public void Initialize() { SettingManager.registerSetting(rainbow, Aoba.getInstance().settingManager.configContainer); SettingManager.registerSetting(ah, Aoba.getInstance().settingManager.configContainer); - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); - Aoba.getInstance().eventManager.AddListener(LeftMouseUpListener.class, this); - + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); + clickGuiNavBar.setSelectedIndex(0); } @@ -292,14 +291,13 @@ public void toggleMouse() { } @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - if (this.clickGuiOpen) { - event.cancel(); + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT) { + if(event.action == MouseAction.DOWN && this.clickGuiOpen) { + event.cancel(); + }else if(event.action == MouseAction.UP) { + currentGrabbed = null; + } } } - - @Override - public void OnLeftMouseUp(LeftMouseUpEvent event) { - currentGrabbed = null; - } } diff --git a/src/main/java/net/aoba/gui/NavigationBar.java b/src/main/java/net/aoba/gui/NavigationBar.java index aee279f..50515a3 100644 --- a/src/main/java/net/aoba/gui/NavigationBar.java +++ b/src/main/java/net/aoba/gui/NavigationBar.java @@ -23,16 +23,18 @@ import org.joml.Matrix4f; import net.aoba.Aoba; import net.aoba.AobaClient; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.gui.colors.Color; import net.aoba.misc.RenderUtils; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; -public class NavigationBar implements LeftMouseDownListener { +public class NavigationBar implements MouseClickListener { MinecraftClient mc = MinecraftClient.getInstance(); private List options; @@ -40,7 +42,7 @@ public class NavigationBar implements LeftMouseDownListener { public NavigationBar() { options = new ArrayList(); - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); } public void addPane(Page pane) { @@ -97,22 +99,24 @@ public void draw(DrawContext drawContext, float partialTicks) { } @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - AobaClient aoba = Aoba.getInstance(); - Window window = mc.getWindow(); - - double mouseX = event.GetMouseX(); - double mouseY = event.GetMouseY(); - int width = 100 * options.size(); - int centerX = (window.getWidth() / 2); - int x = centerX - (width / 2); - - if (aoba.hudManager.isClickGuiOpen() && GuiManager.currentGrabbed == null) { - if (mouseX >= (x) && mouseX <= (x + width)) { - if (mouseY >= (25) && mouseY <= (50)) { - int mouseXInt = (int) mouseX; - int selection = (mouseXInt - x) / 100; - this.setSelectedIndex(selection); + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + AobaClient aoba = Aoba.getInstance(); + Window window = mc.getWindow(); + + double mouseX = event.mouseX; + double mouseY = event.mouseY; + int width = 100 * options.size(); + int centerX = (window.getWidth() / 2); + int x = centerX - (width / 2); + + if (aoba.hudManager.isClickGuiOpen() && GuiManager.currentGrabbed == null) { + if (mouseX >= (x) && mouseX <= (x + width)) { + if (mouseY >= (25) && mouseY <= (50)) { + int mouseXInt = (int) mouseX; + int selection = (mouseXInt - x) / 100; + this.setSelectedIndex(selection); + } } } } diff --git a/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java b/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java index 6ee05d1..b6427c0 100644 --- a/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java +++ b/src/main/java/net/aoba/gui/tabs/ClickGuiTab.java @@ -23,10 +23,9 @@ package net.aoba.gui.tabs; import org.joml.Matrix4f; - import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.event.listeners.MouseMoveListener; import net.aoba.gui.AbstractGui; import net.aoba.gui.GuiManager; @@ -35,12 +34,14 @@ import net.aoba.misc.RenderUtils; import net.aoba.settings.SettingManager; import net.aoba.settings.types.BooleanSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.aoba.utils.types.Vector2; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; -public class ClickGuiTab extends AbstractGui implements LeftMouseDownListener, MouseMoveListener { +public class ClickGuiTab extends AbstractGui implements MouseClickListener, MouseMoveListener { protected String title; protected boolean pinnable = true; @@ -152,31 +153,33 @@ public void draw(DrawContext drawContext, float partialTicks) { child.draw(drawContext, partialTicks); } } - + @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - double mouseX = mc.mouse.getX(); - double mouseY = mc.mouse.getY(); - Vector2 pos = position.getValue(); - - if (Aoba.getInstance().hudManager.isClickGuiOpen()) { - // Allow the user to move the clickgui if it within the header bar and NOT pinned. - if(!isPinned.getValue()) { - if(mouseX >= pos.x && mouseX <= pos.x + width) { - if(mouseY >= pos.y && mouseY <= pos.y + 24) { - lastClickOffsetX = mouseX - pos.x; - lastClickOffsetY = mouseY - pos.y; - GuiManager.currentGrabbed = this; + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + double mouseX = mc.mouse.getX(); + double mouseY = mc.mouse.getY(); + Vector2 pos = position.getValue(); + + if (Aoba.getInstance().hudManager.isClickGuiOpen()) { + // Allow the user to move the clickgui if it within the header bar and NOT pinned. + if(!isPinned.getValue()) { + if(mouseX >= pos.x && mouseX <= pos.x + width) { + if(mouseY >= pos.y && mouseY <= pos.y + 24) { + lastClickOffsetX = mouseX - pos.x; + lastClickOffsetY = mouseY - pos.y; + GuiManager.currentGrabbed = this; + } } } - } - - // If the GUI is pinnable, allow the user to click the pin button to pin a gui - if (pinnable) { - if (mouseX >= (pos.x + width - 24) && mouseX <= (pos.x + width - 2)) { - if (mouseY >= (pos.y + 4) && mouseY <= (pos.y + 20)) { - GuiManager.currentGrabbed = null; - isPinned.silentSetValue(!isPinned.getValue()); + + // If the GUI is pinnable, allow the user to click the pin button to pin a gui + if (pinnable) { + if (mouseX >= (pos.x + width - 24) && mouseX <= (pos.x + width - 2)) { + if (mouseY >= (pos.y + 4) && mouseY <= (pos.y + 20)) { + GuiManager.currentGrabbed = null; + isPinned.silentSetValue(!isPinned.getValue()); + } } } } diff --git a/src/main/java/net/aoba/gui/tabs/ModuleSettingsTab.java b/src/main/java/net/aoba/gui/tabs/ModuleSettingsTab.java index 379e2c6..9b5cb5c 100644 --- a/src/main/java/net/aoba/gui/tabs/ModuleSettingsTab.java +++ b/src/main/java/net/aoba/gui/tabs/ModuleSettingsTab.java @@ -20,7 +20,7 @@ import org.joml.Matrix4f; import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; +import net.aoba.event.events.MouseClickEvent; import net.aoba.gui.AbstractGui; import net.aoba.gui.GuiManager; import net.aoba.gui.colors.Color; @@ -40,6 +40,8 @@ import net.aoba.settings.types.BooleanSetting; import net.aoba.settings.types.ColorSetting; import net.aoba.settings.types.FloatSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.aoba.utils.types.Vector2; public class ModuleSettingsTab extends AbstractGui { @@ -142,24 +144,26 @@ public void draw(DrawContext drawContext, float partialTicks) { } @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - double mouseX = mc.mouse.getX(); - double mouseY = mc.mouse.getY(); - Vector2 pos = position.getValue(); - - if (Aoba.getInstance().hudManager.isClickGuiOpen()) { - if (mouseX >= pos.x && mouseX <= pos.x + width) { - if (mouseY >= pos.y && mouseY <= pos.y + 24) { - this.lastClickOffsetX = mouseX - pos.x; - this.lastClickOffsetY = mouseY - pos.y; - GuiManager.currentGrabbed = this; + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + double mouseX = mc.mouse.getX(); + double mouseY = mc.mouse.getY(); + Vector2 pos = position.getValue(); + + if (Aoba.getInstance().hudManager.isClickGuiOpen()) { + if (mouseX >= pos.x && mouseX <= pos.x + width) { + if (mouseY >= pos.y && mouseY <= pos.y + 24) { + this.lastClickOffsetX = mouseX - pos.x; + this.lastClickOffsetY = mouseY - pos.y; + GuiManager.currentGrabbed = this; + } } - } - if (mouseX >= (pos.x + width - 24) && mouseX <= (pos.x + width - 2)) { - if (mouseY >= (pos.y + 4) && mouseY <= (pos.y + 20)) { - GuiManager.currentGrabbed = null; - Aoba.getInstance().hudManager.RemoveHud(this, "Modules"); + if (mouseX >= (pos.x + width - 24) && mouseX <= (pos.x + width - 2)) { + if (mouseY >= (pos.y + 4) && mouseY <= (pos.y + 20)) { + GuiManager.currentGrabbed = null; + Aoba.getInstance().hudManager.RemoveHud(this, "Modules"); + } } } } diff --git a/src/main/java/net/aoba/gui/tabs/components/BlocksComponent.java b/src/main/java/net/aoba/gui/tabs/components/BlocksComponent.java index 525236b..594836b 100644 --- a/src/main/java/net/aoba/gui/tabs/components/BlocksComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/BlocksComponent.java @@ -19,24 +19,25 @@ package net.aoba.gui.tabs.components; import org.joml.Matrix4f; - import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; +import net.aoba.event.events.MouseClickEvent; import net.aoba.event.events.MouseScrollEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.event.listeners.MouseScrollListener; import net.aoba.gui.GuiManager; import net.aoba.gui.IGuiElement; import net.aoba.gui.colors.Color; import net.aoba.misc.RenderUtils; import net.aoba.settings.types.BlocksSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.block.Block; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; -public class BlocksComponent extends Component implements MouseScrollListener, LeftMouseDownListener { +public class BlocksComponent extends Component implements MouseScrollListener, MouseClickListener { private BlocksSetting blocks; private String text; @@ -119,40 +120,42 @@ public void OnMouseScroll(MouseScrollEvent event) { public void OnVisibilityChanged() { if(this.isVisible()) { Aoba.getInstance().eventManager.AddListener(MouseScrollListener.class, this); - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); }else { Aoba.getInstance().eventManager.RemoveListener(MouseScrollListener.class, this); - Aoba.getInstance().eventManager.RemoveListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); } } @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - double mouseX = event.GetMouseX(); - double mouseY = event.GetMouseY(); - - if(mouseX > (actualX + 4) && mouseY < (actualX + (36 * visibleColumns) + 4)) { - if(mouseY > actualY && mouseY < actualY + 25) { - collapsed = !collapsed; - if(collapsed) - this.setHeight(collapsedHeight); - else - this.setHeight(expandedHeight); - }else if(mouseY > (actualY + 25) && mouseY < (actualY + (36 * visibleRows) + 25)) { - int col = (int) (mouseX - actualX - 8) / 36; - int row = (int) ((mouseY - actualY - 24) / 36) + scroll; - - int index = (row * visibleColumns) + col; - if(index > Registries.BLOCK.size()) - return; - - Block block = Registries.BLOCK.get(index); - if(this.blocks.getValue().contains(block)) { - this.blocks.getValue().remove(block); - this.blocks.update(); - }else { - this.blocks.getValue().add(block); - this.blocks.update(); + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + double mouseX = event.mouseX; + double mouseY = event.mouseY; + + if(mouseX > (actualX + 4) && mouseY < (actualX + (36 * visibleColumns) + 4)) { + if(mouseY > actualY && mouseY < actualY + 25) { + collapsed = !collapsed; + if(collapsed) + this.setHeight(collapsedHeight); + else + this.setHeight(expandedHeight); + }else if(mouseY > (actualY + 25) && mouseY < (actualY + (36 * visibleRows) + 25)) { + int col = (int) (mouseX - actualX - 8) / 36; + int row = (int) ((mouseY - actualY - 24) / 36) + scroll; + + int index = (row * visibleColumns) + col; + if(index > Registries.BLOCK.size()) + return; + + Block block = Registries.BLOCK.get(index); + if(this.blocks.getValue().contains(block)) { + this.blocks.getValue().remove(block); + this.blocks.update(); + }else { + this.blocks.getValue().add(block); + this.blocks.update(); + } } } } diff --git a/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java b/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java index 67a4d9f..a43f5b6 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ButtonComponent.java @@ -19,17 +19,18 @@ package net.aoba.gui.tabs.components; import org.joml.Matrix4f; - import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.gui.IGuiElement; import net.aoba.gui.colors.Color; import net.aoba.misc.RenderUtils; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class ButtonComponent extends Component implements LeftMouseDownListener { +public class ButtonComponent extends Component implements MouseClickListener { private String text; private Runnable onClick; @@ -113,23 +114,21 @@ public void draw(DrawContext drawContext, float partialTicks) { RenderUtils.drawString(drawContext, this.text, actualX + 8, actualY + 8, 0xFFFFFF); } - /** - * Triggered when the user clicks the Left Mouse Button (LMB) - * @param event Event fired. - */ - @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - if(this.hovered && this.isVisible() && onClick != null) { - this.onClick.run(); - } - } - @Override public void OnVisibilityChanged() { if(this.isVisible()) { - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); }else { - Aoba.getInstance().eventManager.RemoveListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); + } + } + + @Override + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + if(this.hovered && this.isVisible() && onClick != null) { + this.onClick.run(); + } } } } diff --git a/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java b/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java index 35e294d..416116e 100644 --- a/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/CheckboxComponent.java @@ -20,16 +20,18 @@ import org.joml.Matrix4f; import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.gui.IGuiElement; import net.aoba.gui.colors.Color; import net.aoba.misc.RenderUtils; import net.aoba.settings.types.BooleanSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class CheckboxComponent extends Component implements LeftMouseDownListener { +public class CheckboxComponent extends Component implements MouseClickListener { private String text; private BooleanSetting checkbox; private Runnable onClick; @@ -42,8 +44,6 @@ public CheckboxComponent(IGuiElement parent, BooleanSetting checkbox) { this.setLeft(2); this.setRight(2); this.setHeight(30); - - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); } /** @@ -78,18 +78,24 @@ public void draw(DrawContext drawContext, float partialTicks) { public void update() { super.update(); } + + @Override + public void OnVisibilityChanged() { + if(this.isVisible()) { + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); + }else { + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); + } + } - /** - * Triggered when the user clicks the Left Mouse Button (LMB) - * - * @param event Event fired. - */ @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { - checkbox.toggle(); - if(onClick != null) { - onClick.run(); + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { + checkbox.toggle(); + if(onClick != null) { + onClick.run(); + } } } } diff --git a/src/main/java/net/aoba/gui/tabs/components/ColorPickerComponent.java b/src/main/java/net/aoba/gui/tabs/components/ColorPickerComponent.java index b356a4c..6040d3f 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ColorPickerComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ColorPickerComponent.java @@ -19,24 +19,23 @@ package net.aoba.gui.tabs.components; import org.joml.Matrix4f; - import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.events.LeftMouseUpEvent; +import net.aoba.event.events.MouseClickEvent; import net.aoba.event.events.MouseMoveEvent; -import net.aoba.event.listeners.LeftMouseDownListener; -import net.aoba.event.listeners.LeftMouseUpListener; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.event.listeners.MouseMoveListener; import net.aoba.gui.GuiManager; import net.aoba.gui.IGuiElement; import net.aoba.gui.colors.Color; import net.aoba.misc.RenderUtils; import net.aoba.settings.types.ColorSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class ColorPickerComponent extends Component implements LeftMouseDownListener, LeftMouseUpListener, MouseMoveListener { +public class ColorPickerComponent extends Component implements MouseClickListener, MouseMoveListener { private String text; private boolean isSliding = false; @@ -55,9 +54,6 @@ public ColorPickerComponent(String text, IGuiElement parent) { this.setHeight(145); this.setLeft(4); this.setRight(4); - - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); - Aoba.getInstance().eventManager.AddListener(LeftMouseUpListener.class, this); } public ColorPickerComponent(IGuiElement parent, ColorSetting color) { @@ -74,9 +70,6 @@ public ColorPickerComponent(IGuiElement parent, ColorSetting color) { this.setHeight(30); this.setLeft(4); this.setRight(4); - - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); - Aoba.getInstance().eventManager.AddListener(LeftMouseUpListener.class, this); } public void ensureGuiUpdated(Color newColor) { @@ -95,28 +88,29 @@ public String getText() { } @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - double mouseY = event.GetMouseY(); - - if(hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { - if(mouseY < actualY + 29) { - collapsed = !collapsed; - if(collapsed) - this.setHeight(30); - else - this.setHeight(145); - }else { - if(!collapsed) - isSliding = true; + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT) { + if(event.action == MouseAction.DOWN) { + double mouseY = event.mouseY; + + if(hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { + if(mouseY < actualY + 29) { + collapsed = !collapsed; + if(collapsed) + this.setHeight(30); + else + this.setHeight(145); + }else { + if(!collapsed) + isSliding = true; + } + } + }else if(event.action == MouseAction.UP) { + isSliding = false; } } } - @Override - public void OnLeftMouseUp(LeftMouseUpEvent event) { - isSliding = false; - } - @Override public void OnMouseMove(MouseMoveEvent event) { super.OnMouseMove(event); @@ -145,6 +139,15 @@ public void OnMouseMove(MouseMoveEvent event) { } + @Override + public void OnVisibilityChanged() { + if(this.isVisible()) { + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); + }else { + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); + } + } + @Override public void update() { super.update(); diff --git a/src/main/java/net/aoba/gui/tabs/components/HudComponent.java b/src/main/java/net/aoba/gui/tabs/components/HudComponent.java index 13ecedc..80ce8f4 100644 --- a/src/main/java/net/aoba/gui/tabs/components/HudComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/HudComponent.java @@ -19,14 +19,16 @@ package net.aoba.gui.tabs.components; import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.gui.IGuiElement; import net.aoba.gui.hud.AbstractHud; import net.aoba.misc.RenderUtils; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.gui.DrawContext; -public class HudComponent extends Component implements LeftMouseDownListener { +public class HudComponent extends Component implements MouseClickListener { private String text; private AbstractHud hud; @@ -54,20 +56,22 @@ public void draw(DrawContext drawContext, float partialTicks) { } } - @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - if(this.hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { - boolean visibility = hud.activated.getValue(); - Aoba.getInstance().hudManager.SetHudActive(hud, !visibility); - } - } - @Override public void OnVisibilityChanged() { if(this.isVisible()) { - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); }else { - Aoba.getInstance().eventManager.RemoveListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); + } + } + + @Override + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + if(this.hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { + boolean visibility = hud.activated.getValue(); + Aoba.getInstance().hudManager.SetHudActive(hud, !visibility); + } } } } \ No newline at end of file diff --git a/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java b/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java index 1d601d8..de62f60 100644 --- a/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/KeybindComponent.java @@ -20,21 +20,22 @@ import org.joml.Matrix4f; import org.lwjgl.glfw.GLFW; - import net.aoba.Aoba; import net.aoba.event.events.KeyDownEvent; -import net.aoba.event.events.LeftMouseDownEvent; +import net.aoba.event.events.MouseClickEvent; import net.aoba.event.listeners.KeyDownListener; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.gui.IGuiElement; import net.aoba.gui.colors.Color; import net.aoba.misc.RenderUtils; import net.aoba.settings.types.KeybindSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.math.MatrixStack; -public class KeybindComponent extends Component implements LeftMouseDownListener, KeyDownListener { +public class KeybindComponent extends Component implements MouseClickListener, KeyDownListener { private boolean listeningForKey; private KeybindSetting keyBind; @@ -42,9 +43,18 @@ public KeybindComponent(IGuiElement parent, KeybindSetting keyBind) { super(parent); this.keyBind = keyBind; - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); Aoba.getInstance().eventManager.AddListener(KeyDownListener.class, this); } + + @Override + public void OnVisibilityChanged() { + if(this.isVisible()) { + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); + }else { + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); + } + } @Override public void update() { @@ -70,12 +80,14 @@ public void draw(DrawContext drawContext, float partialTicks) { } @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { - listeningForKey = !listeningForKey; + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { + listeningForKey = !listeningForKey; + } } } - + @Override public void OnKeyDown(KeyDownEvent event) { if(listeningForKey) { diff --git a/src/main/java/net/aoba/gui/tabs/components/ListComponent.java b/src/main/java/net/aoba/gui/tabs/components/ListComponent.java index 75f1047..92bf164 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ListComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ListComponent.java @@ -20,14 +20,16 @@ import java.util.List; import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.gui.IGuiElement; import net.aoba.misc.RenderUtils; import net.aoba.settings.types.StringSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.gui.DrawContext; -public class ListComponent extends Component implements LeftMouseDownListener { +public class ListComponent extends Component implements MouseClickListener { private StringSetting listSetting; private List options; @@ -38,7 +40,7 @@ public ListComponent(IGuiElement parent, List options) { this.setLeft(2); this.setRight(2); this.setHeight(30); - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); this.options = options; } @@ -51,7 +53,7 @@ public ListComponent(IGuiElement parent, List options, StringSetting lis this.setRight(2); this.setHeight(30); - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); this.options = options; } @@ -65,23 +67,25 @@ public void draw(DrawContext drawContext, float partialTicks) { RenderUtils.drawString(drawContext, ">>", actualX + 8 + (actualWidth - 34), actualY + 4, 0xFFFFFF); } + public void setSelectedIndex(int index) { + selectedIndex = index; + listSetting.setValue(options.get(selectedIndex)); + } + @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - double mouseX = event.GetMouseX(); + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + double mouseX = event.mouseX; - // Mouse is on the left - if(this.hovered) { - if (mouseX > actualX && mouseX < (actualX + 32)) { - setSelectedIndex(Math.max(--selectedIndex, 0)); - // Mouse is on the right - } else if (mouseX > (actualX + actualWidth - 32) && mouseX < (actualX + actualWidth)) { - setSelectedIndex(Math.min(++selectedIndex, options.size() - 1)); + // Mouse is on the left + if(this.hovered) { + if (mouseX > actualX && mouseX < (actualX + 32)) { + setSelectedIndex(Math.max(--selectedIndex, 0)); + // Mouse is on the right + } else if (mouseX > (actualX + actualWidth - 32) && mouseX < (actualX + actualWidth)) { + setSelectedIndex(Math.min(++selectedIndex, options.size() - 1)); + } } } } - - public void setSelectedIndex(int index) { - selectedIndex = index; - listSetting.setValue(options.get(selectedIndex)); - } } diff --git a/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java b/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java index 63abec4..0e5425f 100644 --- a/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/ModuleComponent.java @@ -19,11 +19,12 @@ package net.aoba.gui.tabs.components; import org.joml.Matrix4f; - import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.listeners.LeftMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.module.Module; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.aoba.gui.GuiManager; import net.aoba.gui.IGuiElement; import net.aoba.gui.colors.Color; @@ -33,7 +34,7 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; -public class ModuleComponent extends Component implements LeftMouseDownListener { +public class ModuleComponent extends Component implements MouseClickListener { private String text; private Module module; @@ -72,33 +73,35 @@ public void draw(DrawContext drawContext, float partialTicks) { } } - @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - double mouseX = event.GetMouseX(); - if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { - boolean isOnOptionsButton = (mouseX >= (actualX + actualWidth - 34) && mouseX <= (actualX + actualWidth)); - if (isOnOptionsButton) { - if(lastSettingsTab == null) { - lastSettingsTab = new ModuleSettingsTab(this.module.getName(), this.actualX + this.actualWidth + 1, this.actualY, this.module); - lastSettingsTab.setVisible(true); - Aoba.getInstance().hudManager.AddHud(lastSettingsTab, "Modules"); - }else { - Aoba.getInstance().hudManager.RemoveHud(lastSettingsTab, "Modules"); - lastSettingsTab = null; - } - } else { - module.toggle(); - return; - } - } - } - @Override public void OnVisibilityChanged() { if(this.isVisible()) { - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); }else { - Aoba.getInstance().eventManager.RemoveListener(LeftMouseDownListener.class, this); + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); + } + } + + @Override + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT && event.action == MouseAction.DOWN) { + double mouseX = event.mouseX; + if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { + boolean isOnOptionsButton = (mouseX >= (actualX + actualWidth - 34) && mouseX <= (actualX + actualWidth)); + if (isOnOptionsButton) { + if(lastSettingsTab == null) { + lastSettingsTab = new ModuleSettingsTab(this.module.getName(), this.actualX + this.actualWidth + 1, this.actualY, this.module); + lastSettingsTab.setVisible(true); + Aoba.getInstance().hudManager.AddHud(lastSettingsTab, "Modules"); + }else { + Aoba.getInstance().hudManager.RemoveHud(lastSettingsTab, "Modules"); + lastSettingsTab = null; + } + } else { + module.toggle(); + return; + } + } } } } diff --git a/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java b/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java index d842f63..f395c3b 100644 --- a/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java +++ b/src/main/java/net/aoba/gui/tabs/components/SliderComponent.java @@ -19,24 +19,23 @@ package net.aoba.gui.tabs.components; import org.joml.Matrix4f; - import net.aoba.Aoba; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.events.LeftMouseUpEvent; +import net.aoba.event.events.MouseClickEvent; import net.aoba.event.events.MouseMoveEvent; -import net.aoba.event.listeners.LeftMouseDownListener; -import net.aoba.event.listeners.LeftMouseUpListener; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.event.listeners.MouseMoveListener; import net.aoba.gui.GuiManager; import net.aoba.gui.IGuiElement; import net.aoba.gui.colors.Color; import net.aoba.misc.RenderUtils; import net.aoba.settings.types.FloatSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.util.math.MatrixStack; -public class SliderComponent extends Component implements LeftMouseDownListener, LeftMouseUpListener, MouseMoveListener { +public class SliderComponent extends Component implements MouseClickListener, MouseMoveListener { private String text; private float currentSliderPosition = 0.4f; @@ -57,8 +56,7 @@ public SliderComponent(String text, IGuiElement parent) { this.setLeft(4); this.setRight(4); - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); - Aoba.getInstance().eventManager.AddListener(LeftMouseUpListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); } public SliderComponent(IGuiElement parent, FloatSetting slider) { @@ -72,8 +70,7 @@ public SliderComponent(IGuiElement parent, FloatSetting slider) { this.setLeft(4); this.setRight(4); - Aoba.getInstance().eventManager.AddListener(LeftMouseDownListener.class, this); - Aoba.getInstance().eventManager.AddListener(LeftMouseUpListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); } public float getSliderPosition() { @@ -97,17 +94,18 @@ public void setColor(float r, float g, float b) { this.g = g; this.b = b; } - - @Override - public void OnLeftMouseDown(LeftMouseDownEvent event) { - if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { - isSliding = true; - } - } @Override - public void OnLeftMouseUp(LeftMouseUpEvent event) { - isSliding = false; + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.LEFT) { + if(event.action == MouseAction.DOWN) { + if (hovered && Aoba.getInstance().hudManager.isClickGuiOpen()) { + isSliding = true; + } + }else if(event.action == MouseAction.UP) { + isSliding = false; + } + } } @Override diff --git a/src/main/java/net/aoba/mixin/ClientPlayerEntityMixin.java b/src/main/java/net/aoba/mixin/ClientPlayerEntityMixin.java index 90b39e9..7758b65 100644 --- a/src/main/java/net/aoba/mixin/ClientPlayerEntityMixin.java +++ b/src/main/java/net/aoba/mixin/ClientPlayerEntityMixin.java @@ -32,6 +32,7 @@ import net.aoba.module.modules.movement.Fly; import net.aoba.module.modules.movement.Freecam; import net.aoba.module.modules.movement.HighJump; +import net.aoba.module.modules.movement.Noclip; import net.aoba.module.modules.movement.Step; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; @@ -79,6 +80,9 @@ protected void onGetOffGroundSpeed(CallbackInfoReturnable cir) { if(Aoba.getInstance().moduleManager.fly.getState()) { Fly fly = (Fly)Aoba.getInstance().moduleManager.fly; cir.setReturnValue((float)fly.getSpeed()); + }else if (Aoba.getInstance().moduleManager.noclip.getState()) { + Noclip noclip = (Noclip)Aoba.getInstance().moduleManager.noclip; + cir.setReturnValue(noclip.getSpeed()); } } diff --git a/src/main/java/net/aoba/mixin/MouseMixin.java b/src/main/java/net/aoba/mixin/MouseMixin.java index 27bf750..355ddb2 100644 --- a/src/main/java/net/aoba/mixin/MouseMixin.java +++ b/src/main/java/net/aoba/mixin/MouseMixin.java @@ -28,10 +28,9 @@ import net.aoba.AobaClient; import net.aoba.event.events.MouseMoveEvent; import net.aoba.event.events.MouseScrollEvent; -import net.aoba.event.events.RightMouseDownEvent; -import net.aoba.event.events.RightMouseUpEvent; -import net.aoba.event.events.LeftMouseDownEvent; -import net.aoba.event.events.LeftMouseUpEvent; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; +import net.aoba.event.events.MouseClickEvent; import net.minecraft.client.Mouse; @Mixin(Mouse.class) @@ -45,45 +44,37 @@ public class MouseMixin { private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) { AobaClient aoba = Aoba.getInstance(); if(aoba != null && aoba.eventManager != null) { + MouseClickEvent event = null; + switch (button) { case GLFW.GLFW_MOUSE_BUTTON_LEFT: if (action == 1) { - LeftMouseDownEvent event = new LeftMouseDownEvent(x, y); - aoba.eventManager.Fire(event); - - if (event.isCancelled()) { - ci.cancel(); - } + event = new MouseClickEvent(x, y, MouseButton.LEFT, MouseAction.DOWN); } else { - LeftMouseUpEvent event = new LeftMouseUpEvent(x, y); - aoba.eventManager.Fire(event); - - if (event.isCancelled()) { - ci.cancel(); - } + event = new MouseClickEvent(x, y, MouseButton.LEFT, MouseAction.UP); } break; case GLFW.GLFW_MOUSE_BUTTON_MIDDLE: - + if (action == 1) { + event = new MouseClickEvent(x, y, MouseButton.MIDDLE, MouseAction.DOWN); + } else { + event = new MouseClickEvent(x, y, MouseButton.MIDDLE, MouseAction.UP); + } break; case GLFW.GLFW_MOUSE_BUTTON_RIGHT: if (action == 1) { - RightMouseDownEvent event2 = new RightMouseDownEvent(x, y); - aoba.eventManager.Fire(event2); - - if (event2.isCancelled()) { - ci.cancel(); - } + event = new MouseClickEvent(x, y, MouseButton.RIGHT, MouseAction.DOWN); } else { - RightMouseUpEvent event2 = new RightMouseUpEvent(x, y); - aoba.eventManager.Fire(event2); - - if (event2.isCancelled()) { - ci.cancel(); - } + event = new MouseClickEvent(x, y, MouseButton.RIGHT, MouseAction.UP); } break; } + + aoba.eventManager.Fire(event); + + if (event.isCancelled()) { + ci.cancel(); + } } } diff --git a/src/main/java/net/aoba/module/ModuleManager.java b/src/main/java/net/aoba/module/ModuleManager.java index 5f5eb7c..feb5e0c 100644 --- a/src/main/java/net/aoba/module/ModuleManager.java +++ b/src/main/java/net/aoba/module/ModuleManager.java @@ -174,9 +174,6 @@ public ModuleManager() { Aoba.getInstance().eventManager.AddListener(KeyDownListener.class, this); } - public void update() { - } - public void render(MatrixStack matrices) { GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); diff --git a/src/main/java/net/aoba/module/modules/movement/ClickTP.java b/src/main/java/net/aoba/module/modules/movement/ClickTP.java index 9b873e5..108360c 100644 --- a/src/main/java/net/aoba/module/modules/movement/ClickTP.java +++ b/src/main/java/net/aoba/module/modules/movement/ClickTP.java @@ -3,13 +3,15 @@ import org.lwjgl.glfw.GLFW; import net.aoba.Aoba; import net.aoba.AobaClient; -import net.aoba.event.events.RightMouseDownEvent; -import net.aoba.event.listeners.RightMouseDownListener; +import net.aoba.event.events.MouseClickEvent; +import net.aoba.event.listeners.MouseClickListener; import net.aoba.misc.FakePlayerEntity; import net.aoba.mixin.interfaces.ICamera; import net.aoba.module.Module; import net.aoba.settings.types.FloatSetting; import net.aoba.settings.types.KeybindSetting; +import net.aoba.utils.types.MouseAction; +import net.aoba.utils.types.MouseButton; import net.minecraft.block.BlockState; import net.minecraft.client.render.Camera; import net.minecraft.client.util.InputUtil; @@ -23,7 +25,7 @@ import net.minecraft.util.shape.VoxelShape; import net.minecraft.world.RaycastContext; -public class ClickTP extends Module implements RightMouseDownListener { +public class ClickTP extends Module implements MouseClickListener { private FloatSetting distance; @@ -41,12 +43,12 @@ public ClickTP() { @Override public void onDisable() { - Aoba.getInstance().eventManager.RemoveListener(RightMouseDownListener.class, this); + Aoba.getInstance().eventManager.RemoveListener(MouseClickListener.class, this); } @Override public void onEnable() { - Aoba.getInstance().eventManager.AddListener(RightMouseDownListener.class, this); + Aoba.getInstance().eventManager.AddListener(MouseClickListener.class, this); } @Override @@ -55,35 +57,36 @@ public void onToggle() { } @Override - public void OnRightMouseDown(RightMouseDownEvent event) { + public void OnMouseClick(MouseClickEvent event) { + if(event.button == MouseButton.RIGHT && event.action == MouseAction.DOWN) { + Camera camera = MC.gameRenderer.getCamera(); + ICamera icamera = (ICamera)camera; + + Vec3d direction = Vec3d.fromPolar(camera.getPitch(), camera.getYaw()).multiply(210); + Vec3d targetPos = camera.getPos().add(direction); - Camera camera = MC.gameRenderer.getCamera(); - ICamera icamera = (ICamera)camera; - - Vec3d direction = Vec3d.fromPolar(camera.getPitch(), camera.getYaw()).multiply(210); - Vec3d targetPos = camera.getPos().add(direction); - - RaycastContext context = new RaycastContext(camera.getPos(), targetPos, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, MC.player); + RaycastContext context = new RaycastContext(camera.getPos(), targetPos, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, MC.player); - HitResult raycast = MC.world.raycast(context); - - if (raycast.getType() == HitResult.Type.BLOCK) { - BlockHitResult raycastBlock = (BlockHitResult) raycast; - BlockPos pos = raycastBlock.getBlockPos(); - Direction side = raycastBlock.getSide(); + HitResult raycast = MC.world.raycast(context); + + if (raycast.getType() == HitResult.Type.BLOCK) { + BlockHitResult raycastBlock = (BlockHitResult) raycast; + BlockPos pos = raycastBlock.getBlockPos(); + Direction side = raycastBlock.getSide(); - Vec3d newPos = new Vec3d(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + 1, pos.getZ() + 0.5 + side.getOffsetZ()); - int packetsRequired = (int) Math.ceil(MC.player.getPos().distanceTo(newPos) / 10) - 1; + Vec3d newPos = new Vec3d(pos.getX() + 0.5 + side.getOffsetX(), pos.getY() + 1, pos.getZ() + 0.5 + side.getOffsetZ()); + int packetsRequired = (int) Math.ceil(MC.player.getPos().distanceTo(newPos) / 10) - 1; - for (int i = 0; i < packetsRequired; i++) { - MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true)); - } + for (int i = 0; i < packetsRequired; i++) { + MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true)); + } - MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(newPos.x, newPos.y, newPos.z, true)); - - - AobaClient aoba = Aoba.getInstance(); - MC.player.setPosition(newPos); - } + MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(newPos.x, newPos.y, newPos.z, true)); + + + AobaClient aoba = Aoba.getInstance(); + MC.player.setPosition(newPos); + } + } } } diff --git a/src/main/java/net/aoba/module/modules/movement/Noclip.java b/src/main/java/net/aoba/module/modules/movement/Noclip.java index 3b24044..c1406b6 100644 --- a/src/main/java/net/aoba/module/modules/movement/Noclip.java +++ b/src/main/java/net/aoba/module/modules/movement/Noclip.java @@ -26,13 +26,15 @@ import net.aoba.event.events.TickEvent; import net.aoba.event.listeners.TickListener; import net.aoba.module.Module; +import net.aoba.settings.types.FloatSetting; import net.aoba.settings.types.KeybindSetting; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.util.InputUtil; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.util.math.Vec3d; public class Noclip extends Module implements TickListener { - private float flySpeed = 5; + private FloatSetting flySpeed; public Noclip() { super(new KeybindSetting("key.noclip", "Noclip Key", InputUtil.fromKeyCode(GLFW.GLFW_KEY_UNKNOWN, 0))); @@ -40,10 +42,17 @@ public Noclip() { this.setName("Noclip"); this.setCategory(Category.Movement); this.setDescription("Allows the player to clip through blocks (Only work clientside)."); + + flySpeed = new FloatSetting("noclip_speed", "Speed", "Fly speed.", 2f, 0.1f, 15f, 0.5f); + this.addSetting(flySpeed); } public void setSpeed(float speed) { - this.flySpeed = speed; + this.flySpeed.setValue(speed); + } + + public float getSpeed() { + return this.flySpeed.getValue(); } @Override @@ -67,22 +76,38 @@ public void onToggle() { @Override public void OnUpdate(TickEvent event) { ClientPlayerEntity player = MC.player; - player.noClip = true; + + float speed = this.flySpeed.getDefaultValue(); if (MC.options.sprintKey.isPressed()) { - this.flySpeed *= 1.5; + speed *= 1.5; } player.setVelocity(new Vec3d(0,0,0)); - Vec3d vec = new Vec3d(0,0,0); - if (MC.options.jumpKey.isPressed()) { - vec = new Vec3d(0,flySpeed * 0.2f,0); - } - if (MC.options.sneakKey.isPressed()) { - vec = new Vec3d(0,-flySpeed * 0.2f,0); - } - if (MC.options.sprintKey.isPressed()) { - this.flySpeed /= 1.5; - } - player.setVelocity(vec); + Vec3d forward = Vec3d.fromPolar(0, player.getYaw()); + Vec3d right = Vec3d.fromPolar(0, player.getYaw() + 90); + + Vec3d vec = new Vec3d(0, 0, 0); + + if(MC.options.forwardKey.isPressed()) { + vec = vec.add(forward.multiply(speed)); + }else if (MC.options.backKey.isPressed()) { + vec = vec.subtract(forward.multiply(speed)); + } + + if(MC.options.rightKey.isPressed()) { + vec = vec.add(right.multiply(speed)); + }else if(MC.options.leftKey.isPressed()) { + vec = vec.subtract(right.multiply(speed)); + } + + + Vec3d newPos = player.getPos().add(vec); + int packetsRequired = (int) Math.ceil(MC.player.getPos().distanceTo(newPos) / 10) - 1; + + for (int i = 0; i < packetsRequired; i++) { + MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true)); + } + + MC.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(newPos.x, newPos.y, newPos.z, true)); } } diff --git a/src/main/java/net/aoba/module/modules/render/ChestESP.java b/src/main/java/net/aoba/module/modules/render/ChestESP.java index 955993c..e4f71db 100644 --- a/src/main/java/net/aoba/module/modules/render/ChestESP.java +++ b/src/main/java/net/aoba/module/modules/render/ChestESP.java @@ -35,6 +35,7 @@ import net.aoba.settings.types.ColorSetting; import net.aoba.settings.types.FloatSetting; import net.aoba.settings.types.KeybindSetting; +import net.minecraft.block.entity.BarrelBlockEntity; import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.ChestBlockEntity; import net.minecraft.block.entity.TrappedChestBlockEntity; @@ -79,7 +80,7 @@ public void onToggle() { public void OnRender(RenderEvent event) { ArrayList blockEntities = ModuleUtils.getTileEntities().collect(Collectors.toCollection(ArrayList::new)); for(BlockEntity blockEntity : blockEntities) { - if(blockEntity instanceof ChestBlockEntity || blockEntity instanceof TrappedChestBlockEntity) { + if(blockEntity instanceof ChestBlockEntity || blockEntity instanceof TrappedChestBlockEntity || blockEntity instanceof BarrelBlockEntity) { Box box = new Box(blockEntity.getPos()); RenderUtils.draw3DBox(event.GetMatrix().peek().getPositionMatrix(), box, color.getValue()); } diff --git a/src/main/java/net/aoba/module/modules/render/Tracer.java b/src/main/java/net/aoba/module/modules/render/Tracer.java index e5a8f40..2e67aa7 100644 --- a/src/main/java/net/aoba/module/modules/render/Tracer.java +++ b/src/main/java/net/aoba/module/modules/render/Tracer.java @@ -79,6 +79,7 @@ public void OnRender(RenderEvent event) { Vec3d eyePosition = new Vec3d(0, 0, 1); Camera camera = MC.gameRenderer.getCamera(); Vec3d offset = RenderUtils.getEntityPositionOffsetInterpolated(MC.cameraEntity, event.GetPartialTicks()); + eyePosition = eyePosition.rotateX((float) -Math.toRadians(camera.getPitch())); eyePosition = eyePosition.rotateY((float) -Math.toRadians(camera.getYaw())); eyePosition = eyePosition.add(MC.cameraEntity.getEyePos()); diff --git a/src/main/java/net/aoba/module/modules/render/Trajectory.java b/src/main/java/net/aoba/module/modules/render/Trajectory.java index e785575..f81de72 100644 --- a/src/main/java/net/aoba/module/modules/render/Trajectory.java +++ b/src/main/java/net/aoba/module/modules/render/Trajectory.java @@ -21,6 +21,8 @@ */ package net.aoba.module.modules.render; +import java.util.function.Predicate; + import org.joml.Matrix4f; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; @@ -30,20 +32,29 @@ import net.aoba.event.listeners.RenderListener; import net.aoba.gui.colors.Color; import net.aoba.misc.ModuleUtils; +import net.aoba.misc.RenderUtils; import net.aoba.module.Module; import net.aoba.settings.types.ColorSetting; import net.aoba.settings.types.KeybindSetting; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferRenderer; +import net.minecraft.client.render.Camera; import net.minecraft.client.render.GameRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.InputUtil; +import net.minecraft.entity.Entity; +import net.minecraft.entity.projectile.ProjectileUtil; import net.minecraft.item.BowItem; import net.minecraft.item.ItemStack; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.RaycastContext; +import net.minecraft.world.RaycastContext.FluidHandling; public class Trajectory extends Module implements RenderListener { @@ -76,42 +87,82 @@ public void onToggle() { @Override public void OnRender(RenderEvent event) { - MinecraftClient mc = MinecraftClient.getInstance(); + if(MC.player.isUsingItem()) { + Color renderColor = color.getValue(); + Matrix4f matrix = event.GetMatrix().peek().getPositionMatrix(); + + ItemStack itemStack = MC.player.getActiveItem(); + if(ModuleUtils.isThrowable(itemStack)) { + RenderSystem.setShaderColor(renderColor.getRedFloat(), renderColor.getGreenFloat(), renderColor.getBlueFloat(), renderColor.getAlphaFloat()); + + GL11.glEnable(GL11.GL_BLEND); + GL11.glDisable(GL11.GL_DEPTH_TEST); + + Tessellator tessellator = RenderSystem.renderThreadTesselator(); + RenderSystem.setShader(GameRenderer::getPositionProgram); + BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION); - Matrix4f matrix4f = event.GetMatrix().peek().getPositionMatrix(); - RenderSystem.setShaderColor(0, 0, 0, 1); - - GL11.glEnable(GL11.GL_BLEND); - GL11.glDisable(GL11.GL_DEPTH_TEST); + float initialVelocity = (52f * BowItem.getPullProgress(MC.player.getItemUseTime())); + + Camera camera = MC.gameRenderer.getCamera(); + Vec3d offset = RenderUtils.getEntityPositionOffsetInterpolated(MC.cameraEntity, event.GetPartialTicks()); + Vec3d eyePos = MC.cameraEntity.getEyePos(); + + // Calculate look direction. + Vec3d right = Vec3d.fromPolar(0, camera.getYaw() + 90).multiply(0.14f); + Vec3d lookDirection = Vec3d.fromPolar(camera.getPitch(), camera.getYaw()); + Vec3d velocity = lookDirection.multiply(initialVelocity).multiply(0.2f); + + // Calculate starting point. + Vec3d prevPoint = new Vec3d(0, 0, 0).add(eyePos).subtract(offset).add(right); + Vec3d landPosition = null; + + for(int iteration = 0; iteration < 150; iteration++){ + Vec3d nextPoint = prevPoint.add(velocity.multiply(0.1)); + bufferBuilder.vertex(matrix, (float) prevPoint.x, (float) prevPoint.y, (float) prevPoint.z); - Tessellator tessellator = RenderSystem.renderThreadTesselator(); - - RenderSystem.setShader(GameRenderer::getPositionProgram); - - ItemStack itemStack = mc.player.getActiveItem(); + // Check to see if we have collided with a block. + RaycastContext context = new RaycastContext(prevPoint, nextPoint, RaycastContext.ShapeType.COLLIDER, FluidHandling.NONE, MC.player); + BlockHitResult result = MC.world.raycast(context); - if(!(ModuleUtils.isThrowable(itemStack))) return; - - float initialVelocity = (52 * BowItem.getPullProgress(mc.player.getItemUseTime())); - Vec3d prevPoint = new Vec3d(0,0,0); - - BufferBuilder bufferBuilder = tessellator.begin(VertexFormat.DrawMode.LINES, VertexFormats.POSITION); - for(int iteration = 0; iteration < 1000; iteration++){ - bufferBuilder.vertex(matrix4f, (float) prevPoint.x, (float) prevPoint.y, (float) prevPoint.z); - - float distance = (float) ((initialVelocity)*Math.sin(2*mc.player.getRotationVector().x) / 9.0f); - Vec3d nextPoint = mc.player.getRotationVector().multiply(distance); - bufferBuilder.vertex(matrix4f, (float) nextPoint.x, (float) nextPoint.y, (float) nextPoint.z); - - prevPoint = nextPoint; + if(result.getType() != HitResult.Type.MISS) { + landPosition = result.getPos(); + bufferBuilder.vertex(matrix, (float) landPosition.x, (float) landPosition.y, (float) landPosition.z); + break; + }else { + Box box = new Box(prevPoint, nextPoint); + Predicate predicate = e -> !e.isSpectator() && e.canHit(); + EntityHitResult entityResult = ProjectileUtil.raycast(MC.player, prevPoint, nextPoint, box, predicate, 4096); + + if(entityResult != null && entityResult.getType() != HitResult.Type.MISS) { + landPosition = entityResult.getPos(); + bufferBuilder.vertex(matrix, (float) landPosition.x, (float) landPosition.y, (float) landPosition.z); + break; + }else { + bufferBuilder.vertex(matrix, (float) nextPoint.x, (float) nextPoint.y, (float) nextPoint.z); + } + } + + prevPoint = nextPoint; + velocity = velocity.multiply(0.999).add(0, -0.05f, 0); + } + + + BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + RenderSystem.setShaderColor(1, 1, 1, 1); + + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_BLEND); + + // Draw Cube + if(landPosition != null) { + float size = 0.25f; + Vec3d pos1 = landPosition.add(-size, -size, -size); + Vec3d pos2 = landPosition.add(size, size, size); + Box box = new Box(pos1.x, pos1.y, pos1.z, pos2.x, pos2.y, pos2.z); + RenderUtils.draw3DBox(matrix, box, renderColor); + } + } } - - BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); - RenderSystem.setShaderColor(1, 1, 1, 1); - - GL11.glEnable(GL11.GL_DEPTH_TEST); - GL11.glDisable(GL11.GL_BLEND); - } - } \ No newline at end of file diff --git a/src/main/java/net/aoba/utils/types/MouseAction.java b/src/main/java/net/aoba/utils/types/MouseAction.java new file mode 100644 index 0000000..4a899a5 --- /dev/null +++ b/src/main/java/net/aoba/utils/types/MouseAction.java @@ -0,0 +1,5 @@ +package net.aoba.utils.types; + +public enum MouseAction{ + DOWN, UP +} \ No newline at end of file diff --git a/src/main/java/net/aoba/utils/types/MouseButton.java b/src/main/java/net/aoba/utils/types/MouseButton.java new file mode 100644 index 0000000..28cfbd3 --- /dev/null +++ b/src/main/java/net/aoba/utils/types/MouseButton.java @@ -0,0 +1,5 @@ +package net.aoba.utils.types; + +public enum MouseButton{ + LEFT, RIGHT, MIDDLE +} \ No newline at end of file