From 4e4058da31c3575b69c69d2d7bb3c9af29e248dc Mon Sep 17 00:00:00 2001 From: ThatGravyBoat Date: Thu, 15 Jul 2021 04:07:36 +0000 Subject: Prettified Code! --- .../com/thatgravyboat/skyblockhud/SkyblockHud.java | 8 +- .../java/com/thatgravyboat/skyblockhud/Utils.java | 2 +- .../api/events/SkyBlockEntityKilled.java | 1 + .../api/sbentities/EntityTypeHelper.java | 11 +- .../skyblockhud/config/SBHConfig.java | 9 +- .../skyblockhud/config/SBHConfigEditor.java | 30 +- .../skyblockhud/core/BackgroundBlur.java | 58 ++-- .../skyblockhud/core/ChromaColour.java | 20 +- .../skyblockhud/core/GlScissorStack.java | 23 +- .../thatgravyboat/skyblockhud/core/GuiElement.java | 4 +- .../skyblockhud/core/GuiElementBoolean.java | 44 ++- .../skyblockhud/core/GuiElementColour.java | 237 +++++++-------- .../skyblockhud/core/GuiElementTextField.java | 336 ++++++++++----------- .../skyblockhud/core/config/Config.java | 4 +- .../skyblockhud/core/config/KeybindHelper.java | 25 +- .../config/annotations/ConfigEditorKeybind.java | 2 - .../core/config/gui/GuiOptionEditor.java | 22 +- .../core/config/gui/GuiOptionEditorAccordion.java | 20 +- .../core/config/gui/GuiOptionEditorBoolean.java | 11 +- .../core/config/gui/GuiOptionEditorButton.java | 19 +- .../core/config/gui/GuiOptionEditorColour.java | 36 +-- .../config/gui/GuiOptionEditorDraggableList.java | 148 ++++----- .../core/config/gui/GuiOptionEditorDropdown.java | 79 +++-- .../core/config/gui/GuiOptionEditorKeybind.java | 31 +- .../core/config/gui/GuiOptionEditorSlider.java | 97 +++--- .../core/config/gui/GuiOptionEditorText.java | 34 +-- .../core/config/gui/GuiPositionEditor.java | 55 ++-- .../core/config/struct/ConfigProcessor.java | 89 +++--- .../skyblockhud/core/util/GuiElementSlider.java | 58 ++-- .../skyblockhud/core/util/StringUtils.java | 1 - .../skyblockhud/core/util/lerp/LerpUtils.java | 11 +- .../skyblockhud/core/util/lerp/LerpingFloat.java | 16 +- .../skyblockhud/core/util/lerp/LerpingInteger.java | 16 +- .../core/util/render/TextRenderUtils.java | 20 +- .../skyblockhud/handlers/SlayerHandler.java | 4 +- .../mixins/MixinNetHandlerPlayClient.java | 7 +- .../skyblockhud/overlay/GenericOverlays.java | 6 +- .../skyblockhud/tracker/TrackerFileLoader.java | 66 ++-- .../skyblockhud/tracker/TrackerHandler.java | 13 +- .../skyblockhud/tracker/TrackerObject.java | 8 +- 40 files changed, 777 insertions(+), 904 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java index 1cb00bb..7e1f215 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java @@ -129,21 +129,19 @@ public class SkyblockHud { // DISABLE UNTIL NEW SYSTEM @EventHandler - public void loadComplete(FMLLoadCompleteEvent event){ + public void loadComplete(FMLLoadCompleteEvent event) { TrackerFileLoader.loadTrackersFile(); - if (TrackerFileLoader.loadTrackerStatsFile(configDirectory)){ + if (TrackerFileLoader.loadTrackerStatsFile(configDirectory)) { TrackerFileLoader.saveTrackerStatsFile(configDirectory); } } @SubscribeEvent - public void onLeaveServer(FMLNetworkEvent.ClientDisconnectionFromServerEvent event){ + public void onLeaveServer(FMLNetworkEvent.ClientDisconnectionFromServerEvent event) { TrackerFileLoader.saveTrackerStatsFile(configDirectory); } - - public static boolean hasSkyblockScoreboard() { Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/Utils.java b/src/main/java/com/thatgravyboat/skyblockhud/Utils.java index 157077b..f65af86 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/Utils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/Utils.java @@ -361,6 +361,6 @@ public class Utils { public static String formattedNumber(int number, int numberToFormatAt) { DecimalFormat formatter = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); formatter.setRoundingMode(RoundingMode.FLOOR); - return number > numberToFormatAt-1 ? formatter.format((double) number / 1000) + "k" : String.valueOf(number); + return number > numberToFormatAt - 1 ? formatter.format((double) number / 1000) + "k" : String.valueOf(number); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java index 15fb01a..61f8d82 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SkyBlockEntityKilled.java @@ -7,6 +7,7 @@ import net.minecraftforge.fml.common.eventhandler.Event; public class SkyBlockEntityKilled extends Event { public String id; + @Nullable public Entity entity; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java b/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java index 8dc63c8..bb14e5d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/sbentities/EntityTypeHelper.java @@ -21,17 +21,14 @@ public class EntityTypeHelper { return false; } - public static boolean isCrypt(Entity entity){ + public static boolean isCrypt(Entity entity) { if (entity instanceof EntityZombie) { EntityZombie zombie = ((EntityZombie) entity); double maxHealthBase = zombie.getAttributeMap().getAttributeInstanceByName("generic.maxHealth").getBaseValue(); if (maxHealthBase != 2000d) return false; - if (zombie.getEquipmentInSlot(0) == null || !zombie.getEquipmentInSlot(0).getItem().equals(Items.iron_sword)) - return false; - if (zombie.getEquipmentInSlot(1) == null || !zombie.getEquipmentInSlot(1).getItem().equals(Items.chainmail_boots)) - return false; - if (zombie.getEquipmentInSlot(2) == null || !zombie.getEquipmentInSlot(2).getItem().equals(Items.chainmail_leggings)) - return false; + if (zombie.getEquipmentInSlot(0) == null || !zombie.getEquipmentInSlot(0).getItem().equals(Items.iron_sword)) return false; + if (zombie.getEquipmentInSlot(1) == null || !zombie.getEquipmentInSlot(1).getItem().equals(Items.chainmail_boots)) return false; + if (zombie.getEquipmentInSlot(2) == null || !zombie.getEquipmentInSlot(2).getItem().equals(Items.chainmail_leggings)) return false; return zombie.getEquipmentInSlot(3) != null && zombie.getEquipmentInSlot(3).getItem().equals(Items.chainmail_chestplate); } return false; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java index 9b42192..04d4a8c 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java @@ -96,13 +96,8 @@ public class SBHConfig extends Config { public boolean hideScoreboard = false; @Expose - @ConfigOption( - name = "Bar Textures", - desc = "Change the style of bars. Dont change this unless the pack ur using tells you can." - ) - @ConfigEditorDropdown( - values = {"Style 1", "Style 2"} - ) + @ConfigOption(name = "Bar Textures", desc = "Change the style of bars. Dont change this unless the pack ur using tells you can.") + @ConfigEditorDropdown(values = { "Style 1", "Style 2" }) public int barTexture = 0; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java index 90325f8..1130370 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java @@ -1,5 +1,8 @@ package com.thatgravyboat.skyblockhud.config; +import static com.thatgravyboat.skyblockhud.GuiTextures.DISCORD; +import static com.thatgravyboat.skyblockhud.GuiTextures.TWITTER; + import com.google.common.collect.Lists; import com.thatgravyboat.skyblockhud.core.GlScissorStack; import com.thatgravyboat.skyblockhud.core.GuiElement; @@ -13,8 +16,8 @@ import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; import com.thatgravyboat.skyblockhud.core.util.render.TextRenderUtils; import java.awt.*; import java.net.URI; -import java.util.List; import java.util.*; +import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -25,9 +28,6 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import static com.thatgravyboat.skyblockhud.GuiTextures.DISCORD; -import static com.thatgravyboat.skyblockhud.GuiTextures.TWITTER; - public class SBHConfigEditor extends GuiElement { private static final ResourceLocation[] socialsIco = new ResourceLocation[] { DISCORD, TWITTER }; @@ -237,11 +237,11 @@ public class SBHConfigEditor extends GuiElement { for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; if (option.accordionId >= 0) { - if(!activeAccordions.containsKey(option.accordionId)) { + if (!activeAccordions.containsKey(option.accordionId)) { continue; } int accordionDepth = activeAccordions.get(option.accordionId); - optionWidth = optionWidthDefault - (2 * innerPadding)*(accordionDepth + 1); + optionWidth = optionWidthDefault - (2 * innerPadding) * (accordionDepth + 1); } GuiOptionEditor editor = option.editor; @@ -253,7 +253,7 @@ public class SBHConfigEditor extends GuiElement { if (accordion.getToggled()) { int accordionDepth = 0; if (option.accordionId >= 0) { - accordionDepth = activeAccordions.get(option.accordionId)+1; + accordionDepth = activeAccordions.get(option.accordionId) + 1; } activeAccordions.put(accordion.getAccordionId(), accordionDepth); } @@ -300,7 +300,7 @@ public class SBHConfigEditor extends GuiElement { if (accordion.getToggled()) { int accordionDepth = 0; if (option.accordionId >= 0) { - accordionDepth = activeAccordions.get(option.accordionId)+1; + accordionDepth = activeAccordions.get(option.accordionId) + 1; } activeAccordions.put(accordion.getAccordionId(), accordionDepth); } @@ -431,7 +431,7 @@ public class SBHConfigEditor extends GuiElement { if (accordion.getToggled()) { int accordionDepth = 0; if (option.accordionId >= 0) { - accordionDepth = activeAccordions.get(option.accordionId)+1; + accordionDepth = activeAccordions.get(option.accordionId) + 1; } activeAccordions.put(accordion.getAccordionId(), accordionDepth); } @@ -491,7 +491,7 @@ public class SBHConfigEditor extends GuiElement { continue; } int accordionDepth = activeAccordions.get(option.accordionId); - optionWidth = optionWidthDefault - (2*innerPadding)*(accordionDepth+1); + optionWidth = optionWidthDefault - (2 * innerPadding) * (accordionDepth + 1); } GuiOptionEditor editor = option.editor; @@ -503,7 +503,7 @@ public class SBHConfigEditor extends GuiElement { if (accordion.getToggled()) { int accordionDepth = 0; if (option.accordionId >= 0) { - accordionDepth = activeAccordions.get(option.accordionId)+1; + accordionDepth = activeAccordions.get(option.accordionId) + 1; } activeAccordions.put(accordion.getAccordionId(), accordionDepth); } @@ -528,7 +528,7 @@ public class SBHConfigEditor extends GuiElement { continue; } int accordionDepth = activeAccordions.get(option.accordionId); - optionWidth = optionWidthDefault - (2*innerPadding)*(accordionDepth+1); + optionWidth = optionWidthDefault - (2 * innerPadding) * (accordionDepth + 1); } GuiOptionEditor editor = option.editor; @@ -540,7 +540,7 @@ public class SBHConfigEditor extends GuiElement { if (accordion.getToggled()) { int accordionDepth = 0; if (option.accordionId >= 0) { - accordionDepth = activeAccordions.get(option.accordionId)+1; + accordionDepth = activeAccordions.get(option.accordionId) + 1; } activeAccordions.put(accordion.getAccordionId(), accordionDepth); } @@ -586,7 +586,7 @@ public class SBHConfigEditor extends GuiElement { if (accordion.getToggled()) { int accordionDepth = 0; if (option.accordionId >= 0) { - accordionDepth = activeAccordions.get(option.accordionId)+1; + accordionDepth = activeAccordions.get(option.accordionId) + 1; } activeAccordions.put(accordion.getAccordionId(), accordionDepth); } @@ -599,4 +599,4 @@ public class SBHConfigEditor extends GuiElement { return true; } -} \ No newline at end of file +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java index f143b97..64f04fe 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java @@ -23,6 +23,7 @@ import org.lwjgl.opengl.GL30; public class BackgroundBlur { private static class OutputStuff { + public Framebuffer framebuffer; public Shader blurShaderHorz = null; public Shader blurShaderVert = null; @@ -41,8 +42,9 @@ public class BackgroundBlur { private static int fogColour = 0; private static boolean registered = false; + public static void registerListener() { - if(!registered) { + if (!registered) { registered = true; MinecraftForge.EVENT_BUS.register(new BackgroundBlur()); } @@ -69,18 +71,21 @@ public class BackgroundBlur { int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; - OutputStuff output = blurOutput.computeIfAbsent(blur, k -> { - Framebuffer fb = new Framebuffer(width, height, false); - fb.setFramebufferFilter(GL11.GL_NEAREST); - return new OutputStuff(fb, null, null); - }); + OutputStuff output = blurOutput.computeIfAbsent( + blur, + k -> { + Framebuffer fb = new Framebuffer(width, height, false); + fb.setFramebufferFilter(GL11.GL_NEAREST); + return new OutputStuff(fb, null, null); + } + ); - if(output.framebuffer.framebufferWidth != width || output.framebuffer.framebufferHeight != height) { + if (output.framebuffer.framebufferWidth != width || output.framebuffer.framebufferHeight != height) { output.framebuffer.createBindFramebuffer(width, height); - if(output.blurShaderHorz != null) { + if (output.blurShaderHorz != null) { output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); } - if(output.blurShaderVert != null) { + if (output.blurShaderVert != null) { output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); } } @@ -105,7 +110,7 @@ public class BackgroundBlur { @SubscribeEvent(priority = EventPriority.HIGHEST) public void onScreenRender(RenderGameOverlayEvent.Pre event) { - if(event.type == RenderGameOverlayEvent.ElementType.ALL) { + if (event.type == RenderGameOverlayEvent.ElementType.ALL) { processBlurs(); } } @@ -141,7 +146,7 @@ public class BackgroundBlur { } private static void blurBackground(OutputStuff output, float blurFactor) { - if(!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; + if (!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; @@ -153,36 +158,34 @@ public class BackgroundBlur { GlStateManager.loadIdentity(); GlStateManager.translate(0.0F, 0.0F, -2000.0F); - if(blurOutputHorz == null) { + if (blurOutputHorz == null) { blurOutputHorz = new Framebuffer(width, height, false); blurOutputHorz.setFramebufferFilter(GL11.GL_NEAREST); } - if(blurOutputHorz == null || output == null) { + if (blurOutputHorz == null || output == null) { return; } - if(blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { + if (blurOutputHorz.framebufferWidth != width || blurOutputHorz.framebufferHeight != height) { blurOutputHorz.createBindFramebuffer(width, height); Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); } - if(output.blurShaderHorz == null) { + if (output.blurShaderHorz == null) { try { - output.blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - output.framebuffer, blurOutputHorz); + output.blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", output.framebuffer, blurOutputHorz); output.blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); output.blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception ignored) { } + } catch (Exception ignored) {} } - if(output.blurShaderVert == null) { + if (output.blurShaderVert == null) { try { - output.blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - blurOutputHorz, output.framebuffer); + output.blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", blurOutputHorz, output.framebuffer); output.blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); output.blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception ignored) { } + } catch (Exception ignored) {} } - if(output.blurShaderHorz != null && output.blurShaderVert != null) { - if(output.blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { + if (output.blurShaderHorz != null && output.blurShaderVert != null) { + if (output.blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { //Corrupted shader? return; } @@ -193,9 +196,7 @@ public class BackgroundBlur { GL11.glPushMatrix(); GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, Minecraft.getMinecraft().getFramebuffer().framebufferObject); GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, output.framebuffer.framebufferObject); - GL30.glBlitFramebuffer(0, 0, width, height, - 0, 0, output.framebuffer.framebufferWidth, output.framebuffer.framebufferHeight, - GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); + GL30.glBlitFramebuffer(0, 0, width, height, 0, 0, output.framebuffer.framebufferWidth, output.framebuffer.framebufferHeight, GL11.GL_COLOR_BUFFER_BIT, GL11.GL_NEAREST); output.blurShaderHorz.loadShader(0); output.blurShaderVert.loadShader(0); @@ -228,7 +229,7 @@ public class BackgroundBlur { if (blurOutput.isEmpty()) return; OutputStuff out = blurOutput.get(blurStrength); - if(out == null) { + if (out == null) { out = blurOutput.values().iterator().next(); } @@ -245,5 +246,4 @@ public class BackgroundBlur { out.framebuffer.unbindFramebufferTexture(); GlStateManager.depthMask(true); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java b/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java index b9f4e79..d43e8b9 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/ChromaColour.java @@ -25,9 +25,8 @@ public class ChromaColour { int[] arr = new int[split.length]; - - for(int i=0; i 0) { + if (chr > 0) { float seconds = getSecondsForSpeed(chr); - hsv[0] += (System.currentTimeMillis()-startTime)/1000f/seconds; + hsv[0] += (System.currentTimeMillis() - startTime) / 1000f / seconds; hsv[0] %= 1; - if(hsv[0] < 0) hsv[0] += 1; + if (hsv[0] < 0) hsv[0] += 1; } return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); @@ -85,11 +85,9 @@ public class ChromaColour { float[] hsv = Color.RGBtoHSB(r, g, b, null); - hsv[0] += degrees/360f; + hsv[0] += degrees / 360f; hsv[0] %= 1; return (a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF); } - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java index 6f21e9a..0e1694e 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GlScissorStack.java @@ -1,14 +1,14 @@ package com.thatgravyboat.skyblockhud.core; +import java.util.LinkedList; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import org.lwjgl.opengl.GL11; -import java.util.LinkedList; - public class GlScissorStack { private static class Bounds { + int left; int top; int right; @@ -27,10 +27,10 @@ public class GlScissorStack { right = Math.min(right, this.right); bottom = Math.min(bottom, this.bottom); - if(top > bottom) { + if (top > bottom) { top = bottom; } - if(left > right) { + if (left > right) { left = right; } @@ -40,39 +40,39 @@ public class GlScissorStack { public void set(ScaledResolution scaledResolution) { int height = Minecraft.getMinecraft().displayHeight; int scale = scaledResolution.getScaleFactor(); - GL11.glScissor(left*scale, height-bottom*scale, (right-left)*scale, (bottom-top)*scale); + GL11.glScissor(left * scale, height - bottom * scale, (right - left) * scale, (bottom - top) * scale); } } private static final LinkedList boundsStack = new LinkedList<>(); public static void push(int left, int top, int right, int bottom, ScaledResolution scaledResolution) { - if(right < left) { + if (right < left) { int temp = right; right = left; left = temp; } - if(bottom < top) { + if (bottom < top) { int temp = bottom; bottom = top; top = temp; } - if(boundsStack.isEmpty()) { + if (boundsStack.isEmpty()) { boundsStack.push(new Bounds(left, top, right, bottom)); } else { boundsStack.push(boundsStack.peek().createSubBound(left, top, right, bottom)); } - if(!boundsStack.isEmpty()) { + if (!boundsStack.isEmpty()) { boundsStack.peek().set(scaledResolution); } GL11.glEnable(GL11.GL_SCISSOR_TEST); } public static void pop(ScaledResolution scaledResolution) { - if(!boundsStack.isEmpty()) { + if (!boundsStack.isEmpty()) { boundsStack.pop(); } - if(boundsStack.isEmpty()) { + if (boundsStack.isEmpty()) { GL11.glDisable(GL11.GL_SCISSOR_TEST); } else { boundsStack.peek().set(scaledResolution); @@ -83,5 +83,4 @@ public class GlScissorStack { boundsStack.clear(); GL11.glDisable(GL11.GL_SCISSOR_TEST); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java index ff817cf..e8d9d62 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java @@ -2,9 +2,11 @@ package com.thatgravyboat.skyblockhud.core; import net.minecraft.client.gui.Gui; -public abstract class GuiElement extends Gui { +public abstract class GuiElement extends Gui { public abstract void render(); + public abstract boolean mouseInput(int mouseX, int mouseY); + public abstract boolean keyboardInput(); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java index 7c401ed..8daf4b1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java @@ -37,7 +37,7 @@ public class GuiElementBoolean extends GuiElement { this.toggleCallback = toggleCallback; this.lastMillis = System.currentTimeMillis(); - if(value) animation = 36; + if (value) animation = 36; } @Override @@ -51,58 +51,56 @@ public class GuiElementBoolean extends GuiElement { long deltaMillis = currentMillis - lastMillis; lastMillis = currentMillis; boolean passedLimit = false; - if(previewValue != value) { - if((previewValue && animation > 12) || - (!previewValue && animation < 24)) { + if (previewValue != value) { + if ((previewValue && animation > 12) || (!previewValue && animation < 24)) { passedLimit = true; } } - if(previewValue != passedLimit) { - animation += deltaMillis/10; + if (previewValue != passedLimit) { + animation += deltaMillis / 10; } else { - animation -= deltaMillis/10; + animation -= deltaMillis / 10; } - lastMillis -= deltaMillis%10; + lastMillis -= deltaMillis % 10; - if(previewValue == value) { + if (previewValue == value) { animation = Math.max(0, Math.min(36, animation)); - } else if(!passedLimit) { - if(previewValue) { + } else if (!passedLimit) { + if (previewValue) { animation = Math.max(0, Math.min(12, animation)); } else { animation = Math.max(24, Math.min(36, animation)); } } else { - if(previewValue) { + if (previewValue) { animation = Math.max(12, animation); } else { animation = Math.min(24, animation); } } - int animation = (int)(LerpUtils.sigmoidZeroOne(this.animation/36f)*36); - if(animation < 3) { + int animation = (int) (LerpUtils.sigmoidZeroOne(this.animation / 36f) * 36); + if (animation < 3) { buttonLoc = GuiTextures.OFF; - } else if(animation < 13) { + } else if (animation < 13) { buttonLoc = GuiTextures.ONE; - } else if(animation < 23) { + } else if (animation < 23) { buttonLoc = GuiTextures.TWO; - } else if(animation < 33) { + } else if (animation < 33) { buttonLoc = GuiTextures.THREE; } Minecraft.getMinecraft().getTextureManager().bindTexture(buttonLoc); - RenderUtils.drawTexturedRect(x+animation, y, 12, 14); + RenderUtils.drawTexturedRect(x + animation, y, 12, 14); } @Override public boolean mouseInput(int mouseX, int mouseY) { - if(mouseX > x-clickRadius && mouseX < x+xSize+clickRadius && - mouseY > y-clickRadius && mouseY < y+ySize+clickRadius) { - if(Mouse.getEventButton() == 0) { - if(Mouse.getEventButtonState()) { + if (mouseX > x - clickRadius && mouseX < x + xSize + clickRadius && mouseY > y - clickRadius && mouseY < y + ySize + clickRadius) { + if (Mouse.getEventButton() == 0) { + if (Mouse.getEventButtonState()) { previewValue = !value; - } else if(previewValue == !value) { + } else if (previewValue == !value) { value = !value; toggleCallback.accept(value); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java index e2d3e0a..27a1d84 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java @@ -45,17 +45,15 @@ public class GuiElementColour extends GuiElement { private final boolean opacitySlider; private final boolean valueSlider; - public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, - Runnable closeCallback) { + public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, Runnable closeCallback) { this(x, y, initialColour, colourChangedCallback, closeCallback, true, true); } - public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, - Runnable closeCallback, boolean opacitySlider, boolean valueSlider) { + public GuiElementColour(int x, int y, String initialColour, Consumer colourChangedCallback, Runnable closeCallback, boolean opacitySlider, boolean valueSlider) { final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - this.y = Math.max(10, Math.min(scaledResolution.getScaledHeight()-ySize-10, y)); - this.x = Math.max(10, Math.min(scaledResolution.getScaledWidth()-xSize-10, x)); + this.y = Math.max(10, Math.min(scaledResolution.getScaledHeight() - ySize - 10, y)); + this.x = Math.max(10, Math.min(scaledResolution.getScaledWidth() - xSize - 10, x)); this.colour = initialColour; this.colourChangedCallback = colourChangedCallback; @@ -69,13 +67,13 @@ public class GuiElementColour extends GuiElement { this.opacitySlider = opacitySlider; this.valueSlider = valueSlider; - if(!valueSlider) xSize -= 15; - if(!opacitySlider) xSize -= 15; + if (!valueSlider) xSize -= 15; + if (!opacitySlider) xSize -= 15; } public void updateAngleAndRadius(float[] hsv) { this.wheelRadius = hsv[1]; - this.wheelAngle = hsv[0]*360; + this.wheelAngle = hsv[0] * 360; } public void render() { @@ -87,79 +85,76 @@ public class GuiElementColour extends GuiElement { BufferedImage bufferedImage = new BufferedImage(288, 288, BufferedImage.TYPE_INT_ARGB); float borderRadius = 0.05f; - if(Keyboard.isKeyDown(Keyboard.KEY_N)) borderRadius = 0; - for(int x=-16; x<272; x++) { - for(int y=-16; y<272; y++) { - float radius = (float) Math.sqrt(((x-128)*(x-128)+(y-128)*(y-128))/16384f); - float angle = (float) Math.toDegrees(Math.atan((128-x)/(y-128+1E-5))+Math.PI/2); - if(y < 128) angle += 180; - if(radius <= 1) { - int rgb = Color.getHSBColor(angle/360f, (float)Math.pow(radius, 1.5f), hsv[2]).getRGB(); - bufferedImage.setRGB(x+16, y+16, rgb); - } else if(radius <= 1+borderRadius) { - float invBlackAlpha = Math.abs(radius-1-borderRadius/2)/borderRadius*2; - float blackAlpha = 1-invBlackAlpha; - - if(radius > 1+borderRadius/2) { - bufferedImage.setRGB(x+16, y+16, (int)(blackAlpha*255) << 24); + if (Keyboard.isKeyDown(Keyboard.KEY_N)) borderRadius = 0; + for (int x = -16; x < 272; x++) { + for (int y = -16; y < 272; y++) { + float radius = (float) Math.sqrt(((x - 128) * (x - 128) + (y - 128) * (y - 128)) / 16384f); + float angle = (float) Math.toDegrees(Math.atan((128 - x) / (y - 128 + 1E-5)) + Math.PI / 2); + if (y < 128) angle += 180; + if (radius <= 1) { + int rgb = Color.getHSBColor(angle / 360f, (float) Math.pow(radius, 1.5f), hsv[2]).getRGB(); + bufferedImage.setRGB(x + 16, y + 16, rgb); + } else if (radius <= 1 + borderRadius) { + float invBlackAlpha = Math.abs(radius - 1 - borderRadius / 2) / borderRadius * 2; + float blackAlpha = 1 - invBlackAlpha; + + if (radius > 1 + borderRadius / 2) { + bufferedImage.setRGB(x + 16, y + 16, (int) (blackAlpha * 255) << 24); } else { - Color col = Color.getHSBColor(angle/360f, 1, hsv[2]); - int rgb = (int)(col.getRed()*invBlackAlpha) << 16 | - (int)(col.getGreen()*invBlackAlpha) << 8 | - (int)(col.getBlue()*invBlackAlpha); - bufferedImage.setRGB(x+16, y+16, 0xff000000 | rgb); + Color col = Color.getHSBColor(angle / 360f, 1, hsv[2]); + int rgb = (int) (col.getRed() * invBlackAlpha) << 16 | (int) (col.getGreen() * invBlackAlpha) << 8 | (int) (col.getBlue() * invBlackAlpha); + bufferedImage.setRGB(x + 16, y + 16, 0xff000000 | rgb); } - } } } BufferedImage bufferedImageValue = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); - for(int x=0; x<10; x++) { - for(int y=0; y<64; y++) { - if((x == 0 || x == 9) && (y == 0 || y == 63)) continue; + for (int x = 0; x < 10; x++) { + for (int y = 0; y < 64; y++) { + if ((x == 0 || x == 9) && (y == 0 || y == 63)) continue; - int rgb = Color.getHSBColor(wheelAngle/360, wheelRadius, (64-y)/64f).getRGB(); + int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, (64 - y) / 64f).getRGB(); bufferedImageValue.setRGB(x, y, rgb); } } BufferedImage bufferedImageOpacity = new BufferedImage(10, 64, BufferedImage.TYPE_INT_ARGB); - for(int x=0; x<10; x++) { - for(int y=0; y<64; y++) { - if((x == 0 || x == 9) && (y == 0 || y == 63)) continue; + for (int x = 0; x < 10; x++) { + for (int y = 0; y < 64; y++) { + if ((x == 0 || x == 9) && (y == 0 || y == 63)) continue; - int rgb = (currentColour & 0x00FFFFFF) | (Math.min(255, (64-y)*4) << 24); + int rgb = (currentColour & 0x00FFFFFF) | (Math.min(255, (64 - y) * 4) << 24); bufferedImageOpacity.setRGB(x, y, rgb); } } - float selradius = (float)Math.pow(wheelRadius, 1/1.5f)*32; - int selx = (int)(Math.cos(Math.toRadians(wheelAngle))*selradius); - int sely = (int)(Math.sin(Math.toRadians(wheelAngle))*selradius); + float selradius = (float) Math.pow(wheelRadius, 1 / 1.5f) * 32; + int selx = (int) (Math.cos(Math.toRadians(wheelAngle)) * selradius); + int sely = (int) (Math.sin(Math.toRadians(wheelAngle)) * selradius); int valueOffset = 0; - if(valueSlider) { + if (valueSlider) { valueOffset = 15; Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerBarValueLocation, new DynamicTexture(bufferedImageValue)); Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarValueLocation); GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x+5+64+5, y+5, 10, 64, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + 5, y + 5, 10, 64, GL11.GL_NEAREST); } int opacityOffset = 0; - if(opacitySlider) { + if (opacitySlider) { opacityOffset = 15; Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar_alpha); GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x+5+64+5+valueOffset, y+5, 10, 64, GL11.GL_NEAREST); - + RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); + Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerBarOpacityLocation, new DynamicTexture(bufferedImageOpacity)); Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerBarOpacityLocation); GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x+5+64+5+valueOffset, y+5, 10, 64, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); } int chromaSpeed = ChromaColour.getSpeed(colour); @@ -167,139 +162,120 @@ public class GuiElementColour extends GuiElement { Color cChroma = new Color(currentColourChroma, true); float hsvChroma[] = Color.RGBtoHSB(cChroma.getRed(), cChroma.getGreen(), cChroma.getBlue(), null); - if(chromaSpeed > 0) { - Gui.drawRect(x+5+64+valueOffset+opacityOffset+5+1, y+5+1, - x+5+64+valueOffset+opacityOffset+5+10-1, y+5+64-1, - Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f)); + if (chromaSpeed > 0) { + Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5 + 1, y + 5 + 1, x + 5 + 64 + valueOffset + opacityOffset + 5 + 10 - 1, y + 5 + 64 - 1, Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f)); } else { - Gui.drawRect(x+5+64+valueOffset+opacityOffset+5+1, y+5+27+1, - x+5+64+valueOffset+opacityOffset+5+10-1, y+5+37-1, - Color.HSBtoRGB((hsvChroma[0]+(System.currentTimeMillis()-ChromaColour.startTime)/1000f)%1, 0.8f, 0.8f)); + Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5 + 1, y + 5 + 27 + 1, x + 5 + 64 + valueOffset + opacityOffset + 5 + 10 - 1, y + 5 + 37 - 1, Color.HSBtoRGB((hsvChroma[0] + (System.currentTimeMillis() - ChromaColour.startTime) / 1000f) % 1, 0.8f, 0.8f)); } Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar); GlStateManager.color(1, 1, 1, 1); - if(valueSlider) RenderUtils.drawTexturedRect(x+5+64+5, y+5, 10, 64, GL11.GL_NEAREST); - if(opacitySlider) RenderUtils.drawTexturedRect(x+5+64+5+valueOffset, y+5, 10, 64, GL11.GL_NEAREST); + if (valueSlider) RenderUtils.drawTexturedRect(x + 5 + 64 + 5, y + 5, 10, 64, GL11.GL_NEAREST); + if (opacitySlider) RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); - if(chromaSpeed > 0) { - RenderUtils.drawTexturedRect(x+5+64+valueOffset+opacityOffset+5, y+5, 10, 64, GL11.GL_NEAREST); + if (chromaSpeed > 0) { + RenderUtils.drawTexturedRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5, 10, 64, GL11.GL_NEAREST); } else { Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_chroma); - RenderUtils.drawTexturedRect(x+5+64+valueOffset+opacityOffset+5, y+5+27, 10, 10, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5 + 27, 10, 10, GL11.GL_NEAREST); } - if(valueSlider) Gui.drawRect(x+5+64+5, y+5+64-(int)(64*hsv[2]), - x+5+64+valueOffset, y+5+64-(int)(64*hsv[2])+1, 0xFF000000); - if(opacitySlider) Gui.drawRect(x+5+64+5+valueOffset, y+5+64-c.getAlpha()/4, - x+5+64+valueOffset+opacityOffset, y+5+64-c.getAlpha()/4-1, 0xFF000000); - if(chromaSpeed > 0) { - Gui.drawRect(x+5+64+valueOffset+opacityOffset+5, - y+5+64-(int)(chromaSpeed/255f*64), - x+5+64+valueOffset+opacityOffset+5+10, - y+5+64-(int)(chromaSpeed/255f*64)+1, 0xFF000000); + if (valueSlider) Gui.drawRect(x + 5 + 64 + 5, y + 5 + 64 - (int) (64 * hsv[2]), x + 5 + 64 + valueOffset, y + 5 + 64 - (int) (64 * hsv[2]) + 1, 0xFF000000); + if (opacitySlider) Gui.drawRect(x + 5 + 64 + 5 + valueOffset, y + 5 + 64 - c.getAlpha() / 4, x + 5 + 64 + valueOffset + opacityOffset, y + 5 + 64 - c.getAlpha() / 4 - 1, 0xFF000000); + if (chromaSpeed > 0) { + Gui.drawRect(x + 5 + 64 + valueOffset + opacityOffset + 5, y + 5 + 64 - (int) (chromaSpeed / 255f * 64), x + 5 + 64 + valueOffset + opacityOffset + 5 + 10, y + 5 + 64 - (int) (chromaSpeed / 255f * 64) + 1, 0xFF000000); } Minecraft.getMinecraft().getTextureManager().loadTexture(colourPickerLocation, new DynamicTexture(bufferedImage)); Minecraft.getMinecraft().getTextureManager().bindTexture(colourPickerLocation); GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x+1, y+1, 72, 72, GL11.GL_LINEAR); + RenderUtils.drawTexturedRect(x + 1, y + 1, 72, 72, GL11.GL_LINEAR); Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_dot); GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x+5+32+selx-4, y+5+32+sely-4, 8, 8, GL11.GL_NEAREST); - - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+Math.round(hsv[2]*100)+"", - Minecraft.getMinecraft().fontRendererObj, - x+5+64+5+5-(Math.round(hsv[2]*100)==100?1:0), y+5+64+5+5, true, 13, -1); - if(opacitySlider) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+Math.round(c.getAlpha()/255f*100)+"", - Minecraft.getMinecraft().fontRendererObj, - x+5+64+5+valueOffset+5, y+5+64+5+5, true, 13, -1); + RenderUtils.drawTexturedRect(x + 5 + 32 + selx - 4, y + 5 + 32 + sely - 4, 8, 8, GL11.GL_NEAREST); + + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + Math.round(hsv[2] * 100) + "", Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + 5 - (Math.round(hsv[2] * 100) == 100 ? 1 : 0), y + 5 + 64 + 5 + 5, true, 13, -1); + if (opacitySlider) { + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + Math.round(c.getAlpha() / 255f * 100) + "", Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + valueOffset + 5, y + 5 + 64 + 5 + 5, true, 13, -1); } - if(chromaSpeed > 0) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+ - (int)ChromaColour.getSecondsForSpeed(chromaSpeed)+"s", - Minecraft.getMinecraft().fontRendererObj, - x+5+64+5+valueOffset+opacityOffset+6, y+5+64+5+5, true, 13, -1); + if (chromaSpeed > 0) { + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + (int) ChromaColour.getSecondsForSpeed(chromaSpeed) + "s", Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + valueOffset + opacityOffset + 6, y + 5 + 64 + 5 + 5, true, 13, -1); } hexField.setSize(48, 10); - if(!hexField.getFocus()) hexField.setText(Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase()); + if (!hexField.getFocus()) hexField.setText(Integer.toHexString(c.getRGB() & 0xFFFFFF).toUpperCase()); - StringBuilder sb = new StringBuilder(EnumChatFormatting.GRAY+"#"); - for(int i=0; i<6-hexField.getText().length(); i++) { + StringBuilder sb = new StringBuilder(EnumChatFormatting.GRAY + "#"); + for (int i = 0; i < 6 - hexField.getText().length(); i++) { sb.append("0"); } sb.append(EnumChatFormatting.WHITE); hexField.setPrependText(sb.toString()); - hexField.render(x+5+8, y+5+64+5); + hexField.render(x + 5 + 8, y + 5 + 64 + 5); } public boolean mouseInput(int mouseX, int mouseY) { ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - float mouseXF = (float)(Mouse.getX() * scaledResolution.getScaledWidth_double() / - Minecraft.getMinecraft().displayWidth); - float mouseYF = (float)(scaledResolution.getScaledHeight_double() - Mouse.getY() * - scaledResolution.getScaledHeight_double() / Minecraft.getMinecraft().displayHeight - 1); - - if((Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1) && Mouse.getEventButtonState()) { - if(mouseX > x+5+8 && mouseX < x+5+8+48) { - if(mouseY > y+5+64+5 && mouseY < y+5+64+5+10) { + float mouseXF = (float) (Mouse.getX() * scaledResolution.getScaledWidth_double() / Minecraft.getMinecraft().displayWidth); + float mouseYF = (float) (scaledResolution.getScaledHeight_double() - Mouse.getY() * scaledResolution.getScaledHeight_double() / Minecraft.getMinecraft().displayHeight - 1); + + if ((Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1) && Mouse.getEventButtonState()) { + if (mouseX > x + 5 + 8 && mouseX < x + 5 + 8 + 48) { + if (mouseY > y + 5 + 64 + 5 && mouseY < y + 5 + 64 + 5 + 10) { hexField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); clickedComponent = -1; return true; } } } - if(!Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (!Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { clickedComponent = -1; } - if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if(mouseX >= x && mouseX <= x+119 && - mouseY >= y && mouseY <= y+89) { + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (mouseX >= x && mouseX <= x + 119 && mouseY >= y && mouseY <= y + 89) { hexField.unfocus(); int xWheel = mouseX - x - 5; int yWheel = mouseY - y - 5; - if(xWheel > 0 && xWheel < 64) { - if(yWheel > 0 && yWheel < 64) { + if (xWheel > 0 && xWheel < 64) { + if (yWheel > 0 && yWheel < 64) { clickedComponent = 0; } } - int xValue = mouseX - (x+5+64+5); + int xValue = mouseX - (x + 5 + 64 + 5); int y = mouseY - this.y - 5; int opacityOffset = opacitySlider ? 15 : 0; int valueOffset = valueSlider ? 15 : 0; - if(y > -5 && y <= 69) { - if(valueSlider) { - if(xValue > 0 && xValue < 10) { + if (y > -5 && y <= 69) { + if (valueSlider) { + if (xValue > 0 && xValue < 10) { clickedComponent = 1; } } - if(opacitySlider) { - int xOpacity = mouseX - (x+5+64+5+valueOffset); + if (opacitySlider) { + int xOpacity = mouseX - (x + 5 + 64 + 5 + valueOffset); - if(xOpacity > 0 && xOpacity < 10) { + if (xOpacity > 0 && xOpacity < 10) { clickedComponent = 2; } } } int chromaSpeed = ChromaColour.getSpeed(colour); - int xChroma = mouseX - (x+5+64+valueOffset+opacityOffset+5); - if(xChroma > 0 && xChroma < 10) { - if(chromaSpeed > 0) { - if(y > -5 && y <= 69) { + int xChroma = mouseX - (x + 5 + 64 + valueOffset + opacityOffset + 5); + if (xChroma > 0 && xChroma < 10) { + if (chromaSpeed > 0) { + if (y > -5 && y <= 69) { clickedComponent = 3; } - } else if(mouseY > this.y+5+27 && mouseY < this.y+5+37) { + } else if (mouseY > this.y + 5 + 27 && mouseY < this.y + 5 + 37) { int currentColour = ChromaColour.specialToSimpleRGB(colour); Color c = new Color(currentColour, true); colour = ChromaColour.special(200, c.getAlpha(), currentColour); @@ -312,7 +288,7 @@ public class GuiElementColour extends GuiElement { return false; } } - if(Mouse.isButtonDown(0) && clickedComponent >= 0) { + if (Mouse.isButtonDown(0) && clickedComponent >= 0) { int currentColour = ChromaColour.specialToSimpleRGB(colour); Color c = new Color(currentColour, true); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); @@ -320,16 +296,16 @@ public class GuiElementColour extends GuiElement { float xWheel = mouseXF - x - 5; float yWheel = mouseYF - y - 5; - if(clickedComponent == 0) { - float angle = (float) Math.toDegrees(Math.atan((32-xWheel)/(yWheel-32+1E-5))+Math.PI/2); + if (clickedComponent == 0) { + float angle = (float) Math.toDegrees(Math.atan((32 - xWheel) / (yWheel - 32 + 1E-5)) + Math.PI / 2); xWheel = Math.max(0, Math.min(64, xWheel)); yWheel = Math.max(0, Math.min(64, yWheel)); - float radius = (float) Math.sqrt(((xWheel-32)*(xWheel-32)+(yWheel-32)*(yWheel-32))/1024f); - if(yWheel < 32) angle += 180; + float radius = (float) Math.sqrt(((xWheel - 32) * (xWheel - 32) + (yWheel - 32) * (yWheel - 32)) / 1024f); + if (yWheel < 32) angle += 180; this.wheelAngle = angle; - this.wheelRadius = (float)Math.pow(Math.min(1, radius), 1.5f); - int rgb = Color.getHSBColor(angle/360f, wheelRadius, hsv[2]).getRGB(); + this.wheelRadius = (float) Math.pow(Math.min(1, radius), 1.5f); + int rgb = Color.getHSBColor(angle / 360f, wheelRadius, hsv[2]).getRGB(); colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); colourChangedCallback.accept(colour); return true; @@ -339,22 +315,21 @@ public class GuiElementColour extends GuiElement { y = Math.max(0, Math.min(64, y)); System.out.println(y); - if(clickedComponent == 1) { - int rgb = Color.getHSBColor(wheelAngle/360, wheelRadius, 1-y/64f).getRGB(); + if (clickedComponent == 1) { + int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, 1 - y / 64f).getRGB(); colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); colourChangedCallback.accept(colour); return true; } - if(clickedComponent == 2) { - colour = ChromaColour.special(ChromaColour.getSpeed(colour), - 255-Math.round(y/64f*255), currentColour); + if (clickedComponent == 2) { + colour = ChromaColour.special(ChromaColour.getSpeed(colour), 255 - Math.round(y / 64f * 255), currentColour); colourChangedCallback.accept(colour); return true; } - if(clickedComponent == 3) { - colour = ChromaColour.special(255-Math.round(y/64f*255), c.getAlpha(), currentColour); + if (clickedComponent == 3) { + colour = ChromaColour.special(255 - Math.round(y / 64f * 255), c.getAlpha(), currentColour); colourChangedCallback.accept(colour); } return true; @@ -363,7 +338,7 @@ public class GuiElementColour extends GuiElement { } public boolean keyboardInput() { - if(Keyboard.getEventKeyState() && hexField.getFocus()) { + if (Keyboard.getEventKeyState() && hexField.getFocus()) { if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { hexField.unfocus(); return true; @@ -372,7 +347,7 @@ public class GuiElementColour extends GuiElement { hexField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); - if(hexField.getText().length() > 6) { + if (hexField.getText().length() > 6) { hexField.setText(old); } else { try { @@ -386,13 +361,11 @@ public class GuiElementColour extends GuiElement { Color c = new Color(rgb); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); updateAngleAndRadius(hsv); - } catch(Exception e) {}; + } catch (Exception e) {} } return true; } return false; } - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementTextField.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementTextField.java index b16f672..bbb29ee 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementTextField.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementTextField.java @@ -37,8 +37,7 @@ public class GuiElementTextField { private String prependText = ""; private int customTextColour = 0xffffffff; - private final GuiTextField textField = new GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, - 0 , 0, 0, 0); + private final GuiTextField textField = new GuiTextField(0, Minecraft.getMinecraft().fontRendererObj, 0, 0, 0, 0); private int customBorderColour = -1; @@ -74,11 +73,11 @@ public class GuiElementTextField { public String getTextDisplay() { String textNoColour = getText(); - while(true) { + while (true) { Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColour); - if(!matcher.find()) break; + if (!matcher.find()) break; String code = matcher.group(1); - textNoColour = matcher.replaceFirst("\u00B6"+code); + textNoColour = matcher.replaceFirst("\u00B6" + code); } return textNoColour; @@ -89,13 +88,13 @@ public class GuiElementTextField { } public void setText(String text) { - if(textField.getText() == null || !textField.getText().equals(text)) { + if (textField.getText() == null || !textField.getText().equals(text)) { textField.setText(text); } } public void setSize(int searchBarXSize, int searchBarYSize) { - this.searchBarXSize = searchBarXSize; + this.searchBarXSize = searchBarXSize; this.searchBarYSize = searchBarYSize; } @@ -110,34 +109,35 @@ public class GuiElementTextField { public void setFocus(boolean focus) { this.focus = focus; - if(!focus) { + if (!focus) { textField.setCursorPosition(textField.getCursorPosition()); } } + public boolean getFocus() { return focus; } public int getHeight() { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); + int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); - int numLines = org.apache.commons.lang3.StringUtils.countMatches(textField.getText(), "\n")+1; - int extraSize = (searchBarYSize-8)/2+8; - int bottomTextBox = searchBarYSize + extraSize*(numLines-1); + int numLines = org.apache.commons.lang3.StringUtils.countMatches(textField.getText(), "\n") + 1; + int extraSize = (searchBarYSize - 8) / 2 + 8; + int bottomTextBox = searchBarYSize + extraSize * (numLines - 1); - return bottomTextBox + paddingUnscaled*2; + return bottomTextBox + paddingUnscaled * 2; } public int getWidth() { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); - int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); + int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); - return searchBarXSize + paddingUnscaled*2; + return searchBarXSize + paddingUnscaled * 2; } private float getScaleFactor(String str) { - return Math.min(1, (searchBarXSize-2)/(float)Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)); + return Math.min(1, (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)); } private boolean isScaling() { @@ -150,60 +150,60 @@ public class GuiElementTextField { int xComp = mouseX - x; int yComp = mouseY - y; - int extraSize = (searchBarYSize-8)/2+8; + int extraSize = (searchBarYSize - 8) / 2 + 8; String renderText = prependText + textField.getText(); - int lineNum = Math.round(((yComp - (searchBarYSize-8)/2))/extraSize); + int lineNum = Math.round(((yComp - (searchBarYSize - 8) / 2)) / extraSize); String text = renderText; String textNoColour = renderText; - if((options & COLOUR) != 0) { - while(true) { + if ((options & COLOUR) != 0) { + while (true) { Matcher matcher = PATTERN_CONTROL_CODE.matcher(text); - if(!matcher.find() || matcher.groupCount() < 1) break; + if (!matcher.find() || matcher.groupCount() < 1) break; String code = matcher.group(1); - if(code.isEmpty()) { + if (code.isEmpty()) { text = matcher.replaceFirst("\u00A7r\u00B6"); } else { - text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); } } } - while(true) { + while (true) { Matcher matcher = PATTERN_CONTROL_CODE.matcher(textNoColour); - if(!matcher.find() || matcher.groupCount() < 1) break; + if (!matcher.find() || matcher.groupCount() < 1) break; String code = matcher.group(1); - textNoColour = matcher.replaceFirst("\u00B6"+code); + textNoColour = matcher.replaceFirst("\u00B6" + code); } int currentLine = 0; int cursorIndex = 0; - for(; cursorIndex