From 9aefa64b9a6ee99cd038b72564d3831a0e84227a Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Sat, 24 Aug 2024 23:15:35 +0530 Subject: [PATCH] Fixed Button rendering. Changed lockcanvas in Painter to ButtonSetting from BooleanSetting. Removed debug statement. --- .../java/dev/heliosclient/module/Module_.java | 15 +++++------ .../module/modules/chat/Spammer.java | 2 +- .../module/modules/combat/TriggerBot.java | 13 +++------- .../module/modules/world/painter/Painter.java | 25 +++++++------------ .../module/settings/buttonsetting/Button.java | 6 ++--- .../scripting/LuaEventManager.java | 3 +-- .../ui/clickgui/ConsoleScreen.java | 4 +-- .../ui/clickgui/ModuleButton.java | 9 ++----- .../ui/clickgui/ScriptManagerScreen.java | 8 ++---- .../dev/heliosclient/util/KeyboardUtils.java | 7 ++---- 10 files changed, 34 insertions(+), 58 deletions(-) diff --git a/src/main/java/dev/heliosclient/module/Module_.java b/src/main/java/dev/heliosclient/module/Module_.java index 1cdecdfb..e7d92ab0 100644 --- a/src/main/java/dev/heliosclient/module/Module_.java +++ b/src/main/java/dev/heliosclient/module/Module_.java @@ -296,13 +296,14 @@ public void loadFromFile(Map MAP) { for (SettingGroup settingGroup : this.settingGroups) { for (Setting setting : settingGroup.getSettings()) { if (!setting.shouldSaveAndLoad()) continue; - //Any error caught should not cause the whole config system to fail to load. - //Hopefully - try { - setting.loadFromFile(MAP); - } catch (Exception e) { - e.printStackTrace(); - } + + //Any error caught should not cause the whole config system to fail to load. + //Hopefully + try { + setting.loadFromFile(MAP); + } catch (Exception e) { + e.printStackTrace(); + } if (setting == this.active && this.isActive()) { this.onEnable(); } diff --git a/src/main/java/dev/heliosclient/module/modules/chat/Spammer.java b/src/main/java/dev/heliosclient/module/modules/chat/Spammer.java index 0332baa7..20e99c52 100644 --- a/src/main/java/dev/heliosclient/module/modules/chat/Spammer.java +++ b/src/main/java/dev/heliosclient/module/modules/chat/Spammer.java @@ -205,7 +205,7 @@ public void loadFromFile(Map MAP) { super.loadFromFile(MAP); String filePath = (String) MAP.get("File"); - if(filePath.equals("unknown")) return; + if(filePath == null || filePath.equals("unknown")) return; spamFile = new File(filePath); if (spamFile.exists() && spamFile.isFile()) { diff --git a/src/main/java/dev/heliosclient/module/modules/combat/TriggerBot.java b/src/main/java/dev/heliosclient/module/modules/combat/TriggerBot.java index e7515c8b..7a4b6335 100644 --- a/src/main/java/dev/heliosclient/module/modules/combat/TriggerBot.java +++ b/src/main/java/dev/heliosclient/module/modules/combat/TriggerBot.java @@ -13,6 +13,7 @@ import dev.heliosclient.module.settings.lists.EntityTypeListSetting; import dev.heliosclient.system.TickRate; import dev.heliosclient.util.SortMethod; +import dev.heliosclient.util.TickTimer; import dev.heliosclient.util.player.PlayerUtils; import dev.heliosclient.util.player.TargetUtils; import dev.heliosclient.util.render.TargetRenderer; @@ -146,7 +147,7 @@ public class TriggerBot extends Module_ { ); TargetUtils targetFinder = new TargetUtils(); - private int delay; + private TickTimer timer = new TickTimer(); private Entity targetEntity; public TriggerBot() { @@ -162,7 +163,7 @@ public TriggerBot() { @Override public void onEnable() { super.onEnable(); - delay = 0; + timer = new TickTimer(); } private boolean isTeamMate(LivingEntity targetEntity) { @@ -193,13 +194,7 @@ public boolean shouldAttack() { if (smartDelay.value) { return mc.player.getAttackCooldownProgress(baseTimer) >= 1; } else { - if (this.delay < baseTimer) { - this.delay++; - return false; - } else { - this.delay = 0; - return true; - } + return timer.incrementAndEvery((int) baseTimer); } } diff --git a/src/main/java/dev/heliosclient/module/modules/world/painter/Painter.java b/src/main/java/dev/heliosclient/module/modules/world/painter/Painter.java index f2bd101f..4487f8d3 100644 --- a/src/main/java/dev/heliosclient/module/modules/world/painter/Painter.java +++ b/src/main/java/dev/heliosclient/module/modules/world/painter/Painter.java @@ -9,10 +9,10 @@ import dev.heliosclient.module.Module_; import dev.heliosclient.module.settings.*; import dev.heliosclient.module.settings.buttonsetting.ButtonSetting; -import dev.heliosclient.util.blocks.BlockUtils; import dev.heliosclient.util.ChatUtils; import dev.heliosclient.util.ColorUtils; import dev.heliosclient.util.FileUtils; +import dev.heliosclient.util.blocks.BlockUtils; import dev.heliosclient.util.player.InventoryUtils; import dev.heliosclient.util.render.Renderer3D; import dev.heliosclient.util.render.color.QuadColor; @@ -162,14 +162,12 @@ public class Painter extends Module_ { .shouldRender(() -> !autoRotate.value) .build() ); - BooleanSetting lockCanvas = sgGeneral.add(new BooleanSetting.Builder() - .name("Lock Canvas") - .description("Locks canvas to the current set direction and position") - .value(false) - .defaultValue(false) - .onSettingChange(this) + ButtonSetting canvasState = sgGeneral.add(new ButtonSetting.Builder() + .name("Canvas state") + .description("Locks canvas to the current set direction and position or unlocks the canvas to return to normal") .build() ); + KeyBind lockCanvasKey = sgGeneral.add(new KeyBind.Builder() .name("Lock Canvas Key") .description("Keybind to lock canvas") @@ -285,6 +283,10 @@ public Painter() { ChatUtils.sendHeliosMsg(ColorUtils.red + "File selected is not selected."); } }); + + canvasState.addButton("Lock",0,0, this::lock); + canvasState.addButton("Unlock",1,0, this::unlock); + } @SubscribeEvent @@ -292,10 +294,8 @@ public void keyPressedEvent(KeyPressedEvent e) { if (e.getKey() == lockCanvasKey.value) { if (!isLocked) { lock(); - lockCanvas.setValue(isLocked); } else { unlock(); - lockCanvas.setValue(isLocked); } } } @@ -303,7 +303,6 @@ public void keyPressedEvent(KeyPressedEvent e) { @Override public void onEnable() { super.onEnable(); - isLocked = !lockCanvas.value; ticksPassed = 0; loadCanvas(); @@ -326,12 +325,6 @@ private void loadCanvas(){ @SubscribeEvent public void onTick(TickEvent.CLIENT event) { if(!HeliosClient.shouldUpdate()) return; - - if (lockCanvas.value && !isLocked) { - lock(); - } else if (!lockCanvas.value && isLocked) { - unlock(); - } if (CANVAS_MAP == null || !autoPlace.value) return; ticksPassed++; diff --git a/src/main/java/dev/heliosclient/module/settings/buttonsetting/Button.java b/src/main/java/dev/heliosclient/module/settings/buttonsetting/Button.java index 9e2e1f6b..d8b9895d 100644 --- a/src/main/java/dev/heliosclient/module/settings/buttonsetting/Button.java +++ b/src/main/java/dev/heliosclient/module/settings/buttonsetting/Button.java @@ -24,11 +24,11 @@ public Button(String text, Runnable task, int x, int y, int width, int height) { public void render(DrawContext drawContext, int mouseX, int mouseY, TextRenderer textRenderer) { int fillColor = Color.DARK_GRAY.getRGB(); int borderColor = hovered(mouseX, mouseY) ? Color.WHITE.getRGB() : Color.BLACK.getRGB(); - Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width - 4, 14, 2, fillColor); - Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width - 4, 14, 2, 0.7f, borderColor); + Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width, 14, 2, fillColor); + Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width, 14, 2, 0.7f, borderColor); // Render button text - double textX = x + ((width / 2.0) - (Renderer2D.getFxStringWidth(text) / 2.0)) - 0.2; + double textX = x + ((width - Renderer2D.getFxStringWidth(text)) / 2.0); float textHeight = Renderer2D.getFxStringHeight(); float textY = y + (14 - textHeight) / 2; // Center the text vertically diff --git a/src/main/java/dev/heliosclient/scripting/LuaEventManager.java b/src/main/java/dev/heliosclient/scripting/LuaEventManager.java index 667b5e5d..09550e81 100644 --- a/src/main/java/dev/heliosclient/scripting/LuaEventManager.java +++ b/src/main/java/dev/heliosclient/scripting/LuaEventManager.java @@ -41,8 +41,7 @@ public void unregister(String eventType, LuaValue listener) { LuaFunction luaFunction = listener.checkfunction(); List eventListeners = listeners.get(eventType); if (eventListeners != null) { - System.out.println(eventListeners); - System.out.println( eventListeners.remove(luaFunction)); + eventListeners.remove(luaFunction); } } diff --git a/src/main/java/dev/heliosclient/ui/clickgui/ConsoleScreen.java b/src/main/java/dev/heliosclient/ui/clickgui/ConsoleScreen.java index 4b587a69..3f54e6bf 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/ConsoleScreen.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/ConsoleScreen.java @@ -23,7 +23,7 @@ public ConsoleScreen() { consoleBox.displayLineNos = true; consoleBox.autoScroll = true; - enterBox = new InputBox(33, 13, "", 256, InputBox.InputMode.ALL); + enterBox = new InputBox(29, 13, "", 256, InputBox.InputMode.ALL); enterButton = new Button("Enter", () -> { if (!enterBox.getValue().isEmpty()) { HeliosClient.LOGGER.info(enterBox.getValue()); @@ -54,7 +54,7 @@ public void onDisplayed() { private void resizeBoxes(){ consoleBox.setSize(HeliosClient.MC.getWindow().getScaledWidth() - 40, HeliosClient.MC.getWindow().getScaledHeight() - 55); - enterBox.setSize(HeliosClient.MC.getWindow().getScaledWidth() - 82, 13); + enterBox.setSize(HeliosClient.MC.getWindow().getScaledWidth() - 86, 13); enterButton.setX(HeliosClient.MC.getWindow().getScaledWidth() - 58); enterButton.setY(HeliosClient.MC.getWindow().getScaledHeight() - 33); } diff --git a/src/main/java/dev/heliosclient/ui/clickgui/ModuleButton.java b/src/main/java/dev/heliosclient/ui/clickgui/ModuleButton.java index 3cc8467b..48e18676 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/ModuleButton.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/ModuleButton.java @@ -9,9 +9,7 @@ import dev.heliosclient.module.Module_; import dev.heliosclient.module.modules.render.GUI; import dev.heliosclient.module.settings.ParentScreenSetting; -import dev.heliosclient.module.settings.RGBASetting; import dev.heliosclient.module.settings.Setting; -import dev.heliosclient.module.settings.lists.ListSetting; import dev.heliosclient.module.sysmodules.ClickGUI; import dev.heliosclient.ui.clickgui.gui.HudBox; import dev.heliosclient.ui.clickgui.settings.SettingsScreen; @@ -74,6 +72,8 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float x, int this.x = x; this.y = y; this.shouldRender = shouldRender; + this.width = maxWidth; + hitBox.set(this.x, this.y, width, height); if (!shouldRender) return; @@ -85,10 +85,6 @@ public void render(DrawContext drawContext, int mouseX, int mouseY, float x, int // Get the width and height of the module name int moduleNameHeight = (int) Renderer2D.getFxStringHeight(module.name) - 1; - this.width = maxWidth; - - hitBox.set(x, y, width, height); - Color fillColorStart = module.isActive() ? ColorManager.INSTANCE.primaryGradientStart : ColorUtils.changeAlpha(ModuleManager.get(GUI.class).buttonColor.getColor(), 100); Color fillColorEnd = module.isActive() ? ColorManager.INSTANCE.primaryGradientEnd : ColorUtils.changeAlpha(ModuleManager.get(GUI.class).buttonColor.getColor(), 100); Color blendedColor = ColorUtils.blend(fillColorStart, fillColorEnd, 1 / 2f); @@ -135,7 +131,6 @@ private void drawGradientRectangleWithShadow(MatrixStack stack, float x, float y } public int renderSettings(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) { - if (!shouldRender){ updateScale(false); return (int) (boxHeight * scale); diff --git a/src/main/java/dev/heliosclient/ui/clickgui/ScriptManagerScreen.java b/src/main/java/dev/heliosclient/ui/clickgui/ScriptManagerScreen.java index 1cd4a370..7c3efc51 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/ScriptManagerScreen.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/ScriptManagerScreen.java @@ -2,7 +2,6 @@ import dev.heliosclient.managers.ColorManager; import dev.heliosclient.module.modules.render.GUI; -import dev.heliosclient.module.settings.buttonsetting.Button; import dev.heliosclient.scripting.LuaFile; import dev.heliosclient.scripting.LuaScriptManager; import dev.heliosclient.ui.clickgui.gui.PolygonMeshPatternRenderer; @@ -325,7 +324,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { @Override public boolean shouldCloseOnEsc() { - return false; + return true; } @Override @@ -387,9 +386,7 @@ public void setPosition(double x, double y) { } @Override - public void setWidth(double width) { - - } + public void setWidth(double width) {} public double getX() { return x; @@ -399,5 +396,4 @@ public double getY() { return y - ScriptManagerScreen.this.scrollOffset; } } - } \ No newline at end of file diff --git a/src/main/java/dev/heliosclient/util/KeyboardUtils.java b/src/main/java/dev/heliosclient/util/KeyboardUtils.java index 4858195c..5e35081f 100644 --- a/src/main/java/dev/heliosclient/util/KeyboardUtils.java +++ b/src/main/java/dev/heliosclient/util/KeyboardUtils.java @@ -1,10 +1,7 @@ package dev.heliosclient.util; -import dev.heliosclient.HeliosClient; -import net.minecraft.client.Keyboard; import org.lwjgl.glfw.GLFW; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE; /** * Utils for working with GLFW keycodes. @@ -181,7 +178,7 @@ public static String translate(Integer keyCode) { case GLFW.GLFW_KEY_NUM_LOCK -> { return "NUM_LOCK"; } - case GLFW_KEY_SPACE -> { + case GLFW.GLFW_KEY_SPACE -> { return "SPACE"; } case GLFW.GLFW_KEY_ENTER -> { @@ -371,7 +368,7 @@ public static String translateShort(Integer keyCode) { case GLFW.GLFW_KEY_NUM_LOCK -> { return "NUM"; } - case GLFW_KEY_SPACE -> { + case GLFW.GLFW_KEY_SPACE -> { return "SPACE"; } case GLFW.GLFW_KEY_ENTER -> {