From 921fc6dcea9a42a47785f6dd175ab0051f554fa7 Mon Sep 17 00:00:00 2001 From: tanishisherewithhh <120117618+tanishisherewithhh@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:40:52 +0530 Subject: [PATCH] New Script Entries. Quad Holes in HoleUtils. ScriptScreen optimisation. InputBox enterTask supplier. Wrong color used by a few settings. Scaling method in fxFontRenderer and added more documentation. --- .../module/modules/render/HoleESP.java | 14 +- .../module/settings/DoubleSetting.java | 4 + .../module/settings/GradientSetting.java | 5 +- .../heliosclient/module/settings/Option.java | 1 - .../module/settings/RGBASetting.java | 35 ++- .../module/sysmodules/ClickGUI.java | 1 + .../dev/heliosclient/scripting/LuaLoader.java | 14 +- .../ui/clickgui/CategoryPane.java | 4 +- .../heliosclient/ui/clickgui/SearchBar.java | 2 +- .../clickgui/script/ScriptManagerScreen.java | 291 ++++++++++++++---- .../dev/heliosclient/util/ColorUtils.java | 8 +- .../heliosclient/util/blocks/HoleUtils.java | 189 +++++++++++- .../util/fontutils/FontRenderers.java | 37 ++- .../util/fontutils/fxFontRenderer.java | 18 +- .../heliosclient/util/inputbox/InputBox.java | 6 + 15 files changed, 522 insertions(+), 107 deletions(-) diff --git a/src/main/java/dev/heliosclient/module/modules/render/HoleESP.java b/src/main/java/dev/heliosclient/module/modules/render/HoleESP.java index 270db613..919a6d4b 100644 --- a/src/main/java/dev/heliosclient/module/modules/render/HoleESP.java +++ b/src/main/java/dev/heliosclient/module/modules/render/HoleESP.java @@ -28,6 +28,14 @@ public class HoleESP extends Module_ { .onSettingChange(this) .build() ); + BooleanSetting quads = sgGeneral.add(new BooleanSetting.Builder() + .name("Show Quad holes") + .description("Shows quad holes (4 block holes). May drain fps.") + .value(false) + .defaultValue(false) + .onSettingChange(this) + .build() + ); DoubleSetting holeRange = sgGeneral.add(new DoubleSetting.Builder() .name("Hole Range") .description("Maximum distance of the hole to the player") @@ -190,8 +198,6 @@ public class HoleESP extends Module_ { .build() ); - - public HoleESP() { super("HoleESP", "Displays holes in your area", Categories.RENDER); addSettingGroup(sgGeneral); @@ -205,7 +211,7 @@ public HoleESP() { @SubscribeEvent public void onTick(TickEvent.PLAYER event) { - holes = HoleUtils.getHoles((int) holeRange.value, (int) holeRangeVertical.value).stream().toList(); + holes = HoleUtils.getHoles((int) holeRange.value, (int) holeRangeVertical.value,quads.value).stream().toList(); } @SubscribeEvent @@ -216,7 +222,7 @@ public void onRender3d(Render3DEvent event) { QuadColor.CardinalDirection direction = gradientDirection.getOption().equals("Down") ? QuadColor.CardinalDirection.SOUTH : QuadColor.CardinalDirection.NORTH; for (HoleUtils.HoleInfo info : holes) { - if (!renderSelf.value && mc.player.getBlockPos().isWithinDistance(info.holePosition, 1d)) { + if (!renderSelf.value && info.holeBox.intersects(mc.player.getBoundingBox().contract(0.2f))) { continue; } diff --git a/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java b/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java index dfed0694..7620cd3c 100644 --- a/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java +++ b/src/main/java/dev/heliosclient/module/settings/DoubleSetting.java @@ -259,6 +259,10 @@ public Builder defaultValue(float val) { this.defaultValue = (double) val; return this; } + public Builder value(float val) { + this.value = (double) val; + return this; + } @Override public DoubleSetting build() { diff --git a/src/main/java/dev/heliosclient/module/settings/GradientSetting.java b/src/main/java/dev/heliosclient/module/settings/GradientSetting.java index 5c130b38..2004c215 100644 --- a/src/main/java/dev/heliosclient/module/settings/GradientSetting.java +++ b/src/main/java/dev/heliosclient/module/settings/GradientSetting.java @@ -2,6 +2,7 @@ import dev.heliosclient.HeliosClient; +import dev.heliosclient.managers.ColorManager; import dev.heliosclient.managers.GradientManager; import dev.heliosclient.module.settings.lists.ListSetting; import dev.heliosclient.ui.clickgui.gui.tables.Table; @@ -53,7 +54,7 @@ public void createTable(double width){ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) { super.render(drawContext, x, y, mouseX, mouseY, textRenderer); - Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 4, -1); + Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 4, ColorManager.INSTANCE.defaultTextColor); // Draw a '🖋' button next to the text nameWidth = Renderer2D.getFxStringWidth(name); @@ -128,7 +129,7 @@ public void renderAllGradients(DrawContext context, int mouseX, int mouseY){ @Override public void renderCompact(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) { super.renderCompact(drawContext, x, y, mouseX, mouseY, textRenderer); - Renderer2D.drawFixedString(drawContext.getMatrices(), FontRenderers.fxfontRenderer.trimToWidth(name, moduleWidth), x + 2, y + 4, -1); + Renderer2D.drawFixedString(drawContext.getMatrices(), FontRenderers.fxfontRenderer.trimToWidth(name, moduleWidth), x + 2, y + 4, ColorManager.INSTANCE.defaultTextColor); // Draw a '🖋' button next to the text nameWidth = Renderer2D.getFxStringWidth(FontRenderers.fxfontRenderer.trimToWidth(name, moduleWidth)); diff --git a/src/main/java/dev/heliosclient/module/settings/Option.java b/src/main/java/dev/heliosclient/module/settings/Option.java index 432e3f3e..2269f4d4 100644 --- a/src/main/java/dev/heliosclient/module/settings/Option.java +++ b/src/main/java/dev/heliosclient/module/settings/Option.java @@ -1,6 +1,5 @@ package dev.heliosclient.module.settings; - //what is this anyone explain pls. public class Option { private String name; diff --git a/src/main/java/dev/heliosclient/module/settings/RGBASetting.java b/src/main/java/dev/heliosclient/module/settings/RGBASetting.java index b21f4a84..110c920e 100644 --- a/src/main/java/dev/heliosclient/module/settings/RGBASetting.java +++ b/src/main/java/dev/heliosclient/module/settings/RGBASetting.java @@ -4,6 +4,7 @@ import dev.heliosclient.event.SubscribeEvent; import dev.heliosclient.event.events.TickEvent; import dev.heliosclient.event.listener.Listener; +import dev.heliosclient.managers.ColorManager; import dev.heliosclient.managers.EventManager; import dev.heliosclient.ui.clickgui.settings.RGBASettingScreen; import dev.heliosclient.util.ColorUtils; @@ -80,6 +81,20 @@ public RGBASetting(String name, String description, Color defaultColor, boolean alphaHandleY = Math.round((1.0f - alpha) * (float) boxHeight); hexInput = new InputBox(50, 11, ColorUtils.colorToHex(value), 7, InputBox.InputMode.ALL); + hexInput.enterTask = ()->{ + if (ColorUtils.isHexColor(hexInput.getValue().trim())) { + try { + value = ColorUtils.hexToColor(hexInput.getValue().trim()); + updateHandles(true); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + // Something went wrong + } + } + return true; + }; } @Override @@ -87,7 +102,7 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY super.render(drawContext, x, y, mouseX, mouseY, textRenderer); this.x = x; this.y = y; - Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 4, -1); + Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 2, y + 4, ColorManager.INSTANCE.defaultTextColor()); Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 170, y + 2, 15, 15, 2, value.getRGB()); } @@ -97,7 +112,7 @@ public void renderSetting(DrawContext drawContext, int x, int y, int mouseX, int // Draw the name of setting and the value of the color we have set - Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 3, y + 2, -1); + Renderer2D.drawFixedString(drawContext.getMatrices(), name, x + 3, y + 2, ColorManager.INSTANCE.defaultTextColor()); Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 170, y + 2, 15, 15, 2, value.getRGB()); int value1 = hoveredOverGradientBox(mouseX, mouseY) ? Color.DARK_GRAY.getRGB() : Color.BLACK.brighter().getRGB(); @@ -135,10 +150,10 @@ public void renderSetting(DrawContext drawContext, int x, int y, int mouseX, int FontRenderers.Mid_iconRenderer.drawString(drawContext.getMatrices(), "\uF1FB", x + offsetX + Renderer2D.getFxStringWidth("Rainbow ") + 6.5f, y + offsetY + gradientBoxHeight + 6.5f, isPicking ? Color.GREEN.getRGB() : Color.RED.getRGB()); //Render the texts - Renderer2D.drawFixedString(drawContext.getMatrices(), "Alpha: " + value.getAlpha(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 9, -1); - Renderer2D.drawFixedString(drawContext.getMatrices(), "Red: " + value.getRed(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 18, -1); - Renderer2D.drawFixedString(drawContext.getMatrices(), "Green: " + value.getGreen(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 27, -1); - Renderer2D.drawFixedString(drawContext.getMatrices(), "Blue: " + value.getBlue(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 36, -1); + Renderer2D.drawFixedString(drawContext.getMatrices(), "Alpha: " + value.getAlpha(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 9, ColorManager.INSTANCE.defaultTextColor()); + Renderer2D.drawFixedString(drawContext.getMatrices(), "Red: " + value.getRed(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 18, ColorManager.INSTANCE.defaultTextColor()); + Renderer2D.drawFixedString(drawContext.getMatrices(), "Green: " + value.getGreen(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 27, ColorManager.INSTANCE.defaultTextColor()); + Renderer2D.drawFixedString(drawContext.getMatrices(), "Blue: " + value.getBlue(), gradientBoxX, y + offsetY + gradientBoxHeight + Renderer2D.getFxStringHeight() + 36, ColorManager.INSTANCE.defaultTextColor()); // Draw the handles Renderer2D.drawFilledCircle(drawContext.getMatrices().peek().getPositionMatrix(), gradientBoxX + handleX, gradientBoxY + handleY, 1, -1); @@ -195,7 +210,7 @@ public void drawAlphaSlider(DrawContext drawContext, int x, int y, int value3) { Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x - 1, y - 1, sliderWidth + 2, boxHeight + 2, 1, 1, value3); - FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Alpha", x - 5, y + boxHeight + 2, -1); // Below the alpha slider + FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), "Alpha", x - 5, y + boxHeight + 2, ColorManager.INSTANCE.defaultTextColor()); // Below the alpha slider } public void drawBrightnessSaturationBox(DrawContext drawContext, int x, int y, float hue, int value3) { @@ -243,7 +258,7 @@ public boolean hoveredOverBrightnessSaturationBox(double mouseX, double mouseY) @Override public void renderCompact(DrawContext drawContext, int x, int y, int mouseX, int mouseY, TextRenderer textRenderer) { super.renderCompact(drawContext, x, y, mouseX, mouseY, textRenderer); - FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), name.substring(0, Math.min(12, name.length())) + "...", x + 3, y + 1, -1); + FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), name.substring(0, Math.min(12, name.length())) + "...", x + 3, y + 1, ColorManager.INSTANCE.defaultTextColor()); Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(), x + 71, y + 1, 10, 10, 2, value.getRGB()); } @@ -298,9 +313,9 @@ public void mouse(double mouseX, double mouseY, int button) { public void keyPress(int keyCode) { if ((keyCode == GLFW.GLFW_KEY_KP_ENTER || keyCode == GLFW.GLFW_KEY_ENTER) && hexInput.isFocused()) { - if (ColorUtils.isHexColor(hexInput.getValue())) { + if (ColorUtils.isHexColor(hexInput.getValue().trim())) { try { - value = ColorUtils.hexToColor(hexInput.getValue()); + value = ColorUtils.hexToColor(hexInput.getValue().trim()); updateHandles(true); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java b/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java index 792151b9..c40cd36d 100644 --- a/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java +++ b/src/main/java/dev/heliosclient/module/sysmodules/ClickGUI.java @@ -55,6 +55,7 @@ public class ClickGUI extends Module_ { .name("ClickGUI roundness") .description("Control the roundness of the click gui") .onSettingChange(this) + .value(2d) .defaultValue(2) .min(1) .max(7) diff --git a/src/main/java/dev/heliosclient/scripting/LuaLoader.java b/src/main/java/dev/heliosclient/scripting/LuaLoader.java index be1a33d0..71c53991 100644 --- a/src/main/java/dev/heliosclient/scripting/LuaLoader.java +++ b/src/main/java/dev/heliosclient/scripting/LuaLoader.java @@ -44,7 +44,12 @@ public void load(LuaFile luaFile) { LuaValue onRunFunction = luaFile.getExecutor().getFunction("onRun"); if (onRunFunction.isfunction()) { - onRunFunction.call(); + try { + onRunFunction.call(); + }catch (Throwable e){ + ChatUtils.sendHeliosMsg(ColorUtils.darkRed + "Error caught while calling the onRun() function: " + e.getMessage()); + HeliosClient.LOGGER.error("Error caught while calling the onRun() function...", e); + } } else { ChatUtils.sendHeliosMsg(ColorUtils.darkRed + "onRun() function not found for " + ColorUtils.blue + luaFile.getAbsolutePath() + ColorUtils.darkRed + " while loading"); HeliosClient.LOGGER.error("onRun() function not found for file: {} while loading", luaFile.getName()); @@ -78,7 +83,12 @@ public void close(LuaFile file) { try { LuaValue onStopFunction = file.getExecutor().getFunction("onStop"); if (onStopFunction.isfunction()) { - onStopFunction.call(); + try { + onStopFunction.call(); + }catch (Throwable e){ + ChatUtils.sendHeliosMsg(ColorUtils.darkRed + "Error caught while calling the onStop() function: " + e.getMessage()); + HeliosClient.LOGGER.error("Error caught while calling the onStop() function...", e); + } } else { ChatUtils.sendHeliosMsg(ColorUtils.darkRed + "onStop() function not found for " + ColorUtils.blue + file.getAbsolutePath() + ColorUtils.darkRed + " while closing"); HeliosClient.LOGGER.error("onStop() function not found for file: {} while closing", file.getAbsolutePath()); diff --git a/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java b/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java index 419c1202..c00b3f2c 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/CategoryPane.java @@ -145,7 +145,9 @@ public void keepOnlyModule(Module_ module) { } public void removeModules() { - moduleButtons.clear(); + if(!moduleButtons.isEmpty()) + moduleButtons.clear(); + height = 4; maxWidth = 0; } diff --git a/src/main/java/dev/heliosclient/ui/clickgui/SearchBar.java b/src/main/java/dev/heliosclient/ui/clickgui/SearchBar.java index 58266c0c..c1a6794b 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/SearchBar.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/SearchBar.java @@ -21,7 +21,7 @@ public void render(DrawContext drawContext, int x, int y, int mouseX, int mouseY Renderer2D.drawOutlineRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x - 15 + 1.5f, y - 0.5f, width + 14f, height + 1f, 3, 0.5f, focused ? Color.WHITE.getRGB() : ColorUtils.argbToRgb(ColorManager.INSTANCE.clickGuiPrimary)); Renderer2D.drawRoundedRectangleWithShadow(drawContext.getMatrices(), x - 15 + 2, y, width + 13f, height, 2, 6, ColorUtils.argbToRgb(ColorManager.INSTANCE.clickGuiPrimary,200)); - FontRenderers.Large_iconRenderer.drawString(drawContext.getMatrices(), "\uEA17", x - 15 + 4, y + 1, -1); + FontRenderers.Large_iconRenderer.drawString(drawContext.getMatrices(), "\uEA17", x - 15 + 4, y + 1, ColorManager.INSTANCE.defaultTextColor); float textHeight = Renderer2D.getFxStringHeight(); float textY = y + (height - textHeight) / 2; // Center the text vertically diff --git a/src/main/java/dev/heliosclient/ui/clickgui/script/ScriptManagerScreen.java b/src/main/java/dev/heliosclient/ui/clickgui/script/ScriptManagerScreen.java index 8fb83b11..f0bd06fa 100644 --- a/src/main/java/dev/heliosclient/ui/clickgui/script/ScriptManagerScreen.java +++ b/src/main/java/dev/heliosclient/ui/clickgui/script/ScriptManagerScreen.java @@ -42,6 +42,7 @@ public class ScriptManagerScreen extends Screen { private int scrollOffset = 0, maxScroll; static int lightBlack = ColorUtils.changeAlphaGetInt(0xFF000000, 165); //private int entryWidth, entryHeight; + private static final int SCROLLBAR_WIDTH = 3; private Table scriptTable = new Table(); @@ -173,6 +174,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { public void drawLocalScriptEntries(DrawContext context, int mouseX, int mouseY) { // Enable scissor for scrolling float startEntryX = startX + (managerWidth * 0.20f) - 2; + int visibleHeight = managerHeight - 18; // Subtract header height Renderer2D.enableScissor((int) (startEntryX), 50, managerWidth + 50, mc.getWindow().getScaledHeight() - 98); @@ -180,7 +182,9 @@ public void drawLocalScriptEntries(DrawContext context, int mouseX, int mouseY) for(List row: scriptTable.table){ for (TableEntry entry : row) { if (entry instanceof ScriptEntry scriptEntry) { - drawScript(context, (float) scriptEntry.getX(), (float) scriptEntry.getY(), mouseX, mouseY, scriptEntry.getLuaFile()); + if (scriptEntry.getY() + scriptEntry.getHeight() > 50 && scriptEntry.getY() < 50 + visibleHeight) { + scriptEntry.renderScript(context, (float) scriptEntry.getX(), (float) scriptEntry.getY(), mouseX, mouseY); + } } } } @@ -188,46 +192,55 @@ public void drawLocalScriptEntries(DrawContext context, int mouseX, int mouseY) Renderer2D.disableScissor(); // Draw scrollbar + + drawScrollbar(context); + + /* int scrollbarX = startX + managerWidth + 5; int scrollbarY = 50; float scrollbarHeight = maxScroll > 0 ? (int) (Math.pow(70 + 10, 2) * 2 / maxScroll) : 0; float scrollbarPosition = maxScroll > 0 ? scrollbarY + (scaledHeight - 100 - scrollbarHeight) * scrollOffset / maxScroll : scrollbarY; // Position of the scrollbar depends on the current scroll offset Renderer2D.drawRectangleWithShadow(context.getMatrices(), scrollbarX, scrollbarPosition, 1.5f, scrollbarHeight, Color.BLACK.brighter().brighter().getRGB(), 2); - } - - public void drawScript(DrawContext drawContext, float x, float y, int mouseX, int mouseY, LuaFile file) { - //Icon - Renderer2D.drawRoundedRectangleWithShadow(drawContext.getMatrices(), x, y, 60, 70, 4, 4, ColorUtils.changeAlpha(ColorManager.INSTANCE.ClickGuiPrimary().darker().darker().darker(), 169).getRGB()); - Renderer2D.drawOutlineGradientRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, 60, 70, 4, 0.7f, ColorManager.INSTANCE.getPrimaryGradientStart(), ColorManager.INSTANCE.getPrimaryGradientEnd(), ColorManager.INSTANCE.getPrimaryGradientEnd(), ColorManager.INSTANCE.getPrimaryGradientStart()); - FontRenderers.Ultra_Large_iconRenderer.drawString(drawContext.getMatrices(), "\uF0F6", x + 19, y + 12, Color.WHITE.getRGB()); - - Renderer2D.drawRoundedGradientRectangle(drawContext.getMatrices().peek().getPositionMatrix(), ColorManager.INSTANCE.getPrimaryGradientStart(), ColorManager.INSTANCE.getPrimaryGradientEnd(), ColorManager.INSTANCE.getPrimaryGradientEnd(), ColorManager.INSTANCE.getPrimaryGradientStart(), x, y + 58, 60, 12, 3, false, false, true, true); - //Name - FontRenderers.Mid_fxfontRenderer.drawString(drawContext.getMatrices(), file.getScriptName(), x + 30 - FontRenderers.Mid_fxfontRenderer.getStringWidth(file.getScriptName()) / 2.0f, y + 43f, Color.WHITE.getRGB()); + */ + } - //Bind - String bindKey = KeyboardUtils.translateShort(file.bindKey).toUpperCase(); - if (file.isListeningForBind) { - bindKey = "Set"; + private void drawScrollbar(DrawContext context) { + int scrollbarX = startX + managerWidth + 5; + int scrollbarY = 50; + int scrollbarHeight = managerHeight - 18; // Subtract header height + + // Draw scrollbar background + Renderer2D.drawRoundedRectangle(context.getMatrices().peek().getPositionMatrix(), + scrollbarX, scrollbarY, SCROLLBAR_WIDTH, scrollbarHeight,2, + lightBlack); + + if (maxScroll > 0) { + float scrollPercentage = (float) scrollOffset / maxScroll; + int handleHeight = Math.max(20, scrollbarHeight * scrollbarHeight / (scrollbarHeight + maxScroll)); + int handleY = scrollbarY + (int) ((scrollbarHeight - handleHeight) * scrollPercentage); + + // Draw scrollbar handle + Renderer2D.drawRoundedRectangle(context.getMatrices().peek().getPositionMatrix(), + scrollbarX, handleY, SCROLLBAR_WIDTH, handleHeight,2, + Color.BLACK.getRGB()); } - Renderer2D.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), x + 4, y + 60, FontRenderers.Small_fxfontRenderer.getStringWidth(bindKey) + 3, 8, 2, Color.BLACK.getRGB(), 100, 1, 1); - FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), bindKey, x + 4.9f, y + 60.5f, Color.WHITE.getRGB()); - - //File state (loaded/unloaded) - drawOnOffButton(drawContext, x + 26, y + 60, file.isLoaded()); - //Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(),xModified + 10, y + 60,FontRenderers.Small_fxfontRenderer.getStringWidth(file.isLoaded? "DISABLE":"ENABLE") + 3,7,2,Color.BLACK.getRGB()); - //FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(),file.isLoaded? "DISABLE":"ENABLE",xModified + 10,y + 60.5f, file.isLoaded? Color.RED.getRGB() : Color.GREEN.getRGB()); - - //Refresh / Reload - Renderer2D.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), x + 45f, y + 59.5f, FontRenderers.Small_iconRenderer.getStringWidth("\uEA75") + 2, 8, 2, Color.BLACK.getRGB(), 100, 1, 1); - FontRenderers.Small_iconRenderer.drawString(drawContext.getMatrices(), "\uEA1D", x + 46f, y + 60.5f, Color.WHITE.getRGB()); - - if (isMouseOver(mouseX, mouseY, x, y, 60, 70)) { - //Edit - Renderer2D.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), x + 46f, y + 3f, FontRenderers.Small_iconRenderer.getStringWidth("\uEAF3") + 2, 8, 2, Color.WHITE.getRGB(), 100, 1, 1); - FontRenderers.Small_iconRenderer.drawString(drawContext.getMatrices(), "\uEAF3", x + 47f, y + 3.5f, Color.BLACK.getRGB()); + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (button == 0 && mouseX >= startX + managerWidth && mouseX <= startX + managerWidth + 5 + SCROLLBAR_WIDTH * 2) { + int scrollbarY = 50; + int scrollbarHeight = managerHeight - 18; + + if (mouseY >= scrollbarY && mouseY <= scrollbarY + scrollbarHeight) { + float scrollPercentage = (float) (mouseY - scrollbarY) / scrollbarHeight; + scrollOffset = (int) (maxScroll * scrollPercentage); + scrollOffset = MathHelper.clamp(scrollOffset, 0, maxScroll); + return true; + } } + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); } private void addTableEntries(){ @@ -237,21 +250,25 @@ private void addTableEntries(){ managerHeight = scaledHeight - 80; scriptTable = new Table(); - for (LuaFile luaFile: LuaScriptManager.luaFiles) { - scriptTable.addEntry(new ScriptEntry(luaFile),managerWidth * 0.88 - 15); + + if(showLocalScripts) { + for (LuaFile luaFile : LuaScriptManager.luaFiles) { + scriptTable.addEntry(new ScriptEntry(luaFile), managerWidth * 0.88 - 15); + } } } public void calculateTable() { float startEntryX = startX + (managerWidth * 0.20f) + 10; - maxScroll = (int) Math.ceil(scriptTable.adjustTableLayout(startEntryX, 65,managerWidth * 0.8 - 15,false)); + float availableWidth = managerWidth * 0.8f - 10 * 2 - SCROLLBAR_WIDTH; + int totalHeight = (int) Math.round(scriptTable.adjustTableLayout(startEntryX, 65, availableWidth, false)) + 10; + maxScroll = Math.max(0, totalHeight - (managerHeight - 18)); } public boolean hoveredOverRefreshAll(double mouseX, double mouseY) { return isMouseOver(mouseX, mouseY, scaledWidth - 125, 33, 15, 15); } - public boolean hoveredOverLocalScripts(double mouseX, double mouseY) { return isMouseOver(mouseX, mouseY, startX + 12, 66, managerWidth * 0.18f - 15, 20); } @@ -263,23 +280,6 @@ public boolean hoveredOverForceCloseAll(double mouseX, double mouseY) { return isMouseOver(mouseX, mouseY, startX + 12, 134, managerWidth * 0.18f - 15, 20); } - public boolean hoveredOverFileState(double mouseX, double mouseY, double entryX, double entryY) { - return isMouseOver(mouseX, mouseY, entryX + 26, entryY + 60, 16, 8); - } - - public boolean hoveredOverRefreshFile(double mouseX, double mouseY, double entryX, double entryY) { - return isMouseOver(mouseX, mouseY, entryX + 45f, entryY + 59.5f, 4 + FontRenderers.Small_iconRenderer.getStringWidth("\uEA75"), 8); - } - - public boolean hoveredOverEditFile(double mouseX, double mouseY, double entryX, double entryY) { - return isMouseOver(mouseX, mouseY, entryX + 46f, entryY + 3f, 4 + FontRenderers.Small_iconRenderer.getStringWidth("\uEAF3"), 8); - } - - public boolean hoveredOverBind(double mouseX, double mouseY, LuaFile file, double entryX, double entryY) { - String bindKeyName = KeyboardUtils.translateShort(file.bindKey).toUpperCase(); - return isMouseOver(mouseX, mouseY, entryX + 5f, entryY + 60f, FontRenderers.Small_fxfontRenderer.getStringWidth(bindKeyName) + 3, 7.4f); - } - @Override public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { scrollOffset = MathHelper.clamp(scrollOffset - (int) verticalAmount * 10, 0, maxScroll); // Clamp the scroll offset between 0 and maxScroll @@ -294,7 +294,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { for (TableEntry entry : row) { if (entry instanceof ScriptEntry scriptEntry) { LuaFile file = scriptEntry.getLuaFile(); - if (hoveredOverFileState(mouseX, mouseY, scriptEntry.getX(), scriptEntry.getY())) { + if (scriptEntry.hoveredOverFileState(mouseX, mouseY)) { SoundUtils.playInstanceSound(SoundUtils.CLICK_SOUNDEVENT); if (file.isLoaded()) { LuaScriptManager.INSTANCE.closeScript(file); @@ -302,15 +302,15 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { LuaScriptManager.INSTANCE.loadScript(file); } } - if (hoveredOverRefreshFile(mouseX, mouseY, scriptEntry.getX(), scriptEntry.getY())) { + if (scriptEntry.hoveredOverRefreshFile(mouseX, mouseY)) { LuaScriptManager.reloadScript(file); } - if (hoveredOverBind(mouseX, mouseY, file, scriptEntry.getX(), scriptEntry.getY())) { + if (scriptEntry.hoveredOverBind(mouseX, mouseY, file)) { file.setListening(true); isListening = true; } - if (hoveredOverEditFile(mouseX, mouseY, scriptEntry.getX(), scriptEntry.getY())) { + if (scriptEntry.hoveredOverEditFile(mouseX, mouseY)) { //Todo } } @@ -322,6 +322,9 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { } if (hoveredOverCloudScripts(mouseX, mouseY)) { showLocalScripts = false; + + // Cloud entries to be added yet + addTableEntries(); SoundUtils.playInstanceSound(SoundUtils.CLICK_SOUNDEVENT); } if (hoveredOverForceCloseAll(mouseX, mouseY)) { @@ -372,16 +375,16 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { } public class ScriptEntry implements TableEntry { - private final LuaFile luaFile; - private double x; - private double y; + private final LuaFile file; + private double entryX; + private double entryY; public ScriptEntry(LuaFile luaFile) { - this.luaFile = luaFile; + this.file = luaFile; } public LuaFile getLuaFile() { - return luaFile; + return file; } @Override @@ -396,19 +399,175 @@ public double getHeight() { @Override public void setPosition(double x, double y) { - this.x = x; - this.y = y; + this.entryX = x; + this.entryY = y; } @Override public void setWidth(double width) {} public double getX() { - return x; + return entryX; + } + + public boolean hoveredOverFileState(double mouseX, double mouseY) { + return isMouseOver(mouseX, mouseY, entryX + 26, getY() + 60, 16, 8); + } + + public boolean hoveredOverRefreshFile(double mouseX, double mouseY) { + return isMouseOver(mouseX, mouseY, entryX + 45f, getY() + 59.5f, 4 + FontRenderers.Small_iconRenderer.getStringWidth("\uEA75"), 8); + } + + public boolean hoveredOverEditFile(double mouseX, double mouseY) { + return isMouseOver(mouseX, mouseY, entryX + 46f, getY() + 3f, 4 + FontRenderers.Small_iconRenderer.getStringWidth("\uEAF3"), 8); + } + + public boolean hoveredOverBind(double mouseX, double mouseY, LuaFile file) { + String bindKeyName = KeyboardUtils.translateShort(file.bindKey).toUpperCase(); + return isMouseOver(mouseX, mouseY, entryX + 5f, getY() + 60f, FontRenderers.Small_fxfontRenderer.getStringWidth(bindKeyName) + 3, 7.4f); + } + + public void renderScript(DrawContext drawContext, float x, float y, int mouseX, int mouseY){ + float width = 60; + float height = 70; + + Renderer2D.drawRoundedRectangleWithShadow(drawContext.getMatrices(), + x, y, width, height, + 4, 4, + ColorUtils.changeAlpha(ColorManager.INSTANCE.ClickGuiPrimary().darker().darker(), 169).getRGB() + ); + + //Separating line + Renderer2D.drawRoundedRectangleWithShadow(drawContext.getMatrices(), + x, y, width,4.5f + Renderer2D.getCustomStringHeight(FontRenderers.Small_fxfontRenderer), 4,10, + Color.DARK_GRAY.darker().darker().darker().getRGB(), + Color.BLACK.getRGB(), + true,true,false,false + ); + + Renderer2D.drawOutlineGradientRoundedBox(drawContext.getMatrices().peek().getPositionMatrix(), x, y, width, height, 4, 0.7f, + ColorManager.INSTANCE.getPrimaryGradientStart(), + ColorManager.INSTANCE.getPrimaryGradientEnd(), + ColorManager.INSTANCE.getPrimaryGradientEnd(), + ColorManager.INSTANCE.getPrimaryGradientStart() + ); + + //Smaller Icon, in the future, different icons should be supported for different types of scripts. + FontRenderers.Small_iconRenderer.drawString(drawContext.getMatrices(), "\uF0F6", x + 3, y + 3, Color.WHITE.getRGB()); + + Renderer2D.drawRoundedGradientRectangle(drawContext.getMatrices().peek().getPositionMatrix(), + ColorManager.INSTANCE.getPrimaryGradientStart(), + ColorManager.INSTANCE.getPrimaryGradientEnd(), + ColorManager.INSTANCE.getPrimaryGradientEnd(), + ColorManager.INSTANCE.getPrimaryGradientStart(), + x, y + 58, width, 12, 3, false, false, true, true + ); + + //Name + FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), file.getScriptName(), + x + ((width + 1)/2.0f) - FontRenderers.Small_fxfontRenderer.getStringWidth(file.getScriptName()) / 2.0f, + y + 4, + Color.WHITE.getRGB() + ); + + //Separating line + /* + Renderer2D.drawRectangle(drawContext.getMatrices().peek().getPositionMatrix(), + x, y + 4.5f + Renderer2D.getCustomStringHeight(FontRenderers.Small_fxfontRenderer), width,0.7f, + ColorManager.INSTANCE.getPrimaryGradientStart().getRGB() + ); + + */ + + //Author + String author = "author245252"; + author = FontRenderers.Small_fxfontRenderer.trimToWidth(author,width/2 - 1); + + //Check if the author name matches the orignal auth + if(!author.equals("author245252")){ + if(isMouseOver(mouseX,mouseY,x + 3,y + 7, FontRenderers.Small_fxfontRenderer.getStringWidth(author) + 1,FontRenderers.Small_fxfontRenderer.getStringHeight(author) + 1)){ + //Display org author here: + Tooltip.tooltip.changeText("author245252"); + } + } + + FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), author, + x + 3, + y + 6 + Renderer2D.getCustomStringHeight(FontRenderers.Small_fxfontRenderer), + Color.MAGENTA.getRGB() + ); + + + FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), "v1.0.0", + x + width - FontRenderers.Small_fxfontRenderer.getStringWidth("v1.0.0") - 3, + y + 6 + Renderer2D.getCustomStringHeight(FontRenderers.Small_fxfontRenderer), + Color.GRAY.getRGB() + ); + + String desc = "Standard Description of script"; + float yOff = 16 + Renderer2D.getCustomStringHeight(FontRenderers.Small_fxfontRenderer); + for(String str: Renderer2D.wrapText(desc, Math.round(width - 4),FontRenderers.Small_fxfontRenderer)) { + FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), str, + x + width/2.0f - FontRenderers.Small_fxfontRenderer.getStringWidth(str)/2.0f, + y + yOff, + Color.LIGHT_GRAY.getRGB() + ); + yOff += FontRenderers.Small_fxfontRenderer.getStringHeight(str) + 1; + } + + //Bind + String bindKey = KeyboardUtils.translateShort(file.bindKey).toUpperCase(); + if (file.isListeningForBind) { + bindKey = "Set"; //I think we should change this to "..." + } + Renderer2D.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), + x + 4, + y + 60, + FontRenderers.Small_fxfontRenderer.getStringWidth(bindKey) + 3, + 8, + 2, + Color.BLACK.getRGB(), + 100, 1, 1 + ); + + FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(), bindKey, x + 4.9f, y + 60.5f, Color.WHITE.getRGB()); + + //File state (loaded/unloaded) + drawOnOffButton(drawContext, x + 26, y + 60, file.isLoaded()); + //Renderer2D.drawRoundedRectangle(drawContext.getMatrices().peek().getPositionMatrix(),xModified + 10, y + 60,FontRenderers.Small_fxfontRenderer.getStringWidth(file.isLoaded? "DISABLE":"ENABLE") + 3,7,2,Color.BLACK.getRGB()); + //FontRenderers.Small_fxfontRenderer.drawString(drawContext.getMatrices(),file.isLoaded? "DISABLE":"ENABLE",xModified + 10,y + 60.5f, file.isLoaded? Color.RED.getRGB() : Color.GREEN.getRGB()); + + //Refresh / Reload + Renderer2D.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), + x + 45, + y + 59.5f, + FontRenderers.Small_iconRenderer.getStringWidth("\uEA75") + 2, + 8, + 2, + Color.BLACK.getRGB(), + 100, 1, 1 + ); + + FontRenderers.Small_iconRenderer.drawString(drawContext.getMatrices(), "\uEA1D", x + 46, y + 60.5f, Color.WHITE.getRGB()); + + if (isMouseOver(mouseX, mouseY, x, y, 60, 70)) { + //Edit + Renderer2D.drawRoundedRectangleWithShadowBadWay(drawContext.getMatrices().peek().getPositionMatrix(), + x + 46, + y + 3, + FontRenderers.Small_iconRenderer.getStringWidth("\uEAF3") + 2, + 8, + 2, + Color.WHITE.getRGB(), + 100, 1, 1 + ); + + FontRenderers.Small_iconRenderer.drawString(drawContext.getMatrices(), "\uEAF3", x + 47f, y + 3.5f, Color.BLACK.getRGB()); + } } public double getY() { - return y - ScriptManagerScreen.this.scrollOffset; + return entryY - ScriptManagerScreen.this.scrollOffset; } } } \ No newline at end of file diff --git a/src/main/java/dev/heliosclient/util/ColorUtils.java b/src/main/java/dev/heliosclient/util/ColorUtils.java index 90582b51..94888ac9 100644 --- a/src/main/java/dev/heliosclient/util/ColorUtils.java +++ b/src/main/java/dev/heliosclient/util/ColorUtils.java @@ -260,14 +260,8 @@ public static int getBlue(int color) { * @return Boolean value if the string is color encoded or not */ public static boolean isHexColor(String value) { - if (value.startsWith("#")) { - value = value.substring(1); - } - if (value.length() != 6) { - return false; - } try { - Color.decode("#" + value); + Color.decode(value); return true; } catch (NumberFormatException e) { e.printStackTrace(); diff --git a/src/main/java/dev/heliosclient/util/blocks/HoleUtils.java b/src/main/java/dev/heliosclient/util/blocks/HoleUtils.java index 35403f1f..ef4924f4 100644 --- a/src/main/java/dev/heliosclient/util/blocks/HoleUtils.java +++ b/src/main/java/dev/heliosclient/util/blocks/HoleUtils.java @@ -8,13 +8,49 @@ import net.minecraft.util.math.Direction; import net.minecraft.world.World; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class HoleUtils { + // List of blocks considered blast-proof (cannot be destroyed by explosions) + static List blastProofBlocks = List.of(Blocks.BEDROCK, Blocks.OBSIDIAN, Blocks.ENDER_CHEST,Blocks.CRYING_OBSIDIAN); - public static Set getHoles(int range, int vRange) { + // Arrays to define the relative positions of blast-resistant blocks and air blocks in a quad hole + // North and south are on the Z axis + + // All three down below are configured using the 2D diagram, so the "0"th rel position of the block corresponds to the 0th element of these array. + // (That's why these are lookup tables) + static Direction[][] blastResistantOffset = new Direction[][]{ + {Direction.NORTH, Direction.WEST}, + {Direction.NORTH, Direction.EAST}, + {Direction.SOUTH, Direction.WEST}, + {Direction.SOUTH, Direction.EAST} + }; + + //This is basically "relPosNum" array but instead of byte, we use Direction to specify the relative pos offset + // (because it is easier to work with BlockPos this way) + static Direction[][] airOffset = new Direction[][]{ + {Direction.SOUTH, Direction.EAST}, + {Direction.SOUTH, Direction.WEST}, + {Direction.NORTH, Direction.EAST}, + {Direction.NORTH, Direction.WEST} + }; + + // Lookup table for relative position numbering in a quad hole + // This one is required because the above 2 arrays use index same as the block position (check the diagram). + static byte[][] relPosNum = new byte[][]{ + {2, 1}, + {3, 0}, + {0, 3}, + {1, 2} + }; + + /** + * Finds all holes within a given range around the player. + * @param range Horizontal range to search for holes + * @param vRange Vertical range to search for holes + * @return A set of HoleInfo objects representing found holes + */ + public static Set getHoles(int range, int vRange, boolean quadChecker) { Set holes = Collections.synchronizedSet(new HashSet<>()); BlockIterator iterator = new BlockIterator(HeliosClient.MC.player, range, vRange); Set checkedPositions = Collections.synchronizedSet(new HashSet<>()); @@ -23,7 +59,7 @@ public static Set getHoles(int range, int vRange) { BlockPos pos = iterator.next(); if (checkedPositions.contains(pos)) continue; - HoleInfo hole = getHoleType(HeliosClient.MC.world, pos, checkedPositions); + HoleInfo hole = getHoleType(HeliosClient.MC.world, pos, checkedPositions,quadChecker); if (hole != null) { holes.add(hole); } @@ -31,10 +67,151 @@ public static Set getHoles(int range, int vRange) { return holes; } - private static HoleInfo getHoleType(World world, BlockPos pos, Set checkedPositions) { + public static boolean isQuad(BlockPos pos, World world, Set checked) { + if (!world.isAir(pos)) return false; + + // This is to get the position of the pos as 0,1,2,3 instead of BlockPos (For lookup tables). + // Also, this is relative otherwise 4 quads will be displayed. + byte relPos = getRelativePosition(pos, world); + if (relPos < 0 || relPos > 3) return false; + + // Okay, so I will do the full 2D diagram I used to derive this algorithm (??): + + // Key short forms I used: + // "B" - Blast resistant block, "0,1,2,3" - look up for block offsets from the origin (which is the relPos byte) + // "N,S,E,W" respectively are the cardinal directions with the N facing this direction ^ for this diagram. + // All the arrays have been configured using the 2D representative of the quad hole. (Because we only check horizontally and down) + + // So, lets assume, the following diagram is our quad hole. So in this, if we search from the pos number "0", + // then we will first check if the "B" around pos 0 are solid or not, at the same time we check if 1 and 2 is air or not (for pos 0). + // If one of these conditions fail (i.e. 1 and 2 are not air OR "0" is not covered by B blocks) + // Then using the offset of X and Z from 1 and 2 (respectively) we get the diagonal block 3 (pythagoras). + // Before checking if 1 and 2 is covered by B, we check if 3 is air and if it is covered by B blocks. + // This is to do early return, so that we don't waste time for checking 1 and 2 as well. + // Using the Lookup tables (the static arrays defined above), we check with the same above algorithm (??). + // Use of byte is enough since we only need to go from 0 to 3 at max. + // This might be complex (who even knows to use D.D Arrays) and unnecessary but, I thought of this while sleeping and the anxiety got to me. + // B B + // - - - - - - - - - + // B | | | B + // | 0 | 1 | + // |- - - - | - - - -| + // | | | + // B | 2 | 3 | B + // - - - - - - - - - + // B B + + // Note: In all the arrays above, the first element is for Z position and the second element is for X position. + + // And at last, this is kind of better than running loops or using BlockPos offsets to check (sometimes recursive). + // All of this becomes linear and checks 2 things at once. + + // P.S If you remove the check for diagonals, and with a few more tweaks, you could make it show Triples as well. + + return checkQuadCorners(relPos, world, pos, checked); + } + + /** + * Determines the relative position of a block in a potential quad hole. + * @param pos The position to check + * @param world The world in which to check + * @return A byte representing the relative position, or -1 if not part of a quad hole + */ + private static byte getRelativePosition(BlockPos pos, World world) { + byte relPos = -1; + + boolean northBlastProof = isBlastProof(world.getBlockState(pos.north()).getBlock()); + boolean southBlastProof = isBlastProof(world.getBlockState(pos.south()).getBlock()); + boolean westBlastProof = isBlastProof(world.getBlockState(pos.west()).getBlock()); + boolean eastBlastProof = isBlastProof(world.getBlockState(pos.east()).getBlock()); + + // Determine the relative position based on blast-proof and air blocks + if (northBlastProof && world.isAir(pos.south())) relPos = 0; + else if (southBlastProof && world.isAir(pos.north())) relPos = 2; + + if (westBlastProof && world.isAir(pos.east())) return relPos; + else if (eastBlastProof && world.isAir(pos.west()) && relPos != -1) return (byte)(relPos + 1); + + return relPos; + } + + /** + * Checks all corners of a potential quad hole. + * @param relPos The relative position of the initial block + * @param world The world in which to check + * @param origin The origin position of the potential quad hole + * @param checked Set of already checked positions + * @return true if all corners form a valid quad hole, false otherwise + */ + private static boolean checkQuadCorners(byte relPos, World world, BlockPos origin, Set checked) { + // Check the diagonal position + BlockPos diagPos = origin.offset(airOffset[relPos][0]).offset(airOffset[relPos][1]); + Direction[] blastResisOffset = blastResistantOffset[3 - relPos]; + + Block diagXBlock = world.getBlockState(diagPos.offset(blastResisOffset[1])).getBlock(); + Block diagZBlock = world.getBlockState(diagPos.offset(blastResisOffset[0])).getBlock(); + + // If diagonal position isn't air or isn't surrounded by blast-proof blocks or the block below it is not blast-proof then it's not a quad hole + if (!world.isAir(diagPos) || !checkIfIsBlastProof(diagXBlock,diagZBlock) || /* This checks below the diag Block */ !isBlastProof(world.getBlockState(diagPos.down()).getBlock())) return false; + + addToChecked(checked, diagPos); + + // Check the other two corners + byte airOffX = relPosNum[relPos][1]; + byte airOffZ = relPosNum[relPos][0]; + //System.out.println(airOffX + " airOffX"); + //System.out.println(airOffZ + " airOffZ"); + + return checkCorner(world, origin, airOffX,relPos,checked,false) && checkCorner(world, origin, airOffZ,relPos, checked,true); + } + + private static boolean checkCorner(World world, BlockPos origin, byte airOff,byte relPos, Set checked, boolean isZ) { + Direction[] blastResistOff = blastResistantOffset[airOff]; + BlockPos airPos = origin.offset(airOffset[relPos][isZ ? 0 : 1]); + + BlockPos xPos = airPos.offset(blastResistOff[1]); + BlockPos zPos = airPos.offset(blastResistOff[0]); + + Block xBlock = world.getBlockState(xPos).getBlock(); + Block zBlock = world.getBlockState(zPos).getBlock(); + + addToChecked(checked, airPos, xPos, zPos); + + // We don't need to check if the block is air because we already did in the getRelativePosition() (except for the diagonal); + + // If the air position isn't surrounded by blast-proof blocks + // or the block below it is not blast-proof then it's not a valid corner + return checkIfIsBlastProof(xBlock,zBlock) && isBlastProof(world.getBlockState(airPos.down()).getBlock()); + } + + private static void addToChecked(Set checked, BlockPos... positions) { + checked.addAll(Arrays.asList(positions)); + } + + private static boolean checkIfIsBlastProof(Block pos1, Block pos2){ + return isBlastProof(pos1) && isBlastProof(pos2); + } + + private static boolean isBlastProof(Block block){ + return blastProofBlocks.contains(block); + } + + private static HoleInfo getHoleType(World world, BlockPos pos, Set checkedPositions, boolean quadChecker) { if (!world.getBlockState(pos).isAir() || !world.getBlockState(pos.up()).isAir() || checkedPositions.contains(pos)) { return null; } + + + if (quadChecker && isQuad(pos, world,checkedPositions)) { + //System.out.println("QUAD: " + pos); + + //Return a box containing all the four poses. + BlockPos start = pos.offset(airOffset[0][0]).offset(airOffset[0][1]); + checkedPositions.add(pos); + + return new HoleInfo(HoleType.UNSAFE, pos, new Box(pos).union(new Box(start)).contract(0.005f, 0f, 0.005f).offset(0, 0.005f, 0)); + } + checkedPositions.add(pos); HoleType hT = null; diff --git a/src/main/java/dev/heliosclient/util/fontutils/FontRenderers.java b/src/main/java/dev/heliosclient/util/fontutils/FontRenderers.java index c204018d..c92ea2b2 100644 --- a/src/main/java/dev/heliosclient/util/fontutils/FontRenderers.java +++ b/src/main/java/dev/heliosclient/util/fontutils/FontRenderers.java @@ -3,24 +3,51 @@ import me.x150.renderer.font.FontRenderer; public class FontRenderers { + /** This fontRenderer is used by the HUD mainly through the Renderer2D drawing string functions */ public static FontRenderer fontRenderer; - public static fxFontRenderer iconRenderer; + + /** + * These font renderers are standard font renderer for the clickGUI, whose size is modified by the user + * (except the iconRenderer which is at 10f) + */ public static fxFontRenderer fxfontRenderer; + public static fxFontRenderer iconRenderer; + + /** + * This fontRenderer uses the DComicFont font for HitEffect Text mode + * Size: 12f + */ + public static fxFontRenderer Comical_fxfontRenderer; + + // -- These fontRenderers have fixed size which cannot be changed. -- // + + /** + * Size 4f + */ public static fxFontRenderer Super_Small_iconRenderer; public static fxFontRenderer Super_Small_fxfontRenderer; + + /** + * Size 6f + */ public static fxFontRenderer Small_iconRenderer; public static fxFontRenderer Small_fxfontRenderer; + /** + * Size 8f + */ public static fxFontRenderer Mid_iconRenderer; public static fxFontRenderer Mid_fxfontRenderer; + /** + * Size 13f + */ public static fxFontRenderer Large_iconRenderer; public static fxFontRenderer Large_fxfontRenderer; - public static fxFontRenderer Comical_fxfontRenderer; - - + /** + * Size 25f + */ public static fxFontRenderer Ultra_Large_iconRenderer; - } diff --git a/src/main/java/dev/heliosclient/util/fontutils/fxFontRenderer.java b/src/main/java/dev/heliosclient/util/fontutils/fxFontRenderer.java index 0e84de83..ff36c010 100644 --- a/src/main/java/dev/heliosclient/util/fontutils/fxFontRenderer.java +++ b/src/main/java/dev/heliosclient/util/fontutils/fxFontRenderer.java @@ -1,11 +1,15 @@ package dev.heliosclient.util.fontutils; import dev.heliosclient.util.ColorUtils; +import dev.heliosclient.util.render.Renderer2D; import me.x150.renderer.font.FontRenderer; import net.minecraft.client.util.math.MatrixStack; import java.awt.*; +/** + * fx means Fixed, originally was made for rendering with fixed sizes. + */ public class fxFontRenderer extends FontRenderer { /** @@ -24,6 +28,8 @@ public fxFontRenderer(Font[] fonts, float sizePx) { * @param text The text to trim. * @param width The maximum width of the rendered text. * @return The trimmed text. + * + * @see dev.heliosclient.util.render.Renderer2D#wrapText(String, int, fxFontRenderer) , int) */ public String trimToWidth(String text, float width) { float textWidth = this.getStringWidth(text); @@ -39,8 +45,13 @@ public String trimToWidth(String text, float width) { } } - public void drawString(MatrixStack matrixStack, String text, float x, float y, int color) { + public void drawString(MatrixStack matrixStack, String text, float x, float y, float scale, int color) { + Renderer2D.scaleAndPosition(matrixStack,x,y,scale); + this.drawString(matrixStack,text,x,y,color); + Renderer2D.stopScaling(matrixStack); + } + public void drawString(MatrixStack matrixStack, String text, float x, float y, int color) { int r = 256 - ColorUtils.getRed(color); int g = 256 - ColorUtils.getGreen(color); int b = 256 - ColorUtils.getBlue(color); @@ -60,7 +71,10 @@ public void drawCenteredString(MatrixStack stack, String s, float x, float y, in int b = 256 - ColorUtils.getBlue(color); int a = 256 - ColorUtils.getAlpha(color); - super.drawCenteredString(stack, s, x, y, r, g, b, a); + try { + super.drawCenteredString(stack, s, x, y, r, g, b, a); + } catch (NullPointerException ignored) { + } } } diff --git a/src/main/java/dev/heliosclient/util/inputbox/InputBox.java b/src/main/java/dev/heliosclient/util/inputbox/InputBox.java index dbe1e409..d030bd32 100644 --- a/src/main/java/dev/heliosclient/util/inputbox/InputBox.java +++ b/src/main/java/dev/heliosclient/util/inputbox/InputBox.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.regex.Pattern; public class InputBox implements Listener { @@ -39,6 +40,9 @@ public class InputBox implements Listener { protected boolean selectedAll = false; protected Screen screen; + /** This supplier is called before the user un-focuses the inputbox (by pressing enter), if false is returned then it won't un-focus. */ + public Supplier enterTask = ()->true; + public InputBox(int width, int height, String value, int characterLimit, InputMode inputMode) { this.width = width; this.height = height; @@ -81,7 +85,9 @@ public void keyHeld(KeyHeldEvent event) { } case GLFW.GLFW_KEY_ENTER, GLFW.GLFW_KEY_KP_ENTER -> { + if(enterTask.get()){ focused = false; + } } } }