diff options
author | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-06 19:09:11 -0230 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-06 19:09:11 -0230 |
commit | 93248d28d6b314b42f6b0d82164975343b214ece (patch) | |
tree | e3e06c24454080f059355133d633e5a076d85ad3 /src/main/java/com/thatgravyboat | |
parent | 91464c8f433e8bf323932ac956678971207b607e (diff) | |
parent | 804767ebfc26e2a1252bc327def02389b35dfc6e (diff) | |
download | SkyblockHud-Death-Defied-93248d28d6b314b42f6b0d82164975343b214ece.tar.gz SkyblockHud-Death-Defied-93248d28d6b314b42f6b0d82164975343b214ece.tar.bz2 SkyblockHud-Death-Defied-93248d28d6b314b42f6b0d82164975343b214ece.zip |
Merge pull request #2 from ThatGravyBoat/prettier
Add prettier settings and format code
Diffstat (limited to 'src/main/java/com/thatgravyboat')
89 files changed, 2180 insertions, 2851 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/ComponentBuilder.java b/src/main/java/com/thatgravyboat/skyblockhud/ComponentBuilder.java index e5299d5..b0c17be 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/ComponentBuilder.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/ComponentBuilder.java @@ -2,54 +2,53 @@ package com.thatgravyboat.skyblockhud; public class ComponentBuilder { - public StringBuilder builder; - - public ComponentBuilder(){ - this.builder = new StringBuilder(); - } - - public ComponentBuilder apd(String text) { - return apd(text, '7'); - } - - public ComponentBuilder apd(String text, char[] colors) { - for (char color: colors) { - builder.append("\u00A7").append(color); - } - builder.append(text).append("\u00A7").append('r'); - return this; - } - - public ComponentBuilder apd(String text, char color) { - builder.append("\u00A7").append(color).append(text).append("\u00A7").append('r'); - return this; - } - - public ComponentBuilder nl(){ - builder.append("\n"); - return this; - } - - public ComponentBuilder nl(String text, char color){ - apd(text, color); - builder.append("\n"); - return this; - } - - public ComponentBuilder nl(String text, char[] colors){ - apd(text, colors); - builder.append("\n"); - return this; - } - - public ComponentBuilder nl(String text){ - apd(text); - builder.append("\n"); - return this; - } - - public String build() { - return builder.toString(); - } - + public StringBuilder builder; + + public ComponentBuilder() { + this.builder = new StringBuilder(); + } + + public ComponentBuilder apd(String text) { + return apd(text, '7'); + } + + public ComponentBuilder apd(String text, char[] colors) { + for (char color : colors) { + builder.append("\u00A7").append(color); + } + builder.append(text).append("\u00A7").append('r'); + return this; + } + + public ComponentBuilder apd(String text, char color) { + builder.append("\u00A7").append(color).append(text).append("\u00A7").append('r'); + return this; + } + + public ComponentBuilder nl() { + builder.append("\n"); + return this; + } + + public ComponentBuilder nl(String text, char color) { + apd(text, color); + builder.append("\n"); + return this; + } + + public ComponentBuilder nl(String text, char[] colors) { + apd(text, colors); + builder.append("\n"); + return this; + } + + public ComponentBuilder nl(String text) { + apd(text); + builder.append("\n"); + return this; + } + + public String build() { + return builder.toString(); + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/ComponentHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/ComponentHandler.java index 3c671f0..d56fd30 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/ComponentHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/ComponentHandler.java @@ -5,6 +5,9 @@ import com.google.common.collect.Ordering; import com.thatgravyboat.skyblockhud.dungeons.DungeonHandler; import com.thatgravyboat.skyblockhud.location.*; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import java.util.Comparator; +import java.util.List; +import java.util.regex.Pattern; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetworkPlayerInfo; import net.minecraft.scoreboard.ScorePlayerTeam; @@ -17,108 +20,98 @@ import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import java.util.Comparator; -import java.util.List; -import java.util.regex.Pattern; - public class ComponentHandler { + public static final Pattern SCOREBOARD_CHARACTERS = Pattern.compile("[^]\\[a-z A-Z:0-9/'.()+\\d-§?]"); - private static final Ordering<NetworkPlayerInfo> sortingList = Ordering.from(new PlayerComparator()); + private static final Ordering<NetworkPlayerInfo> sortingList = Ordering.from(new PlayerComparator()); private static int ticksExisted = 0; @SubscribeEvent - public void onClientTick(TickEvent.ClientTickEvent event){ + public void onClientTick(TickEvent.ClientTickEvent event) { Minecraft mc = Minecraft.getMinecraft(); - ticksExisted++; + ticksExisted++; boolean eventPass = false; - if (mc.theWorld != null) { - List<NetworkPlayerInfo> players = sortingList.sortedCopy(mc.thePlayer.sendQueue.getPlayerInfoMap()); - GuiIngameForge.renderObjective = !SkyblockHud.hasSkyblockScoreboard() || !SkyblockHud.config.misc.hideScoreboard; - if (players != null && SkyblockHud.hasSkyblockScoreboard()){ - - if (ticksExisted % 60 == 0) { - for (NetworkPlayerInfo player : players) { - if (player.getDisplayName() != null) { - String formattedTabListPlayer = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(player.getDisplayName().getFormattedText())).replaceAll(""); - if (LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { - if (formattedTabListPlayer.toLowerCase().contains("secrets found:")) - DungeonHandler.parseTotalSecrets(formattedTabListPlayer); - if (formattedTabListPlayer.toLowerCase().contains("deaths:")) - DungeonHandler.parseDeaths(formattedTabListPlayer); - if (formattedTabListPlayer.toLowerCase().contains("crypts:")) - DungeonHandler.parseCrypts(formattedTabListPlayer); - }else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)){ - if (formattedTabListPlayer.toLowerCase().contains("mithril powder:")){ - DwarvenMineHandler.parseMithril(formattedTabListPlayer); - } - }else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.MUSHROOMDESERT)){ - if (formattedTabListPlayer.toLowerCase().contains("pelts:")){ - try { - FarmingIslandHandler.pelts = Integer.parseInt(formattedTabListPlayer.toLowerCase().replace("pelts:","").trim()); - }catch (Exception ignored){} - } - } - } - } - if (players.size() > 80) { - for (int i = 61; i <= 80; i++) { - if (players.get(i).getDisplayName() != null) { - String formattedTabListPlayer = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(players.get(i).getDisplayName().getFormattedText())).replaceAll(""); - if (formattedTabListPlayer.toLowerCase().contains("event:")) { - if (i < 80) { - if (players.get(i + 1).getDisplayName() != null) { - String secondLine = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(players.get(i + 1).getDisplayName().getFormattedText())).replaceAll(""); - SeasonDateHandler.setCurrentEvent(formattedTabListPlayer.replace("Event:", ""), secondLine); - eventPass = true; - } - } - } - } - if (i == 80 && !eventPass) { - SeasonDateHandler.setCurrentEvent("", ""); - } - } - } - } - if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK)) { - if (players.size() >= 80) { - for (int i = 41; i <= 60; i++) { - if (players.get(i).getDisplayName() != null) { - String formattedTabListPlayer = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(players.get(i).getDisplayName().getFormattedText())).replaceAll(""); - if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK)) { - if (formattedTabListPlayer.toLowerCase().contains("rain:")) { - ParkIslandHandler.parseRain(formattedTabListPlayer.toLowerCase()); - } - } - } - } - } - }else if (ParkIslandHandler.isRaining()) { - ParkIslandHandler.parseRain(null); - } - } + if (mc.theWorld != null) { + List<NetworkPlayerInfo> players = sortingList.sortedCopy(mc.thePlayer.sendQueue.getPlayerInfoMap()); + GuiIngameForge.renderObjective = !SkyblockHud.hasSkyblockScoreboard() || !SkyblockHud.config.misc.hideScoreboard; + if (players != null && SkyblockHud.hasSkyblockScoreboard()) { + if (ticksExisted % 60 == 0) { + for (NetworkPlayerInfo player : players) { + if (player.getDisplayName() != null) { + String formattedTabListPlayer = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(player.getDisplayName().getFormattedText())).replaceAll(""); + if (LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { + if (formattedTabListPlayer.toLowerCase().contains("secrets found:")) DungeonHandler.parseTotalSecrets(formattedTabListPlayer); + if (formattedTabListPlayer.toLowerCase().contains("deaths:")) DungeonHandler.parseDeaths(formattedTabListPlayer); + if (formattedTabListPlayer.toLowerCase().contains("crypts:")) DungeonHandler.parseCrypts(formattedTabListPlayer); + } else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)) { + if (formattedTabListPlayer.toLowerCase().contains("mithril powder:")) { + DwarvenMineHandler.parseMithril(formattedTabListPlayer); + } + } else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.MUSHROOMDESERT)) { + if (formattedTabListPlayer.toLowerCase().contains("pelts:")) { + try { + FarmingIslandHandler.pelts = Integer.parseInt(formattedTabListPlayer.toLowerCase().replace("pelts:", "").trim()); + } catch (Exception ignored) {} + } + } + } + } + if (players.size() > 80) { + for (int i = 61; i <= 80; i++) { + if (players.get(i).getDisplayName() != null) { + String formattedTabListPlayer = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(players.get(i).getDisplayName().getFormattedText())).replaceAll(""); + if (formattedTabListPlayer.toLowerCase().contains("event:")) { + if (i < 80) { + if (players.get(i + 1).getDisplayName() != null) { + String secondLine = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(players.get(i + 1).getDisplayName().getFormattedText())).replaceAll(""); + SeasonDateHandler.setCurrentEvent(formattedTabListPlayer.replace("Event:", ""), secondLine); + eventPass = true; + } + } + } + } + if (i == 80 && !eventPass) { + SeasonDateHandler.setCurrentEvent("", ""); + } + } + } + } + if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK)) { + if (players.size() >= 80) { + for (int i = 41; i <= 60; i++) { + if (players.get(i).getDisplayName() != null) { + String formattedTabListPlayer = SCOREBOARD_CHARACTERS.matcher(Utils.removeColor(players.get(i).getDisplayName().getFormattedText())).replaceAll(""); + if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK)) { + if (formattedTabListPlayer.toLowerCase().contains("rain:")) { + ParkIslandHandler.parseRain(formattedTabListPlayer.toLowerCase()); + } + } + } + } + } + } else if (ParkIslandHandler.isRaining()) { + ParkIslandHandler.parseRain(null); + } + } } } @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onStatusBar(ClientChatReceivedEvent event){ - if (event.type == 2){ - if (LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) DungeonHandler.parseSecrets(event.message.getFormattedText()); - } - } + public void onStatusBar(ClientChatReceivedEvent event) { + if (event.type == 2) { + if (LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) DungeonHandler.parseSecrets(event.message.getFormattedText()); + } + } - @SideOnly(Side.CLIENT) - static class PlayerComparator implements Comparator<NetworkPlayerInfo> - { - private PlayerComparator() - { - } + @SideOnly(Side.CLIENT) + static class PlayerComparator implements Comparator<NetworkPlayerInfo> { - public int compare(NetworkPlayerInfo p_compare_1_, NetworkPlayerInfo p_compare_2_) - { - ScorePlayerTeam scoreplayerteam = p_compare_1_.getPlayerTeam(); - ScorePlayerTeam scoreplayerteam1 = p_compare_2_.getPlayerTeam(); - return ComparisonChain.start().compareTrueFirst(p_compare_1_.getGameType() != WorldSettings.GameType.SPECTATOR, p_compare_2_.getGameType() != WorldSettings.GameType.SPECTATOR).compare(scoreplayerteam != null ? scoreplayerteam.getRegisteredName() : "", scoreplayerteam1 != null ? scoreplayerteam1.getRegisteredName() : "").compare(p_compare_1_.getGameProfile().getName(), p_compare_2_.getGameProfile().getName()).result(); - } - } + private PlayerComparator() {} + + public int compare(NetworkPlayerInfo p_compare_1_, NetworkPlayerInfo p_compare_2_) { + ScorePlayerTeam scoreplayerteam = p_compare_1_.getPlayerTeam(); + ScorePlayerTeam scoreplayerteam1 = p_compare_2_.getPlayerTeam(); + return ComparisonChain.start().compareTrueFirst(p_compare_1_.getGameType() != WorldSettings.GameType.SPECTATOR, p_compare_2_.getGameType() != WorldSettings.GameType.SPECTATOR).compare(scoreplayerteam != null ? scoreplayerteam.getRegisteredName() : "", scoreplayerteam1 != null ? scoreplayerteam1.getRegisteredName() : "").compare(p_compare_1_.getGameProfile().getName(), p_compare_2_.getGameProfile().getName()).result(); + } + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java index 435c2a5..9198433 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/GuiTextures.java @@ -28,10 +28,9 @@ public class GuiTextures { public static final ResourceLocation slider_on_segment = new ResourceLocation("skyblockhud:core/slider/slider_on_segment.png"); public static final ResourceLocation slider_button_new = new ResourceLocation("skyblockhud:core/slider/slider_button.png"); - public static final ResourceLocation overlay = new ResourceLocation("skyblockhud","stats.png"); - public static final ResourceLocation dungeon = new ResourceLocation("skyblockhud","dungeon.png"); - public static final ResourceLocation playerStat = new ResourceLocation("skyblockhud","playerstats.png"); - public static final ResourceLocation bars = new ResourceLocation("skyblockhud","bars.png"); - public static final ResourceLocation mapOverlay = new ResourceLocation("skyblockhud","maps/map_overlay.png"); - + public static final ResourceLocation overlay = new ResourceLocation("skyblockhud", "stats.png"); + public static final ResourceLocation dungeon = new ResourceLocation("skyblockhud", "dungeon.png"); + public static final ResourceLocation playerStat = new ResourceLocation("skyblockhud", "playerstats.png"); + public static final ResourceLocation bars = new ResourceLocation("skyblockhud", "bars.png"); + public static final ResourceLocation mapOverlay = new ResourceLocation("skyblockhud", "maps/map_overlay.png"); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java index a31889e..f461f6d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SkyblockHud.java @@ -19,6 +19,11 @@ import com.thatgravyboat.skyblockhud.overlay.OverlayHud; import com.thatgravyboat.skyblockhud.overlay.RPGHud; import com.thatgravyboat.skyblockhud.playerstats.ActionBarParsing; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import java.awt.*; +import java.awt.datatransfer.StringSelection; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.Set; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.scoreboard.ScoreObjective; @@ -36,15 +41,9 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.lwjgl.input.Keyboard; -import java.awt.*; -import java.awt.datatransfer.StringSelection; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.Set; - @Mod(modid = SkyblockHud.MODID, version = SkyblockHud.VERSION) -public class SkyblockHud -{ +public class SkyblockHud { + public static final String MODID = "skyblockhud"; public static final String VERSION = "1.12"; @@ -52,14 +51,14 @@ public class SkyblockHud private File configFile; - private static final Set<String> SKYBLOCK_IN_ALL_LANGUAGES = Sets.newHashSet("SKYBLOCK","\u7A7A\u5C9B\u751F\u5B58"); + private static final Set<String> SKYBLOCK_IN_ALL_LANGUAGES = Sets.newHashSet("SKYBLOCK", "\u7A7A\u5C9B\u751F\u5B58"); private final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create(); private static File configDirectory; @EventHandler - public void preInit(FMLPreInitializationEvent event){ + public void preInit(FMLPreInitializationEvent event) { MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new LeaderboardGetter()); MinecraftForge.EVENT_BUS.register(new SeasonDateHandler()); @@ -86,14 +85,13 @@ public class SkyblockHud configFile = new File(event.getModConfigurationDirectory(), "sbh-config.json"); - if(configFile.exists()) { - try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { + if (configFile.exists()) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { config = gson.fromJson(reader, SBHConfig.class); - } catch(Exception ignored) { } + } catch (Exception ignored) {} } - - if(config == null) { + if (config == null) { config = new SBHConfig(); saveConfig(); } @@ -108,14 +106,14 @@ public class SkyblockHud try { configFile.createNewFile(); - try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { writer.write(gson.toJson(config)); } - } catch(IOException ignored) {} + } catch (IOException ignored) {} } @EventHandler - public void postInit(FMLPostInitializationEvent event){ + public void postInit(FMLPostInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new OverlayHud()); MinecraftForge.EVENT_BUS.register(new RPGHud()); MinecraftForge.EVENT_BUS.register(new DungeonOverlay()); @@ -161,19 +159,18 @@ public class SkyblockHud } @SubscribeEvent - public void onTooltip(ItemTooltipEvent event){ + public void onTooltip(ItemTooltipEvent event) { if (event.itemStack != null && Keyboard.isKeyDown(Keyboard.KEY_BACKSLASH)) { try { StringSelection clipboard = new StringSelection(event.itemStack.serializeNBT().toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(clipboard, clipboard); - } catch (Exception ignored) { - } + } catch (Exception ignored) {} } } @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onStatusBar(ClientChatReceivedEvent event){ - if (Utils.removeColor(event.message.getUnformattedText()).toLowerCase().trim().startsWith("your profile was changed to:")){ + public void onStatusBar(ClientChatReceivedEvent event) { + if (Utils.removeColor(event.message.getUnformattedText()).toLowerCase().trim().startsWith("your profile was changed to:")) { MinecraftForge.EVENT_BUS.post(new ProfileSwitchedEvent()); } } @@ -182,10 +179,10 @@ public class SkyblockHud private static int screenTicks = 0; @SubscribeEvent - public void onClientTick(TickEvent.ClientTickEvent event){ - if (screenToOpen != null){ + public void onClientTick(TickEvent.ClientTickEvent event) { + if (screenToOpen != null) { screenTicks++; - if (screenTicks == 5){ + if (screenTicks == 5) { Minecraft.getMinecraft().displayGuiScreen(screenToOpen); screenTicks = 0; screenToOpen = null; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java b/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java index 8501c9d..38a48cc 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/SpecialColour.java @@ -25,9 +25,8 @@ public class SpecialColour { int[] arr = new int[split.length]; - - for(int i=0; i<split.length; i++) { - arr[i] = Integer.parseInt(split[split.length-1-i], RADIX); + for (int i = 0; i < split.length; i++) { + arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); } return arr; } @@ -40,7 +39,7 @@ public class SpecialColour { int a = d[3]; int chr = d[4]; - return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); + return ((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); } public static int getSpeed(String special) { @@ -48,15 +47,16 @@ public class SpecialColour { } public static float getSecondsForSpeed(int speed) { - return (255-speed)/254f*(MAX_CHROMA_SECS-MIN_CHROMA_SECS)+MIN_CHROMA_SECS; + return ((255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS); } private static final int MIN_CHROMA_SECS = 1; private static final int MAX_CHROMA_SECS = 60; public static long startTime = -1; + public static int specialToChromaRGB(String special) { - if(startTime < 0) startTime = System.currentTimeMillis(); + if (startTime < 0) startTime = System.currentTimeMillis(); int[] d = decompose(special); int chr = d[4]; @@ -67,14 +67,14 @@ public class SpecialColour { float[] hsv = Color.RGBtoHSB(r, g, b, null); - if(chr > 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); + return ((a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF)); } public static int rotateHue(int argb, int degrees) { @@ -85,11 +85,9 @@ public class SpecialColour { 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); + return ((a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF)); } - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/Utils.java b/src/main/java/com/thatgravyboat/skyblockhud/Utils.java index 31f6aa8..a7621ef 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/Utils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/Utils.java @@ -1,6 +1,9 @@ package com.thatgravyboat.skyblockhud; - +import java.nio.FloatBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.FontRenderer; @@ -17,11 +20,6 @@ import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL14; -import java.nio.FloatBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedList; - public class Utils { private static LinkedList<Integer> guiScales = new LinkedList<>(); @@ -30,18 +28,18 @@ public class Utils { private static FloatBuffer projectionMatrixOld = BufferUtils.createFloatBuffer(16); private static FloatBuffer modelviewMatrixOld = BufferUtils.createFloatBuffer(16); - public static String removeColor(String input) { return input.replaceAll("(?i)\\u00A7.", ""); } - public static String removeWhiteSpaceAndRemoveWord(String input, String replace) {return input.toLowerCase().replace( " ", "").replace(replace, ""); } + public static String removeWhiteSpaceAndRemoveWord(String input, String replace) { + return input.toLowerCase().replace(" ", "").replace(replace, ""); + } public static boolean isPlayerHoldingRedstone(EntityPlayerSP player) { - if (!SkyblockHud.config.main.requireRedstone) return true; - ArrayList<Item> redstoneItems = new ArrayList<>(Arrays.asList(Items.redstone, Items.repeater, Items.comparator, Item.getByNameOrId("minecraft:redstone_torch"))); - if (player.getHeldItem()!=null) - return redstoneItems.contains(player.getHeldItem().getItem()); + if (!SkyblockHud.config.main.requireRedstone) return true; + ArrayList<Item> redstoneItems = new ArrayList<>(Arrays.asList(Items.redstone, Items.repeater, Items.comparator, Item.getByNameOrId("minecraft:redstone_torch"))); + if (player.getHeldItem() != null) return redstoneItems.contains(player.getHeldItem().getItem()); return false; } @@ -49,60 +47,82 @@ public class Utils { return value <= max && value >= min; } - public static int whatRomanNumeral(String roman){ + public static int whatRomanNumeral(String roman) { switch (roman.toLowerCase()) { - case "i": return 1; - case "ii": return 2; - case "iii": return 3; - case "iv": return 4; - case "v": return 5; - case "vi": return 6; - case "vii": return 7; - case "viii": return 8; - case "ix": return 9; - case "x": return 10; - default: return 0; + case "i": + return 1; + case "ii": + return 2; + case "iii": + return 3; + case "iv": + return 4; + case "v": + return 5; + case "vi": + return 6; + case "vii": + return 7; + case "viii": + return 8; + case "ix": + return 9; + case "x": + return 10; + default: + return 0; } } - public static String intToRomanNumeral(int i){ + public static String intToRomanNumeral(int i) { switch (i) { - case 1: return "I"; - case 2: return "II"; - case 3: return "III"; - case 4: return "IV"; - case 5: return "V"; - case 6: return "VI"; - case 7: return "VII"; - case 8: return "VIII"; - case 9: return "IX"; - case 10: return "X"; - default: return ""; + case 1: + return "I"; + case 2: + return "II"; + case 3: + return "III"; + case 4: + return "IV"; + case 5: + return "V"; + case 6: + return "VI"; + case 7: + return "VII"; + case 8: + return "VIII"; + case 9: + return "IX"; + case 10: + return "X"; + default: + return ""; } } - public static boolean overlayShouldRender(RenderGameOverlayEvent.ElementType type, boolean... booleans){ + public static boolean overlayShouldRender(RenderGameOverlayEvent.ElementType type, boolean... booleans) { return overlayShouldRender(false, type, RenderGameOverlayEvent.ElementType.HOTBAR, booleans); } - public static boolean overlayShouldRender(boolean hideOnf3, RenderGameOverlayEvent.ElementType type, RenderGameOverlayEvent.ElementType checkType, boolean... booleans){ + public static boolean overlayShouldRender(boolean hideOnf3, RenderGameOverlayEvent.ElementType type, RenderGameOverlayEvent.ElementType checkType, boolean... booleans) { Minecraft mc = Minecraft.getMinecraft(); boolean shouldRender; - if (booleans.length > 1){ + if (booleans.length > 1) { for (boolean aBoolean : booleans) if (!aBoolean) return false; shouldRender = true; - }else shouldRender = booleans.length != 1 || booleans[0]; + } else shouldRender = booleans.length != 1 || booleans[0]; if (hideOnf3) { if (mc.gameSettings.showDebugInfo || (mc.gameSettings.keyBindPlayerList.isKeyDown() && (!mc.isIntegratedServerRunning() || mc.thePlayer.sendQueue.getPlayerInfoMap().size() > 1))) { return false; } } - return shouldRender && ((type == null && Loader.isModLoaded("labymod")) || type == checkType); + return (shouldRender && ((type == null && Loader.isModLoaded("labymod")) || type == checkType)); } public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; + float factor = len / (float) strLen; factor = Math.min(1, factor); drawStringScaled(str, fr, x, y, shadow, colour, factor); @@ -110,16 +130,16 @@ public class Utils { public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { GlStateManager.scale(factor, factor, 1); - fr.drawString(str, x/factor, y/factor, colour, shadow); - GlStateManager.scale(1/factor, 1/factor, 1); + fr.drawString(str, x / factor, y / factor, colour, shadow); + GlStateManager.scale(1 / factor, 1 / factor, 1); } public static void drawStringCenteredScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; - float fontHeight = 8*factor; + float factor = len / (float) strLen; + float fontHeight = 8 * factor; - drawStringScaled(str, fr, x-len/2f, y-fontHeight/2f, shadow, colour, factor); + drawStringScaled(str, fr, x - len / 2f, y - fontHeight / 2f, shadow, colour, factor); } public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { @@ -133,18 +153,10 @@ public class Utils { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer - .pos(x, y+height, 0.0D) - .tex(uMin, vMax).endVertex(); - worldrenderer - .pos(x+width, y+height, 0.0D) - .tex(uMax, vMax).endVertex(); - worldrenderer - .pos(x+width, y, 0.0D) - .tex(uMax, vMin).endVertex(); - worldrenderer - .pos(x, y, 0.0D) - .tex(uMin, vMin).endVertex(); + worldrenderer.pos(x, y + height, 0.0D).tex(uMin, vMax).endVertex(); + worldrenderer.pos(x + width, y + height, 0.0D).tex(uMax, vMax).endVertex(); + worldrenderer.pos(x + width, y, 0.0D).tex(uMax, vMin).endVertex(); + worldrenderer.pos(x, y, 0.0D).tex(uMin, vMin).endVertex(); tessellator.draw(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); @@ -154,15 +166,15 @@ public class Utils { } public static void drawTexturedRect(float x, float y, float width, float height) { - drawTexturedRect(x, y, width, height, 0, 1, 0 , 1); + drawTexturedRect(x, y, width, height, 0, 1, 0, 1); } public static void drawTexturedRect(float x, float y, float width, float height, int filter) { - drawTexturedRect(x, y, width, height, 0, 1, 0 , 1, filter); + drawTexturedRect(x, y, width, height, 0, 1, 0, 1, filter); } public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { - drawTexturedRect(x, y, width, height, uMin, uMax, vMin , vMax, GL11.GL_LINEAR); + drawTexturedRect(x, y, width, height, uMin, uMax, vMin, vMax, GL11.GL_LINEAR); } public static void resetGuiScale() { @@ -174,19 +186,19 @@ public class Utils { } public static ScaledResolution pushGuiScale(int scale) { - if(guiScales.size() == 0) { - if(Loader.isModLoaded("labymod")) { + if (guiScales.size() == 0) { + if (Loader.isModLoaded("labymod")) { GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionMatrixOld); GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelviewMatrixOld); } } - if(scale < 0) { - if(guiScales.size() > 0) { + if (scale < 0) { + if (guiScales.size() > 0) { guiScales.pop(); } } else { - if(scale == 0) { + if (scale == 0) { guiScales.push(Minecraft.getMinecraft().gameSettings.guiScale); } else { guiScales.push(scale); @@ -194,25 +206,23 @@ public class Utils { } int newScale = guiScales.size() > 0 ? Math.max(0, Math.min(4, guiScales.peek())) : Minecraft.getMinecraft().gameSettings.guiScale; - if(newScale == 0) newScale = Minecraft.getMinecraft().gameSettings.guiScale; + if (newScale == 0) newScale = Minecraft.getMinecraft().gameSettings.guiScale; int oldScale = Minecraft.getMinecraft().gameSettings.guiScale; Minecraft.getMinecraft().gameSettings.guiScale = newScale; ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); Minecraft.getMinecraft().gameSettings.guiScale = oldScale; - if(guiScales.size() > 0) { + if (guiScales.size() > 0) { GlStateManager.viewport(0, 0, Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, - scaledresolution.getScaledWidth_double(), - scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); + GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.loadIdentity(); GlStateManager.translate(0.0F, 0.0F, -2000.0F); } else { - if(Loader.isModLoaded("labymod") && projectionMatrixOld.limit() > 0 && modelviewMatrixOld.limit() > 0) { + if (Loader.isModLoaded("labymod") && projectionMatrixOld.limit() > 0 && modelviewMatrixOld.limit() > 0) { GlStateManager.matrixMode(GL11.GL_PROJECTION); GL11.glLoadMatrix(projectionMatrixOld); GlStateManager.matrixMode(GL11.GL_MODELVIEW); @@ -220,9 +230,7 @@ public class Utils { } else { GlStateManager.matrixMode(GL11.GL_PROJECTION); GlStateManager.loadIdentity(); - GlStateManager.ortho(0.0D, - scaledresolution.getScaledWidth_double(), - scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); + GlStateManager.ortho(0.0D, scaledresolution.getScaledWidth_double(), scaledresolution.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D); GlStateManager.matrixMode(GL11.GL_MODELVIEW); GlStateManager.loadIdentity(); GlStateManager.translate(0.0F, 0.0F, -2000.0F); @@ -236,12 +244,11 @@ public class Utils { public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { int strLen = fr.getStringWidth(str); - float x2 = x - strLen/2f; - float y2 = y - fr.FONT_HEIGHT/2f; + float x2 = x - strLen / 2f; + float y2 = y - fr.FONT_HEIGHT / 2f; GL11.glTranslatef(x2, y2, 0); fr.drawString(str, 0, 0, colour, shadow); GL11.glTranslatef(-x2, -y2, 0); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java index fbf68c9..b1115ae 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/LeaderboardGetter.java @@ -1,9 +1,13 @@ package com.thatgravyboat.skyblockhud.api; +import static com.thatgravyboat.skyblockhud.ComponentHandler.SCOREBOARD_CHARACTERS; + import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPreGetEvent; +import java.util.*; +import java.util.stream.Collectors; import net.minecraft.client.Minecraft; import net.minecraft.scoreboard.Score; import net.minecraft.scoreboard.ScoreObjective; @@ -13,11 +17,6 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -import java.util.*; -import java.util.stream.Collectors; - -import static com.thatgravyboat.skyblockhud.ComponentHandler.SCOREBOARD_CHARACTERS; - public class LeaderboardGetter { private static Map<Integer, String> cachedScores = new HashMap<>(); @@ -26,7 +25,7 @@ public class LeaderboardGetter { private static int ticks = 0; @SubscribeEvent - public void onClientUpdate(TickEvent.ClientTickEvent event){ + public void onClientUpdate(TickEvent.ClientTickEvent event) { if (event.phase.equals(TickEvent.Phase.START)) return; ticks++; if (ticks % 5 != 0) return; @@ -41,11 +40,13 @@ public class LeaderboardGetter { Map<Integer, String> scores = scoreList.stream().collect(Collectors.toMap(Score::getScorePoints, this::getLine)); if (!cachedScores.equals(scores)) { - scores.forEach((score, name) -> { - if (cachedScores.get(score) == null || !cachedScores.get(score).equals(name)) { - MinecraftForge.EVENT_BUS.post(new SidebarLineUpdateEvent(name, SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim(), score, scores.size(), scoreboard, sidebarObjective)); + scores.forEach( + (score, name) -> { + if (cachedScores.get(score) == null || !cachedScores.get(score).equals(name)) { + MinecraftForge.EVENT_BUS.post(new SidebarLineUpdateEvent(name, SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim(), score, scores.size(), scoreboard, sidebarObjective)); + } } - }); + ); cachedScores = scores; cachedScoresList = scores.values().stream().map(name -> SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim()).collect(Collectors.toList()); } @@ -58,6 +59,4 @@ public class LeaderboardGetter { ScorePlayerTeam scorePlayerTeam = score.getScoreScoreboard().getPlayersTeam(score.getPlayerName()); return Utils.removeColor(ScorePlayerTeam.formatPlayerName(scorePlayerTeam, score.getPlayerName())); } - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarPostEvent.java b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarPostEvent.java index b81859a..34d27e6 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarPostEvent.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/api/events/SidebarPostEvent.java @@ -1,11 +1,10 @@ package com.thatgravyboat.skyblockhud.api.events; +import java.util.List; import net.minecraft.scoreboard.ScoreObjective; import net.minecraft.scoreboard.Scoreboard; import net.minecraftforge.fml.common.eventhandler.Event; -import java.util.List; - public class SidebarPostEvent extends Event { public Scoreboard scoreboard; @@ -17,6 +16,6 @@ public class SidebarPostEvent extends Event { this.scoreboard = scoreboard; this.objective = objective; this.scores = scores; - this.arrayScores = scores.toArray(new String[]{}); + this.arrayScores = scores.toArray(new String[] {}); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java b/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java index 3ca82e7..ef3df57 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/commands/Commands.java @@ -14,7 +14,7 @@ public class Commands { private static final SimpleCommand.ProcessCommandRunnable settingsRunnable = new SimpleCommand.ProcessCommandRunnable() { public void processCommand(ICommandSender sender, String[] args) { - if(args.length > 0) { + if (args.length > 0) { SkyblockHud.screenToOpen = new GuiScreenElementWrapper(new SBHConfigEditor(SkyblockHud.config, StringUtils.join(args, " "))); } else { SkyblockHud.screenToOpen = new GuiScreenElementWrapper(new SBHConfigEditor(SkyblockHud.config)); @@ -26,14 +26,16 @@ public class Commands { private static final SimpleCommand settingsCommand2 = new SimpleCommand("sbhsettings", settingsRunnable); private static final SimpleCommand settingsCommand3 = new SimpleCommand("sbhud", settingsRunnable); - private static final SimpleCommand mapCommand = new SimpleCommand("sbhmap", new SimpleCommand.ProcessCommandRunnable() { - public void processCommand(ICommandSender sender, String[] args) { - if (LocationHandler.getCurrentLocation().getCategory().getMap() != null) - SkyblockHud.screenToOpen = new MapHandler.MapScreen(); + private static final SimpleCommand mapCommand = new SimpleCommand( + "sbhmap", + new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + if (LocationHandler.getCurrentLocation().getCategory().getMap() != null) SkyblockHud.screenToOpen = new MapHandler.MapScreen(); + } } - }); + ); - public static void init(){ + public static void init() { ClientCommandHandler.instance.registerCommand(settingsCommand); ClientCommandHandler.instance.registerCommand(settingsCommand2); ClientCommandHandler.instance.registerCommand(settingsCommand3); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java index 7fc7920..db23b8e 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java @@ -1,12 +1,11 @@ package com.thatgravyboat.skyblockhud.commands; +import java.util.List; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.util.BlockPos; -import java.util.List; - /** @author Moulberry **/ @@ -28,10 +27,12 @@ public class SimpleCommand extends CommandBase { } public abstract static class ProcessCommandRunnable { + public abstract void processCommand(ICommandSender sender, String[] args); } public abstract static class TabCompleteRunnable { + public abstract List<String> tabComplete(ICommandSender sender, String[] args, BlockPos pos); } @@ -52,7 +53,7 @@ public class SimpleCommand extends CommandBase { } public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) { - if(tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos); + if (tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos); return null; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/KeyBindings.java b/src/main/java/com/thatgravyboat/skyblockhud/config/KeyBindings.java index 805b906..9ffd352 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/KeyBindings.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/KeyBindings.java @@ -3,7 +3,6 @@ package com.thatgravyboat.skyblockhud.config; import net.minecraft.client.settings.KeyBinding; public class KeyBindings { - public static KeyBinding map = new KeyBinding("Opens the big map.", 50, "SkyblockHud"); + public static KeyBinding map = new KeyBinding("Opens the big map.", 50, "SkyblockHud"); } - diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java index 1f6e581..90f4c19 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfig.java @@ -12,22 +12,16 @@ import net.minecraft.client.Minecraft; public class SBHConfig extends Config { private void editOverlay(String activeConfig, int width, int height, Position position) { - Minecraft.getMinecraft().displayGuiScreen( - new GuiPositionEditor(position, width, height, - () -> {}, - () -> {}, - () -> SkyblockHud.screenToOpen = new GuiScreenElementWrapper(new SBHConfigEditor(SkyblockHud.config, activeConfig)) - ) - ); + Minecraft.getMinecraft().displayGuiScreen(new GuiPositionEditor(position, width, height, () -> {}, () -> {}, () -> SkyblockHud.screenToOpen = new GuiScreenElementWrapper(new SBHConfigEditor(SkyblockHud.config, activeConfig)))); } @Override public void executeRunnable(String runnableId) { String activeConfigCategory = null; - if(Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper) { + if (Minecraft.getMinecraft().currentScreen instanceof GuiScreenElementWrapper) { GuiScreenElementWrapper wrapper = (GuiScreenElementWrapper) Minecraft.getMinecraft().currentScreen; - if(wrapper.element instanceof SBHConfigEditor) { - activeConfigCategory = ((SBHConfigEditor)wrapper.element).getSelectedCategoryName(); + if (wrapper.element instanceof SBHConfigEditor) { + activeConfigCategory = ((SBHConfigEditor) wrapper.element).getSelectedCategoryName(); } } @@ -63,424 +57,263 @@ public class SBHConfig extends Config { } @Expose - @Category( - name = "Misc Options", - desc = "Just a bunch of random options." - ) + @Category(name = "Misc Options", desc = "Just a bunch of random options.") public Misc misc = new Misc(); @Expose - @Category( - name = "Main Hud", - desc = "All Options for the main hud." - ) + @Category(name = "Main Hud", desc = "All Options for the main hud.") public MainHud main = new MainHud(); @Expose - @Category( - name = "RPG Hud", - desc = "All Options for the RPG hud." - ) + @Category(name = "RPG Hud", desc = "All Options for the RPG hud.") public RPGHud rpg = new RPGHud(); @Expose - @Category( - name = "Dungeon Hud", - desc = "All Options for the Dungeon hud." - ) + @Category(name = "Dungeon Hud", desc = "All Options for the Dungeon hud.") public DungeonHud dungeon = new DungeonHud(); @Expose - @Category( - name = "Renderer", - desc = "All Options for rendering." - ) + @Category(name = "Renderer", desc = "All Options for rendering.") public Renderer renderer = new Renderer(); @Expose - @Category( - name = "Map", - desc = "All Options for the Map." - ) + @Category(name = "Map", desc = "All Options for the Map.") public Map map = new Map(); @Expose - @Category( - name = "Tracker", - desc = "All Options for the Trackers." - ) + @Category(name = "Tracker", desc = "All Options for the Trackers.") public Trackers trackers = new Trackers(); public static class Misc { + @Expose - @ConfigOption( - name = "Hide Scoreboard", - desc = "Hides the scoreboard when in skyblock." - ) + @ConfigOption(name = "Hide Scoreboard", desc = "Hides the scoreboard when in skyblock.") @ConfigEditorBoolean public boolean hideScoreboard = false; } public static class MainHud { + @Expose - @ConfigOption( - name = "Main Hud Position", - desc = "" - ) - @ConfigEditorButton( - runnableId = "main", - buttonText = "Edit" - ) + @ConfigOption(name = "Main Hud Position", desc = "") + @ConfigEditorButton(runnableId = "main", buttonText = "Edit") public Position mainHudPos = new Position(0, 1, true, false); @Expose - @ConfigOption( - name = "Twelve Hour Clock", - desc = "Allows you to change the clock to be 12 hour instead of 24 hour." - ) + @ConfigOption(name = "Twelve Hour Clock", desc = "Allows you to change the clock to be 12 hour instead of 24 hour.") @ConfigEditorBoolean public boolean twelveHourClock = false; @Expose - @ConfigOption( - name = "Shift hud with boss", - desc = "Shifts the hud when bossbar is visible." - ) + @ConfigOption(name = "Shift hud with boss", desc = "Shifts the hud when bossbar is visible.") @ConfigEditorBoolean public boolean bossShiftHud = true; @Expose - @ConfigOption( - name = "Require Redstone", - desc = "Allows to make it so that the redstone percentage requires you to hold a redstone item to show." - ) + @ConfigOption(name = "Require Redstone", desc = "Allows to make it so that the redstone percentage requires you to hold a redstone item to show.") @ConfigEditorBoolean public boolean requireRedstone = true; } public static class RPGHud { + @Expose - @ConfigOption( - name = "Show RPG Hud", - desc = "Allows you to show or hide the RPG Hud." - ) + @ConfigOption(name = "Show RPG Hud", desc = "Allows you to show or hide the RPG Hud.") @ConfigEditorBoolean public boolean showRpgHud = true; @Expose - @ConfigOption( - name = "RPG Hud Position", - desc = "Allows you to change the position of the RPG Hud." - ) - @ConfigEditorButton( - runnableId = "rpg", - buttonText = "Edit" - ) + @ConfigOption(name = "RPG Hud Position", desc = "Allows you to change the position of the RPG Hud.") + @ConfigEditorButton(runnableId = "rpg", buttonText = "Edit") public Position rpgHudPosition = new Position(1, 1); } public static class DungeonHud { @Expose - @ConfigOption( - name = "Dungeon Ultimate Bar", - desc = "" - ) + @ConfigOption(name = "Dungeon Ultimate Bar", desc = "") @ConfigEditorAccordion(id = 2) public boolean ultimateBar = false; @Expose - @ConfigOption( - name = "Hide Ultimate Bar", - desc = "Hides the custom ultimate bar." - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Hide Ultimate Bar", desc = "Hides the custom ultimate bar.") + @ConfigEditorBoolean @ConfigAccordionId(id = 2) public boolean hideUltimateBar = false; @Expose - @ConfigOption( - name = "Bar Position", - desc = "Change the position of the bar." - ) - @ConfigEditorButton( - runnableId = "ultimate", - buttonText = "Edit" - ) + @ConfigOption(name = "Bar Position", desc = "Change the position of the bar.") + @ConfigEditorButton(runnableId = "ultimate", buttonText = "Edit") @ConfigAccordionId(id = 2) public Position barPosition = new Position(0, 50, true, false); @Expose - @ConfigOption( - name = "Bar Loading Color", - desc = "The color of the bar when its loading." - ) - @ConfigEditorColour() + @ConfigOption(name = "Bar Loading Color", desc = "The color of the bar when its loading.") + @ConfigEditorColour @ConfigAccordionId(id = 2) public String barLoadColor = "159:0:0:0:255"; @Expose - @ConfigOption( - name = "Bar Full Color", - desc = "The color of the bar when its full." - ) - @ConfigEditorColour() + @ConfigOption(name = "Bar Full Color", desc = "The color of the bar when its full.") + @ConfigEditorColour @ConfigAccordionId(id = 2) public String barFullColor = "255:0:0:0:255"; @Expose - @ConfigOption( - name = "Bar Style", - desc = "Change the style of the bar" - ) - @ConfigEditorDropdown(values = {"No Notch", "6 Notch", "10 Notch", "12 Notch", "20 Notch"}) + @ConfigOption(name = "Bar Style", desc = "Change the style of the bar") + @ConfigEditorDropdown(values = { "No Notch", "6 Notch", "10 Notch", "12 Notch", "20 Notch" }) @ConfigAccordionId(id = 2) public int barStyle = 2; @Expose - @ConfigOption( - name = "Dungeon Players", - desc = "" - ) + @ConfigOption(name = "Dungeon Players", desc = "") @ConfigEditorAccordion(id = 1) public boolean dungeonPlayerAccordion = false; @Expose - @ConfigOption( - name = "Hide Dungeon Players", - desc = "Allows you to hide the dungeon player hud" - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Hide Dungeon Players", desc = "Allows you to hide the dungeon player hud") + @ConfigEditorBoolean @ConfigAccordionId(id = 1) public boolean hideDungeonPlayers = false; @Expose - @ConfigOption( - name = "Dungeon Player Opacity", - desc = "Allows you to change the opacity of the dungeon players." - ) + @ConfigOption(name = "Dungeon Player Opacity", desc = "Allows you to change the opacity of the dungeon players.") @ConfigEditorSlider(minValue = 0, maxValue = 100, minStep = 1) @ConfigAccordionId(id = 1) public int dungeonPlayerOpacity = 0; @Expose - @ConfigOption( - name = "Hide Dead Players", - desc = "Allows you to hide players that are dead or have left." - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Hide Dead Players", desc = "Allows you to hide players that are dead or have left.") + @ConfigEditorBoolean @ConfigAccordionId(id = 1) public boolean hideDeadDungeonPlayers = false; @Expose - @ConfigOption( - name = "Player Position 1", - desc = "Change the position of this dungeon player." - ) - @ConfigEditorButton( - runnableId = "d1", - buttonText = "Edit" - ) + @ConfigOption(name = "Player Position 1", desc = "Change the position of this dungeon player.") + @ConfigEditorButton(runnableId = "d1", buttonText = "Edit") @ConfigAccordionId(id = 1) public Position dungeonPlayer1 = new Position(5, 5); - @Expose - @ConfigOption( - name = "Player Position 2", - desc = "Change the position of this dungeon player." - ) - @ConfigEditorButton( - runnableId = "d2", - buttonText = "Edit" - ) + @ConfigOption(name = "Player Position 2", desc = "Change the position of this dungeon player.") + @ConfigEditorButton(runnableId = "d2", buttonText = "Edit") @ConfigAccordionId(id = 1) public Position dungeonPlayer2 = new Position(5, 42); @Expose - @ConfigOption( - name = "Player Position 3", - desc = "Change the position of this dungeon player." - ) - @ConfigEditorButton( - runnableId = "d3", - buttonText = "Edit" - ) + @ConfigOption(name = "Player Position 3", desc = "Change the position of this dungeon player.") + @ConfigEditorButton(runnableId = "d3", buttonText = "Edit") @ConfigAccordionId(id = 1) public Position dungeonPlayer3 = new Position(5, 79); @Expose - @ConfigOption( - name = "Player Position 4", - desc = "Change the position of this dungeon player." - ) - @ConfigEditorButton( - runnableId = "d4", - buttonText = "Edit" - ) + @ConfigOption(name = "Player Position 4", desc = "Change the position of this dungeon player.") + @ConfigEditorButton(runnableId = "d4", buttonText = "Edit") @ConfigAccordionId(id = 1) public Position dungeonPlayer4 = new Position(5, 116); - } public static class Renderer { + @Expose - @ConfigOption( - name = "Hide Boss Bar", - desc = "Hides Boss Bar when certain conditions are met such as the name is just wither or it starts with objective:" - ) + @ConfigOption(name = "Hide Boss Bar", desc = "Hides Boss Bar when certain conditions are met such as the name is just wither or it starts with objective:") @ConfigEditorBoolean public boolean hideBossBar = true; @Expose - @ConfigOption( - name = "Hide XP Bar", - desc = "Hides xp bar." - ) + @ConfigOption(name = "Hide XP Bar", desc = "Hides xp bar.") @ConfigEditorBoolean public boolean hideXpBar = true; @Expose - @ConfigOption( - name = "Hide Food", - desc = "Hides food." - ) + @ConfigOption(name = "Hide Food", desc = "Hides food.") @ConfigEditorBoolean public boolean hideFood = true; @Expose - @ConfigOption( - name = "Hide air", - desc = "Hides air." - ) + @ConfigOption(name = "Hide air", desc = "Hides air.") @ConfigEditorBoolean public boolean hideAir = true; @Expose - @ConfigOption( - name = "Hide hearts", - desc = "Hides hearts." - ) + @ConfigOption(name = "Hide hearts", desc = "Hides hearts.") @ConfigEditorBoolean public boolean hideHearts = true; @Expose - @ConfigOption( - name = "Hide armor", - desc = "Hides armor." - ) + @ConfigOption(name = "Hide armor", desc = "Hides armor.") @ConfigEditorBoolean public boolean hideArmor = true; @Expose - @ConfigOption( - name = "Hide Animal Hearts", - desc = "Hides Animal Hearts." - ) + @ConfigOption(name = "Hide Animal Hearts", desc = "Hides Animal Hearts.") @ConfigEditorBoolean public boolean hideAnimalHearts = true; } public static class Map { + @Expose - @ConfigOption( - name = "Show Player Location", - desc = "This feature is off by default as Hypixel's rules are so vague that this would fall under their disallowed modifications." - ) + @ConfigOption(name = "Show Player Location", desc = "This feature is off by default as Hypixel's rules are so vague that this would fall under their disallowed modifications.") @ConfigEditorBoolean public boolean showPlayerLocation = false; @Expose - @ConfigOption( - name = "Show Mini-Map", - desc = "Shows the Mini-Map on your overlay if turned off you can still use /sbhmap to see the map in fullscreen." - ) + @ConfigOption(name = "Show Mini-Map", desc = "Shows the Mini-Map on your overlay if turned off you can still use /sbhmap to see the map in fullscreen.") @ConfigEditorBoolean public boolean showMiniMap = false; @Expose - @ConfigOption( - name = "Mini-Map Position", - desc = "Allows you to change the position of the Mini-Map." - ) - @ConfigEditorButton( - runnableId = "map", - buttonText = "Edit" - ) + @ConfigOption(name = "Mini-Map Position", desc = "Allows you to change the position of the Mini-Map.") + @ConfigEditorButton(runnableId = "map", buttonText = "Edit") public Position miniMapPosition = new Position(0, 100, false, false); @Expose - @ConfigOption( - name = "Icons", - desc = "" - ) + @ConfigOption(name = "Icons", desc = "") @ConfigEditorAccordion(id = 3) public boolean icons = false; @Expose - @ConfigOption( - name = "NPC", - desc = "Show NPC Icons" - ) - @ConfigEditorBoolean() + @ConfigOption(name = "NPC", desc = "Show NPC Icons") + @ConfigEditorBoolean @ConfigAccordionId(id = 3) public boolean showNpcIcons = true; @Expose - @ConfigOption( - name = "Info", - desc = "Show Info Icons" - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Info", desc = "Show Info Icons") + @ConfigEditorBoolean @ConfigAccordionId(id = 3) public boolean showInfoIcons = true; @Expose - @ConfigOption( - name = "Misc", - desc = "Show Misc Icons" - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Misc", desc = "Show Misc Icons") + @ConfigEditorBoolean @ConfigAccordionId(id = 3) public boolean showMiscIcons = true; @Expose - @ConfigOption( - name = "Shops", - desc = "Show Shop Icons" - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Shops", desc = "Show Shop Icons") + @ConfigEditorBoolean @ConfigAccordionId(id = 3) public boolean showShopIcons = true; @Expose - @ConfigOption( - name = "Quests", - desc = "Show Quest Icons" - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Quests", desc = "Show Quest Icons") + @ConfigEditorBoolean @ConfigAccordionId(id = 3) public boolean showQuestIcons = false; } public static class Trackers { + @Expose - @ConfigOption( - name = "Tracker Position", - desc = "Allows you to change the position of the Trackers." - ) - @ConfigEditorButton( - runnableId = "tracker", - buttonText = "Edit" - ) + @ConfigOption(name = "Tracker Position", desc = "Allows you to change the position of the Trackers.") + @ConfigEditorButton(runnableId = "tracker", buttonText = "Edit") public Position trackerPosition = new Position(-1, 200); @Expose - @ConfigOption( - name = "Hide Tracker", - desc = "It will still track the data just in case." - ) - @ConfigEditorBoolean() + @ConfigOption(name = "Hide Tracker", desc = "It will still track the data just in case.") + @ConfigEditorBoolean public boolean hideTracker = false; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java index 7f4bd23..0496a8f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/config/SBHConfigEditor.java @@ -1,5 +1,7 @@ package com.thatgravyboat.skyblockhud.config; +import static com.thatgravyboat.skyblockhud.GuiTextures.*; + import com.google.common.collect.Lists; import com.thatgravyboat.skyblockhud.core.GlScissorStack; import com.thatgravyboat.skyblockhud.core.GuiElement; @@ -11,6 +13,10 @@ import com.thatgravyboat.skyblockhud.core.util.lerp.LerpUtils; import com.thatgravyboat.skyblockhud.core.util.lerp.LerpingInteger; 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.*; +import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -21,23 +27,10 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import java.awt.*; -import java.net.URI; -import java.util.*; -import java.util.List; - -import static com.thatgravyboat.skyblockhud.GuiTextures.*; - public class SBHConfigEditor extends GuiElement { - private static final ResourceLocation[] socialsIco = new ResourceLocation[] { - DISCORD, - TWITTER - }; - private static final String[] socialsLink = new String[] { - "https://discord.gg/moulberry", - "https://twitter.com/thatgravytboat/" - }; + private static final ResourceLocation[] socialsIco = new ResourceLocation[] { DISCORD, TWITTER }; + private static final String[] socialsLink = new String[] { "https://discord.gg/moulberry", "https://twitter.com/thatgravytboat/" }; private final long openedMillis; @@ -57,30 +50,30 @@ public class SBHConfigEditor extends GuiElement { this.openedMillis = System.currentTimeMillis(); this.processedConfig = ConfigProcessor.create(config); - for(ConfigProcessor.ProcessedCategory category : processedConfig.values()) { - for(ConfigProcessor.ProcessedOption option : category.options.values()) { + for (ConfigProcessor.ProcessedCategory category : processedConfig.values()) { + for (ConfigProcessor.ProcessedOption option : category.options.values()) { categoryForOption.put(option, category); } } - if(categoryOpen != null) { - for(Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { - if(category.getValue().name.equalsIgnoreCase(categoryOpen)) { + if (categoryOpen != null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { + if (category.getValue().name.equalsIgnoreCase(categoryOpen)) { selectedCategory = category.getKey(); break; } } - if(selectedCategory == null) { - for(Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { - if(category.getValue().name.toLowerCase().startsWith(categoryOpen.toLowerCase())) { + if (selectedCategory == null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { + if (category.getValue().name.toLowerCase().startsWith(categoryOpen.toLowerCase())) { selectedCategory = category.getKey(); break; } } } - if(selectedCategory == null) { - for(Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { - if(category.getValue().name.toLowerCase().contains(categoryOpen.toLowerCase())) { + if (selectedCategory == null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> category : processedConfig.entrySet()) { + if (category.getValue().name.toLowerCase().contains(categoryOpen.toLowerCase())) { selectedCategory = category.getKey(); break; } @@ -125,199 +118,184 @@ public class SBHConfigEditor extends GuiElement { int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth; int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1; - float opacityFactor = LerpUtils.sigmoidZeroOne(delta/500f); - RenderUtils.drawGradientRect(0, 0, 0, width, height, - (int)(0x80*opacityFactor) << 24 | 0x101010, - (int)(0x90*opacityFactor) << 24 | 0x101010); + float opacityFactor = LerpUtils.sigmoidZeroOne(delta / 500f); + RenderUtils.drawGradientRect(0, 0, 0, width, height, (int) (0x80 * opacityFactor) << 24 | 0x101010, (int) (0x90 * opacityFactor) << 24 | 0x101010); - int xSize = Math.min(scaledResolution.getScaledWidth()-100/scaledResolution.getScaleFactor(), 500); - int ySize = Math.min(scaledResolution.getScaledHeight()-100/scaledResolution.getScaleFactor(), 400); + int xSize = Math.min(scaledResolution.getScaledWidth() - 100 / scaledResolution.getScaleFactor(), 500); + int ySize = Math.min(scaledResolution.getScaledHeight() - 100 / scaledResolution.getScaleFactor(), 400); - int x = (scaledResolution.getScaledWidth() - xSize)/2; - int y = (scaledResolution.getScaledHeight() - ySize)/2; + int x = (scaledResolution.getScaledWidth() - xSize) / 2; + int y = (scaledResolution.getScaledHeight() - ySize) / 2; int adjScaleFactor = Math.max(2, scaledResolution.getScaleFactor()); int openingXSize = xSize; int openingYSize = ySize; - if(delta < 150) { - openingXSize = (int)(delta*xSize/150); + if (delta < 150) { + openingXSize = (int) (delta * xSize / 150); openingYSize = 5; - } else if(delta < 300) { - openingYSize = 5 + (int)(delta-150)*(ySize-5)/150; + } else if (delta < 300) { + openingYSize = 5 + (int) (delta - 150) * (ySize - 5) / 150; } - RenderUtils.drawFloatingRectDark( - (scaledResolution.getScaledWidth() - openingXSize)/2, - (scaledResolution.getScaledHeight() - openingYSize)/2, - openingXSize, openingYSize); + RenderUtils.drawFloatingRectDark((scaledResolution.getScaledWidth() - openingXSize) / 2, (scaledResolution.getScaledHeight() - openingYSize) / 2, openingXSize, openingYSize); GlScissorStack.clear(); - GlScissorStack.push((scaledResolution.getScaledWidth() - openingXSize)/2, - (scaledResolution.getScaledHeight() - openingYSize)/2, - (scaledResolution.getScaledWidth() + openingXSize)/2, - (scaledResolution.getScaledHeight() + openingYSize)/2, scaledResolution); + GlScissorStack.push((scaledResolution.getScaledWidth() - openingXSize) / 2, (scaledResolution.getScaledHeight() - openingYSize) / 2, (scaledResolution.getScaledWidth() + openingXSize) / 2, (scaledResolution.getScaledHeight() + openingYSize) / 2, scaledResolution); - RenderUtils.drawFloatingRectDark(x+5, y+5, xSize-10, 20, false); + RenderUtils.drawFloatingRectDark(x + 5, y + 5, xSize - 10, 20, false); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - TextRenderUtils.drawStringCenteredScaledMaxWidth("SkyBlockHud by "+EnumChatFormatting.RED+"ThatGravyBoat"+EnumChatFormatting.RESET+", config by "+EnumChatFormatting.DARK_PURPLE+"Moulberry", - fr, x+xSize/2f, y+15, false, 200, 0xa0a0a0); - - RenderUtils.drawFloatingRectDark(x+4, y+49-20, - 140, ySize-54+20, false); - - int innerPadding = 20/adjScaleFactor; - int innerLeft = x+4+innerPadding; - int innerRight = x+144-innerPadding; - int innerTop = y+49+innerPadding; - int innerBottom = y+ySize-5-innerPadding; - Gui.drawRect(innerLeft, innerTop, innerLeft+1, innerBottom, 0xff08080E); //Left - Gui.drawRect(innerLeft+1, innerTop, innerRight, innerTop+1, 0xff08080E); //Top - Gui.drawRect(innerRight-1, innerTop+1, innerRight, innerBottom, 0xff28282E); //Right - Gui.drawRect(innerLeft+1, innerBottom-1, innerRight-1, innerBottom, 0xff28282E); //Bottom - Gui.drawRect(innerLeft+1, innerTop+1, innerRight-1, innerBottom-1, 0x6008080E); //Middle - - GlScissorStack.push(0, innerTop+1, scaledResolution.getScaledWidth(), - innerBottom-1, scaledResolution); + TextRenderUtils.drawStringCenteredScaledMaxWidth("SkyBlockHud by " + EnumChatFormatting.RED + "ThatGravyBoat" + EnumChatFormatting.RESET + ", config by " + EnumChatFormatting.DARK_PURPLE + "Moulberry", fr, x + xSize / 2f, y + 15, false, 200, 0xa0a0a0); + + RenderUtils.drawFloatingRectDark(x + 4, y + 49 - 20, 140, ySize - 54 + 20, false); + + int innerPadding = 20 / adjScaleFactor; + int innerLeft = x + 4 + innerPadding; + int innerRight = x + 144 - innerPadding; + int innerTop = y + 49 + innerPadding; + int innerBottom = y + ySize - 5 - innerPadding; + Gui.drawRect(innerLeft, innerTop, innerLeft + 1, innerBottom, 0xff08080E); //Left + Gui.drawRect(innerLeft + 1, innerTop, innerRight, innerTop + 1, 0xff08080E); //Top + Gui.drawRect(innerRight - 1, innerTop + 1, innerRight, innerBottom, 0xff28282E); //Right + Gui.drawRect(innerLeft + 1, innerBottom - 1, innerRight - 1, innerBottom, 0xff28282E); //Bottom + Gui.drawRect(innerLeft + 1, innerTop + 1, innerRight - 1, innerBottom - 1, 0x6008080E); //Middle + + GlScissorStack.push(0, innerTop + 1, scaledResolution.getScaledWidth(), innerBottom - 1, scaledResolution); float catBarSize = 1; int catY = -categoryScroll.getValue(); LinkedHashMap<String, ConfigProcessor.ProcessedCategory> currentConfigEditing = getCurrentConfigEditing(); - for(Map.Entry<String, ConfigProcessor.ProcessedCategory> entry : currentConfigEditing.entrySet()) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> entry : currentConfigEditing.entrySet()) { String selectedCategory = getSelectedCategory(); - if(selectedCategory == null || !currentConfigEditing.containsKey(selectedCategory)) { + if (selectedCategory == null || !currentConfigEditing.containsKey(selectedCategory)) { setSelectedCategory(entry.getKey()); } String catName = entry.getValue().name; - if(entry.getKey().equals(getSelectedCategory())) { + if (entry.getKey().equals(getSelectedCategory())) { catName = EnumChatFormatting.DARK_AQUA.toString() + EnumChatFormatting.UNDERLINE + catName; } else { catName = EnumChatFormatting.GRAY + catName; } - TextRenderUtils.drawStringCenteredScaledMaxWidth(catName, - fr, x+75, y+70+catY, false, 100, -1); + TextRenderUtils.drawStringCenteredScaledMaxWidth(catName, fr, x + 75, y + 70 + catY, false, 100, -1); catY += 15; - if(catY > 0) { - catBarSize = LerpUtils.clampZeroOne((float)(innerBottom-innerTop-2)/(catY+5+categoryScroll.getValue())); + if (catY > 0) { + catBarSize = LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (catY + 5 + categoryScroll.getValue())); } } - float catBarStart = categoryScroll.getValue() / (float)(catY + categoryScroll.getValue()); - float catBarEnd = catBarStart+catBarSize; - if(catBarEnd > 1) { + float catBarStart = categoryScroll.getValue() / (float) (catY + categoryScroll.getValue()); + float catBarEnd = catBarStart + catBarSize; + if (catBarEnd > 1) { catBarEnd = 1; - if(categoryScroll.getTarget()/(float)(catY + categoryScroll.getValue())+catBarSize < 1) { + if (categoryScroll.getTarget() / (float) (catY + categoryScroll.getValue()) + catBarSize < 1) { int target = optionsScroll.getTarget(); - categoryScroll.setValue((int)Math.ceil((catY+5+categoryScroll.getValue())-catBarSize*(catY+5+categoryScroll.getValue()))); + categoryScroll.setValue((int) Math.ceil((catY + 5 + categoryScroll.getValue()) - catBarSize * (catY + 5 + categoryScroll.getValue()))); categoryScroll.setTarget(target); } else { - categoryScroll.setValue((int)Math.ceil((catY+5+categoryScroll.getValue())-catBarSize*(catY+5+categoryScroll.getValue()))); + categoryScroll.setValue((int) Math.ceil((catY + 5 + categoryScroll.getValue()) - catBarSize * (catY + 5 + categoryScroll.getValue()))); } } - int catDist = innerBottom-innerTop-12; - Gui.drawRect(innerLeft+2, innerTop+5, innerLeft+7, innerBottom-5, 0xff101010); - Gui.drawRect(innerLeft+3, innerTop+6+(int)(catDist*catBarStart), innerLeft+6, - innerTop+6+(int)(catDist*catBarEnd), 0xff303030); + int catDist = innerBottom - innerTop - 12; + Gui.drawRect(innerLeft + 2, innerTop + 5, innerLeft + 7, innerBottom - 5, 0xff101010); + Gui.drawRect(innerLeft + 3, innerTop + 6 + (int) (catDist * catBarStart), innerLeft + 6, innerTop + 6 + (int) (catDist * catBarEnd), 0xff303030); GlScissorStack.pop(scaledResolution); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Categories", - fr, x+75, y+44, false, 120, 0xa368ef); + TextRenderUtils.drawStringCenteredScaledMaxWidth("Categories", fr, x + 75, y + 44, false, 120, 0xa368ef); - RenderUtils.drawFloatingRectDark(x+149, y+29, xSize-154, ySize-34, false); + RenderUtils.drawFloatingRectDark(x + 149, y + 29, xSize - 154, ySize - 34, false); - innerLeft = x+149+innerPadding; - innerRight =x+xSize-5-innerPadding; - innerBottom = y+ySize-5-innerPadding; + innerLeft = x + 149 + innerPadding; + innerRight = x + xSize - 5 - innerPadding; + innerBottom = y + ySize - 5 - innerPadding; GlStateManager.color(1, 1, 1, 1); int rightStuffLen = 20; - if(getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = currentConfigEditing.get(getSelectedCategory()); - TextRenderUtils.drawStringScaledMaxWidth(cat.desc, - fr, innerLeft+5, y+40, true, innerRight-innerLeft-rightStuffLen-10, 0xb0b0b0); + TextRenderUtils.drawStringScaledMaxWidth(cat.desc, fr, innerLeft + 5, y + 40, true, innerRight - innerLeft - rightStuffLen - 10, 0xb0b0b0); } - Gui.drawRect(innerLeft, innerTop, innerLeft+1, innerBottom, 0xff08080E); //Left - Gui.drawRect(innerLeft+1, innerTop, innerRight, innerTop+1, 0xff08080E); //Top - Gui.drawRect(innerRight-1, innerTop+1, innerRight, innerBottom, 0xff303036); //Right - Gui.drawRect(innerLeft+1, innerBottom-1, innerRight-1, innerBottom, 0xff303036); //Bottom - Gui.drawRect(innerLeft+1, innerTop+1, innerRight-1, innerBottom-1, 0x6008080E); //Middle + Gui.drawRect(innerLeft, innerTop, innerLeft + 1, innerBottom, 0xff08080E); //Left + Gui.drawRect(innerLeft + 1, innerTop, innerRight, innerTop + 1, 0xff08080E); //Top + Gui.drawRect(innerRight - 1, innerTop + 1, innerRight, innerBottom, 0xff303036); //Right + Gui.drawRect(innerLeft + 1, innerBottom - 1, innerRight - 1, innerBottom, 0xff303036); //Bottom + Gui.drawRect(innerLeft + 1, innerTop + 1, innerRight - 1, innerBottom - 1, 0x6008080E); //Middle - GlScissorStack.push(innerLeft+1, innerTop+1, innerRight-1, innerBottom-1, scaledResolution); + GlScissorStack.push(innerLeft + 1, innerTop + 1, innerRight - 1, innerBottom - 1, scaledResolution); float barSize = 1; int optionY = -optionsScroll.getValue(); - if(getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = currentConfigEditing.get(getSelectedCategory()); - int optionWidthDefault = innerRight-innerLeft-20; + int optionWidthDefault = innerRight - innerLeft - 20; GlStateManager.enableDepth(); Set<Integer> activeAccordions = new HashSet<>(); - for(ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { + for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; - if(option.accordionId >= 0) { - if(!activeAccordions.contains(option.accordionId)) { + if (option.accordionId >= 0) { + if (!activeAccordions.contains(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2*innerPadding; + optionWidth = optionWidthDefault - 2 * innerPadding; } GuiOptionEditor editor = option.editor; - if(editor == null) { + if (editor == null) { continue; } - if(editor instanceof GuiOptionEditorAccordion) { + if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; - if(accordion.getToggled()) { + if (accordion.getToggled()) { activeAccordions.add(accordion.getAccordionId()); } } int optionHeight = editor.getHeight(); - if(innerTop+5+optionY+optionHeight > innerTop+1 && innerTop+5+optionY < innerBottom-1) { - editor.render((innerLeft+innerRight-optionWidth)/2-5, innerTop+5+optionY, optionWidth); + if (innerTop + 5 + optionY + optionHeight > innerTop + 1 && innerTop + 5 + optionY < innerBottom - 1) { + editor.render((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionY, optionWidth); } optionY += optionHeight + 5; } GlStateManager.disableDepth(); - if(optionY > 0) { - barSize = LerpUtils.clampZeroOne((float)(innerBottom-innerTop-2)/(optionY+5+optionsScroll.getValue())); + if (optionY > 0) { + barSize = LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (optionY + 5 + optionsScroll.getValue())); } } GlScissorStack.pop(scaledResolution); GL11.glDisable(GL11.GL_SCISSOR_TEST); - if(getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && currentConfigEditing.containsKey(getSelectedCategory())) { int optionYOverlay = -optionsScroll.getValue(); ConfigProcessor.ProcessedCategory cat = currentConfigEditing.get(getSelectedCategory()); - int optionWidthDefault = innerRight-innerLeft-20; + int optionWidthDefault = innerRight - innerLeft - 20; GlStateManager.translate(0, 0, 10); GlStateManager.enableDepth(); Set<Integer> activeAccordions = new HashSet<>(); - for(ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { + for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; - if(option.accordionId >= 0) { - if(!activeAccordions.contains(option.accordionId)) { + if (option.accordionId >= 0) { + if (!activeAccordions.contains(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2*innerPadding; + optionWidth = optionWidthDefault - 2 * innerPadding; } GuiOptionEditor editor = option.editor; - if(editor == null) { + if (editor == null) { continue; } - if(editor instanceof GuiOptionEditorAccordion) { + if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; - if(accordion.getToggled()) { + if (accordion.getToggled()) { activeAccordions.add(accordion.getAccordionId()); } } int optionHeight = editor.getHeight(); - if(innerTop+5+optionYOverlay+optionHeight > innerTop+1 && innerTop+5+optionYOverlay < innerBottom-1) { - editor.renderOverlay((innerLeft+innerRight-optionWidth)/2-5, innerTop+5+optionYOverlay, optionWidth); + if (innerTop + 5 + optionYOverlay + optionHeight > innerTop + 1 && innerTop + 5 + optionYOverlay < innerBottom - 1) { + editor.renderOverlay((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionYOverlay, optionWidth); } optionYOverlay += optionHeight + 5; } @@ -326,37 +304,36 @@ public class SBHConfigEditor extends GuiElement { } GL11.glEnable(GL11.GL_SCISSOR_TEST); - float barStart = optionsScroll.getValue() / (float)(optionY + optionsScroll.getValue()); - float barEnd = barStart+barSize; - if(barEnd > 1) { + float barStart = optionsScroll.getValue() / (float) (optionY + optionsScroll.getValue()); + float barEnd = barStart + barSize; + if (barEnd > 1) { barEnd = 1; - if(optionsScroll.getTarget()/(float)(optionY + optionsScroll.getValue())+barSize < 1) { + if (optionsScroll.getTarget() / (float) (optionY + optionsScroll.getValue()) + barSize < 1) { int target = optionsScroll.getTarget(); - optionsScroll.setValue((int)Math.ceil((optionY+5+optionsScroll.getValue())-barSize*(optionY+5+optionsScroll.getValue()))); + optionsScroll.setValue((int) Math.ceil((optionY + 5 + optionsScroll.getValue()) - barSize * (optionY + 5 + optionsScroll.getValue()))); optionsScroll.setTarget(target); } else { - optionsScroll.setValue((int)Math.ceil((optionY+5+optionsScroll.getValue())-barSize*(optionY+5+optionsScroll.getValue()))); + optionsScroll.setValue((int) Math.ceil((optionY + 5 + optionsScroll.getValue()) - barSize * (optionY + 5 + optionsScroll.getValue()))); } } - int dist = innerBottom-innerTop-12; - Gui.drawRect(innerRight-10, innerTop+5, innerRight-5, innerBottom-5, 0xff101010); - Gui.drawRect(innerRight-9, innerTop+6+(int)(dist*barStart), innerRight-6, innerTop+6+(int)(dist*barEnd), 0xff303030); + int dist = innerBottom - innerTop - 12; + Gui.drawRect(innerRight - 10, innerTop + 5, innerRight - 5, innerBottom - 5, 0xff101010); + Gui.drawRect(innerRight - 9, innerTop + 6 + (int) (dist * barStart), innerRight - 6, innerTop + 6 + (int) (dist * barEnd), 0xff303030); - for(int socialIndex=0; socialIndex<socialsIco.length; socialIndex++) { + for (int socialIndex = 0; socialIndex < socialsIco.length; socialIndex++) { Minecraft.getMinecraft().getTextureManager().bindTexture(socialsIco[socialIndex]); GlStateManager.color(1, 1, 1, 1); - int socialLeft = x+xSize-23-18*socialIndex; - RenderUtils.drawTexturedRect(socialLeft, y+7, 16, 16, GL11.GL_LINEAR); + int socialLeft = x + xSize - 23 - 18 * socialIndex; + RenderUtils.drawTexturedRect(socialLeft, y + 7, 16, 16, GL11.GL_LINEAR); - if(mouseX >= socialLeft && mouseX <= socialLeft+16 && - mouseY >= y+6 && mouseY <= y+23) { - tooltipToDisplay = Lists.newArrayList(EnumChatFormatting.YELLOW+"Go to: "+EnumChatFormatting.RESET+socialsLink[socialIndex]); + if (mouseX >= socialLeft && mouseX <= socialLeft + 16 && mouseY >= y + 6 && mouseY <= y + 23) { + tooltipToDisplay = Lists.newArrayList(EnumChatFormatting.YELLOW + "Go to: " + EnumChatFormatting.RESET + socialsLink[socialIndex]); } } GlScissorStack.clear(); - if(tooltipToDisplay != null) { + if (tooltipToDisplay != null) { TextRenderUtils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1, fr); } @@ -368,106 +345,105 @@ public class SBHConfigEditor extends GuiElement { int width = scaledResolution.getScaledWidth(); int height = scaledResolution.getScaledHeight(); - int xSize = Math.min(width-100/scaledResolution.getScaleFactor(), 500); - int ySize = Math.min(height-100/scaledResolution.getScaleFactor(), 400); + int xSize = Math.min(width - 100 / scaledResolution.getScaleFactor(), 500); + int ySize = Math.min(height - 100 / scaledResolution.getScaleFactor(), 400); - int x = (scaledResolution.getScaledWidth() - xSize)/2; - int y = (scaledResolution.getScaledHeight() - ySize)/2; + int x = (scaledResolution.getScaledWidth() - xSize) / 2; + int y = (scaledResolution.getScaledHeight() - ySize) / 2; int adjScaleFactor = Math.max(2, scaledResolution.getScaleFactor()); - int innerPadding = 20/adjScaleFactor; - int innerTop = y+49+innerPadding; - int innerBottom = y+ySize-5-innerPadding; - int innerLeft = x+149+innerPadding; - int innerRight = x+xSize-5-innerPadding; + int innerPadding = 20 / adjScaleFactor; + int innerTop = y + 49 + innerPadding; + int innerBottom = y + ySize - 5 - innerPadding; + int innerLeft = x + 149 + innerPadding; + int innerRight = x + xSize - 5 - innerPadding; int dWheel = Mouse.getEventDWheel(); - if(mouseY > innerTop && mouseY < innerBottom && dWheel != 0) { - if(dWheel < 0) { + if (mouseY > innerTop && mouseY < innerBottom && dWheel != 0) { + if (dWheel < 0) { dWheel = -1; } - if(dWheel > 0) { + if (dWheel > 0) { dWheel = 1; } - if(mouseX < innerLeft) { - int newTarget = categoryScroll.getTarget() - dWheel*30; - if(newTarget < 0) { + if (mouseX < innerLeft) { + int newTarget = categoryScroll.getTarget() - dWheel * 30; + if (newTarget < 0) { newTarget = 0; } float catBarSize = 1; int catY = -newTarget; - for(Map.Entry<String, ConfigProcessor.ProcessedCategory> entry : getCurrentConfigEditing().entrySet()) { - if(getSelectedCategory() == null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> entry : getCurrentConfigEditing().entrySet()) { + if (getSelectedCategory() == null) { setSelectedCategory(entry.getKey()); } catY += 15; - if(catY > 0) { - catBarSize = LerpUtils.clampZeroOne((float)(innerBottom-innerTop-2)/(catY+5+newTarget)); + if (catY > 0) { + catBarSize = LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (catY + 5 + newTarget)); } } - int barMax = (int)Math.floor((catY+5+newTarget)-catBarSize*(catY+5+newTarget)); - if(newTarget > barMax) { + int barMax = (int) Math.floor((catY + 5 + newTarget) - catBarSize * (catY + 5 + newTarget)); + if (newTarget > barMax) { newTarget = barMax; } categoryScroll.resetTimer(); categoryScroll.setTarget(newTarget); } else { - int newTarget = optionsScroll.getTarget() - dWheel*30; - if(newTarget < 0) { + int newTarget = optionsScroll.getTarget() - dWheel * 30; + if (newTarget < 0) { newTarget = 0; } float barSize = 1; int optionY = -newTarget; - if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); Set<Integer> activeAccordions = new HashSet<>(); - for(ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { - if(option.accordionId >= 0) { - if(!activeAccordions.contains(option.accordionId)) { + for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { + if (option.accordionId >= 0) { + if (!activeAccordions.contains(option.accordionId)) { continue; } } GuiOptionEditor editor = option.editor; - if(editor == null) { + if (editor == null) { continue; } - if(editor instanceof GuiOptionEditorAccordion) { + if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; - if(accordion.getToggled()) { + if (accordion.getToggled()) { activeAccordions.add(accordion.getAccordionId()); } } optionY += editor.getHeight() + 5; - if(optionY > 0) { - barSize = LerpUtils.clampZeroOne((float)(innerBottom-innerTop-2)/(optionY+5 + newTarget)); + if (optionY > 0) { + barSize = LerpUtils.clampZeroOne((float) (innerBottom - innerTop - 2) / (optionY + 5 + newTarget)); } } } - int barMax = (int)Math.floor((optionY+5+newTarget)-barSize*(optionY+5+newTarget)); - if(newTarget > barMax) { + int barMax = (int) Math.floor((optionY + 5 + newTarget) - barSize * (optionY + 5 + newTarget)); + if (newTarget > barMax) { newTarget = barMax; } - optionsScroll.setTimeToReachTarget(Math.min(150, Math.max(10, 5*Math.abs(newTarget - optionsScroll.getValue())))); + optionsScroll.setTimeToReachTarget(Math.min(150, Math.max(10, 5 * Math.abs(newTarget - optionsScroll.getValue())))); optionsScroll.resetTimer(); optionsScroll.setTarget(newTarget); } - } else if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if(getCurrentConfigEditing() != null) { + } else if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (getCurrentConfigEditing() != null) { int catY = -categoryScroll.getValue(); - for(Map.Entry<String, ConfigProcessor.ProcessedCategory> entry : getCurrentConfigEditing().entrySet()) { - if(getSelectedCategory() == null) { + for (Map.Entry<String, ConfigProcessor.ProcessedCategory> entry : getCurrentConfigEditing().entrySet()) { + if (getSelectedCategory() == null) { setSelectedCategory(entry.getKey()); } - if(mouseX >= x+5 && mouseX <= x+145 && - mouseY >= y+70+catY-7 && mouseY <= y+70+catY+7) { + if (mouseX >= x + 5 && mouseX <= x + 145 && mouseY >= y + 70 + catY - 7 && mouseY <= y + 70 + catY + 7) { setSelectedCategory(entry.getKey()); return true; } @@ -475,76 +451,75 @@ public class SBHConfigEditor extends GuiElement { } } - for(int socialIndex=0; socialIndex<socialsLink.length; socialIndex++) { - int socialLeft = x+xSize-23-18*socialIndex; + for (int socialIndex = 0; socialIndex < socialsLink.length; socialIndex++) { + int socialLeft = x + xSize - 23 - 18 * socialIndex; - if(mouseX >= socialLeft && mouseX <= socialLeft+16 && - mouseY >= y+6 && mouseY <= y+23) { + if (mouseX >= socialLeft && mouseX <= socialLeft + 16 && mouseY >= y + 6 && mouseY <= y + 23) { try { Desktop.getDesktop().browse(new URI(socialsLink[socialIndex])); - } catch(Exception ignored) {} + } catch (Exception ignored) {} return true; } } } int optionY = -optionsScroll.getValue(); - if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { - int optionWidthDefault = innerRight-innerLeft-20; - ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory());Set<Integer> activeAccordions = new HashSet<>(); - for(ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + int optionWidthDefault = innerRight - innerLeft - 20; + ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); + Set<Integer> activeAccordions = new HashSet<>(); + for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; - if(option.accordionId >= 0) { - if(!activeAccordions.contains(option.accordionId)) { + if (option.accordionId >= 0) { + if (!activeAccordions.contains(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2*innerPadding; + optionWidth = optionWidthDefault - 2 * innerPadding; } GuiOptionEditor editor = option.editor; - if(editor == null) { + if (editor == null) { continue; } - if(editor instanceof GuiOptionEditorAccordion) { + if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; - if(accordion.getToggled()) { + if (accordion.getToggled()) { activeAccordions.add(accordion.getAccordionId()); } } - if(editor.mouseInputOverlay((innerLeft+innerRight-optionWidth)/2-5, innerTop+5+optionY, optionWidth, mouseX, mouseY)) { + if (editor.mouseInputOverlay((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionY, optionWidth, mouseX, mouseY)) { return true; } optionY += editor.getHeight() + 5; } } - if(mouseX > innerLeft && mouseX < innerRight && - mouseY > innerTop && mouseY < innerBottom) { + if (mouseX > innerLeft && mouseX < innerRight && mouseY > innerTop && mouseY < innerBottom) { optionY = -optionsScroll.getValue(); - if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { - int optionWidthDefault = innerRight-innerLeft-20; + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + int optionWidthDefault = innerRight - innerLeft - 20; ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); Set<Integer> activeAccordions = new HashSet<>(); - for(ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { + for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { int optionWidth = optionWidthDefault; - if(option.accordionId >= 0) { - if(!activeAccordions.contains(option.accordionId)) { + if (option.accordionId >= 0) { + if (!activeAccordions.contains(option.accordionId)) { continue; } - optionWidth = optionWidthDefault - 2*innerPadding; + optionWidth = optionWidthDefault - 2 * innerPadding; } GuiOptionEditor editor = option.editor; - if(editor == null) { + if (editor == null) { continue; } - if(editor instanceof GuiOptionEditorAccordion) { + if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; - if(accordion.getToggled()) { + if (accordion.getToggled()) { activeAccordions.add(accordion.getAccordionId()); } } - if(editor.mouseInput((innerLeft+innerRight-optionWidth)/2-5, innerTop+5+optionY, optionWidth, mouseX, mouseY)) { + if (editor.mouseInput((innerLeft + innerRight - optionWidth) / 2 - 5, innerTop + 5 + optionY, optionWidth, mouseX, mouseY)) { return true; } optionY += editor.getHeight() + 5; @@ -559,34 +534,34 @@ public class SBHConfigEditor extends GuiElement { ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); int width = scaledResolution.getScaledWidth(); - int xSize = Math.min(width-100/scaledResolution.getScaleFactor(), 500); + int xSize = Math.min(width - 100 / scaledResolution.getScaleFactor(), 500); int adjScaleFactor = Math.max(2, scaledResolution.getScaleFactor()); - int innerPadding = 20/adjScaleFactor; - int innerWidth = xSize-154-innerPadding*2; + int innerPadding = 20 / adjScaleFactor; + int innerWidth = xSize - 154 - innerPadding * 2; - if(getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { + if (getSelectedCategory() != null && getCurrentConfigEditing() != null && getCurrentConfigEditing().containsKey(getSelectedCategory())) { ConfigProcessor.ProcessedCategory cat = getCurrentConfigEditing().get(getSelectedCategory()); Set<Integer> activeAccordions = new HashSet<>(); - for(ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { - if(option.accordionId >= 0) { - if(!activeAccordions.contains(option.accordionId)) { + for (ConfigProcessor.ProcessedOption option : getOptionsInCategory(cat).values()) { + if (option.accordionId >= 0) { + if (!activeAccordions.contains(option.accordionId)) { continue; } } GuiOptionEditor editor = option.editor; - if(editor == null) { + if (editor == null) { continue; } - if(editor instanceof GuiOptionEditorAccordion) { + if (editor instanceof GuiOptionEditorAccordion) { GuiOptionEditorAccordion accordion = (GuiOptionEditorAccordion) editor; - if(accordion.getToggled()) { + if (accordion.getToggled()) { activeAccordions.add(accordion.getAccordionId()); } } - if(editor.keyboardInput()) { + if (editor.keyboardInput()) { return true; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java index 6782052..a9d9d5d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/BackgroundBlur.java @@ -1,6 +1,10 @@ package com.thatgravyboat.skyblockhud.core; import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; @@ -15,11 +19,6 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import org.lwjgl.opengl.GL11; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - public class BackgroundBlur { private static HashMap<Float, Framebuffer> blurOutput = new HashMap<>(); @@ -29,8 +28,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()); } @@ -39,29 +39,32 @@ public class BackgroundBlur { private static boolean shouldBlur = true; public static void markDirty() { - if(Minecraft.getMinecraft().theWorld != null) { + if (Minecraft.getMinecraft().theWorld != null) { shouldBlur = true; } } public static void processBlurs() { - if(shouldBlur) { + if (shouldBlur) { shouldBlur = false; long currentTime = System.currentTimeMillis(); - for(float blur : requestedBlurs) { + for (float blur : requestedBlurs) { lastBlur = currentTime; lastBlurUse.put(blur, currentTime); int width = Minecraft.getMinecraft().displayWidth; int height = Minecraft.getMinecraft().displayHeight; - Framebuffer output = blurOutput.computeIfAbsent(blur, k -> { - Framebuffer fb = new Framebuffer(width, height, false); - fb.setFramebufferFilter(GL11.GL_NEAREST); - return fb; - }); + Framebuffer output = blurOutput.computeIfAbsent( + blur, + k -> { + Framebuffer fb = new Framebuffer(width, height, false); + fb.setFramebufferFilter(GL11.GL_NEAREST); + return fb; + } + ); output.framebufferWidth = output.framebufferTextureWidth = width; output.framebufferHeight = output.framebufferTextureHeight = height; @@ -70,8 +73,8 @@ public class BackgroundBlur { } Set<Float> remove = new HashSet<>(); - for(Map.Entry<Float, Long> entry : lastBlurUse.entrySet()) { - if(currentTime - entry.getValue() > 30*1000) { + for (Map.Entry<Float, Long> entry : lastBlurUse.entrySet()) { + if (currentTime - entry.getValue() > 30 * 1000) { remove.add(entry.getKey()); } } @@ -86,7 +89,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(); } } @@ -94,9 +97,9 @@ public class BackgroundBlur { @SubscribeEvent public void onFogColour(EntityViewRenderEvent.FogColors event) { fogColour = 0xff000000; - fogColour |= ((int)(event.red*255) & 0xFF) << 16; - fogColour |= ((int)(event.green*255) & 0xFF) << 8; - fogColour |= (int)(event.blue*255) & 0xFF; + fogColour |= ((int) (event.red * 255) & 0xFF) << 16; + fogColour |= ((int) (event.green * 255) & 0xFF) << 8; + fogColour |= (int) (event.blue * 255) & 0xFF; } private static Shader blurShaderHorz = null; @@ -111,10 +114,10 @@ public class BackgroundBlur { * apply scales and translations manually. */ private static Matrix4f createProjectionMatrix(int width, int height) { - Matrix4f projMatrix = new Matrix4f(); + Matrix4f projMatrix = new Matrix4f(); projMatrix.setIdentity(); - projMatrix.m00 = 2.0F / (float)width; - projMatrix.m11 = 2.0F / (float)(-height); + projMatrix.m00 = 2.0F / (float) width; + projMatrix.m11 = 2.0F / (float) (-height); projMatrix.m22 = -0.0020001999F; projMatrix.m33 = 1.0F; projMatrix.m03 = -1.0F; @@ -124,7 +127,7 @@ public class BackgroundBlur { } private static void blurBackground(Framebuffer 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; @@ -136,33 +139,31 @@ 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); blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); Minecraft.getMinecraft().getFramebuffer().bindFramebuffer(false); } try { - blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - Minecraft.getMinecraft().getFramebuffer(), blurOutputHorz); + blurShaderHorz = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", Minecraft.getMinecraft().getFramebuffer(), blurOutputHorz); blurShaderHorz.getShaderManager().getShaderUniform("BlurDir").set(1, 0); blurShaderHorz.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception ignored) { } + } catch (Exception ignored) {} try { - blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", - blurOutputHorz, output); + blurShaderVert = new Shader(Minecraft.getMinecraft().getResourceManager(), "blur", blurOutputHorz, output); blurShaderVert.getShaderManager().getShaderUniform("BlurDir").set(0, 1); blurShaderVert.setProjectionMatrix(createProjectionMatrix(width, height)); - } catch(Exception ignored) { } - if(blurShaderHorz != null && blurShaderVert != null) { - if(blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { + } catch (Exception ignored) {} + if (blurShaderHorz != null && blurShaderVert != null) { + if (blurShaderHorz.getShaderManager().getShaderUniform("Radius") == null) { //Corrupted shader? return; } @@ -186,8 +187,7 @@ public class BackgroundBlur { } } - public static void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, - int x, int y, int blurWidth, int blurHeight) { + public static void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, int x, int y, int blurWidth, int blurHeight) { renderBlurredBackground(blurStrength, screenWidth, screenHeight, x, y, blurWidth, blurHeight, false); } @@ -195,37 +195,35 @@ public class BackgroundBlur { * Renders a subsection of the blurred framebuffer on to the corresponding section of the screen. * Essentially, this method will "blur" the background inside the bounds specified by [x->x+blurWidth, y->y+blurHeight] */ - public static void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, - int x, int y, int blurWidth, int blurHeight, boolean forcedUpdate) { - if(!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; - if(blurStrength < 0.5) return; + public static void renderBlurredBackground(float blurStrength, int screenWidth, int screenHeight, int x, int y, int blurWidth, int blurHeight, boolean forcedUpdate) { + if (!OpenGlHelper.isFramebufferEnabled() || !OpenGlHelper.areShadersSupported()) return; + if (blurStrength < 0.5) return; requestedBlurs.add(blurStrength); long currentTime = System.currentTimeMillis(); - if(currentTime - lastBlur > 300) { + if (currentTime - lastBlur > 300) { shouldBlur = true; - if(currentTime - lastBlur > 400 && forcedUpdate) return; + if (currentTime - lastBlur > 400 && forcedUpdate) return; } - if(blurOutput.isEmpty()) return; + if (blurOutput.isEmpty()) return; Framebuffer fb = blurOutput.get(blurStrength); - if(fb == null) { + if (fb == null) { fb = blurOutput.values().iterator().next(); } - float uMin = x/(float)screenWidth; - float uMax = (x+blurWidth)/(float)screenWidth; - float vMin = (screenHeight-y)/(float)screenHeight; - float vMax = (screenHeight-y-blurHeight)/(float)screenHeight; + float uMin = x / (float) screenWidth; + float uMax = (x + blurWidth) / (float) screenWidth; + float vMin = (screenHeight - y) / (float) screenHeight; + float vMax = (screenHeight - y - blurHeight) / (float) screenHeight; GlStateManager.depthMask(false); - Gui.drawRect(x, y, x+blurWidth, y+blurHeight, fogColour); + Gui.drawRect(x, y, x + blurWidth, y + blurHeight, fogColour); fb.bindFramebufferTexture(); GlStateManager.color(1f, 1f, 1f, 1f); RenderUtils.drawTexturedRect(x, y, blurWidth, blurHeight, uMin, uMax, vMin, vMax); fb.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..3137153 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<split.length; i++) { - arr[i] = Integer.parseInt(split[split.length-1-i], RADIX); + for (int i = 0; i < split.length; i++) { + arr[i] = Integer.parseInt(split[split.length - 1 - i], RADIX); } return arr; } @@ -40,7 +39,7 @@ public class ChromaColour { int a = d[3]; int chr = d[4]; - return (a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF); + return ((a & 0xFF) << 24 | (r & 0xFF) << 16 | (g & 0xFF) << 8 | (b & 0xFF)); } public static int getSpeed(String special) { @@ -48,15 +47,16 @@ public class ChromaColour { } public static float getSecondsForSpeed(int speed) { - return (255-speed)/254f*(MAX_CHROMA_SECS-MIN_CHROMA_SECS)+MIN_CHROMA_SECS; + return ((255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS); } private static final int MIN_CHROMA_SECS = 1; private static final int MAX_CHROMA_SECS = 60; public static long startTime = -1; + public static int specialToChromaRGB(String special) { - if(startTime < 0) startTime = System.currentTimeMillis(); + if (startTime < 0) startTime = System.currentTimeMillis(); int[] d = decompose(special); int chr = d[4]; @@ -67,14 +67,14 @@ public class ChromaColour { float[] hsv = Color.RGBtoHSB(r, g, b, null); - if(chr > 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); + return ((a & 0xFF) << 24 | (Color.HSBtoRGB(hsv[0], hsv[1], hsv[2]) & 0x00FFFFFF)); } public static int rotateHue(int argb, int degrees) { @@ -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); + 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<Bounds> 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 94d2375..cb9b15a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElement.java @@ -3,6 +3,8 @@ package com.thatgravyboat.skyblockhud.core; public abstract class GuiElement { 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 d403bef..8daf4b1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementBoolean.java @@ -1,15 +1,14 @@ package com.thatgravyboat.skyblockhud.core; +import com.thatgravyboat.skyblockhud.GuiTextures; import com.thatgravyboat.skyblockhud.core.util.lerp.LerpUtils; import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; -import com.thatgravyboat.skyblockhud.GuiTextures; +import java.util.function.Consumer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; -import java.util.function.Consumer; - public class GuiElementBoolean extends GuiElement { public int x; @@ -38,7 +37,7 @@ public class GuiElementBoolean extends GuiElement { this.toggleCallback = toggleCallback; this.lastMillis = System.currentTimeMillis(); - if(value) animation = 36; + if (value) animation = 36; } @Override @@ -52,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 8774595..2092b31 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementColour.java @@ -2,6 +2,9 @@ package com.thatgravyboat.skyblockhud.core; import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; import com.thatgravyboat.skyblockhud.core.util.render.TextRenderUtils; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.util.function.Consumer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; @@ -13,10 +16,6 @@ import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.util.function.Consumer; - public class GuiElementColour extends GuiElement { public static final ResourceLocation colour_selector_dot = new ResourceLocation("skyblockhud:core/colour_selector_dot.png"); @@ -27,8 +26,7 @@ public class GuiElementColour extends GuiElement { private static final ResourceLocation colourPickerLocation = new ResourceLocation("mbcore:dynamic/colourpicker"); private static final ResourceLocation colourPickerBarValueLocation = new ResourceLocation("mbcore:dynamic/colourpickervalue"); private static final ResourceLocation colourPickerBarOpacityLocation = new ResourceLocation("mbcore:dynamic/colourpickeropacity"); - private final GuiElementTextField hexField = new GuiElementTextField("", - GuiElementTextField.SCALE_TEXT | GuiElementTextField.FORCE_CAPS | GuiElementTextField.NO_SPACE); + private final GuiElementTextField hexField = new GuiElementTextField("", GuiElementTextField.SCALE_TEXT | GuiElementTextField.FORCE_CAPS | GuiElementTextField.NO_SPACE); private int x; private int y; @@ -44,13 +42,11 @@ public class GuiElementColour extends GuiElement { private Runnable closeCallback; private String colour; - public GuiElementColour(int x, int y, String initialColour, Consumer<String> colourChangedCallback, - Runnable closeCallback) { - + public GuiElementColour(int x, int y, String initialColour, Consumer<String> colourChangedCallback, Runnable closeCallback) { 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; @@ -64,7 +60,7 @@ public class GuiElementColour extends GuiElement { public void updateAngleAndRadius(float[] hsv) { this.wheelRadius = hsv[1]; - this.wheelAngle = hsv[0]*360; + this.wheelAngle = hsv[0] * 360; } public void render() { @@ -76,200 +72,178 @@ 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); Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_bar_alpha); GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(x+5+64+5+10+5, y+5, 10, 64, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + 10 + 5, y + 5, 10, 64, GL11.GL_NEAREST); 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); 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+10+5, y+5, 10, 64, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + 10 + 5, y + 5, 10, 64, GL11.GL_NEAREST); int chromaSpeed = ChromaColour.getSpeed(colour); int currentColourChroma = ChromaColour.specialToChromaRGB(colour); 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+5+10+5+10+5+1, y+5+1, - x+5+64+5+10+5+10+5+10-1, y+5+64-1, - Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f)); + if (chromaSpeed > 0) { + Gui.drawRect(x + 5 + 64 + 5 + 10 + 5 + 10 + 5 + 1, y + 5 + 1, x + 5 + 64 + 5 + 10 + 5 + 10 + 5 + 10 - 1, y + 5 + 64 - 1, Color.HSBtoRGB(hsvChroma[0], 0.8f, 0.8f)); } else { - Gui.drawRect(x+5+64+5+10+5+10+5+1, y+5+27+1, - x+5+64+5+10+5+10+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 + 5 + 10 + 5 + 10 + 5 + 1, y + 5 + 27 + 1, x + 5 + 64 + 5 + 10 + 5 + 10 + 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); - RenderUtils.drawTexturedRect(x+5+64+5, y+5, 10, 64, GL11.GL_NEAREST); - RenderUtils.drawTexturedRect(x+5+64+5+10+5, y+5, 10, 64, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + 5, y + 5, 10, 64, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + 10 + 5, y + 5, 10, 64, GL11.GL_NEAREST); - if(chromaSpeed > 0) { - RenderUtils.drawTexturedRect(x+5+64+5+10+5+10+5, y+5, 10, 64, GL11.GL_NEAREST); + if (chromaSpeed > 0) { + RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + 10 + 5 + 10 + 5, y + 5, 10, 64, GL11.GL_NEAREST); } else { Minecraft.getMinecraft().getTextureManager().bindTexture(colour_selector_chroma); - RenderUtils.drawTexturedRect(x+5+64+5+10+5+10+5, y+5+27, 10, 10, GL11.GL_NEAREST); + RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + 10 + 5 + 10 + 5, y + 5 + 27, 10, 10, GL11.GL_NEAREST); } - Gui.drawRect(x+5+64+5, y+5+64-(int)(64*hsv[2]), - x+5+64+5+10, y+5+64-(int)(64*hsv[2])+1, 0xFF000000); - Gui.drawRect(x+5+64+5+10+5, y+5+64-c.getAlpha()/4, - x+5+64+5+10+5+10, y+5+64-c.getAlpha()/4-1, 0xFF000000); - if(chromaSpeed > 0) { - Gui.drawRect(x+5+64+5+10+5+10+5, - y+5+64-(int)(chromaSpeed/255f*64), - x+5+64+5+10+5+10+5+10, - y+5+64-(int)(chromaSpeed/255f*64)+1, 0xFF000000); + Gui.drawRect(x + 5 + 64 + 5, y + 5 + 64 - (int) (64 * hsv[2]), x + 5 + 64 + 5 + 10, y + 5 + 64 - (int) (64 * hsv[2]) + 1, 0xFF000000); + Gui.drawRect(x + 5 + 64 + 5 + 10 + 5, y + 5 + 64 - c.getAlpha() / 4, x + 5 + 64 + 5 + 10 + 5 + 10, y + 5 + 64 - c.getAlpha() / 4 - 1, 0xFF000000); + if (chromaSpeed > 0) { + Gui.drawRect(x + 5 + 64 + 5 + 10 + 5 + 10 + 5, y + 5 + 64 - (int) (chromaSpeed / 255f * 64), x + 5 + 64 + 5 + 10 + 5 + 10 + 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); - TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString()+Math.round(c.getAlpha()/255f*100)+"", - Minecraft.getMinecraft().fontRendererObj, - x+5+64+5+15+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+30+6, 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); + TextRenderUtils.drawStringCenteredScaledMaxWidth(EnumChatFormatting.GRAY.toString() + Math.round(c.getAlpha() / 255f * 100) + "", Minecraft.getMinecraft().fontRendererObj, x + 5 + 64 + 5 + 15 + 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 + 30 + 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; - if(y > -5 && y <= 69) { - if(xValue > 0 && xValue < 10) { + if (y > -5 && y <= 69) { + if (xValue > 0 && xValue < 10) { clickedComponent = 1; } - int xOpacity = mouseX - (x+5+64+5+10+5); + int xOpacity = mouseX - (x + 5 + 64 + 5 + 10 + 5); - if(xOpacity > 0 && xOpacity < 10) { + if (xOpacity > 0 && xOpacity < 10) { clickedComponent = 2; } } int chromaSpeed = ChromaColour.getSpeed(colour); - int xChroma = mouseX - (x+5+64+5+10+5+10+5); - if(xChroma > 0 && xChroma < 10) { - if(chromaSpeed > 0) { - if(y > -5 && y <= 69) { + int xChroma = mouseX - (x + 5 + 64 + 5 + 10 + 5 + 10 + 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); @@ -282,7 +256,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); @@ -290,16 +264,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; @@ -309,22 +283,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; @@ -333,7 +306,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; @@ -342,7 +315,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 { @@ -356,13 +329,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 e2d6557..867efc1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementTextField.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiElementTextField.java @@ -2,6 +2,9 @@ package com.thatgravyboat.skyblockhud.core; import com.thatgravyboat.skyblockhud.core.util.StringUtils; import com.thatgravyboat.skyblockhud.core.util.render.TextRenderUtils; +import java.awt.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; @@ -9,10 +12,6 @@ import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; -import java.awt.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class GuiElementTextField { public static final int SCALE_TEXT = 0b100000; @@ -35,8 +34,7 @@ public class GuiElementTextField { private String prependText = ""; - 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; @@ -71,13 +69,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; } @@ -93,30 +91,31 @@ public class GuiElementTextField { public void setFocus(boolean focus) { this.focus = focus; } + 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() { @@ -124,8 +123,8 @@ public class GuiElementTextField { } private float getStringWidth(String str) { - if(isScaling()) { - return Minecraft.getMinecraft().fontRendererObj.getStringWidth(str)*getScaleFactor(str); + if (isScaling()) { + return (Minecraft.getMinecraft().fontRendererObj.getStringWidth(str) * getScaleFactor(str)); } else { return Minecraft.getMinecraft().fontRendererObj.getStringWidth(str); } @@ -135,58 +134,57 @@ 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); Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6])(?!\\u00B6)"); String text = renderText; String textNoColour = renderText; - if((options & COLOUR) != 0) { - while(true) { + if ((options & COLOUR) != 0) { + while (true) { Matcher matcher = patternControlCode.matcher(text); - if(!matcher.find() || matcher.groupCount() < 1) break; + if (!matcher.find() || matcher.groupCount() < 1) break; String code = matcher.group(1); - text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); } } - while(true) { + while (true) { Matcher matcher = patternControlCode.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<textNoColour.length(); cursorIndex++) { - if(currentLine == lineNum) break; - if(textNoColour.charAt(cursorIndex) == '\n') { + for (; cursorIndex < textNoColour.length(); cursorIndex++) { + if (currentLine == lineNum) break; + if (textNoColour.charAt(cursorIndex) == '\n') { currentLine++; } } - String textNC = textNoColour.substring(0, cursorIndex); int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNC, "\u00B6"); - String line = text.substring(cursorIndex+(((options & COLOUR) != 0)?colorCodes*2:0)).split("\n")[0]; - int padding = Math.min(5, searchBarXSize-strLenNoColor(line))/2; - String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(line, xComp-padding); + String line = text.substring(cursorIndex + (((options & COLOUR) != 0) ? colorCodes * 2 : 0)).split("\n")[0]; + int padding = Math.min(5, searchBarXSize - strLenNoColor(line)) / 2; + String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(line, xComp - padding); int linePos = strLenNoColor(trimmed); - if(linePos != strLenNoColor(line)) { + if (linePos != strLenNoColor(line)) { char after = line.charAt(linePos); int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if(trimmedWidth + charWidth/2 < xComp-padding) { + if (trimmedWidth + charWidth / 2 < xComp - padding) { linePos++; } } cursorIndex += linePos; int pre = StringUtils.cleanColour(prependText).length(); - if(cursorIndex < pre) { + if (cursorIndex < pre) { cursorIndex = 0; } else { cursorIndex -= pre; @@ -196,7 +194,7 @@ public class GuiElementTextField { } public void mouseClicked(int mouseX, int mouseY, int mouseButton) { - if(mouseButton == 1) { + if (mouseButton == 1) { textField.setText(""); } else { textField.setCursorPosition(getCursorPos(mouseX, mouseY)); @@ -214,42 +212,42 @@ public class GuiElementTextField { } public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - if(focus) { + if (focus) { textField.setSelectionPos(getCursorPos(mouseX, mouseY)); } } public void keyTyped(char typedChar, int keyCode) { - if(focus) { - if((options & MULTILINE) != 0) { //Carriage return + if (focus) { + if ((options & MULTILINE) != 0) { //Carriage return Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6\n])(?!\\u00B6)"); String text = textField.getText(); String textNoColour = textField.getText(); - while(true) { + while (true) { Matcher matcher = patternControlCode.matcher(text); - if(!matcher.find() || matcher.groupCount() < 1) break; + if (!matcher.find() || matcher.groupCount() < 1) break; String code = matcher.group(1); - text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); } - while(true) { + while (true) { Matcher matcher = patternControlCode.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); } - if(keyCode == 28) { + if (keyCode == 28) { String before = textField.getText().substring(0, textField.getCursorPosition()); String after = textField.getText().substring(textField.getCursorPosition()); int pos = textField.getCursorPosition(); textField.setText(before + "\n" + after); - textField.setCursorPosition(pos+1); + textField.setCursorPosition(pos + 1); return; - } else if(keyCode == 200) { //Up + } else if (keyCode == 200) { //Up String textNCBeforeCursor = textNoColour.substring(0, textField.getSelectionEnd()); int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); - String textBeforeCursor = text.substring(0, textField.getSelectionEnd()+colorCodes*2); + String textBeforeCursor = text.substring(0, textField.getSelectionEnd() + colorCodes * 2); int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); @@ -257,74 +255,70 @@ public class GuiElementTextField { int textBeforeCursorWidth; String lineBefore; String thisLineBeforeCursor; - if(split.length == numLinesBeforeCursor && split.length > 0) { + if (split.length == numLinesBeforeCursor && split.length > 0) { textBeforeCursorWidth = 0; - lineBefore = split[split.length-1]; + lineBefore = split[split.length - 1]; thisLineBeforeCursor = ""; - } else if(split.length > 1) { - thisLineBeforeCursor = split[split.length-1]; - lineBefore = split[split.length-2]; + } else if (split.length > 1) { + thisLineBeforeCursor = split[split.length - 1]; + lineBefore = split[split.length - 2]; textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); } else { return; } - String trimmed = Minecraft.getMinecraft().fontRendererObj - .trimStringToWidth(lineBefore, textBeforeCursorWidth); + String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(lineBefore, textBeforeCursorWidth); int linePos = strLenNoColor(trimmed); - if(linePos != strLenNoColor(lineBefore)) { + if (linePos != strLenNoColor(lineBefore)) { char after = lineBefore.charAt(linePos); int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if(trimmedWidth + charWidth/2 < textBeforeCursorWidth) { + if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { linePos++; } } - int newPos = textField.getSelectionEnd()-strLenNoColor(thisLineBeforeCursor) - -strLenNoColor(lineBefore)-1+linePos; + int newPos = textField.getSelectionEnd() - strLenNoColor(thisLineBeforeCursor) - strLenNoColor(lineBefore) - 1 + linePos; - if(GuiScreen.isShiftKeyDown()) { + if (GuiScreen.isShiftKeyDown()) { textField.setSelectionPos(newPos); } else { textField.setCursorPosition(newPos); } - } else if(keyCode == 208) { //Down + } else if (keyCode == 208) { //Down String textNCBeforeCursor = textNoColour.substring(0, textField.getSelectionEnd()); int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); - String textBeforeCursor = text.substring(0, textField.getSelectionEnd()+colorCodes*2); + String textBeforeCursor = text.substring(0, textField.getSelectionEnd() + colorCodes * 2); int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); String[] split = textBeforeCursor.split("\n"); String thisLineBeforeCursor; int textBeforeCursorWidth; - if(split.length == numLinesBeforeCursor) { + if (split.length == numLinesBeforeCursor) { thisLineBeforeCursor = ""; textBeforeCursorWidth = 0; - } else if(split.length > 0) { - thisLineBeforeCursor = split[split.length-1]; + } else if (split.length > 0) { + thisLineBeforeCursor = split[split.length - 1]; textBeforeCursorWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(thisLineBeforeCursor); } else { return; } String[] split2 = textNoColour.split("\n"); - if(split2.length > numLinesBeforeCursor+1) { - String lineAfter = split2[numLinesBeforeCursor+1]; - String trimmed = Minecraft.getMinecraft().fontRendererObj - .trimStringToWidth(lineAfter, textBeforeCursorWidth); + if (split2.length > numLinesBeforeCursor + 1) { + String lineAfter = split2[numLinesBeforeCursor + 1]; + String trimmed = Minecraft.getMinecraft().fontRendererObj.trimStringToWidth(lineAfter, textBeforeCursorWidth); int linePos = strLenNoColor(trimmed); - if(linePos != strLenNoColor(lineAfter)) { + if (linePos != strLenNoColor(lineAfter)) { char after = lineAfter.charAt(linePos); int trimmedWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(trimmed); int charWidth = Minecraft.getMinecraft().fontRendererObj.getCharWidth(after); - if(trimmedWidth + charWidth/2 < textBeforeCursorWidth) { + if (trimmedWidth + charWidth / 2 < textBeforeCursorWidth) { linePos++; } } - int newPos = textField.getSelectionEnd()-strLenNoColor(thisLineBeforeCursor) - +strLenNoColor(split2[numLinesBeforeCursor])+1+linePos; + int newPos = textField.getSelectionEnd() - strLenNoColor(thisLineBeforeCursor) + strLenNoColor(split2[numLinesBeforeCursor]) + 1 + linePos; - if(GuiScreen.isShiftKeyDown()) { + if (GuiScreen.isShiftKeyDown()) { textField.setSelectionPos(newPos); } else { textField.setCursorPosition(newPos); @@ -334,30 +328,30 @@ public class GuiElementTextField { } String old = textField.getText(); - if((options & FORCE_CAPS) != 0) typedChar = Character.toUpperCase(typedChar); - if((options & NO_SPACE) != 0 && typedChar == ' ') return; + if ((options & FORCE_CAPS) != 0) typedChar = Character.toUpperCase(typedChar); + if ((options & NO_SPACE) != 0 && typedChar == ' ') return; textField.setFocused(true); textField.textboxKeyTyped(typedChar, keyCode); - if((options & COLOUR) != 0) { - if(typedChar == '&') { - int pos = textField.getCursorPosition()-2; - if(pos >= 0 && pos < textField.getText().length()) { - if(textField.getText().charAt(pos) == '&') { + if ((options & COLOUR) != 0) { + if (typedChar == '&') { + int pos = textField.getCursorPosition() - 2; + if (pos >= 0 && pos < textField.getText().length()) { + if (textField.getText().charAt(pos) == '&') { String before = textField.getText().substring(0, pos); String after = ""; - if(pos+2 < textField.getText().length()) { - after = textField.getText().substring(pos+2); + if (pos + 2 < textField.getText().length()) { + after = textField.getText().substring(pos + 2); } textField.setText(before + "\u00A7" + after); - textField.setCursorPosition(pos+1); + textField.setCursorPosition(pos + 1); } } } } - if((options & NUM_ONLY) != 0 && textField.getText().matches("[^0-9.]")) textField.setText(old); + if ((options & NUM_ONLY) != 0 && textField.getText().matches("[^0-9.]")) textField.setText(old); } } @@ -367,8 +361,7 @@ public class GuiElementTextField { drawTextbox(x, y, searchBarXSize, searchBarYSize, searchBarPadding, textField, focus); } - private void drawTextbox(int x, int y, int searchBarXSize, int searchBarYSize, int searchBarPadding, - GuiTextField textField, boolean focus) { + private void drawTextbox(int x, int y, int searchBarXSize, int searchBarYSize, int searchBarPadding, GuiTextField textField, boolean focus) { ScaledResolution scaledresolution = new ScaledResolution(Minecraft.getMinecraft()); String renderText = prependText + textField.getText(); @@ -377,128 +370,110 @@ public class GuiElementTextField { /** * Search bar */ - int paddingUnscaled = searchBarPadding/scaledresolution.getScaleFactor(); - if(paddingUnscaled < 1) paddingUnscaled = 1; + int paddingUnscaled = searchBarPadding / scaledresolution.getScaleFactor(); + if (paddingUnscaled < 1) paddingUnscaled = 1; - int numLines = org.apache.commons.lang3.StringUtils.countMatches(renderText, "\n")+1; - int extraSize = (searchBarYSize-8)/2+8; - int bottomTextBox = y + searchBarYSize + extraSize*(numLines-1); + int numLines = org.apache.commons.lang3.StringUtils.countMatches(renderText, "\n") + 1; + int extraSize = (searchBarYSize - 8) / 2 + 8; + int bottomTextBox = y + searchBarYSize + extraSize * (numLines - 1); int borderColour = focus ? Color.GREEN.getRGB() : Color.WHITE.getRGB(); - if(customBorderColour != -1) { + if (customBorderColour != -1) { borderColour = customBorderColour; } //bar background - Gui.drawRect(x - paddingUnscaled, - y - paddingUnscaled, - x + searchBarXSize + paddingUnscaled, - bottomTextBox + paddingUnscaled, borderColour); - Gui.drawRect(x, - y, - x + searchBarXSize, - bottomTextBox, Color.BLACK.getRGB()); + Gui.drawRect(x - paddingUnscaled, y - paddingUnscaled, x + searchBarXSize + paddingUnscaled, bottomTextBox + paddingUnscaled, borderColour); + Gui.drawRect(x, y, x + searchBarXSize, bottomTextBox, Color.BLACK.getRGB()); //bar text Pattern patternControlCode = Pattern.compile("(?i)\\u00A7([^\\u00B6\n])(?!\\u00B6)"); String text = renderText; String textNoColor = renderText; - if((options & COLOUR) != 0) { - while(true) { + if ((options & COLOUR) != 0) { + while (true) { Matcher matcher = patternControlCode.matcher(text); - if(!matcher.find() || matcher.groupCount() < 1) break; + if (!matcher.find() || matcher.groupCount() < 1) break; String code = matcher.group(1); - text = matcher.replaceFirst("\u00A7"+code+"\u00B6"+code); + text = matcher.replaceFirst("\u00A7" + code + "\u00B6" + code); } } - while(true) { + while (true) { Matcher matcher = patternControlCode.matcher(textNoColor); - if(!matcher.find() || matcher.groupCount() < 1) break; + if (!matcher.find() || matcher.groupCount() < 1) break; String code = matcher.group(1); - textNoColor = matcher.replaceFirst("\u00B6"+code); + textNoColor = matcher.replaceFirst("\u00B6" + code); } int xStartOffset = 5; float scale = 1; String[] texts = text.split("\n"); - for(int yOffI = 0; yOffI < texts.length; yOffI++) { - int yOff = yOffI*extraSize; - - if(isScaling() && Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI])>searchBarXSize-10) { - scale = (searchBarXSize-2)/(float)Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]); - if(scale > 1) scale=1; - float newLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI])*scale; - xStartOffset = (int)((searchBarXSize-newLen)/2f); - - TextRenderUtils.drawStringCenteredScaledMaxWidth(texts[yOffI], Minecraft.getMinecraft().fontRendererObj, x+searchBarXSize/2f, - y+searchBarYSize/2f+yOff, false, - searchBarXSize-2, Color.WHITE.getRGB()); + for (int yOffI = 0; yOffI < texts.length; yOffI++) { + int yOff = yOffI * extraSize; + + if (isScaling() && Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) > searchBarXSize - 10) { + scale = (searchBarXSize - 2) / (float) Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]); + if (scale > 1) scale = 1; + float newLen = Minecraft.getMinecraft().fontRendererObj.getStringWidth(texts[yOffI]) * scale; + xStartOffset = (int) ((searchBarXSize - newLen) / 2f); + + TextRenderUtils.drawStringCenteredScaledMaxWidth(texts[yOffI], Minecraft.getMinecraft().fontRendererObj, x + searchBarXSize / 2f, y + searchBarYSize / 2f + yOff, false, searchBarXSize - 2, Color.WHITE.getRGB()); } else { - Minecraft.getMinecraft().fontRendererObj.drawString(StringUtils.trimToWidth(texts[yOffI], searchBarXSize-10), x + 5, - y+(searchBarYSize-8)/2+yOff, Color.WHITE.getRGB()); + Minecraft.getMinecraft().fontRendererObj.drawString(StringUtils.trimToWidth(texts[yOffI], searchBarXSize - 10), x + 5, y + (searchBarYSize - 8) / 2 + yOff, Color.WHITE.getRGB()); } } - if(focus && System.currentTimeMillis()%1000>500) { - String textNCBeforeCursor = textNoColor.substring(0, textField.getCursorPosition()+prependText.length()); + if (focus && System.currentTimeMillis() % 1000 > 500) { + String textNCBeforeCursor = textNoColor.substring(0, textField.getCursorPosition() + prependText.length()); int colorCodes = org.apache.commons.lang3.StringUtils.countMatches(textNCBeforeCursor, "\u00B6"); - String textBeforeCursor = text.substring(0, textField.getCursorPosition()+prependText.length()+(((options & COLOUR) != 0) ? colorCodes*2 : 0)); + String textBeforeCursor = text.substring(0, textField.getCursorPosition() + prependText.length() + (((options & COLOUR) != 0) ? colorCodes * 2 : 0)); int numLinesBeforeCursor = org.apache.commons.lang3.StringUtils.countMatches(textBeforeCursor, "\n"); - int yOff = numLinesBeforeCursor*extraSize; + int yOff = numLinesBeforeCursor * extraSize; String[] split = textBeforeCursor.split("\n"); int textBeforeCursorWidth; - if(split.length <= numLinesBeforeCursor || split.length == 0) { + if (split.length <= numLinesBeforeCursor || split.length == 0) { textBeforeCursorWidth = 0; } else { - textBeforeCursorWidth = (int)(Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length-1])*scale); + textBeforeCursorWidth = (int) (Minecraft.getMinecraft().fontRendererObj.getStringWidth(split[split.length - 1]) * scale); } - Gui.drawRect(x + xStartOffset + textBeforeCursorWidth, - y+(searchBarYSize-8)/2-1 + yOff, - x + xStartOffset + textBeforeCursorWidth+1, - y+(searchBarYSize-8)/2+9 + yOff, Color.WHITE.getRGB()); + Gui.drawRect(x + xStartOffset + textBeforeCursorWidth, y + (searchBarYSize - 8) / 2 - 1 + yOff, x + xStartOffset + textBeforeCursorWidth + 1, y + (searchBarYSize - 8) / 2 + 9 + yOff, Color.WHITE.getRGB()); } String selectedText = textField.getSelectedText(); - if(!selectedText.isEmpty()) { + if (!selectedText.isEmpty()) { System.out.println("Start"); - int leftIndex = Math.min(textField.getCursorPosition()+prependText.length(), textField.getSelectionEnd()+prependText.length()); - int rightIndex = Math.max(textField.getCursorPosition()+prependText.length(), textField.getSelectionEnd()+prependText.length()); + int leftIndex = Math.min(textField.getCursorPosition() + prependText.length(), textField.getSelectionEnd() + prependText.length()); + int rightIndex = Math.max(textField.getCursorPosition() + prependText.length(), textField.getSelectionEnd() + prependText.length()); float texX = 0; int texY = 0; boolean sectionSignPrev = false; boolean ignoreNext = false; boolean bold = false; - for(int i=0; i<textNoColor.length(); i++) { - if(ignoreNext) { + for (int i = 0; i < textNoColor.length(); i++) { + if (ignoreNext) { ignoreNext = false; continue; } char c = textNoColor.charAt(i); - if(sectionSignPrev) { - if(c != 'k' && c != 'K' - && c != 'm' && c != 'M' - && c != 'n' && c != 'N' - && c != 'o' && c != 'O') { + if (sectionSignPrev) { + if (c != 'k' && c != 'K' && c != 'm' && c != 'M' && c != 'n' && c != 'N' && c != 'o' && c != 'O') { bold = c == 'l' || c == 'L'; } sectionSignPrev = false; - if(i < prependText.length()) continue; + if (i < prependText.length()) continue; } - if(c == '\u00B6') { + if (c == '\u00B6') { sectionSignPrev = true; - if(i < prependText.length()) continue; + if (i < prependText.length()) continue; } - if(c == '\n') { - if(i >= leftIndex && i < rightIndex) { - Gui.drawRect(x + xStartOffset + (int)texX, - y+(searchBarYSize-8)/2-1 + texY, - x + xStartOffset + (int)texX + 3, - y+(searchBarYSize-8)/2+9 + texY, Color.LIGHT_GRAY.getRGB()); + if (c == '\n') { + if (i >= leftIndex && i < rightIndex) { + Gui.drawRect(x + xStartOffset + (int) texX, y + (searchBarYSize - 8) / 2 - 1 + texY, x + xStartOffset + (int) texX + 3, y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB()); } texX = 0; @@ -508,26 +483,19 @@ public class GuiElementTextField { //String c2 = bold ? EnumChatFormatting.BOLD.toString() : "" + c; - System.out.println("Adding len for char:"+c+":"+Integer.toHexString(c)); + System.out.println("Adding len for char:" + c + ":" + Integer.toHexString(c)); int len = Minecraft.getMinecraft().fontRendererObj.getStringWidth(String.valueOf(c)); - if(bold) len++; - if(i >= leftIndex && i < rightIndex) { - Gui.drawRect(x + xStartOffset + (int)texX, - y+(searchBarYSize-8)/2-1 + texY, - x + xStartOffset + (int)(texX + len*scale), - y+(searchBarYSize-8)/2+9 + texY, Color.LIGHT_GRAY.getRGB()); - - TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, - x + xStartOffset + texX, - y+searchBarYSize/2f-scale*8/2f + texY, false, Color.BLACK.getRGB(), scale); - if(bold) { - TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, - x + xStartOffset + texX + 1, - y+searchBarYSize/2f-scale*8/2f + texY, false, Color.BLACK.getRGB(), scale); + if (bold) len++; + if (i >= leftIndex && i < rightIndex) { + Gui.drawRect(x + xStartOffset + (int) texX, y + (searchBarYSize - 8) / 2 - 1 + texY, x + xStartOffset + (int) (texX + len * scale), y + (searchBarYSize - 8) / 2 + 9 + texY, Color.LIGHT_GRAY.getRGB()); + + TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, x + xStartOffset + texX, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale); + if (bold) { + TextRenderUtils.drawStringScaled(String.valueOf(c), Minecraft.getMinecraft().fontRendererObj, x + xStartOffset + texX + 1, y + searchBarYSize / 2f - scale * 8 / 2f + texY, false, Color.BLACK.getRGB(), scale); } } - texX += len*scale; + texX += len * scale; } } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiScreenElementWrapper.java b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiScreenElementWrapper.java index 234cc2d..326c85f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/GuiScreenElementWrapper.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/GuiScreenElementWrapper.java @@ -1,10 +1,9 @@ package com.thatgravyboat.skyblockhud.core; +import java.io.IOException; import net.minecraft.client.gui.GuiScreen; import org.lwjgl.input.Mouse; -import java.io.IOException; - public class GuiScreenElementWrapper extends GuiScreen { public final GuiElement element; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/Config.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/Config.java index 40f8c0e..dbbca74 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/Config.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/Config.java @@ -2,7 +2,5 @@ package com.thatgravyboat.skyblockhud.core.config; public class Config { - public void executeRunnable(String runnableId) { - } - + public void executeRunnable(String runnableId) {} } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/Position.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/Position.java index 1c2de86..0b3a1f5 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/Position.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/Position.java @@ -7,14 +7,16 @@ public class Position { @Expose private int x; + @Expose private int y; + @Expose private boolean centerX; + @Expose private boolean centerY; - private static final int EDGE_OFFSET = 0; public Position(int x, int y) { @@ -58,17 +60,17 @@ public class Position { public int getAbsX(ScaledResolution scaledResolution, int objWidth) { int width = scaledResolution.getScaledWidth(); - if(centerX) { - return width/2 + x; + if (centerX) { + return width / 2 + x; } int ret = x; - if(x < 0) { + if (x < 0) { ret = width + x - objWidth; } - if(ret < 0) ret = 0; - if(ret > width - objWidth) ret = width - objWidth; + if (ret < 0) ret = 0; + if (ret > width - objWidth) ret = width - objWidth; return ret; } @@ -76,17 +78,17 @@ public class Position { public int getAbsY(ScaledResolution scaledResolution, int objHeight) { int height = scaledResolution.getScaledHeight(); - if(centerY) { - return height/2 + y; + if (centerY) { + return height / 2 + y; } int ret = y; - if(y < 0) { + if (y < 0) { ret = height + y - objHeight; } - if(ret < 0) ret = 0; - if(ret > height - objHeight) ret = height - objHeight; + if (ret < 0) ret = 0; + if (ret > height - objHeight) ret = height - objHeight; return ret; } @@ -96,45 +98,45 @@ public class Position { boolean wasPositiveX = this.x >= 0; this.x += deltaX; - if(centerX) { - if(wasPositiveX) { - if(this.x > screenWidth/2-objWidth/2) { - deltaX += screenWidth/2-objWidth/2-this.x; - this.x = screenWidth/2-objWidth/2; + if (centerX) { + if (wasPositiveX) { + if (this.x > screenWidth / 2 - objWidth / 2) { + deltaX += screenWidth / 2 - objWidth / 2 - this.x; + this.x = screenWidth / 2 - objWidth / 2; } } else { - if(this.x < -screenWidth/2+objWidth/2) { - deltaX += -screenWidth/2+objWidth/2-this.x; - this.x = -screenWidth/2+objWidth/2; + if (this.x < -screenWidth / 2 + objWidth / 2) { + deltaX += -screenWidth / 2 + objWidth / 2 - this.x; + this.x = -screenWidth / 2 + objWidth / 2; } } return deltaX; } - if(wasPositiveX) { - if(this.x < EDGE_OFFSET) { - deltaX += EDGE_OFFSET-this.x; + if (wasPositiveX) { + if (this.x < EDGE_OFFSET) { + deltaX += EDGE_OFFSET - this.x; this.x = EDGE_OFFSET; } - if(this.x > screenWidth-EDGE_OFFSET) { - deltaX += screenWidth-EDGE_OFFSET-this.x; - this.x = screenWidth-EDGE_OFFSET; + if (this.x > screenWidth - EDGE_OFFSET) { + deltaX += screenWidth - EDGE_OFFSET - this.x; + this.x = screenWidth - EDGE_OFFSET; } } else { - if(this.x+1 > -EDGE_OFFSET) { - deltaX += -EDGE_OFFSET-1-this.x; - this.x = -EDGE_OFFSET-1; + if (this.x + 1 > -EDGE_OFFSET) { + deltaX += -EDGE_OFFSET - 1 - this.x; + this.x = -EDGE_OFFSET - 1; } - if(this.x+screenWidth < EDGE_OFFSET) { - deltaX += EDGE_OFFSET-screenWidth-this.x; - this.x = EDGE_OFFSET-screenWidth; + if (this.x + screenWidth < EDGE_OFFSET) { + deltaX += EDGE_OFFSET - screenWidth - this.x; + this.x = EDGE_OFFSET - screenWidth; } } - if(this.x >= 0 && this.x+objWidth/2 > screenWidth/2) { + if (this.x >= 0 && this.x + objWidth / 2 > screenWidth / 2) { this.x -= screenWidth - objWidth; } - if(this.x < 0 && this.x+objWidth/2 <= -screenWidth/2) { + if (this.x < 0 && this.x + objWidth / 2 <= -screenWidth / 2) { this.x += screenWidth - objWidth; } return deltaX; @@ -145,52 +147,51 @@ public class Position { boolean wasPositiveY = this.y >= 0; this.y += deltaY; - if(centerY) { - if(wasPositiveY) { - if(this.y > screenHeight/2-objHeight/2) { - deltaY += screenHeight/2-objHeight/2-this.y; - this.y = screenHeight/2-objHeight/2; + if (centerY) { + if (wasPositiveY) { + if (this.y > screenHeight / 2 - objHeight / 2) { + deltaY += screenHeight / 2 - objHeight / 2 - this.y; + this.y = screenHeight / 2 - objHeight / 2; } } else { - if(this.y < -screenHeight/2+objHeight/2) { - deltaY += -screenHeight/2+objHeight/2-this.y; - this.y = -screenHeight/2+objHeight/2; + if (this.y < -screenHeight / 2 + objHeight / 2) { + deltaY += -screenHeight / 2 + objHeight / 2 - this.y; + this.y = -screenHeight / 2 + objHeight / 2; } } return deltaY; } - if(wasPositiveY) { - if(this.y < EDGE_OFFSET) { - deltaY += EDGE_OFFSET-this.y; + if (wasPositiveY) { + if (this.y < EDGE_OFFSET) { + deltaY += EDGE_OFFSET - this.y; this.y = EDGE_OFFSET; } - if(this.y > screenHeight-EDGE_OFFSET) { - deltaY += screenHeight-EDGE_OFFSET-this.y; - this.y = screenHeight-EDGE_OFFSET; + if (this.y > screenHeight - EDGE_OFFSET) { + deltaY += screenHeight - EDGE_OFFSET - this.y; + this.y = screenHeight - EDGE_OFFSET; } } else { - if(this.y+1 > -EDGE_OFFSET) { - deltaY += -EDGE_OFFSET-1-this.y; - this.y = -EDGE_OFFSET-1; + if (this.y + 1 > -EDGE_OFFSET) { + deltaY += -EDGE_OFFSET - 1 - this.y; + this.y = -EDGE_OFFSET - 1; } - if(this.y+screenHeight < EDGE_OFFSET) { - deltaY += EDGE_OFFSET-screenHeight-this.y; - this.y = EDGE_OFFSET-screenHeight; + if (this.y + screenHeight < EDGE_OFFSET) { + deltaY += EDGE_OFFSET - screenHeight - this.y; + this.y = EDGE_OFFSET - screenHeight; } } - if(this.y >= 0 && this.y-objHeight/2 > screenHeight/2) { + if (this.y >= 0 && this.y - objHeight / 2 > screenHeight / 2) { this.y -= screenHeight - objHeight; } - if(this.y < 0 && this.y-objHeight/2 <= -screenHeight/2) { + if (this.y < 0 && this.y - objHeight / 2 <= -screenHeight / 2) { this.y += screenHeight - objHeight; } return deltaY; } - public boolean rightAligned(ScaledResolution scaledResolution, int objWidth){ - return this.getAbsX(scaledResolution, objWidth) > (scaledResolution.getScaledWidth() / 2); + public boolean rightAligned(ScaledResolution scaledResolution, int objWidth) { + return (this.getAbsX(scaledResolution, objWidth) > (scaledResolution.getScaledWidth() / 2)); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/Category.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/Category.java index e1d51ac..05ae6ad 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/Category.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/Category.java @@ -8,8 +8,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface Category { - String name(); - String desc(); + String desc(); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigAccordionId.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigAccordionId.java index 8e2836f..44b82be 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigAccordionId.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigAccordionId.java @@ -8,7 +8,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigAccordionId { - int id(); - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorAccordion.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorAccordion.java index acb60af..9712148 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorAccordion.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorAccordion.java @@ -8,7 +8,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorAccordion { - int id(); - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorBoolean.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorBoolean.java index b1846d3..f86448e 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorBoolean.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorBoolean.java @@ -8,5 +8,4 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorBoolean { - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorButton.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorButton.java index 32425d1..5e4bab8 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorButton.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorButton.java @@ -8,8 +8,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorButton { - String runnableId(); - String buttonText() default ""; + String buttonText() default ""; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorColour.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorColour.java index 1e5713c..146f09a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorColour.java @@ -1,6 +1,5 @@ package com.thatgravyboat.skyblockhud.core.config.annotations; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -9,5 +8,4 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorColour { - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDraggableList.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDraggableList.java index 963c305..6bbeb27 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDraggableList.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDraggableList.java @@ -8,7 +8,5 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorDraggableList { - String[] exampleText(); - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDropdown.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDropdown.java index 5e48e25..cc8bbf4 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDropdown.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorDropdown.java @@ -1,6 +1,5 @@ package com.thatgravyboat.skyblockhud.core.config.annotations; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -9,8 +8,7 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorDropdown { - String[] values(); - int initialIndex() default 0; + int initialIndex() default 0; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorSlider.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorSlider.java index a0fea03..dcdf0b1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorSlider.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorSlider.java @@ -1,6 +1,5 @@ package com.thatgravyboat.skyblockhud.core.config.annotations; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -9,10 +8,9 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorSlider { - float minValue(); + float maxValue(); float minStep(); - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorText.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorText.java index 0c00561..61e7ed5 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorText.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigEditorText.java @@ -1,6 +1,5 @@ package com.thatgravyboat.skyblockhud.core.config.annotations; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -9,5 +8,4 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigEditorText { - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigOption.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigOption.java index 845d01f..4574758 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigOption.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/annotations/ConfigOption.java @@ -1,6 +1,5 @@ package com.thatgravyboat.skyblockhud.core.config.annotations; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -9,9 +8,9 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface ConfigOption { - String name(); + String desc(); - int subcategoryId() default -1; + int subcategoryId() default -1; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditor.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditor.java index e978420..6cae226 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditor.java @@ -21,28 +21,27 @@ public abstract class GuiOptionEditor { FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; RenderUtils.drawFloatingRectDark(x, y, width, height, true); - TextRenderUtils.drawStringCenteredScaledMaxWidth(option.name, - fr, x+width/6f, y+13, true, width/3-10, 0xc0c0c0); + TextRenderUtils.drawStringCenteredScaledMaxWidth(option.name, fr, x + width / 6f, y + 13, true, width / 3 - 10, 0xc0c0c0); int maxLines = 5; float scale = 1; - int lineCount = fr.listFormattedStringToWidth(option.desc, width*2/3-10).size(); + int lineCount = fr.listFormattedStringToWidth(option.desc, width * 2 / 3 - 10).size(); - if(lineCount <= 0) return; + if (lineCount <= 0) return; float paraHeight = 9 * lineCount - 1; - while(paraHeight >= HEIGHT-10) { - scale -= 1/8f; - lineCount = fr.listFormattedStringToWidth(option.desc, (int)(width*2/3/scale-10)).size(); - paraHeight = (int)(9*scale * lineCount - 1*scale); + while (paraHeight >= HEIGHT - 10) { + scale -= 1 / 8f; + lineCount = fr.listFormattedStringToWidth(option.desc, (int) (width * 2 / 3 / scale - 10)).size(); + paraHeight = (int) (9 * scale * lineCount - 1 * scale); } GlStateManager.pushMatrix(); - GlStateManager.translate(x+5+width/3f, y+HEIGHT/2f-paraHeight/2, 0); + GlStateManager.translate(x + 5 + width / 3f, y + HEIGHT / 2f - paraHeight / 2, 0); GlStateManager.scale(scale, scale, 1); - fr.drawSplitString(option.desc, 0, 0, (int)(width*2/3/scale-10), 0xc0c0c0); + fr.drawSplitString(option.desc, 0, 0, (int) (width * 2 / 3 / scale - 10), 0xc0c0c0); GlStateManager.popMatrix(); } @@ -52,11 +51,12 @@ public abstract class GuiOptionEditor { } public abstract boolean mouseInput(int x, int y, int width, int mouseX, int mouseY); + public abstract boolean keyboardInput(); public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { return false; } - public void renderOverlay(int x, int y, int width) {} + public void renderOverlay(int x, int y, int width) {} } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorAccordion.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorAccordion.java index c2b129d..dad85a6 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorAccordion.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorAccordion.java @@ -47,27 +47,25 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(1, 1, 1, 1); worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION); - if(accordionToggled) { - worldrenderer.pos((double)x+6, (double)y+6, 0.0D).endVertex(); - worldrenderer.pos((double)x+9.75f, (double)y+13.5f, 0.0D).endVertex(); - worldrenderer.pos((double)x+13.5f, (double)y+6, 0.0D).endVertex(); + if (accordionToggled) { + worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); + worldrenderer.pos((double) x + 9.75f, (double) y + 13.5f, 0.0D).endVertex(); + worldrenderer.pos((double) x + 13.5f, (double) y + 6, 0.0D).endVertex(); } else { - worldrenderer.pos((double)x+6, (double)y+13.5f, 0.0D).endVertex(); - worldrenderer.pos((double)x+13.5f, (double)y+9.75f, 0.0D).endVertex(); - worldrenderer.pos((double)x+6, (double)y+6, 0.0D).endVertex(); + worldrenderer.pos((double) x + 6, (double) y + 13.5f, 0.0D).endVertex(); + worldrenderer.pos((double) x + 13.5f, (double) y + 9.75f, 0.0D).endVertex(); + worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); } tessellator.draw(); GlStateManager.enableTexture2D(); GlStateManager.disableBlend(); - TextRenderUtils.drawStringScaledMaxWidth(option.name, Minecraft.getMinecraft().fontRendererObj, - x+18, y+6, false, width-10, 0xc0c0c0); + TextRenderUtils.drawStringScaledMaxWidth(option.name, Minecraft.getMinecraft().fontRendererObj, x + 18, y + 6, false, width - 10, 0xc0c0c0); } @Override public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - if(Mouse.getEventButtonState() && mouseX > x && mouseX < x+ width && - mouseY > y && mouseY < y+getHeight()) { + if (Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + getHeight()) { accordionToggled = !accordionToggled; return true; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorBoolean.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorBoolean.java index 3ea70c0..4167e06 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorBoolean.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorBoolean.java @@ -9,8 +9,7 @@ public class GuiOptionEditorBoolean extends GuiOptionEditor { public GuiOptionEditorBoolean(ConfigProcessor.ProcessedOption option) { super(option); - - bool = new GuiElementBoolean(0, 0, (boolean)option.get(), 10, option::set); + bool = new GuiElementBoolean(0, 0, (boolean) option.get(), 10, option::set); } @Override @@ -18,16 +17,16 @@ public class GuiOptionEditorBoolean extends GuiOptionEditor { super.render(x, y, width); int height = getHeight(); - bool.x = x+width/6-24; - bool.y = y+height-7-14; + bool.x = x + width / 6 - 24; + bool.y = y + height - 7 - 14; bool.render(); } @Override public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { int height = getHeight(); - bool.x = x+width/6-24; - bool.y = y+height-7-14; + bool.x = x + width / 6 - 24; + bool.y = y + height - 7 - 14; return bool.mouseInput(mouseX, mouseY); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorButton.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorButton.java index 752b4bf..1950c27 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorButton.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorButton.java @@ -1,5 +1,7 @@ package com.thatgravyboat.skyblockhud.core.config.gui; +import static com.thatgravyboat.skyblockhud.GuiTextures.button_tex; + import com.thatgravyboat.skyblockhud.core.ChromaColour; import com.thatgravyboat.skyblockhud.core.config.Config; import com.thatgravyboat.skyblockhud.core.config.struct.ConfigProcessor; @@ -9,8 +11,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.input.Mouse; -import static com.thatgravyboat.skyblockhud.GuiTextures.button_tex; - public class GuiOptionEditorButton extends GuiOptionEditor { private final String runnableId; @@ -23,7 +23,7 @@ public class GuiOptionEditorButton extends GuiOptionEditor { this.config = config; this.buttonText = buttonText; - if(this.buttonText != null && this.buttonText.isEmpty()) this.buttonText = null; + if (this.buttonText != null && this.buttonText.isEmpty()) this.buttonText = null; } @Override @@ -34,21 +34,18 @@ public class GuiOptionEditorButton extends GuiOptionEditor { GlStateManager.color(1, 1, 1, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); - RenderUtils.drawTexturedRect(x+width/6-24, y+height-7-14, 48, 16); + RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); - if(buttonText != null) { - TextRenderUtils.drawStringCenteredScaledMaxWidth(buttonText, Minecraft.getMinecraft().fontRendererObj, - x+width/6, y+height-7-6, - false, 44, 0xFF303030); + if (buttonText != null) { + TextRenderUtils.drawStringCenteredScaledMaxWidth(buttonText, Minecraft.getMinecraft().fontRendererObj, x + width / 6, y + height - 7 - 6, false, 44, 0xFF303030); } } @Override public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - if(Mouse.getEventButtonState()) { + if (Mouse.getEventButtonState()) { int height = getHeight(); - if(mouseX > x+width/6-24 && mouseX < x+width/6+24 && - mouseY > y+height-7-14 && mouseY < y+height-7+2) { + if (mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { config.executeRunnable(runnableId); return true; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorColour.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorColour.java index 1f03954..95bc868 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorColour.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorColour.java @@ -1,5 +1,7 @@ package com.thatgravyboat.skyblockhud.core.config.gui; +import static com.thatgravyboat.skyblockhud.GuiTextures.*; + import com.thatgravyboat.skyblockhud.core.ChromaColour; import com.thatgravyboat.skyblockhud.core.GuiElementColour; import com.thatgravyboat.skyblockhud.core.config.struct.ConfigProcessor; @@ -8,8 +10,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.input.Mouse; -import static com.thatgravyboat.skyblockhud.GuiTextures.*; - public class GuiOptionEditorColour extends GuiOptionEditor { private String chromaColour; @@ -17,8 +17,7 @@ public class GuiOptionEditorColour extends GuiOptionEditor { public GuiOptionEditorColour(ConfigProcessor.ProcessedOption option) { super(option); - - this.chromaColour = (String)option.get(); + this.chromaColour = (String) option.get(); } @Override @@ -30,34 +29,39 @@ public class GuiOptionEditorColour extends GuiOptionEditor { int r = (argb >> 16) & 0xFF; int g = (argb >> 8) & 0xFF; int b = argb & 0xFF; - GlStateManager.color(r/255f, g/255f, b/255f, 1); + GlStateManager.color(r / 255f, g / 255f, b / 255f, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(button_white); - RenderUtils.drawTexturedRect(x+width/6f-24, y+height-7-14, 48, 16); + RenderUtils.drawTexturedRect(x + width / 6f - 24, y + height - 7 - 14, 48, 16); } @Override public void renderOverlay(int x, int y, int width) { - if(colourElement != null) { + if (colourElement != null) { colourElement.render(); } } @Override public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { - return colourElement != null && colourElement.mouseInput(mouseX, mouseY); + return (colourElement != null && colourElement.mouseInput(mouseX, mouseY)); } @Override public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { int height = getHeight(); - if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0 && - mouseX > x+width/6-24 && mouseX < x+width/6+24 && - mouseY > y+height-7-14 && mouseY < y+height-7+2) { - colourElement = new GuiElementColour(mouseX, mouseY, (String) option.get(), (val) -> { - option.set(val); - chromaColour = val; - }, () -> colourElement = null); + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0 && mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { + colourElement = + new GuiElementColour( + mouseX, + mouseY, + (String) option.get(), + val -> { + option.set(val); + chromaColour = val; + }, + () -> colourElement = null + ); } return false; @@ -67,5 +71,4 @@ public class GuiOptionEditorColour extends GuiOptionEditor { public boolean keyboardInput() { return colourElement != null && colourElement.keyboardInput(); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDraggableList.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDraggableList.java index 59f9e82..e0a9064 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDraggableList.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDraggableList.java @@ -1,10 +1,14 @@ package com.thatgravyboat.skyblockhud.core.config.gui; +import static com.thatgravyboat.skyblockhud.GuiTextures.button_tex; + import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.core.config.struct.ConfigProcessor; import com.thatgravyboat.skyblockhud.core.util.lerp.LerpUtils; import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; import com.thatgravyboat.skyblockhud.core.util.render.TextRenderUtils; +import java.util.ArrayList; +import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -15,11 +19,6 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import java.util.ArrayList; -import java.util.List; - -import static com.thatgravyboat.skyblockhud.GuiTextures.button_tex; - public class GuiOptionEditorDraggableList extends GuiOptionEditor { private static final ResourceLocation DELETE = new ResourceLocation("notenoughupdates:core/delete.png"); @@ -38,7 +37,6 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { public GuiOptionEditorDraggableList(ConfigProcessor.ProcessedOption option, String[] exampleText) { super(option); - this.exampleText = exampleText; this.activeText = (List<Integer>) option.get(); } @@ -47,7 +45,7 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { public int getHeight() { int height = super.getHeight() + 13; - for(int strIndex : activeText) { + for (int strIndex : activeText) { String str = exampleText[strIndex]; height += 10 * str.split("\n").length; } @@ -63,37 +61,34 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { GlStateManager.color(1, 1, 1, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); - RenderUtils.drawTexturedRect(x+width/6f-24, y+45-7-14, 48, 16); + RenderUtils.drawTexturedRect(x + width / 6f - 24, y + 45 - 7 - 14, 48, 16); - TextRenderUtils.drawStringCenteredScaledMaxWidth("Add", Minecraft.getMinecraft().fontRendererObj, - x+width/6f, y+45-7-6, - false, 44, 0xFF303030); + TextRenderUtils.drawStringCenteredScaledMaxWidth("Add", Minecraft.getMinecraft().fontRendererObj, x + width / 6f, y + 45 - 7 - 6, false, 44, 0xFF303030); long currentTime = System.currentTimeMillis(); - float greenBlue = LerpUtils.clampZeroOne(((trashHoverTime < 0 ? 250 : 0) + trashHoverTime - currentTime)/250f); + float greenBlue = LerpUtils.clampZeroOne(((trashHoverTime < 0 ? 250 : 0) + trashHoverTime - currentTime) / 250f); GlStateManager.color(1, greenBlue, greenBlue, 1); Minecraft.getMinecraft().getTextureManager().bindTexture(DELETE); - Utils.drawTexturedRect(x+width/6f+27, y+45-7-13, 11, 14, GL11.GL_NEAREST); + Utils.drawTexturedRect(x + width / 6f + 27, y + 45 - 7 - 13, 11, 14, GL11.GL_NEAREST); - Gui.drawRect(x+5, y+45, x+width-5, y+height-5, 0xffdddddd); - Gui.drawRect(x+6, y+46, x+width-6, y+height-6, 0xff000000); + Gui.drawRect(x + 5, y + 45, x + width - 5, y + height - 5, 0xffdddddd); + Gui.drawRect(x + 6, y + 46, x + width - 6, y + height - 6, 0xff000000); int i = 0; - int yOff=0; - for(int strIndex : activeText) { + int yOff = 0; + for (int strIndex : activeText) { String str = exampleText[strIndex]; String[] multilines = str.split("\n"); int ySize = multilines.length * 10; - if(i++ != dragStartIndex) { - for(int multilineIndex=0; multilineIndex<multilines.length; multilineIndex++) { + if (i++ != dragStartIndex) { + for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { String line = multilines[multilineIndex]; - Utils.drawStringScaledMaxWidth(line+EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, - x+20, y+50+yOff+multilineIndex*10, true, width-20, 0xffffffff); + Utils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, x + 20, y + 50 + yOff + multilineIndex * 10, true, width - 20, 0xffffffff); } - Minecraft.getMinecraft().fontRendererObj.drawString("\u2261", x+10, y+50+yOff + ySize/2f - 4, 0xffffff, true); + Minecraft.getMinecraft().fontRendererObj.drawString("\u2261", x + 10, y + 50 + yOff + ySize / 2f - 4, 0xffffff, true); } yOff += ySize; @@ -104,50 +99,49 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { public void renderOverlay(int x, int y, int width) { super.renderOverlay(x, y, width); - if(dropdownOpen) { + if (dropdownOpen) { List<Integer> remaining = new ArrayList<>(); - for(int i=0; i<exampleText.length; i++) { + for (int i = 0; i < exampleText.length; i++) { remaining.add(i); } remaining.removeAll(activeText); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int dropdownWidth = Math.min(width/2-10, 150); + int dropdownWidth = Math.min(width / 2 - 10, 150); int left = dragOffsetX; int top = dragOffsetY; - int dropdownHeight = -1 + 12*remaining.size(); + int dropdownHeight = -1 + 12 * remaining.size(); int main = 0xff202026; int outline = 0xff404046; - Gui.drawRect(left, top, left+1, top+dropdownHeight, outline); //Left - Gui.drawRect(left+1, top, left+dropdownWidth, top+1, outline); //Top - Gui.drawRect(left+dropdownWidth-1, top+1, left+dropdownWidth, top+dropdownHeight, outline); //Right - Gui.drawRect(left+1, top+dropdownHeight-1, left+dropdownWidth-1, top+dropdownHeight, outline); //Bottom - Gui.drawRect(left+1, top+1, left+dropdownWidth-1, top+dropdownHeight-1, main); //Middle + Gui.drawRect(left, top, left + 1, top + dropdownHeight, outline); //Left + Gui.drawRect(left + 1, top, left + dropdownWidth, top + 1, outline); //Top + Gui.drawRect(left + dropdownWidth - 1, top + 1, left + dropdownWidth, top + dropdownHeight, outline); //Right + Gui.drawRect(left + 1, top + dropdownHeight - 1, left + dropdownWidth - 1, top + dropdownHeight, outline); //Bottom + Gui.drawRect(left + 1, top + 1, left + dropdownWidth - 1, top + dropdownHeight - 1, main); //Middle int dropdownY = -1; - for(int strIndex : remaining) { + for (int strIndex : remaining) { String str = exampleText[strIndex]; - if(str.isEmpty()) { + if (str.isEmpty()) { str = "<NONE>"; } - TextRenderUtils.drawStringScaledMaxWidth(str.replaceAll("(\n.*)+", " ..."), - fr, left+3, top+3+dropdownY, false, dropdownWidth-6, 0xffa0a0a0); + TextRenderUtils.drawStringScaledMaxWidth(str.replaceAll("(\n.*)+", " ..."), fr, left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0); dropdownY += 12; } - } else if(currentDragging >= 0) { + } else if (currentDragging >= 0) { int opacity = 0x80; long currentTime = System.currentTimeMillis(); - if(trashHoverTime < 0) { - float greenBlue = LerpUtils.clampZeroOne((currentTime + trashHoverTime)/250f); - opacity = (int)(opacity * greenBlue); + if (trashHoverTime < 0) { + float greenBlue = LerpUtils.clampZeroOne((currentTime + trashHoverTime) / 250f); + opacity = (int) (opacity * greenBlue); } else { - float greenBlue = LerpUtils.clampZeroOne((250 + trashHoverTime - currentTime)/250f); - opacity = (int)(opacity * greenBlue); + float greenBlue = LerpUtils.clampZeroOne((250 + trashHoverTime - currentTime) / 250f); + opacity = (int) (opacity * greenBlue); } - if(opacity < 20) return; + if (opacity < 20) return; ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); int mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; @@ -158,67 +152,58 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { String[] multilines = str.split("\n"); GlStateManager.enableBlend(); - for(int multilineIndex=0; multilineIndex<multilines.length; multilineIndex++) { + for (int multilineIndex = 0; multilineIndex < multilines.length; multilineIndex++) { String line = multilines[multilineIndex]; - Utils.drawStringScaledMaxWidth(line+EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, - dragOffsetX + mouseX + 10, dragOffsetY + mouseY + multilineIndex*10, true, width-20, 0xffffff | (opacity << 24)); + Utils.drawStringScaledMaxWidth(line + EnumChatFormatting.RESET, Minecraft.getMinecraft().fontRendererObj, dragOffsetX + mouseX + 10, dragOffsetY + mouseY + multilineIndex * 10, true, width - 20, 0xffffff | (opacity << 24)); } int ySize = multilines.length * 10; - Minecraft.getMinecraft().fontRendererObj.drawString("\u2261", - dragOffsetX + mouseX, - dragOffsetY + mouseY + ySize/2f - 4, 0xffffff, true); + Minecraft.getMinecraft().fontRendererObj.drawString("\u2261", dragOffsetX + mouseX, dragOffsetY + mouseY + ySize / 2f - 4, 0xffffff, true); } } @Override public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { - if(!Mouse.getEventButtonState() && !dropdownOpen && - dragStartIndex >= 0 && Mouse.getEventButton() == 0 && - mouseX >= x+width/6+27-3 && mouseX <= x+width/6+27+11+3 && - mouseY >= y+45-7-13-3 && mouseY <= y+45-7-13+14+3) { + if (!Mouse.getEventButtonState() && !dropdownOpen && dragStartIndex >= 0 && Mouse.getEventButton() == 0 && mouseX >= x + width / 6 + 27 - 3 && mouseX <= x + width / 6 + 27 + 11 + 3 && mouseY >= y + 45 - 7 - 13 - 3 && mouseY <= y + 45 - 7 - 13 + 14 + 3) { activeText.remove(dragStartIndex); currentDragging = -1; dragStartIndex = -1; return false; } - if(!Mouse.isButtonDown(0) || dropdownOpen) { + if (!Mouse.isButtonDown(0) || dropdownOpen) { currentDragging = -1; dragStartIndex = -1; - if(trashHoverTime > 0) trashHoverTime = -System.currentTimeMillis(); - } else if(currentDragging >= 0 && - mouseX >= x+width/6+27-3 && mouseX <= x+width/6+27+11+3 && - mouseY >= y+45-7-13-3 && mouseY <= y+45-7-13+14+3) { - if(trashHoverTime < 0) trashHoverTime = System.currentTimeMillis(); + if (trashHoverTime > 0) trashHoverTime = -System.currentTimeMillis(); + } else if (currentDragging >= 0 && mouseX >= x + width / 6 + 27 - 3 && mouseX <= x + width / 6 + 27 + 11 + 3 && mouseY >= y + 45 - 7 - 13 - 3 && mouseY <= y + 45 - 7 - 13 + 14 + 3) { + if (trashHoverTime < 0) trashHoverTime = System.currentTimeMillis(); } else { - if(trashHoverTime > 0) trashHoverTime = -System.currentTimeMillis(); + if (trashHoverTime > 0) trashHoverTime = -System.currentTimeMillis(); } - if(Mouse.getEventButtonState()) { + if (Mouse.getEventButtonState()) { int height = getHeight(); - if(dropdownOpen) { + if (dropdownOpen) { List<Integer> remaining = new ArrayList<>(); - for(int i=0; i<exampleText.length; i++) { + for (int i = 0; i < exampleText.length; i++) { remaining.add(i); } remaining.removeAll(activeText); - int dropdownWidth = Math.min(width/2-10, 150); + int dropdownWidth = Math.min(width / 2 - 10, 150); int left = dragOffsetX; int top = dragOffsetY; - int dropdownHeight = -1 + 12*remaining.size(); + int dropdownHeight = -1 + 12 * remaining.size(); - if(mouseX > left && mouseX < left+dropdownWidth && - mouseY > top && mouseY < top + dropdownHeight) { + if (mouseX > left && mouseX < left + dropdownWidth && mouseY > top && mouseY < top + dropdownHeight) { int dropdownY = -1; - for(int strIndex : remaining) { - if(mouseY < top+dropdownY+12) { + for (int strIndex : remaining) { + if (mouseY < top + dropdownY + 12) { activeText.add(0, strIndex); - if(remaining.size() == 1) dropdownOpen = false; + if (remaining.size() == 1) dropdownOpen = false; return true; } @@ -230,25 +215,21 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { return true; } - if(activeText.size() < exampleText.length && - mouseX > x+width/6-24 && mouseX < x+width/6+24 && - mouseY > y+45-7-14 && mouseY < y+45-7+2) { + if (activeText.size() < exampleText.length && mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + 45 - 7 - 14 && mouseY < y + 45 - 7 + 2) { dropdownOpen = !dropdownOpen; dragOffsetX = mouseX; dragOffsetY = mouseY; return true; } - if(Mouse.getEventButton() == 0 && - mouseX > x+5 && mouseX < x+width-5 && - mouseY > y+45 && mouseY < y+height-6) { - int yOff=0; + if (Mouse.getEventButton() == 0 && mouseX > x + 5 && mouseX < x + width - 5 && mouseY > y + 45 && mouseY < y + height - 6) { + int yOff = 0; int i = 0; - for(int strIndex : activeText) { + for (int strIndex : activeText) { int ySize = 10 * exampleText[strIndex].split("\n").length; - if(mouseY < y+50+yOff+ySize) { - dragOffsetX = x+10 - mouseX; - dragOffsetY = y+50+yOff - mouseY; + if (mouseY < y + 50 + yOff + ySize) { + dragOffsetX = x + 10 - mouseX; + dragOffsetY = y + 50 + yOff - mouseY; currentDragging = strIndex; dragStartIndex = i; @@ -258,11 +239,11 @@ public class GuiOptionEditorDraggableList extends GuiOptionEditor { i++; } } - } else if(Mouse.getEventButton() == -1 && currentDragging >= 0) { - int yOff=0; + } else if (Mouse.getEventButton() == -1 && currentDragging >= 0) { + int yOff = 0; int i = 0; - for(int strIndex : activeText) { - if(dragOffsetY + mouseY + 4 < y+50+yOff+10) { + for (int strIndex : activeText) { + if (dragOffsetY + mouseY + 4 < y + 50 + yOff + 10) { activeText.remove(dragStartIndex); activeText.add(i, currentDragging); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java index 5c797ad..260c2ad 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorDropdown.java @@ -19,7 +19,7 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { public GuiOptionEditorDropdown(ConfigProcessor.ProcessedOption option, String[] values, int selected, boolean useOrdinal) { super(option); - if(selected >= values.length) selected = values.length; + if (selected >= values.length) selected = values.length; this.values = values; this.selected = selected; this.useOrdinal = useOrdinal; @@ -29,68 +29,65 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { public void render(int x, int y, int width) { super.render(x, y, width); - if(!open) { + if (!open) { int height = getHeight(); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int dropdownWidth = Math.min(width/3-10, 80); - int left = x+width/6-dropdownWidth/2; - int top = y+height-7-14; + int dropdownWidth = Math.min(width / 3 - 10, 80); + int left = x + width / 6 - dropdownWidth / 2; + int top = y + height - 7 - 14; String selectedString = " - Select - "; - if(selected >= 0 && selected < values.length) { + if (selected >= 0 && selected < values.length) { selectedString = values[selected]; } RenderUtils.drawFloatingRectDark(left, top, dropdownWidth, 14, false); - TextRenderUtils.drawStringScaled("\u25BC", fr, left+dropdownWidth-10, y+height-7-15, false, 0xffa0a0a0, 2); + TextRenderUtils.drawStringScaled("\u25BC", fr, left + dropdownWidth - 10, y + height - 7 - 15, false, 0xffa0a0a0, 2); - TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left+3, top+3, false, - dropdownWidth-16, 0xffa0a0a0); + TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, dropdownWidth - 16, 0xffa0a0a0); } } @Override public void renderOverlay(int x, int y, int width) { - if(open) { + if (open) { String selectedString = " - Select - "; - if(selected >= 0 && selected < values.length) { + if (selected >= 0 && selected < values.length) { selectedString = values[selected]; } int height = getHeight(); FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; - int dropdownWidth = Math.min(width/3-10, 80); - int left = x+width/6-dropdownWidth/2; - int top = y+height-7-14; + int dropdownWidth = Math.min(width / 3 - 10, 80); + int left = x + width / 6 - dropdownWidth / 2; + int top = y + height - 7 - 14; - int dropdownHeight = 13 + 12*values.length; + int dropdownHeight = 13 + 12 * values.length; int main = 0xff202026; int blue = 0xff2355ad; - Gui.drawRect(left, top, left+1, top+dropdownHeight, blue); //Left - Gui.drawRect(left+1, top, left+dropdownWidth, top+1, blue); //Top - Gui.drawRect(left+dropdownWidth-1, top+1, left+dropdownWidth, top+dropdownHeight, blue); //Right - Gui.drawRect(left+1, top+dropdownHeight-1, left+dropdownWidth-1, top+dropdownHeight, blue); //Bottom - Gui.drawRect(left+1, top+1, left+dropdownWidth-1, top+dropdownHeight-1, main); //Middle + Gui.drawRect(left, top, left + 1, top + dropdownHeight, blue); //Left + Gui.drawRect(left + 1, top, left + dropdownWidth, top + 1, blue); //Top + Gui.drawRect(left + dropdownWidth - 1, top + 1, left + dropdownWidth, top + dropdownHeight, blue); //Right + Gui.drawRect(left + 1, top + dropdownHeight - 1, left + dropdownWidth - 1, top + dropdownHeight, blue); //Bottom + Gui.drawRect(left + 1, top + 1, left + dropdownWidth - 1, top + dropdownHeight - 1, main); //Middle - Gui.drawRect(left+1, top+14-1, left+dropdownWidth-1, top+14, blue); //Bar + Gui.drawRect(left + 1, top + 14 - 1, left + dropdownWidth - 1, top + 14, blue); //Bar int dropdownY = 13; - for(String option : values) { - if(option.isEmpty()) { + for (String option : values) { + if (option.isEmpty()) { option = "<NONE>"; } - TextRenderUtils.drawStringScaledMaxWidth(option, fr, left+3, top+3+dropdownY, false, dropdownWidth-6, 0xffa0a0a0); + TextRenderUtils.drawStringScaledMaxWidth(option, fr, left + 3, top + 3 + dropdownY, false, dropdownWidth - 6, 0xffa0a0a0); dropdownY += 12; } - TextRenderUtils.drawStringScaled("\u25B2", fr, left+dropdownWidth-10, y+height-7-15, false, 0xffa0a0a0, 2); + TextRenderUtils.drawStringScaled("\u25B2", fr, left + dropdownWidth - 10, y + height - 7 - 15, false, 0xffa0a0a0, 2); - - TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left+3, top+3, false, - dropdownWidth-16, 0xffa0a0a0); + TextRenderUtils.drawStringScaledMaxWidth(selectedString, fr, left + 3, top + 3, false, dropdownWidth - 16, 0xffa0a0a0); } } @@ -98,12 +95,11 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { int height = getHeight(); - int left = x+width/6-40; - int top = y+height-7-14; + int left = x + width / 6 - 40; + int top = y + height - 7 - 14; - if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if(mouseX >= left && mouseX <= left+80 && - mouseY >= top && mouseY <= top+14) { + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (mouseX >= left && mouseX <= left + 80 && mouseY >= top && mouseY <= top + 14) { open = !open; return true; } @@ -116,19 +112,18 @@ public class GuiOptionEditorDropdown extends GuiOptionEditor { public boolean mouseInputOverlay(int x, int y, int width, int mouseX, int mouseY) { int height = getHeight(); - int left = x+width/6-40; - int top = y+height-7-14; + int left = x + width / 6 - 40; + int top = y + height - 7 - 14; - if(Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { - if(!(mouseX >= left && mouseX <= left+80 && - mouseY >= top && mouseY <= top+14) && open) { + if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0) { + if (!(mouseX >= left && mouseX <= left + 80 && mouseY >= top && mouseY <= top + 14) && open) { open = false; - if(mouseX >= left && mouseX <= left+80) { + if (mouseX >= left && mouseX <= left + 80) { int dropdownY = 13; - for(int ordinal=0; ordinal < values.length; ordinal++) { - if(mouseY >= top+3+dropdownY && mouseY <= top+3+dropdownY+12) { + for (int ordinal = 0; ordinal < values.length; ordinal++) { + if (mouseY >= top + 3 + dropdownY && mouseY <= top + 3 + dropdownY + 12) { selected = ordinal; - if(useOrdinal) { + if (useOrdinal) { option.set(selected); } else { option.set(values[selected]); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorSlider.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorSlider.java index a37b952..49376e4 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorSlider.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorSlider.java @@ -15,33 +15,42 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { public GuiOptionEditorSlider(ConfigProcessor.ProcessedOption option, float minValue, float maxValue, float minStep) { super(option); - if(minStep < 0) minStep = 0.01f; + if (minStep < 0) minStep = 0.01f; - float floatVal = ((Number)option.get()).floatValue(); + float floatVal = ((Number) option.get()).floatValue(); { String strVal; - if(floatVal % 1 == 0) { - strVal = Integer.toString((int)floatVal); + if (floatVal % 1 == 0) { + strVal = Integer.toString((int) floatVal); } else { strVal = Float.toString(floatVal); } - textField = new GuiElementTextField(strVal, - GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); + textField = new GuiElementTextField(strVal, GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); } - slider = new GuiElementSlider(0, 0, 80, minValue, maxValue, minStep, floatVal, (val) -> { - option.set(val); - - String strVal; - if(val % 1 == 0) { - strVal = Integer.toString(val.intValue()); - } else { - strVal = Float.toString(val); - strVal = strVal.replaceAll("(\\.\\d\\d\\d)(?:\\d)+", "$1"); - strVal = strVal.replaceAll("0+$", ""); - } - textField.setText(strVal); - }); + slider = + new GuiElementSlider( + 0, + 0, + 80, + minValue, + maxValue, + minStep, + floatVal, + val -> { + option.set(val); + + String strVal; + if (val % 1 == 0) { + strVal = Integer.toString(val.intValue()); + } else { + strVal = Float.toString(val); + strVal = strVal.replaceAll("(\\.\\d\\d\\d)(?:\\d)+", "$1"); + strVal = strVal.replaceAll("0+$", ""); + } + textField.setText(strVal); + } + ); } @Override @@ -49,54 +58,52 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { super.render(x, y, width); int height = getHeight(); - int fullWidth = Math.min(width/3-10, 80); - int sliderWidth = (fullWidth-5)*3/4; - int textFieldWidth = (fullWidth-5)/4; + int fullWidth = Math.min(width / 3 - 10, 80); + int sliderWidth = (fullWidth - 5) * 3 / 4; + int textFieldWidth = (fullWidth - 5) / 4; - slider.x = x+width/6-fullWidth/2; - slider.y = y+height-7-14; + slider.x = x + width / 6 - fullWidth / 2; + slider.y = y + height - 7 - 14; slider.width = sliderWidth; slider.render(); - if(textField.getFocus()) { + if (textField.getFocus()) { textField.setOptions(GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY); - textField.setSize(Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10, - 16); + textField.setSize(Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10, 16); } else { textField.setSize(textFieldWidth, 16); textField.setOptions(GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); } - textField.render(x+width/6-fullWidth/2+sliderWidth+5, y+height-7-14); + textField.render(x + width / 6 - fullWidth / 2 + sliderWidth + 5, y + height - 7 - 14); } @Override public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { int height = getHeight(); - int fullWidth = Math.min(width/3-10, 80); - int sliderWidth = (fullWidth-5)*3/4; - int textFieldWidth = (fullWidth-5)/4; + int fullWidth = Math.min(width / 3 - 10, 80); + int sliderWidth = (fullWidth - 5) * 3 / 4; + int textFieldWidth = (fullWidth - 5) / 4; - slider.x = x+width/6-fullWidth/2; - slider.y = y+height-7-14; + slider.x = x + width / 6 - fullWidth / 2; + slider.y = y + height - 7 - 14; slider.width = sliderWidth; - if(slider.mouseInput(mouseX, mouseY)) { + if (slider.mouseInput(mouseX, mouseY)) { textField.unfocus(); return true; } - if(textField.getFocus()) { - textFieldWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10; + if (textField.getFocus()) { + textFieldWidth = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10; } - int textFieldX = x+width/6-fullWidth/2+sliderWidth+5; - int textFieldY = y+height-7-14; + int textFieldX = x + width / 6 - fullWidth / 2 + sliderWidth + 5; + int textFieldY = y + height - 7 - 14; textField.setSize(textFieldWidth, 16); - if(Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { - if(mouseX > textFieldX && mouseX < textFieldX+textFieldWidth && - mouseY > textFieldY && mouseY < textFieldY+16) { + if (Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { + if (mouseX > textFieldX && mouseX < textFieldX + textFieldWidth && mouseY > textFieldY && mouseY < textFieldY + 16) { textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); return true; } @@ -108,18 +115,18 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { @Override public boolean keyboardInput() { - if(Keyboard.getEventKeyState() && textField.getFocus()) { + if (Keyboard.getEventKeyState() && textField.getFocus()) { textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); try { textField.setCustomBorderColour(0xffffffff); float f = Float.parseFloat(textField.getText()); - if(option.set(f)) { + if (option.set(f)) { slider.setValue(f); } else { textField.setCustomBorderColour(0xff0000ff); } - } catch(Exception e) { + } catch (Exception e) { textField.setCustomBorderColour(0xffff0000); } @@ -127,6 +134,4 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { } return false; } - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorText.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorText.java index e42d5b3..e2f96f9 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorText.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiOptionEditorText.java @@ -14,8 +14,7 @@ public class GuiOptionEditorText extends GuiOptionEditor { public GuiOptionEditorText(ConfigProcessor.ProcessedOption option) { super(option); - - textField = new GuiElementTextField((String)option.get(), 0); + textField = new GuiElementTextField((String) option.get(), 0); } @Override @@ -23,36 +22,35 @@ public class GuiOptionEditorText extends GuiOptionEditor { super.render(x, y, width); int height = getHeight(); - int fullWidth = Math.min(width/3-10, 80); + int fullWidth = Math.min(width / 3 - 10, 80); - int textFieldX = x+width/6-fullWidth/2; - if(textField.getFocus()) { - fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10); + int textFieldX = x + width / 6 - fullWidth / 2; + if (textField.getFocus()) { + fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10); } textField.setSize(fullWidth, 16); - textField.render(textFieldX, y+height-7-14); + textField.render(textFieldX, y + height - 7 - 14); } @Override public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { int height = getHeight(); - int fullWidth = Math.min(width/3-10, 80); + int fullWidth = Math.min(width / 3 - 10, 80); - int textFieldX = x+width/6-fullWidth/2; + int textFieldX = x + width / 6 - fullWidth / 2; - if(textField.getFocus()) { - fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText())+10); + if (textField.getFocus()) { + fullWidth = Math.max(fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10); } - int textFieldY = y+height-7-14; + int textFieldY = y + height - 7 - 14; textField.setSize(fullWidth, 16); - if(Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { - if(mouseX > textFieldX && mouseX < textFieldX+fullWidth && - mouseY > textFieldY && mouseY < textFieldY+16) { + if (Mouse.getEventButtonState() && (Mouse.getEventButton() == 0 || Mouse.getEventButton() == 1)) { + if (mouseX > textFieldX && mouseX < textFieldX + fullWidth && mouseY > textFieldY && mouseY < textFieldY + 16) { textField.mouseClicked(mouseX, mouseY, Mouse.getEventButton()); return true; } @@ -64,14 +62,14 @@ public class GuiOptionEditorText extends GuiOptionEditor { @Override public boolean keyboardInput() { - if(Keyboard.getEventKeyState() && textField.getFocus()) { + if (Keyboard.getEventKeyState() && textField.getFocus()) { Keyboard.enableRepeatEvents(true); textField.keyTyped(Keyboard.getEventCharacter(), Keyboard.getEventKey()); try { textField.setCustomBorderColour(0xffffffff); option.set(textField.getText()); - } catch(Exception e) { + } catch (Exception e) { textField.setCustomBorderColour(0xffff0000); } @@ -79,6 +77,4 @@ public class GuiOptionEditorText extends GuiOptionEditor { } return false; } - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiPositionEditor.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiPositionEditor.java index e178843..1f31ec7 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiPositionEditor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/gui/GuiPositionEditor.java @@ -2,6 +2,7 @@ package com.thatgravyboat.skyblockhud.core.config.gui; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.core.config.Position; +import java.io.IOException; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; @@ -10,8 +11,6 @@ import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; -import java.io.IOException; - public class GuiPositionEditor extends GuiScreen { private final Position position; @@ -27,10 +26,7 @@ public class GuiPositionEditor extends GuiScreen { private int guiScaleOverride = -1; - public GuiPositionEditor(Position position, int elementWidth, int elementHeight, - Runnable renderCallback, - Runnable positionChangedCallback, - Runnable closedCallback) { + public GuiPositionEditor(Position position, int elementWidth, int elementHeight, Runnable renderCallback, Runnable positionChangedCallback, Runnable closedCallback) { this.position = position; this.originalPosition = position.clone(); this.elementWidth = elementWidth == -1 ? this.width : elementWidth; @@ -55,7 +51,7 @@ public class GuiPositionEditor extends GuiScreen { public void drawScreen(int mouseX, int mouseY, float partialTicks) { super.drawScreen(mouseX, mouseY, partialTicks); ScaledResolution scaledResolution; - if(guiScaleOverride >= 0) { + if (guiScaleOverride >= 0) { scaledResolution = Utils.pushGuiScale(guiScaleOverride); } else { scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -68,7 +64,7 @@ public class GuiPositionEditor extends GuiScreen { drawDefaultBackground(); - if(clicked) { + if (clicked) { grabbedX += position.moveX(mouseX - grabbedX, elementWidth, scaledResolution); grabbedY += position.moveY(mouseY - grabbedY, elementHeight, scaledResolution); } @@ -78,28 +74,26 @@ public class GuiPositionEditor extends GuiScreen { int x = position.getAbsX(scaledResolution, elementWidth); int y = position.getAbsY(scaledResolution, elementHeight); - if(position.isCenterX()) x -= elementWidth/2; - if(position.isCenterY()) y -= elementHeight/2; - Gui.drawRect(x, y, x+elementWidth, y+elementHeight, 0x80404040); + if (position.isCenterX()) x -= elementWidth / 2; + if (position.isCenterY()) y -= elementHeight / 2; + Gui.drawRect(x, y, x + elementWidth, y + elementHeight, 0x80404040); - if(guiScaleOverride >= 0) { + if (guiScaleOverride >= 0) { Utils.pushGuiScale(-1); } scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - Utils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth()/2f, 8, true, 0xffffff); - Utils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, - scaledResolution.getScaledWidth()/2f, 18, true, 0xffffff); + Utils.drawStringCentered("Position Editor", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2f, 8, true, 0xffffff); + Utils.drawStringCentered("R to Reset - Arrow keys/mouse to move", Minecraft.getMinecraft().fontRendererObj, scaledResolution.getScaledWidth() / 2f, 18, true, 0xffffff); } @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { super.mouseClicked(mouseX, mouseY, mouseButton); - if(mouseButton == 0) { + if (mouseButton == 0) { ScaledResolution scaledResolution; - if(guiScaleOverride >= 0) { + if (guiScaleOverride >= 0) { scaledResolution = Utils.pushGuiScale(guiScaleOverride); } else { scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -109,17 +103,16 @@ public class GuiPositionEditor extends GuiScreen { int x = position.getAbsX(scaledResolution, elementWidth); int y = position.getAbsY(scaledResolution, elementHeight); - if(position.isCenterX()) x -= elementWidth/2; - if(position.isCenterY()) y -= elementHeight/2; + if (position.isCenterX()) x -= elementWidth / 2; + if (position.isCenterY()) y -= elementHeight / 2; - if(mouseX >= x && mouseY >= y && - mouseX <= x+elementWidth && mouseY <= y+elementHeight) { + if (mouseX >= x && mouseY >= y && mouseX <= x + elementWidth && mouseY <= y + elementHeight) { clicked = true; grabbedX = mouseX; grabbedY = mouseY; } - if(guiScaleOverride >= 0) { + if (guiScaleOverride >= 0) { Utils.pushGuiScale(-1); } } @@ -129,18 +122,18 @@ public class GuiPositionEditor extends GuiScreen { protected void keyTyped(char typedChar, int keyCode) throws IOException { Keyboard.enableRepeatEvents(true); - if(keyCode == Keyboard.KEY_R) { + if (keyCode == Keyboard.KEY_R) { position.set(originalPosition); - } else if(!clicked) { + } else if (!clicked) { boolean shiftHeld = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); int dist = shiftHeld ? 10 : 1; - if(keyCode == Keyboard.KEY_DOWN) { + if (keyCode == Keyboard.KEY_DOWN) { position.moveY(dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); - } else if(keyCode == Keyboard.KEY_UP) { + } else if (keyCode == Keyboard.KEY_UP) { position.moveY(-dist, elementHeight, new ScaledResolution(Minecraft.getMinecraft())); - } else if(keyCode == Keyboard.KEY_LEFT) { + } else if (keyCode == Keyboard.KEY_LEFT) { position.moveX(-dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); - } else if(keyCode == Keyboard.KEY_RIGHT) { + } else if (keyCode == Keyboard.KEY_RIGHT) { position.moveX(dist, elementWidth, new ScaledResolution(Minecraft.getMinecraft())); } } @@ -157,9 +150,9 @@ public class GuiPositionEditor extends GuiScreen { protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - if(clicked) { + if (clicked) { ScaledResolution scaledResolution; - if(guiScaleOverride >= 0) { + if (guiScaleOverride >= 0) { scaledResolution = Utils.pushGuiScale(guiScaleOverride); } else { scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -171,7 +164,7 @@ public class GuiPositionEditor extends GuiScreen { grabbedY += position.moveY(mouseY - grabbedY, elementHeight, scaledResolution); positionChangedCallback.run(); - if(guiScaleOverride >= 0) { + if (guiScaleOverride >= 0) { Utils.pushGuiScale(-1); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java b/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java index aef92d8..f1f8733 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/config/struct/ConfigProcessor.java @@ -2,10 +2,9 @@ package com.thatgravyboat.skyblockhud.core.config.struct; import com.google.gson.annotations.Expose; import com.thatgravyboat.skyblockhud.core.config.Config; +import com.thatgravyboat.skyblockhud.core.config.Config; import com.thatgravyboat.skyblockhud.core.config.annotations.*; import com.thatgravyboat.skyblockhud.core.config.gui.*; -import com.thatgravyboat.skyblockhud.core.config.Config; - import java.lang.reflect.Field; import java.util.LinkedHashMap; import java.util.List; @@ -13,6 +12,7 @@ import java.util.List; public class ConfigProcessor { public static class ProcessedCategory { + public final String name; public final String desc; public final LinkedHashMap<String, ProcessedOption> options = new LinkedHashMap<>(); @@ -24,6 +24,7 @@ public class ConfigProcessor { } public static class ProcessedOption { + public final String name; public final String desc; public final int subcategoryId; @@ -46,20 +47,20 @@ public class ConfigProcessor { public Object get() { try { return field.get(container); - } catch(Exception e) { + } catch (Exception e) { return null; } } public boolean set(Object value) { try { - if(field.getType() == int.class && value instanceof Number) { - field.set(container, ((Number)value).intValue()); + if (field.getType() == int.class && value instanceof Number) { + field.set(container, ((Number) value).intValue()); } else { field.set(container, value); } return true; - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); return false; } @@ -68,97 +69,82 @@ public class ConfigProcessor { public static LinkedHashMap<String, ProcessedCategory> create(Config config) { LinkedHashMap<String, ProcessedCategory> processedConfig = new LinkedHashMap<>(); - for(Field categoryField : config.getClass().getDeclaredFields()) { + for (Field categoryField : config.getClass().getDeclaredFields()) { boolean exposePresent = categoryField.isAnnotationPresent(Expose.class); boolean categoryPresent = categoryField.isAnnotationPresent(Category.class); - if(exposePresent && categoryPresent) { + if (exposePresent && categoryPresent) { Object categoryObj; try { categoryObj = categoryField.get(config); - } catch(Exception e) { + } catch (Exception e) { //System.err.printf("Failed to load config category %s. Field was not accessible.\n", categoryField.getName()); continue; } Category categoryAnnotation = categoryField.getAnnotation(Category.class); - ProcessedCategory cat = new ProcessedCategory( - categoryAnnotation.name(), - categoryAnnotation.desc() - ); + ProcessedCategory cat = new ProcessedCategory(categoryAnnotation.name(), categoryAnnotation.desc()); processedConfig.put(categoryField.getName(), cat); - for(Field optionField : categoryObj.getClass().getDeclaredFields()) { + for (Field optionField : categoryObj.getClass().getDeclaredFields()) { boolean optionPresent = optionField.isAnnotationPresent(ConfigOption.class); - if(optionPresent) { + if (optionPresent) { ConfigOption optionAnnotation = optionField.getAnnotation(ConfigOption.class); - ProcessedOption option = new ProcessedOption( - optionAnnotation.name(), - optionAnnotation.desc(), - optionAnnotation.subcategoryId(), - optionField, - categoryObj - ); - if(optionField.isAnnotationPresent(ConfigAccordionId.class)) { + ProcessedOption option = new ProcessedOption(optionAnnotation.name(), optionAnnotation.desc(), optionAnnotation.subcategoryId(), optionField, categoryObj); + if (optionField.isAnnotationPresent(ConfigAccordionId.class)) { ConfigAccordionId annotation = optionField.getAnnotation(ConfigAccordionId.class); option.accordionId = annotation.id(); } GuiOptionEditor editor = null; Class<?> optionType = optionField.getType(); - if(optionField.isAnnotationPresent(ConfigEditorButton.class)) { + if (optionField.isAnnotationPresent(ConfigEditorButton.class)) { ConfigEditorButton configEditorAnnotation = optionField.getAnnotation(ConfigEditorButton.class); editor = new GuiOptionEditorButton(option, configEditorAnnotation.runnableId(), configEditorAnnotation.buttonText(), config); } - if(optionType.isAssignableFrom(boolean.class) && - optionField.isAnnotationPresent(ConfigEditorBoolean.class)) { + if (optionType.isAssignableFrom(boolean.class) && optionField.isAnnotationPresent(ConfigEditorBoolean.class)) { editor = new GuiOptionEditorBoolean(option); } - if(optionType.isAssignableFrom(boolean.class) && - optionField.isAnnotationPresent(ConfigEditorAccordion.class)) { + if (optionType.isAssignableFrom(boolean.class) && optionField.isAnnotationPresent(ConfigEditorAccordion.class)) { ConfigEditorAccordion configEditorAnnotation = optionField.getAnnotation(ConfigEditorAccordion.class); editor = new GuiOptionEditorAccordion(option, configEditorAnnotation.id()); } - if(optionType.isAssignableFrom(int.class)) { - if(optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + if (optionType.isAssignableFrom(int.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); - editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), (int)option.get(), true); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), (int) option.get(), true); } } - if(optionType.isAssignableFrom(List.class)) { - if(optionField.isAnnotationPresent(ConfigEditorDraggableList.class)) { + if (optionType.isAssignableFrom(List.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDraggableList.class)) { ConfigEditorDraggableList configEditorAnnotation = optionField.getAnnotation(ConfigEditorDraggableList.class); editor = new GuiOptionEditorDraggableList(option, configEditorAnnotation.exampleText()); } } - if(optionType.isAssignableFrom(String.class)) { - if(optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + if (optionType.isAssignableFrom(String.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); - editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), - configEditorAnnotation.initialIndex(), false); - } else if(optionField.isAnnotationPresent(ConfigEditorColour.class)) { + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), configEditorAnnotation.initialIndex(), false); + } else if (optionField.isAnnotationPresent(ConfigEditorColour.class)) { editor = new GuiOptionEditorColour(option); - } else if(optionField.isAnnotationPresent(ConfigEditorText.class)) { + } else if (optionField.isAnnotationPresent(ConfigEditorText.class)) { editor = new GuiOptionEditorText(option); } } - if(optionType.isAssignableFrom(int.class) || - optionType.isAssignableFrom(float.class) || - optionType.isAssignableFrom(double.class)) { - if(optionField.isAnnotationPresent(ConfigEditorSlider.class)) { + if (optionType.isAssignableFrom(int.class) || optionType.isAssignableFrom(float.class) || optionType.isAssignableFrom(double.class)) { + if (optionField.isAnnotationPresent(ConfigEditorSlider.class)) { ConfigEditorSlider configEditorAnnotation = optionField.getAnnotation(ConfigEditorSlider.class); - editor = new GuiOptionEditorSlider(option, configEditorAnnotation.minValue(), - configEditorAnnotation.maxValue(), configEditorAnnotation.minStep()); + editor = new GuiOptionEditorSlider(option, configEditorAnnotation.minValue(), configEditorAnnotation.maxValue(), configEditorAnnotation.minStep()); } } - if(optionType.isAssignableFrom(String.class)) { - if(optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { + if (optionType.isAssignableFrom(String.class)) { + if (optionField.isAnnotationPresent(ConfigEditorDropdown.class)) { ConfigEditorDropdown configEditorAnnotation = optionField.getAnnotation(ConfigEditorDropdown.class); - editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), 0,false); + editor = new GuiOptionEditorDropdown(option, configEditorAnnotation.values(), 0, false); } } - if(editor == null) { + if (editor == null) { //System.err.printf("Failed to load config option %s. Could not find suitable editor.\n", optionField.getName()); continue; } @@ -166,11 +152,10 @@ public class ConfigProcessor { cat.options.put(optionField.getName(), option); } } - } else if(exposePresent || categoryPresent) { + } else if (exposePresent || categoryPresent) { //System.err.printf("Failed to load config category %s. Both @Expose and @Category must be present.\n", categoryField.getName()); } } return processedConfig; } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/GuiElementSlider.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/GuiElementSlider.java index ee963c2..9d9fcbd 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/GuiElementSlider.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/GuiElementSlider.java @@ -1,17 +1,16 @@ package com.thatgravyboat.skyblockhud.core.util; +import static com.thatgravyboat.skyblockhud.GuiTextures.*; + import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.core.GuiElement; +import java.util.function.Consumer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; -import java.util.function.Consumer; - -import static com.thatgravyboat.skyblockhud.GuiTextures.*; - public class GuiElementSlider extends GuiElement { public int x; @@ -28,9 +27,8 @@ public class GuiElementSlider extends GuiElement { private boolean clicked = false; - public GuiElementSlider(int x, int y, int width, float minValue, float maxValue, float minStep, - float value, Consumer<Float> setCallback) { - if(minStep < 0) minStep = 0.01f; + public GuiElementSlider(int x, int y, int width, float minValue, float maxValue, float minStep, float value, Consumer<Float> setCallback) { + if (minStep < 0) minStep = 0.01f; this.x = x; this.y = y; @@ -52,62 +50,62 @@ public class GuiElementSlider extends GuiElement { int mouseX = Mouse.getX() * scaledResolution.getScaledWidth() / Minecraft.getMinecraft().displayWidth; float value = this.value; - if(clicked) { - value = (mouseX-x)*(maxValue-minValue)/width+minValue; + if (clicked) { + value = (mouseX - x) * (maxValue - minValue) / width + minValue; value = Math.max(minValue, Math.min(maxValue, value)); - value = Math.round(value/minStep)*minStep; + value = Math.round(value / minStep) * minStep; } - float sliderAmount = Math.max(0, Math.min(1, (value-minValue)/(maxValue-minValue))); - int sliderAmountI = (int)(width*sliderAmount); + float sliderAmount = Math.max(0, Math.min(1, (value - minValue) / (maxValue - minValue))); + int sliderAmountI = (int) (width * sliderAmount); GlStateManager.color(1f, 1f, 1f, 1f); Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_cap); Utils.drawTexturedRect(x, y, 4, HEIGHT, GL11.GL_NEAREST); Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_cap); - Utils.drawTexturedRect(x+width-4, y, 4, HEIGHT, GL11.GL_NEAREST); + Utils.drawTexturedRect(x + width - 4, y, 4, HEIGHT, GL11.GL_NEAREST); - if(sliderAmountI > 5) { + if (sliderAmountI > 5) { Minecraft.getMinecraft().getTextureManager().bindTexture(slider_on_segment); - Utils.drawTexturedRect(x+4, y, sliderAmountI-4, HEIGHT, GL11.GL_NEAREST); + Utils.drawTexturedRect(x + 4, y, sliderAmountI - 4, HEIGHT, GL11.GL_NEAREST); } - if(sliderAmountI < width-5) { + if (sliderAmountI < width - 5) { Minecraft.getMinecraft().getTextureManager().bindTexture(slider_off_segment); - Utils.drawTexturedRect(x+sliderAmountI, y, width-4-sliderAmountI, HEIGHT, GL11.GL_NEAREST); + Utils.drawTexturedRect(x + sliderAmountI, y, width - 4 - sliderAmountI, HEIGHT, GL11.GL_NEAREST); } - for(int i=1; i<4; i++) { - int notchX = x+width*i/4-1; - Minecraft.getMinecraft().getTextureManager().bindTexture(notchX > x+sliderAmountI ? slider_off_notch : slider_on_notch); - Utils.drawTexturedRect(notchX, y+(HEIGHT-4)/2f, 2, 4, GL11.GL_NEAREST); + for (int i = 1; i < 4; i++) { + int notchX = x + width * i / 4 - 1; + Minecraft.getMinecraft().getTextureManager().bindTexture(notchX > x + sliderAmountI ? slider_off_notch : slider_on_notch); + Utils.drawTexturedRect(notchX, y + (HEIGHT - 4) / 2f, 2, 4, GL11.GL_NEAREST); } Minecraft.getMinecraft().getTextureManager().bindTexture(slider_button_new); - Utils.drawTexturedRect(x+sliderAmountI-4, y, 8, HEIGHT, GL11.GL_NEAREST); + Utils.drawTexturedRect(x + sliderAmountI - 4, y, 8, HEIGHT, GL11.GL_NEAREST); } @Override public boolean mouseInput(int mouseX, int mouseY) { - if(!Mouse.isButtonDown(0)) { + if (!Mouse.isButtonDown(0)) { clicked = false; } - if(Mouse.getEventButton() == 0) { - clicked = Mouse.getEventButtonState() && mouseX > x && mouseX < x+width && mouseY > y && mouseY < y+HEIGHT; - if(clicked) { - value = (mouseX-x)*(maxValue-minValue)/width+minValue; + if (Mouse.getEventButton() == 0) { + clicked = Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + HEIGHT; + if (clicked) { + value = (mouseX - x) * (maxValue - minValue) / width + minValue; value = Math.max(minValue, Math.min(maxValue, value)); - value = (float)(Math.round(value/minStep)*(double)minStep); + value = (float) (Math.round(value / minStep) * (double) minStep); setCallback.accept(value); return true; } } - if(!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && clicked) { - value = (mouseX-x)*(maxValue-minValue)/width+minValue; + if (!Mouse.getEventButtonState() && Mouse.getEventButton() == -1 && clicked) { + value = (mouseX - x) * (maxValue - minValue) / width + minValue; value = Math.max(minValue, Math.min(maxValue, value)); - value = Math.round(value/minStep)*minStep; + value = Math.round(value / minStep) * minStep; setCallback.accept(value); return true; } @@ -119,5 +117,4 @@ public class GuiElementSlider extends GuiElement { public boolean keyboardInput() { return false; } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/MiscUtils.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/MiscUtils.java index da89e75..0ee34a1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/MiscUtils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/MiscUtils.java @@ -1,12 +1,5 @@ package com.thatgravyboat.skyblockhud.core.util; -import net.minecraft.client.Minecraft; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.BufferUtils; -import org.lwjgl.input.Cursor; -import org.lwjgl.input.Mouse; - -import javax.imageio.ImageIO; import java.awt.*; import java.awt.datatransfer.StringSelection; import java.awt.image.BufferedImage; @@ -18,21 +11,27 @@ import java.nio.IntBuffer; import java.nio.file.Files; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import javax.imageio.ImageIO; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.BufferUtils; +import org.lwjgl.input.Cursor; +import org.lwjgl.input.Mouse; public class MiscUtils { public static void copyToClipboard(String str) { - Toolkit.getDefaultToolkit().getSystemClipboard() - .setContents(new StringSelection(str), null); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(str), null); } + private static void unzip(InputStream src, File dest) { //buffer for read and write data to file byte[] buffer = new byte[1024]; try { ZipInputStream zis = new ZipInputStream(src); ZipEntry ze = zis.getNextEntry(); - while(ze != null){ - if(!ze.isDirectory()) { + while (ze != null) { + if (!ze.isDirectory()) { String fileName = ze.getName(); File newFile = new File(dest, fileName); //create directories for sub directories in zip @@ -57,8 +56,8 @@ public class MiscUtils { } public static void recursiveDelete(File file) { - if(file.isDirectory() && !Files.isSymbolicLink(file.toPath())) { - for(File child : file.listFiles()) { + if (file.isDirectory() && !Files.isSymbolicLink(file.toPath())) { + for (File child : file.listFiles()) { recursiveDelete(child); } } @@ -68,36 +67,36 @@ public class MiscUtils { private static String currentCursor = null; public static void resetCursor() { - if(currentCursor == null) { + if (currentCursor == null) { return; } currentCursor = null; - try { Mouse.setNativeCursor(null); } catch(Exception ignored) {} + try { + Mouse.setNativeCursor(null); + } catch (Exception ignored) {} } public static void setCursor(ResourceLocation loc, int hotspotX, int hotspotY) { - if(currentCursor != null && loc.getResourcePath().equals(currentCursor)) { + if (currentCursor != null && loc.getResourcePath().equals(currentCursor)) { return; } currentCursor = loc.getResourcePath(); try { - BufferedImage image = ImageIO.read(Minecraft.getMinecraft() - .getResourceManager().getResource(loc).getInputStream()); + BufferedImage image = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream()); int maxSize = Cursor.getMaxCursorSize(); - IntBuffer buffer = BufferUtils.createIntBuffer(maxSize*maxSize); - for(int i=0; i<maxSize*maxSize; i++) { - int cursorX = i%maxSize; - int cursorY = i/maxSize; - if(cursorX >= image.getWidth() || cursorY >= image.getHeight()) { + IntBuffer buffer = BufferUtils.createIntBuffer(maxSize * maxSize); + for (int i = 0; i < maxSize * maxSize; i++) { + int cursorX = i % maxSize; + int cursorY = i / maxSize; + if (cursorX >= image.getWidth() || cursorY >= image.getHeight()) { buffer.put(0x00000000); } else { - buffer.put(image.getRGB(cursorX, image.getHeight()-1-cursorY)); + buffer.put(image.getRGB(cursorX, image.getHeight() - 1 - cursorY)); } } buffer.flip(); - Mouse.setNativeCursor(new Cursor(maxSize, maxSize, hotspotX, hotspotY, 1, - buffer, null)); - } catch(Exception e) { + Mouse.setNativeCursor(new Cursor(maxSize, maxSize, hotspotX, hotspotY, 1, buffer, null)); + } catch (Exception e) { e.printStackTrace(); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/Splitters.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/Splitters.java index 9736803..f13fbc7 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/Splitters.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/Splitters.java @@ -5,6 +5,4 @@ import com.google.common.base.Splitter; public class Splitters { public static final Splitter NEWLINE_SPLITTER = Splitter.on('\n'); - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/StringUtils.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/StringUtils.java index d8fd0e6..5b34cb1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/StringUtils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/StringUtils.java @@ -1,11 +1,10 @@ package com.thatgravyboat.skyblockhud.core.util; import com.google.common.collect.Sets; +import java.util.Set; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; -import java.util.Set; - public class StringUtils { public static final Set<String> PROTOCOLS = Sets.newHashSet("http", "https"); @@ -22,18 +21,17 @@ public class StringUtils { FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; String trim = fr.trimStringToWidth(str, len); - if(str.length() != trim.length() && !trim.endsWith(" ")) { + if (str.length() != trim.length() && !trim.endsWith(" ")) { char next = str.charAt(trim.length()); - if(next != ' ') { + if (next != ' ') { String[] split = trim.split(" "); - String last = split[split.length-1]; - if(last.length() < 8) { - trim = trim.substring(0, trim.length()-last.length()); + String last = split[split.length - 1]; + if (last.length() < 8) { + trim = trim.substring(0, trim.length() - last.length()); } } } return trim; } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpUtils.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpUtils.java index e742ab1..1b88f5a 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpUtils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpUtils.java @@ -7,20 +7,19 @@ public class LerpUtils { } public static float sigmoid(float val) { - return (float)(1/(1 + Math.exp(-val))); + return (float) (1 / (1 + Math.exp(-val))); } private static final float sigmoidStr = 8; - private static final float sigmoidA = -1/(sigmoid(-0.5f * sigmoidStr) - sigmoid(0.5f * sigmoidStr)); - private static final float sigmoidB = sigmoidA*sigmoid(-0.5f * sigmoidStr); + private static final float sigmoidA = -1 / (sigmoid(-0.5f * sigmoidStr) - sigmoid(0.5f * sigmoidStr)); + private static final float sigmoidB = sigmoidA * sigmoid(-0.5f * sigmoidStr); + public static float sigmoidZeroOne(float f) { f = clampZeroOne(f); - return sigmoidA*sigmoid(sigmoidStr*(f-0.5f))-sigmoidB; + return sigmoidA * sigmoid(sigmoidStr * (f - 0.5f)) - sigmoidB; } public static float lerp(float a, float b, float amount) { return b + (a - b) * clampZeroOne(amount); } - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingFloat.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingFloat.java index 4831956..edf129b 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingFloat.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingFloat.java @@ -22,23 +22,23 @@ public class LerpingFloat { int lastTimeSpent = timeSpent; this.timeSpent += System.currentTimeMillis() - lastMillis; - float lastDistPercentToTarget = lastTimeSpent/(float)timeToReachTarget; - float distPercentToTarget = timeSpent/(float)timeToReachTarget; - float fac = (1-lastDistPercentToTarget)/lastDistPercentToTarget; + float lastDistPercentToTarget = lastTimeSpent / (float) timeToReachTarget; + float distPercentToTarget = timeSpent / (float) timeToReachTarget; + float fac = (1 - lastDistPercentToTarget) / lastDistPercentToTarget; - float startValue = lerpValue - (targetValue - lerpValue)/fac; + float startValue = lerpValue - (targetValue - lerpValue) / fac; float dist = targetValue - startValue; - if(dist == 0) return; + if (dist == 0) return; float oldLerpValue = lerpValue; - if(distPercentToTarget >= 1) { + if (distPercentToTarget >= 1) { lerpValue = targetValue; } else { - lerpValue = startValue + dist*distPercentToTarget; + lerpValue = startValue + dist * distPercentToTarget; } - if(lerpValue == oldLerpValue) { + if (lerpValue == oldLerpValue) { timeSpent = lastTimeSpent; } else { this.lastMillis = System.currentTimeMillis(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingInteger.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingInteger.java index 48ae5ad..0bae869 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingInteger.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/lerp/LerpingInteger.java @@ -22,23 +22,23 @@ public class LerpingInteger { int lastTimeSpent = timeSpent; this.timeSpent += System.currentTimeMillis() - lastMillis; - float lastDistPercentToTarget = lastTimeSpent/(float)timeToReachTarget; - float distPercentToTarget = timeSpent/(float)timeToReachTarget; - float fac = (1-lastDistPercentToTarget)/lastDistPercentToTarget; + float lastDistPercentToTarget = lastTimeSpent / (float) timeToReachTarget; + float distPercentToTarget = timeSpent / (float) timeToReachTarget; + float fac = (1 - lastDistPercentToTarget) / lastDistPercentToTarget; - int startValue = lerpValue - (int)((targetValue - lerpValue)/fac); + int startValue = lerpValue - (int) ((targetValue - lerpValue) / fac); int dist = targetValue - startValue; - if(dist == 0) return; + if (dist == 0) return; int oldLerpValue = lerpValue; - if(distPercentToTarget >= 1) { + if (distPercentToTarget >= 1) { lerpValue = targetValue; } else { - lerpValue = startValue + (int)(dist*distPercentToTarget); + lerpValue = startValue + (int) (dist * distPercentToTarget); } - if(lerpValue == oldLerpValue) { + if (lerpValue == oldLerpValue) { timeSpent = lastTimeSpent; } else { this.lastMillis = System.currentTimeMillis(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/RenderUtils.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/RenderUtils.java index 95d1b05..bbaabb8 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/RenderUtils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/RenderUtils.java @@ -21,10 +21,9 @@ public class RenderUtils { public static void drawFloatingRectDark(int x, int y, int width, int height, boolean shadow) { int alpha = 0xf0000000; - if(OpenGlHelper.isFramebufferEnabled()) { + if (OpenGlHelper.isFramebufferEnabled()) { ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - BackgroundBlur.renderBlurredBackground(15, scaledResolution.getScaledWidth(), - scaledResolution.getScaledHeight(), x, y, width, height, true); + BackgroundBlur.renderBlurredBackground(15, scaledResolution.getScaledWidth(), scaledResolution.getScaledHeight(), x, y, width, height, true); } else { alpha = 0xff000000; } @@ -32,14 +31,14 @@ public class RenderUtils { int main = alpha | 0x202026; int light = 0xff303036; int dark = 0xff101016; - Gui.drawRect(x, y, x+1, y+height, light); //Left - Gui.drawRect(x+1, y, x+width, y+1, light); //Top - Gui.drawRect(x+width-1, y+1, x+width, y+height, dark); //Right - Gui.drawRect(x+1, y+height-1, x+width-1, y+height, dark); //Bottom - Gui.drawRect(x+1, y+1, x+width-1, y+height-1, main); //Middle - if(shadow) { - Gui.drawRect(x+width, y+2, x+width+2, y+height+2, 0x70000000); //Right shadow - Gui.drawRect(x+2, y+height, x+width, y+height+2, 0x70000000); //Bottom shadow + Gui.drawRect(x, y, x + 1, y + height, light); //Left + Gui.drawRect(x + 1, y, x + width, y + 1, light); //Top + Gui.drawRect(x + width - 1, y + 1, x + width, y + height, dark); //Right + Gui.drawRect(x + 1, y + height - 1, x + width - 1, y + height, dark); //Bottom + Gui.drawRect(x + 1, y + 1, x + width - 1, y + height - 1, main); //Middle + if (shadow) { + Gui.drawRect(x + width, y + 2, x + width + 2, y + height + 2, 0x70000000); //Right shadow + Gui.drawRect(x + 2, y + height, x + width, y + height + 2, 0x70000000); //Bottom shadow } } @@ -51,18 +50,18 @@ public class RenderUtils { int main = (alpha << 24) | 0xc0c0c0; int light = (alpha << 24) | 0xf0f0f0; int dark = (alpha << 24) | 0x909090; - Gui.drawRect(x, y, x+1, y+height, light); //Left - Gui.drawRect(x+1, y, x+width, y+1, light); //Top - Gui.drawRect(x+width-1, y+1, x+width, y+height, dark); //Right - Gui.drawRect(x+1, y+height-1, x+width-1, y+height, dark); //Bottom - Gui.drawRect(x+1, y+1, x+width-1, y+height-1, main); //Middle - if(shadow) { - Gui.drawRect(x+width, y+2, x+width+2, y+height+2, (alpha*3/5) << 24); //Right shadow - Gui.drawRect(x+2, y+height, x+width, y+height+2, (alpha*3/5) << 24); //Bottom shadow + Gui.drawRect(x, y, x + 1, y + height, light); //Left + Gui.drawRect(x + 1, y, x + width, y + 1, light); //Top + Gui.drawRect(x + width - 1, y + 1, x + width, y + height, dark); //Right + Gui.drawRect(x + 1, y + height - 1, x + width - 1, y + height, dark); //Bottom + Gui.drawRect(x + 1, y + 1, x + width - 1, y + height - 1, main); //Middle + if (shadow) { + Gui.drawRect(x + width, y + 2, x + width + 2, y + height + 2, (alpha * 3 / 5) << 24); //Right shadow + Gui.drawRect(x + 2, y + height, x + width, y + height + 2, (alpha * 3 / 5) << 24); //Bottom shadow } } - public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height){ + public static void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height) { double f = 0.00390625; double f1 = 0.00390625; Tessellator tessellator = Tessellator.getInstance(); @@ -76,15 +75,15 @@ public class RenderUtils { } public static void drawTexturedRect(float x, float y, float width, float height) { - drawTexturedRect(x, y, width, height, 0, 1, 0 , 1); + drawTexturedRect(x, y, width, height, 0, 1, 0, 1); } public static void drawTexturedRect(float x, float y, float width, float height, int filter) { - drawTexturedRect(x, y, width, height, 0, 1, 0 , 1, filter); + drawTexturedRect(x, y, width, height, 0, 1, 0, 1, filter); } public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax) { - drawTexturedRect(x, y, width, height, uMin, uMax, vMin , vMax, GL11.GL_NEAREST); + drawTexturedRect(x, y, width, height, uMin, uMax, vMin, vMax, GL11.GL_NEAREST); } public static void drawTexturedRect(float x, float y, float width, float height, float uMin, float uMax, float vMin, float vMax, int filter) { @@ -105,18 +104,10 @@ public class RenderUtils { Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldrenderer = tessellator.getWorldRenderer(); worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX); - worldrenderer - .pos(x, y+height, 0.0D) - .tex(uMin, vMax).endVertex(); - worldrenderer - .pos(x+width, y+height, 0.0D) - .tex(uMax, vMax).endVertex(); - worldrenderer - .pos(x+width, y, 0.0D) - .tex(uMax, vMin).endVertex(); - worldrenderer - .pos(x, y, 0.0D) - .tex(uMin, vMin).endVertex(); + worldrenderer.pos(x, y + height, 0.0D).tex(uMin, vMax).endVertex(); + worldrenderer.pos(x + width, y + height, 0.0D).tex(uMax, vMax).endVertex(); + worldrenderer.pos(x + width, y, 0.0D).tex(uMax, vMin).endVertex(); + worldrenderer.pos(x, y, 0.0D).tex(uMin, vMin).endVertex(); tessellator.draw(); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); @@ -124,14 +115,14 @@ public class RenderUtils { } public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) { - float startAlpha = (float)(startColor >> 24 & 255) / 255.0F; - float startRed = (float)(startColor >> 16 & 255) / 255.0F; - float startGreen = (float)(startColor >> 8 & 255) / 255.0F; - float startBlue = (float)(startColor & 255) / 255.0F; - float endAlpha = (float)(endColor >> 24 & 255) / 255.0F; - float endRed = (float)(endColor >> 16 & 255) / 255.0F; - float endGreen = (float)(endColor >> 8 & 255) / 255.0F; - float endBlue = (float)(endColor & 255) / 255.0F; + float startAlpha = (float) (startColor >> 24 & 255) / 255.0F; + float startRed = (float) (startColor >> 16 & 255) / 255.0F; + float startGreen = (float) (startColor >> 8 & 255) / 255.0F; + float startBlue = (float) (startColor & 255) / 255.0F; + float endAlpha = (float) (endColor >> 24 & 255) / 255.0F; + float endRed = (float) (endColor >> 16 & 255) / 255.0F; + float endGreen = (float) (endColor >> 8 & 255) / 255.0F; + float endBlue = (float) (endColor & 255) / 255.0F; GlStateManager.disableTexture2D(); GlStateManager.enableBlend(); @@ -154,12 +145,11 @@ public class RenderUtils { GlStateManager.enableTexture2D(); } - public static void drawInnerBox(int left, int top, int width, int height){ - Gui.drawRect(left, top, left+width, top+height, 0x6008080E); //Middle - Gui.drawRect(left, top, left+1, top+height, 0xff08080E); //Left - Gui.drawRect(left, top, left+width, top+1, 0xff08080E); //Top - Gui.drawRect(left+width-1, top, left+width, top+height, 0xff28282E); //Right - Gui.drawRect(left, top+height-1, left+width, top+height, 0xff28282E); //Bottom + public static void drawInnerBox(int left, int top, int width, int height) { + Gui.drawRect(left, top, left + width, top + height, 0x6008080E); //Middle + Gui.drawRect(left, top, left + 1, top + height, 0xff08080E); //Left + Gui.drawRect(left, top, left + width, top + 1, 0xff08080E); //Top + Gui.drawRect(left + width - 1, top, left + width, top + height, 0xff28282E); //Right + Gui.drawRect(left, top + height - 1, left + width, top + height, 0xff28282E); //Bottom } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/TextRenderUtils.java b/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/TextRenderUtils.java index fce2f82..7745562 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/TextRenderUtils.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/core/util/render/TextRenderUtils.java @@ -1,6 +1,8 @@ package com.thatgravyboat.skyblockhud.core.util.render; import com.thatgravyboat.skyblockhud.core.util.StringUtils; +import java.util.ArrayList; +import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.renderer.GlStateManager; @@ -9,13 +11,10 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import org.lwjgl.opengl.GL11; -import java.util.ArrayList; -import java.util.List; - public class TextRenderUtils { public static int getCharVertLen(char c) { - if("acegmnopqrsuvwxyz".indexOf(c) >= 0) { + if ("acegmnopqrsuvwxyz".indexOf(c) >= 0) { return 5; } else { return 7; @@ -25,9 +24,9 @@ public class TextRenderUtils { public static float getVerticalHeight(String str) { str = StringUtils.cleanColour(str); float height = 0; - for(int i=0; i<str.length(); i++) { + for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); - int charHeight = getCharVertLen(c); + int charHeight = getCharVertLen(c); height += charHeight + 1.5f; } return height; @@ -36,12 +35,12 @@ public class TextRenderUtils { public static void drawStringVertical(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { String format = FontRenderer.getFormatFromString(str); str = StringUtils.cleanColour(str); - for(int i=0; i<str.length(); i++) { + for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); - int charHeight = getCharVertLen(c); + int charHeight = getCharVertLen(c); int charWidth = fr.getCharWidth(c); - fr.drawString(format+c, x+(5-charWidth)/2f, y-7+charHeight, colour, shadow); + fr.drawString(format + c, x + (5 - charWidth) / 2f, y - 7 + charHeight, colour, shadow); y += charHeight + 1.5f; } @@ -49,7 +48,7 @@ public class TextRenderUtils { public static void drawStringScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; + float factor = len / (float) strLen; factor = Math.min(1, factor); drawStringScaled(str, fr, x, y, shadow, colour, factor); @@ -58,8 +57,8 @@ public class TextRenderUtils { public static void drawStringCentered(String str, FontRenderer fr, float x, float y, boolean shadow, int colour) { int strLen = fr.getStringWidth(str); - float x2 = x - strLen/2f; - float y2 = y - fr.FONT_HEIGHT/2f; + float x2 = x - strLen / 2f; + float y2 = y - fr.FONT_HEIGHT / 2f; GL11.glTranslatef(x2, y2, 0); fr.drawString(str, 0, 0, colour, shadow); @@ -68,24 +67,23 @@ public class TextRenderUtils { public static void drawStringScaled(String str, FontRenderer fr, float x, float y, boolean shadow, int colour, float factor) { GlStateManager.scale(factor, factor, 1); - fr.drawString(str, x/factor, y/factor, colour, shadow); - GlStateManager.scale(1/factor, 1/factor, 1); + fr.drawString(str, x / factor, y / factor, colour, shadow); + GlStateManager.scale(1 / factor, 1 / factor, 1); } public static void drawStringCenteredScaledMaxWidth(String str, FontRenderer fr, float x, float y, boolean shadow, int len, int colour) { int strLen = fr.getStringWidth(str); - float factor = len/(float)strLen; + float factor = len / (float) strLen; factor = Math.min(1, factor); int newLen = Math.min(strLen, len); - float fontHeight = 8*factor; + float fontHeight = 8 * factor; - drawStringScaled(str, fr, x-newLen/2, y-fontHeight/2, shadow, colour, factor); + drawStringScaled(str, fr, x - newLen / 2, y - fontHeight / 2, shadow, colour, factor); } public static void renderToolTip(ItemStack stack, int mouseX, int mouseY, int screenWidth, int screenHeight, FontRenderer fontStd) { - List<String> list = stack.getTooltip(Minecraft.getMinecraft().thePlayer, - Minecraft.getMinecraft().gameSettings.advancedItemTooltips); + List<String> list = stack.getTooltip(Minecraft.getMinecraft().thePlayer, Minecraft.getMinecraft().gameSettings.advancedItemTooltips); for (int i = 0; i < list.size(); ++i) { if (i == 0) { @@ -96,7 +94,7 @@ public class TextRenderUtils { } FontRenderer font = stack.getItem().getFontRenderer(stack); - drawHoveringText(list, mouseX, mouseY, screenWidth, screenHeight, -1, font == null ? fontStd : font); + drawHoveringText(list, mouseX, mouseY, screenWidth, screenHeight, -1, font == null ? fontStd : font); } public static void drawHoveringText(List<String> textLines, final int mouseX, final int mouseY, final int screenWidth, final int screenHeight, final int maxTextWidth, FontRenderer font) { @@ -121,8 +119,7 @@ public class TextRenderUtils { int tooltipX = mouseX + 12; if (tooltipX + tooltipTextWidth + 4 > screenWidth) { tooltipX = mouseX - 16 - tooltipTextWidth; - if (tooltipX < 4) // if the tooltip doesn't fit on the screen - { + if (tooltipX < 4) { // if the tooltip doesn't fit on the screen if (mouseX > screenWidth / 2) { tooltipTextWidth = mouseX - 12 - 8; } else { @@ -211,5 +208,4 @@ public class TextRenderUtils { } GlStateManager.disableLighting(); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java index 14634d8..b05fe91 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/Classes.java @@ -1,47 +1,45 @@ package com.thatgravyboat.skyblockhud.dungeons; public enum Classes { - - H("Healer", "H", 154), - M("Mage", "M", 90), - B("Berserk", "B", 122), - A("Archer", "A", 58), - T("Tank", "T", 186); - - private final String displayName; - private final String classId; - private final int textureY; - - Classes(String name, String id, int textureY) - { + H("Healer", "H", 154), + M("Mage", "M", 90), + B("Berserk", "B", 122), + A("Archer", "A", 58), + T("Tank", "T", 186); + + private final String displayName; + private final String classId; + private final int textureY; + + Classes(String name, String id, int textureY) { this.displayName = name; this.classId = id; this.textureY = textureY; } - + public String getDisplayName() { - return this.displayName; + return this.displayName; } - + public String getClassId() { - return this.classId; + return this.classId; } public int getTextureY() { return this.textureY; } - public static Classes findClass(String input){ - if (input.length() == 1){ - try{ + public static Classes findClass(String input) { + if (input.length() == 1) { + try { return Classes.valueOf(input.toUpperCase()); - } catch (IllegalArgumentException ignored){} - } else if (input.length() == 3){ - try{ + } catch (IllegalArgumentException ignored) {} + } else if (input.length() == 3) { + try { return Classes.valueOf(input.replace("[", "").replace("]", "").toUpperCase()); - } catch (IllegalArgumentException ignored){} + } catch (IllegalArgumentException ignored) {} } else { - for(Classes clazz : Classes.values()){ + for (Classes clazz : Classes.values()) { if (clazz.displayName.equalsIgnoreCase(input)) return clazz; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java index 4524c0f..2418b13 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonHandler.java @@ -5,14 +5,14 @@ import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; import com.thatgravyboat.skyblockhud.location.LocationHandler; import com.thatgravyboat.skyblockhud.location.Locations; -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class DungeonHandler { + private static final HashMap<String, DungeonPlayer> dungeonPlayersMap = new HashMap<>(); private static int dungeonTime = 0; private static int dungeonCleared = 0; @@ -27,7 +27,7 @@ public class DungeonHandler { private static final Pattern DungeonPlayerRegex = Pattern.compile("^\\[([HMBAT])] ([\\w]+) ([0-9]+|DEAD)$"); @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { if (LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { DungeonHandler.checkForDungeonTime(event.formattedLine); DungeonHandler.checkForDungeonCleared(event.formattedLine); @@ -37,110 +37,110 @@ public class DungeonHandler { } @SubscribeEvent - public void onSidebarPost(SidebarPostEvent event){ + public void onSidebarPost(SidebarPostEvent event) { if (!LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { DungeonHandler.clearDungeonStats(); } } - public static void checkForDungeonPlayers(String scoreLine, Minecraft mc){ + public static void checkForDungeonPlayers(String scoreLine, Minecraft mc) { Matcher dungeonMatcher = DungeonPlayerRegex.matcher(scoreLine); - if (dungeonMatcher.matches() && DungeonHandler.dungeonTime > 0){ + if (dungeonMatcher.matches() && DungeonHandler.dungeonTime > 0) { Classes playerClass = Classes.valueOf(dungeonMatcher.group(1)); String displayName = dungeonMatcher.group(2); String health = dungeonMatcher.group(3); - if (!mc.thePlayer.getName().toLowerCase().startsWith(displayName.toLowerCase().trim())){ + if (!mc.thePlayer.getName().toLowerCase().startsWith(displayName.toLowerCase().trim())) { int healthNum = 0; - if (!health.equalsIgnoreCase("dead")){ + if (!health.equalsIgnoreCase("dead")) { try { healthNum = Integer.parseInt(health); - } catch (NumberFormatException ignored){} + } catch (NumberFormatException ignored) {} } DungeonPlayer player = new DungeonPlayer(playerClass, displayName, healthNum, health.equalsIgnoreCase("dead")); - dungeonPlayersMap.put(displayName.toLowerCase(),player); + dungeonPlayersMap.put(displayName.toLowerCase(), player); } } } - public static void checkForDungeonTime(String scoreLine){ - if (scoreLine.toLowerCase().trim().contains("time elapsed:")){ + public static void checkForDungeonTime(String scoreLine) { + if (scoreLine.toLowerCase().trim().contains("time elapsed:")) { String timeLine = scoreLine.toLowerCase().trim().replace("time elapsed:", ""); String[] times = timeLine.split("m "); int time = 0; try { time += Integer.parseInt(times[0].replace(" ", "").replace("m", "")) * 60; time += Integer.parseInt(times[1].replace(" ", "").replace("s", "")); - } catch (NumberFormatException ignored){} + } catch (NumberFormatException ignored) {} dungeonTime = time; } } - public static void checkForDungeonCleared(String scoreline){ - if (scoreline.toLowerCase().trim().contains("dungeon cleared:")){ + public static void checkForDungeonCleared(String scoreline) { + if (scoreline.toLowerCase().trim().contains("dungeon cleared:")) { String dungeonClearedText = scoreline.toLowerCase().trim().replace("dungeon cleared:", "").replace(" ", "").replace("%", ""); - try{ + try { dungeonCleared = Integer.parseInt(dungeonClearedText); - }catch (NumberFormatException ignored){ } + } catch (NumberFormatException ignored) {} } } - public static void checkForDungeonKeys(String scoreline, String rawString){ - if (scoreline.toLowerCase().trim().contains("keys:")){ + public static void checkForDungeonKeys(String scoreline, String rawString) { + if (scoreline.toLowerCase().trim().contains("keys:")) { String dungeonClearedText = scoreline.toLowerCase().trim().replace("keys:", "").replace(" ", "").replace("x", ""); bloodKey = rawString.contains("\u2713"); - try{ + try { witherKeys = Integer.parseInt(dungeonClearedText); - }catch (NumberFormatException ignored){} + } catch (NumberFormatException ignored) {} } } - public static void parseSecrets(String statusBar){ + public static void parseSecrets(String statusBar) { boolean hasSecrets = false; String[] parts = statusBar.split(" {4,}"); for (String part : parts) { - if (part.toLowerCase().contains("secrets") && !statusBar.toLowerCase().contains("no secrets")){ + if (part.toLowerCase().contains("secrets") && !statusBar.toLowerCase().contains("no secrets")) { hasSecrets = true; try { String secret = Utils.removeColor(part.replace("Secrets", "")).replace(" ", ""); maxSecrets = Integer.parseInt(secret.split("/")[1]); secrets = Integer.parseInt(secret.split("/")[0]); - }catch (NumberFormatException ignored){ } + } catch (NumberFormatException ignored) {} } } - if (!hasSecrets){ + if (!hasSecrets) { maxSecrets = 0; secrets = 0; } } - public static void parseTotalSecrets(String playerName){ - if (playerName.toLowerCase().contains("secrets found:")){ + public static void parseTotalSecrets(String playerName) { + if (playerName.toLowerCase().contains("secrets found:")) { String totalSecret = Utils.removeColor(playerName.toLowerCase().replace("secrets found:", "")).replace(" ", ""); try { totalSecrets = Integer.parseInt(totalSecret); - }catch (NumberFormatException ignored){} + } catch (NumberFormatException ignored) {} } } - public static void parseDeaths(String playerName){ - if (playerName.toLowerCase().contains("deaths:")){ + public static void parseDeaths(String playerName) { + if (playerName.toLowerCase().contains("deaths:")) { String death = Utils.removeColor(playerName.toLowerCase().replace("deaths:", "")).replace("(", "").replace(")", "").replace(" ", ""); try { deaths = Integer.parseInt(death); - }catch (NumberFormatException ignored){} + } catch (NumberFormatException ignored) {} } } - public static void parseCrypts(String playerName){ - if (playerName.toLowerCase().contains("crypts:")){ + public static void parseCrypts(String playerName) { + if (playerName.toLowerCase().contains("crypts:")) { String crypt = Utils.removeColor(playerName.toLowerCase().replace("crypts:", "")).replace(" ", ""); try { crypts = Integer.parseInt(crypt); - }catch (NumberFormatException ignored){} + } catch (NumberFormatException ignored) {} } } - public static void clearDungeonStats(){ + public static void clearDungeonStats() { dungeonPlayersMap.clear(); dungeonTime = 0; dungeonCleared = 0; @@ -153,15 +153,43 @@ public class DungeonHandler { crypts = 0; } - public static HashMap<String,DungeonPlayer> getDungeonPlayers(){ return dungeonPlayersMap; } + public static HashMap<String, DungeonPlayer> getDungeonPlayers() { + return dungeonPlayersMap; + } + + public static int getDungeonTime() { + return dungeonTime; + } + + public static int getDungeonCleared() { + return dungeonCleared; + } + + public static int getWitherKeys() { + return witherKeys; + } + + public static boolean hasBloodkey() { + return bloodKey; + } - public static int getDungeonTime() { return dungeonTime; } - public static int getDungeonCleared() { return dungeonCleared; } - public static int getWitherKeys() { return witherKeys; } - public static boolean hasBloodkey() { return bloodKey; } - public static int getMaxSecrets() { return maxSecrets; } - public static int getSecrets() { return secrets; } - public static int getDeaths() { return deaths; } - public static int getTotalSecrets() { return totalSecrets; } - public static int getCrypts() { return crypts; } + public static int getMaxSecrets() { + return maxSecrets; + } + + public static int getSecrets() { + return secrets; + } + + public static int getDeaths() { + return deaths; + } + + public static int getTotalSecrets() { + return totalSecrets; + } + + public static int getCrypts() { + return crypts; + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java index e34424d..b0816fb 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/dungeons/DungeonPlayer.java @@ -1,31 +1,32 @@ package com.thatgravyboat.skyblockhud.dungeons; public class DungeonPlayer { - private final Classes dungeonClass; - private final String name; - private final int health; - private final boolean dead; - - public DungeonPlayer(Classes playersClass, String playersName, int playersHealth, boolean isDead) { - this.dungeonClass = playersClass; - this.name = playersName; - this.health = isDead ? 0 : playersHealth; - this.dead = isDead; - } - - public Classes getDungeonClass() { - return this.dungeonClass; - } - - public String getName() { - return this.name; - } - - public int getHealth() { - return this.dead ? 0 : this.health; - } - - public boolean isDead() { - return this.dead; - } + + private final Classes dungeonClass; + private final String name; + private final int health; + private final boolean dead; + + public DungeonPlayer(Classes playersClass, String playersName, int playersHealth, boolean isDead) { + this.dungeonClass = playersClass; + this.name = playersName; + this.health = isDead ? 0 : playersHealth; + this.dead = isDead; + } + + public Classes getDungeonClass() { + return this.dungeonClass; + } + + public String getName() { + return this.name; + } + + public int getHealth() { + return this.dead ? 0 : this.health; + } + + public boolean isDead() { + return this.dead; + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/BossbarHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/BossbarHandler.java index 38fa874..b2a148d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/BossbarHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/BossbarHandler.java @@ -18,16 +18,16 @@ public class BossbarHandler { public void onBossbarRender(RenderGameOverlayEvent.Pre event) { if (event.type == RenderGameOverlayEvent.ElementType.BOSSHEALTH && BossStatus.bossName != null) { bossBarRendered = !event.isCanceled(); - if (!SkyblockHud.config.main.bossShiftHud){ + if (!SkyblockHud.config.main.bossShiftHud) { bossBarRendered = false; } String bossName = Utils.removeColor(BossStatus.bossName); - if (SkyblockHud.config.renderer.hideBossBar && DwarvenMineHandler.currentEvent == DwarvenMineHandler.Event.NONE && !LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)){ - if (bossName.equalsIgnoreCase("wither")){ + if (SkyblockHud.config.renderer.hideBossBar && DwarvenMineHandler.currentEvent == DwarvenMineHandler.Event.NONE && !LocationHandler.getCurrentLocation().equals(Locations.CATACOMBS)) { + if (bossName.equalsIgnoreCase("wither")) { event.setCanceled(true); bossBarRendered = false; } - if (bossName.toLowerCase().startsWith("objective:")){ + if (bossName.toLowerCase().startsWith("objective:")) { event.setCanceled(true); bossBarRendered = false; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/CurrencyHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/CurrencyHandler.java index 12b04d8..7da9c9d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/CurrencyHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/CurrencyHandler.java @@ -3,27 +3,37 @@ package com.thatgravyboat.skyblockhud.handlers; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.math.RoundingMode; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Arrays; import java.util.Locale; import java.util.regex.Pattern; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class CurrencyHandler { private static int bits = 0; private static double coins = 0; - public static void setBits(int amount){ bits = amount; } - public static void setCoins(double amount){ coins = amount; } - public static int getBits(){ return bits; } - public static double getCoins(){ return coins; } + public static void setBits(int amount) { + bits = amount; + } + + public static void setCoins(double amount) { + coins = amount; + } + + public static int getBits() { + return bits; + } + + public static double getCoins() { + return coins; + } @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { if (Utils.removeColor(event.formattedLine.toLowerCase().trim()).contains("purse:") || Utils.removeColor(event.formattedLine.toLowerCase().trim()).contains("piggy:")) { CurrencyHandler.checkCoins(event.formattedLine); } @@ -33,32 +43,27 @@ public class CurrencyHandler { } @SubscribeEvent - public void onSidebarPost(SidebarPostEvent event){ - if (!Arrays.toString(event.arrayScores).toLowerCase().contains("bits:")){ + public void onSidebarPost(SidebarPostEvent event) { + if (!Arrays.toString(event.arrayScores).toLowerCase().contains("bits:")) { CurrencyHandler.setBits(0); } } - public static String getCoinsFormatted(){ - + public static String getCoinsFormatted() { DecimalFormat formatter = new DecimalFormat("#,###.0", DecimalFormatSymbols.getInstance(Locale.CANADA)); String output = formatter.format(coins); - if (output.equals(".0")) output = "0.0"; - else if (output.equals(",0")) output = "0,0"; + if (output.equals(".0")) output = "0.0"; else if (output.equals(",0")) output = "0,0"; return output; } - public static String getBitsFormatted(){ + public static String getBitsFormatted() { DecimalFormat formatter = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); formatter.setRoundingMode(RoundingMode.FLOOR); - return bits > 999 ? formatter.format((double)bits / 1000)+ "k" : String.valueOf(bits); + return bits > 999 ? formatter.format((double) bits / 1000) + "k" : String.valueOf(bits); } - public static void checkCoins(String formatedScoreboardLine){ - String purse = Utils.removeWhiteSpaceAndRemoveWord( - Utils.removeColor(formatedScoreboardLine.toLowerCase().trim()), - Utils.removeColor(formatedScoreboardLine.toLowerCase().trim()).contains("purse:") ? "purse:" : "piggy:" - ).replace(",", ""); + public static void checkCoins(String formatedScoreboardLine) { + String purse = Utils.removeWhiteSpaceAndRemoveWord(Utils.removeColor(formatedScoreboardLine.toLowerCase().trim()), Utils.removeColor(formatedScoreboardLine.toLowerCase().trim()).contains("purse:") ? "purse:" : "piggy:").replace(",", ""); if (!purse.contains("(") && !purse.contains("+")) { try { double coins = Double.parseDouble(Pattern.compile("[^0-9.]").matcher(purse).replaceAll("")); @@ -69,7 +74,7 @@ public class CurrencyHandler { } } - public static void checkBits(String formatedScoreboardLine){ + public static void checkBits(String formatedScoreboardLine) { String bits = Utils.removeWhiteSpaceAndRemoveWord(Utils.removeColor(formatedScoreboardLine.toLowerCase().trim()), "bits:").replace(",", ""); try { int bit = Integer.parseInt(Pattern.compile("[^0-9]").matcher(bits).replaceAll("")); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java index 1a401f2..da27590 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/HeldItemHandler.java @@ -12,23 +12,23 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class HeldItemHandler extends Gui { - public void drawFuelBar(Minecraft mc, int current, int max){ - GenericOverlays.drawSmallBar(mc, 100,100,(double)current/(double)max,1.0d,0xff00ff,0xffff00, 0); - drawString(mc.fontRendererObj, "Fuel - " + Math.round(((double)current/(double)max)*100) + "%", 100, 100, 0xffffff); + public void drawFuelBar(Minecraft mc, int current, int max) { + GenericOverlays.drawSmallBar(mc, 100, 100, (double) current / (double) max, 1.0d, 0xff00ff, 0xffff00, 0); + drawString(mc.fontRendererObj, "Fuel - " + Math.round(((double) current / (double) max) * 100) + "%", 100, 100, 0xffffff); } - public boolean isDrill(ItemStack stack){ + public boolean isDrill(ItemStack stack) { if (stack == null) return false; if (!stack.getTagCompound().hasKey("ExtraAttributes")) return false; return stack.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("drill_fuel"); } - public String getDrillFuel(ItemStack stack){ + public String getDrillFuel(ItemStack stack) { NBTTagCompound display = stack.getTagCompound().getCompoundTag("display"); NBTTagList lore = display.getTagList("Lore", 8); for (int i = lore.tagCount() - 1; i >= 0; i--) { String line = Utils.removeColor(lore.getStringTagAt(i)); - if (line.trim().startsWith("Fuel:")){ + if (line.trim().startsWith("Fuel:")) { return line; } } @@ -36,7 +36,7 @@ public class HeldItemHandler extends Gui { } @SubscribeEvent - public void drawOverlay(RenderGameOverlayEvent.Post event){ + public void drawOverlay(RenderGameOverlayEvent.Post event) { /* if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard())){ Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/MapHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/MapHandler.java index eaed920..b7b232f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/MapHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/MapHandler.java @@ -1,5 +1,7 @@ package com.thatgravyboat.skyblockhud.handlers; +import static com.thatgravyboat.skyblockhud.GuiTextures.mapOverlay; + import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.config.KeyBindings; @@ -8,6 +10,10 @@ import com.thatgravyboat.skyblockhud.core.config.Position; import com.thatgravyboat.skyblockhud.handlers.mapicons.DwarvenIcons; import com.thatgravyboat.skyblockhud.handlers.mapicons.HubIcons; import com.thatgravyboat.skyblockhud.location.LocationHandler; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import javax.vecmath.Vector2f; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; @@ -20,16 +26,9 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import org.lwjgl.opengl.GL11; -import javax.vecmath.Vector2f; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static com.thatgravyboat.skyblockhud.GuiTextures.mapOverlay; - public class MapHandler { - public enum MapIconTypes { + public enum MapIconTypes { SHOPS, MISC, NPC, @@ -38,17 +37,18 @@ public class MapHandler { } public static class MapIcon { + public Vector2f position; public ResourceLocation icon; public String tooltip; public String command; public MapIconTypes type; - public MapIcon(Vector2f pos, ResourceLocation icon, String tooltip, MapIconTypes type){ - this(pos,icon,tooltip,type,""); + public MapIcon(Vector2f pos, ResourceLocation icon, String tooltip, MapIconTypes type) { + this(pos, icon, tooltip, type, ""); } - public MapIcon(Vector2f pos, ResourceLocation icon, String tooltip, MapIconTypes type, String command){ + public MapIcon(Vector2f pos, ResourceLocation icon, String tooltip, MapIconTypes type, String command) { this.position = pos; this.icon = icon; this.tooltip = tooltip; @@ -56,24 +56,20 @@ public class MapHandler { this.command = command; } - public boolean canRender(){ + public boolean canRender() { SBHConfig.Map mapConfig = SkyblockHud.config.map; - if (mapConfig.showInfoIcons && type.equals(MapIconTypes.INFO)) return true; - else if (mapConfig.showMiscIcons && type.equals(MapIconTypes.MISC)) return true; - else if (mapConfig.showNpcIcons && type.equals(MapIconTypes.NPC)) return true; - else if (mapConfig.showQuestIcons && type.equals(MapIconTypes.QUEST)) return true; - else return mapConfig.showShopIcons && type.equals(MapIconTypes.SHOPS); + if (mapConfig.showInfoIcons && type.equals(MapIconTypes.INFO)) return true; else if (mapConfig.showMiscIcons && type.equals(MapIconTypes.MISC)) return true; else if (mapConfig.showNpcIcons && type.equals(MapIconTypes.NPC)) return true; else if (mapConfig.showQuestIcons && type.equals(MapIconTypes.QUEST)) return true; else return (mapConfig.showShopIcons && type.equals(MapIconTypes.SHOPS)); } } public enum Maps { - HUB(0.5f,494,444,294,218, 294,224, new ResourceLocation("skyblockhud", "maps/hub.png"), HubIcons.hubIcons), - MUSHROOM(1.0f,318,316,-84,605, -84,612, new ResourceLocation("skyblockhud", "maps/mushroom.png"), Collections.emptyList()), - SPIDERS(1.0f,270,238,400,362, 400,364, new ResourceLocation("skyblockhud", "maps/spidersden.png"), Collections.emptyList()), - NETHER(0.5f,257,371,436,732, 433,736, new ResourceLocation("skyblockhud", "maps/fort.png"), Collections.emptyList()), - BARN(1.5f,135,130,-82,320, -81,318, new ResourceLocation("skyblockhud", "maps/barn.png"), Collections.emptyList()), + HUB(0.5f, 494, 444, 294, 218, 294, 224, new ResourceLocation("skyblockhud", "maps/hub.png"), HubIcons.hubIcons), + MUSHROOM(1.0f, 318, 316, -84, 605, -84, 612, new ResourceLocation("skyblockhud", "maps/mushroom.png"), Collections.emptyList()), + SPIDERS(1.0f, 270, 238, 400, 362, 400, 364, new ResourceLocation("skyblockhud", "maps/spidersden.png"), Collections.emptyList()), + NETHER(0.5f, 257, 371, 436, 732, 433, 736, new ResourceLocation("skyblockhud", "maps/fort.png"), Collections.emptyList()), + BARN(1.5f, 135, 130, -82, 320, -81, 318, new ResourceLocation("skyblockhud", "maps/barn.png"), Collections.emptyList()), DWARVEN(0.5f, 409, 461, 206, 160, 202, 166, new ResourceLocation("skyblockhud", "maps/dwarven.png"), DwarvenIcons.dwarvenIcons), - PARK(1.0f,211, 230, 480, 133, 478,134, new ResourceLocation("skyblockhud", "maps/park.png"), Collections.emptyList()); + PARK(1.0f, 211, 230, 480, 133, 478, 134, new ResourceLocation("skyblockhud", "maps/park.png"), Collections.emptyList()); public float scaleFactor; public int width; @@ -85,8 +81,7 @@ public class MapHandler { public ResourceLocation mapTexture; public List<MapIcon> icons; - - Maps(float scaleFactor, int width, int height, int xMiniOffset, int yMiniOffset, int xOffset, int yOffset, ResourceLocation mapTexture, List<MapIcon> icons){ + Maps(float scaleFactor, int width, int height, int xMiniOffset, int yMiniOffset, int xOffset, int yOffset, ResourceLocation mapTexture, List<MapIcon> icons) { this.scaleFactor = scaleFactor; this.width = width; this.height = height; @@ -105,12 +100,12 @@ public class MapHandler { Minecraft mc = Minecraft.getMinecraft(); if (mc.currentScreen instanceof MapScreen) return; if (LocationHandler.getCurrentLocation().getCategory().getMap() == null) return; - if (mc.thePlayer != null){ + if (mc.thePlayer != null) { MapHandler.Maps map = LocationHandler.getCurrentLocation().getCategory().getMap(); mc.renderEngine.bindTexture(mapOverlay); - GlStateManager.color(1.0f,1.0f, 1.0f,1.0f); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); Position pos = SkyblockHud.config.map.miniMapPosition; - Gui.drawModalRectWithCustomSizedTexture(pos.getAbsX(event.resolution, 72),pos.getAbsY(event.resolution, 72),72,0,72,72,256,256); + Gui.drawModalRectWithCustomSizedTexture(pos.getAbsX(event.resolution, 72), pos.getAbsY(event.resolution, 72), 72, 0, 72, 72, 256, 256); mc.renderEngine.bindTexture(map.mapTexture); int x = mc.thePlayer.getPosition().getX() + map.xMiniOffset; @@ -118,63 +113,56 @@ public class MapHandler { float u = (x / (map.width / 256f)) - 33f; float v = (z / (map.height / 256f)) - 28f; - GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP); - Gui.drawModalRectWithCustomSizedTexture(pos.getAbsX(event.resolution, 72) + 4, - pos.getAbsY(event.resolution, 72) + 2, - u, - v, - 64,64, - 256,256); + Gui.drawModalRectWithCustomSizedTexture(pos.getAbsX(event.resolution, 72) + 4, pos.getAbsY(event.resolution, 72) + 2, u, v, 64, 64, 256, 256); if (SkyblockHud.config.map.showPlayerLocation) { - mc.fontRendererObj.drawString("\u2022", pos.getAbsX(event.resolution, 72) + 36,pos.getAbsY(event.resolution, 72) + 34, 0xff0000, false); + mc.fontRendererObj.drawString("\u2022", pos.getAbsX(event.resolution, 72) + 36, pos.getAbsY(event.resolution, 72) + 34, 0xff0000, false); } - GlStateManager.color(1.0f,1.0f, 1.0f,1.0f); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); mc.renderEngine.bindTexture(mapOverlay); - Gui.drawModalRectWithCustomSizedTexture(pos.getAbsX(event.resolution, 72),pos.getAbsY(event.resolution, 72),0,0,72,72,256,256); + Gui.drawModalRectWithCustomSizedTexture(pos.getAbsX(event.resolution, 72), pos.getAbsY(event.resolution, 72), 0, 0, 72, 72, 256, 256); String keyCode = GameSettings.getKeyDisplayString(KeyBindings.map.getKeyCode()); - Utils.drawStringCenteredScaled(keyCode, mc.fontRendererObj, pos.getAbsX(event.resolution, 64) + 58,pos.getAbsY(event.resolution, 72) + 66, false, 6,0xFFFFFF); + Utils.drawStringCenteredScaled(keyCode, mc.fontRendererObj, pos.getAbsX(event.resolution, 64) + 58, pos.getAbsY(event.resolution, 72) + 66, false, 6, 0xFFFFFF); BlockPos playerPos = mc.thePlayer.getPosition(); String position = String.format("%d/%d/%d", playerPos.getX(), playerPos.getY(), playerPos.getZ()); - Utils.drawStringCenteredScaled(position, mc.fontRendererObj, pos.getAbsX(event.resolution, 64) + 29,pos.getAbsY(event.resolution, 72) + 66, false, 36,0xFFFFFF); - GlStateManager.color(1.0f,1.0f, 1.0f,1.0f); + Utils.drawStringCenteredScaled(position, mc.fontRendererObj, pos.getAbsX(event.resolution, 64) + 29, pos.getAbsY(event.resolution, 72) + 66, false, 36, 0xFFFFFF); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); } } } @SubscribeEvent - public void clientTick(TickEvent.ClientTickEvent event){ - if (KeyBindings.map.isPressed() && LocationHandler.getCurrentLocation().getCategory().getMap() != null && SkyblockHud.hasSkyblockScoreboard()) - SkyblockHud.screenToOpen = new MapScreen(); + public void clientTick(TickEvent.ClientTickEvent event) { + if (KeyBindings.map.isPressed() && LocationHandler.getCurrentLocation().getCategory().getMap() != null && SkyblockHud.hasSkyblockScoreboard()) SkyblockHud.screenToOpen = new MapScreen(); } - public static class MapScreen extends GuiScreen { public MapHandler.Maps map = LocationHandler.getCurrentLocation().getCategory().getMap(); @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { - GlStateManager.color(1.0f, 1.0f, 1.0f,1.0f); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); this.drawWorldBackground(0); this.mc.renderEngine.bindTexture(map.mapTexture); - float mapX = (width / 2f)-((map.width / 2f) * map.scaleFactor); - float mapY = (height / 2f)-((map.height / 2f) * map.scaleFactor); - Gui.drawModalRectWithCustomSizedTexture((int)mapX, (int)mapY, 0,0,(int)(map.width * map.scaleFactor),(int)(map.height * map.scaleFactor), (int)(map.width * map.scaleFactor), (int)(map.height * map.scaleFactor)); - drawIcons((int)mapX, (int)mapY); - if (this.mc.thePlayer != null && SkyblockHud.config.map.showPlayerLocation){ + float mapX = (width / 2f) - ((map.width / 2f) * map.scaleFactor); + float mapY = (height / 2f) - ((map.height / 2f) * map.scaleFactor); + Gui.drawModalRectWithCustomSizedTexture((int) mapX, (int) mapY, 0, 0, (int) (map.width * map.scaleFactor), (int) (map.height * map.scaleFactor), (int) (map.width * map.scaleFactor), (int) (map.height * map.scaleFactor)); + drawIcons((int) mapX, (int) mapY); + if (this.mc.thePlayer != null && SkyblockHud.config.map.showPlayerLocation) { int x = this.mc.thePlayer.getPosition().getX() + map.xOffset; int z = this.mc.thePlayer.getPosition().getZ() + map.yOffset; - fontRendererObj.drawString("\u2022", (int)(x * map.scaleFactor + mapX), (int)(z * map.scaleFactor + mapY), 0xff0000); + fontRendererObj.drawString("\u2022", (int) (x * map.scaleFactor + mapX), (int) (z * map.scaleFactor + mapY), 0xff0000); } GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); - onTooltip(mouseX, mouseY, (int)mapX, (int)mapY); + onTooltip(mouseX, mouseY, (int) mapX, (int) mapY); } - public void drawIcons(int startX, int startY){ + public void drawIcons(int startX, int startY) { if (map.icons == null) return; for (MapIcon icon : map.icons) { if (!icon.canRender()) continue; @@ -183,17 +171,16 @@ public class MapHandler { this.mc.renderEngine.bindTexture(icon.icon); float x = ((icon.position.x + map.xOffset) * map.scaleFactor) + startX - 4; float y = ((icon.position.y + map.yOffset) * map.scaleFactor) + startY - 4; - Gui.drawModalRectWithCustomSizedTexture((int)x, (int)y, 0,0,8,8, 8, 8); - GlStateManager.color(1.0f,1.0f,1.0f,1.0f); + Gui.drawModalRectWithCustomSizedTexture((int) x, (int) y, 0, 0, 8, 8, 8, 8); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); } } - public void onTooltip(int mouseX, int mouseY, int startX, int startY){ + public void onTooltip(int mouseX, int mouseY, int startX, int startY) { if (map.icons == null) return; for (MapIcon icon : map.icons) { if (!icon.canRender()) continue; - if (Utils.inRangeInclusive(mouseX, (int)((icon.position.x + map.xOffset) * map.scaleFactor) + startX - 4, (int)((icon.position.x + map.xOffset) * map.scaleFactor) + startX + 4) && - Utils.inRangeInclusive(mouseY, (int)((icon.position.y + map.yOffset) * map.scaleFactor) + startY - 4, (int)((icon.position.y + map.yOffset) * map.scaleFactor) + startY + 4)){ + if (Utils.inRangeInclusive(mouseX, (int) ((icon.position.x + map.xOffset) * map.scaleFactor) + startX - 4, (int) ((icon.position.x + map.xOffset) * map.scaleFactor) + startX + 4) && Utils.inRangeInclusive(mouseY, (int) ((icon.position.y + map.yOffset) * map.scaleFactor) + startY - 4, (int) ((icon.position.y + map.yOffset) * map.scaleFactor) + startY + 4)) { drawHoveringText(Arrays.asList(icon.tooltip.split("\n")), mouseX, mouseY); break; } @@ -202,14 +189,13 @@ public class MapHandler { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { - int mapX = (int)((width / 2f)-((map.width / 2f) * map.scaleFactor)); - int mapY = (int)((height / 2f)-((map.height / 2f) * map.scaleFactor)); + int mapX = (int) ((width / 2f) - ((map.width / 2f) * map.scaleFactor)); + int mapY = (int) ((height / 2f) - ((map.height / 2f) * map.scaleFactor)); for (MapIcon icon : map.icons) { if (!icon.canRender()) continue; - if (Utils.inRangeInclusive(mouseX, (int)((icon.position.x + map.xOffset) * map.scaleFactor) + mapX - 4, (int)((icon.position.x + map.xOffset) * map.scaleFactor) + mapX + 4) && - Utils.inRangeInclusive(mouseY, (int)((icon.position.y + map.yOffset) * map.scaleFactor) + mapY - 4, (int)((icon.position.y + map.yOffset) * map.scaleFactor) + mapY + 4)){ - if (!icon.command.isEmpty()){ - this.mc.thePlayer.sendChatMessage("/"+icon.command); + if (Utils.inRangeInclusive(mouseX, (int) ((icon.position.x + map.xOffset) * map.scaleFactor) + mapX - 4, (int) ((icon.position.x + map.xOffset) * map.scaleFactor) + mapX + 4) && Utils.inRangeInclusive(mouseY, (int) ((icon.position.y + map.yOffset) * map.scaleFactor) + mapY - 4, (int) ((icon.position.y + map.yOffset) * map.scaleFactor) + mapY + 4)) { + if (!icon.command.isEmpty()) { + this.mc.thePlayer.sendChatMessage("/" + icon.command); } break; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java index b34a156..fbb95eb 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/SlayerHandler.java @@ -3,37 +3,40 @@ package com.thatgravyboat.skyblockhud.handlers; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.util.Arrays; import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class SlayerHandler { + //Optional Characters are required because Hypixel dumb and cuts off text private static final Pattern COMBAT_XP_REGEX = Pattern.compile("\\(([\\d,]+)/([\\dkm]+)\\) comb?a?t? x?p?"); private static final Pattern KILLS_REGEX = Pattern.compile("(\\d+)/(\\d+) kills?"); public enum slayerTypes { - ZOMBIE(34, "Revenant Horror"), WOLF(42, "Sven Packmaster"), SPIDER(50, "Tarantula Broodfather"), VOIDGLOOMSERAPH(50, "Voidgloom Seraph"), - NONE(0,""); + NONE(0, ""); private final String displayName; private final int x; - slayerTypes(int x, String displayName){ + slayerTypes(int x, String displayName) { this.displayName = displayName; this.x = x; } - public String getDisplayName() { return displayName; } + public String getDisplayName() { + return displayName; + } - public int getX() { return x; } + public int getX() { + return x; + } } public static slayerTypes currentSlayer = slayerTypes.NONE; @@ -43,7 +46,8 @@ public class SlayerHandler { public static int maxKills = 0; public static boolean bossSlain = false; public static boolean isKillingBoss = false; - public static void clearSlayer(){ + + public static void clearSlayer() { currentSlayer = slayerTypes.NONE; isDoingSlayer = false; progress = 0; @@ -53,16 +57,16 @@ public class SlayerHandler { } @SubscribeEvent - public void onSidebarPost(SidebarPostEvent event){ + public void onSidebarPost(SidebarPostEvent event) { String arrayString = Arrays.toString(event.arrayScores); isDoingSlayer = Arrays.toString(event.arrayScores).contains("Slayer Quest"); - if (isDoingSlayer && (currentSlayer.equals(slayerTypes.NONE) || !arrayString.replace(" ", "").contains(currentSlayer.getDisplayName().replace(" ", "")+Utils.intToRomanNumeral(slayerTier)))) { + if (isDoingSlayer && (currentSlayer.equals(slayerTypes.NONE) || !arrayString.replace(" ", "").contains(currentSlayer.getDisplayName().replace(" ", "") + Utils.intToRomanNumeral(slayerTier)))) { for (int i = 0; i < event.scores.size(); i++) { String line = event.scores.get(i); - if (line.contains("Slayer Quest") && event.scores.size() > 3){ + if (line.contains("Slayer Quest") && event.scores.size() > 3) { String slayer = event.scores.get(i - 1).toLowerCase(); SlayerHandler.slayerTypes selectedSlayer = SlayerHandler.slayerTypes.NONE; - for (slayerTypes types : slayerTypes.values()){ + for (slayerTypes types : slayerTypes.values()) { if (slayer.contains(types.displayName.toLowerCase(Locale.ENGLISH))) { selectedSlayer = types; break; @@ -81,53 +85,47 @@ public class SlayerHandler { } @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { if (!isDoingSlayer && event.formattedLine.equals("Slayer Quest")) isDoingSlayer = true; - if (isDoingSlayer){ + if (isDoingSlayer) { String line = event.formattedLine.toLowerCase(); Matcher killMatcher = KILLS_REGEX.matcher(line); Matcher xpMatcher = COMBAT_XP_REGEX.matcher(line); - if (killMatcher.find()){ + if (killMatcher.find()) { SlayerHandler.bossSlain = false; SlayerHandler.isKillingBoss = false; try { progress = Integer.parseInt(killMatcher.group(1)); - } catch (Exception ignored){} + } catch (Exception ignored) {} try { maxKills = Integer.parseInt(killMatcher.group(2)); - } catch (Exception ignored){} - }else if (xpMatcher.find()){ + } catch (Exception ignored) {} + } else if (xpMatcher.find()) { SlayerHandler.bossSlain = false; SlayerHandler.isKillingBoss = false; try { progress = Integer.parseInt(xpMatcher.group(1)); - } catch (Exception ignored){} + } catch (Exception ignored) {} try { maxKills = Integer.parseInt(xpMatcher.group(2).replace("k", "")) * (xpMatcher.group(2).contains("k") ? 1000 : xpMatcher.group(2).contains("m") ? 1000000 : 1); - } catch (Exception ignored){} - } else if(line.contains("slay the boss")) { + } catch (Exception ignored) {} + } else if (line.contains("slay the boss")) { SlayerHandler.bossSlain = false; SlayerHandler.isKillingBoss = true; SlayerHandler.maxKills = 0; SlayerHandler.progress = 0; - }else if (line.contains("boss slain")){ + } else if (line.contains("boss slain")) { SlayerHandler.isKillingBoss = false; SlayerHandler.maxKills = 0; SlayerHandler.progress = 0; SlayerHandler.bossSlain = true; } - if (maxKills == 0 && progress == 0){ + if (maxKills == 0 && progress == 0) { SlayerHandler.maxKills = 0; SlayerHandler.progress = 0; } } } - - - - - - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/TimeHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/TimeHandler.java index 06edf6b..f1aa222 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/TimeHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/TimeHandler.java @@ -1,20 +1,19 @@ package com.thatgravyboat.skyblockhud.handlers; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.apache.logging.log4j.LogManager; - import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Locale; import java.util.regex.Pattern; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.apache.logging.log4j.LogManager; public class TimeHandler { public static long time; @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { if (Pattern.matches("([0-9]*):([0-9]*)(pm|am)", event.formattedLine.toLowerCase().trim())) { boolean isPm = event.formattedLine.toLowerCase().trim().endsWith("pm"); SimpleDateFormat parseFormat = new SimpleDateFormat("hh:mm a", Locale.CANADA); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/DwarvenIcons.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/DwarvenIcons.java index 5cd58bc..e599508 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/DwarvenIcons.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/DwarvenIcons.java @@ -2,11 +2,10 @@ package com.thatgravyboat.skyblockhud.handlers.mapicons; import com.thatgravyboat.skyblockhud.ComponentBuilder; import com.thatgravyboat.skyblockhud.handlers.MapHandler; -import net.minecraft.util.ResourceLocation; - -import javax.vecmath.Vector2f; import java.util.ArrayList; import java.util.List; +import javax.vecmath.Vector2f; +import net.minecraft.util.ResourceLocation; public class DwarvenIcons { @@ -20,77 +19,21 @@ public class DwarvenIcons { setupQuestIcons(); } - private static void setupNpcIcons(){ - dwarvenIcons.add(new MapHandler.MapIcon( - new Vector2f(129, 187), - new ResourceLocation("skyblockhud", "maps/icons/puzzle.png"), - new ComponentBuilder() - .nl("Puzzler", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Puzzler gives you a small puzzle each day to solve and") - .nl("gives you 1000 mithril powder.") - .build(), - MapHandler.MapIconTypes.NPC - ) - ); + private static void setupNpcIcons() { + dwarvenIcons.add(new MapHandler.MapIcon(new Vector2f(129, 187), new ResourceLocation("skyblockhud", "maps/icons/puzzle.png"), new ComponentBuilder().nl("Puzzler", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Puzzler gives you a small puzzle each day to solve and").nl("gives you 1000 mithril powder.").build(), MapHandler.MapIconTypes.NPC)); } - private static void setupMiscIcons(){} + private static void setupMiscIcons() {} - private static void setupInfoIcons(){ - dwarvenIcons.add(new MapHandler.MapIcon( - new Vector2f(129, 187), - new ResourceLocation("skyblockhud", "maps/icons/crown.png"), - new ComponentBuilder() - .nl("King", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The King allows you to first start commissions and if you click") - .nl("each king which change every skyblock day you will get") - .nl("the King Talisman.") - .nl() - .apd("Click to open HOTM", new char[]{'6', 'l'}) - .build(), - MapHandler.MapIconTypes.INFO, - "hotm" - ) - ); + private static void setupInfoIcons() { + dwarvenIcons.add(new MapHandler.MapIcon(new Vector2f(129, 187), new ResourceLocation("skyblockhud", "maps/icons/crown.png"), new ComponentBuilder().nl("King", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The King allows you to first start commissions and if you click").nl("each king which change every skyblock day you will get").nl("the King Talisman.").nl().apd("Click to open HOTM", new char[] { '6', 'l' }).build(), MapHandler.MapIconTypes.INFO, "hotm")); } - private static void setupShopIcons(){ - dwarvenIcons.add(new MapHandler.MapIcon( - new Vector2f(4, 8), - new ResourceLocation("skyblockhud", "maps/icons/blacksmith.png"), - new ComponentBuilder() - .nl("Forge", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Forge is where you can go craft special items") - .nl("and fuel your drill.") - .nl("NPCS", new char[]{'c','l'}) - .nl(" Forger - Allows you to forge special items") - .nl(" Jotraeline Greatforge - Allows you to refuel your drill.") - .nl() - .apd("Click to warp", new char[]{'6', 'l'}) - .build(), - MapHandler.MapIconTypes.SHOPS, - "warpforge" - ) - ); + private static void setupShopIcons() { + dwarvenIcons.add(new MapHandler.MapIcon(new Vector2f(4, 8), new ResourceLocation("skyblockhud", "maps/icons/blacksmith.png"), new ComponentBuilder().nl("Forge", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Forge is where you can go craft special items").nl("and fuel your drill.").nl("NPCS", new char[] { 'c', 'l' }).nl(" Forger - Allows you to forge special items").nl(" Jotraeline Greatforge - Allows you to refuel your drill.").nl().apd("Click to warp", new char[] { '6', 'l' }).build(), MapHandler.MapIconTypes.SHOPS, "warpforge")); } - private static void setupQuestIcons(){ - dwarvenIcons.add(new MapHandler.MapIcon( - new Vector2f(67, 204), - new ResourceLocation("skyblockhud", "maps/icons/special.png"), - new ComponentBuilder() - .nl("Royal Resident", new char[]{'a','l'}) - .nl("The Royal Resident is a quest where you right") - .nl("click them for a bit to obtain and if you continue") - .nl("to right click them for about 7 hours it will give") - .apd("the achievement Royal Conversation.") - .build(), - MapHandler.MapIconTypes.QUEST - ) - ); + private static void setupQuestIcons() { + dwarvenIcons.add(new MapHandler.MapIcon(new Vector2f(67, 204), new ResourceLocation("skyblockhud", "maps/icons/special.png"), new ComponentBuilder().nl("Royal Resident", new char[] { 'a', 'l' }).nl("The Royal Resident is a quest where you right").nl("click them for a bit to obtain and if you continue").nl("to right click them for about 7 hours it will give").apd("the achievement Royal Conversation.").build(), MapHandler.MapIconTypes.QUEST)); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/HubIcons.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/HubIcons.java index ad1dbc3..443afb7 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/HubIcons.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/mapicons/HubIcons.java @@ -2,11 +2,10 @@ package com.thatgravyboat.skyblockhud.handlers.mapicons; import com.thatgravyboat.skyblockhud.ComponentBuilder; import com.thatgravyboat.skyblockhud.handlers.MapHandler; -import net.minecraft.util.ResourceLocation; - -import javax.vecmath.Vector2f; import java.util.ArrayList; import java.util.List; +import javax.vecmath.Vector2f; +import net.minecraft.util.ResourceLocation; public class HubIcons { @@ -21,288 +20,36 @@ public class HubIcons { } private static void setupNpcIcons() { - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-2, -34), - new ResourceLocation("skyblockhud", "maps/icons/special.png"), - new ComponentBuilder() - .nl("Event Hut", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Event Hut is where special event npcs") - .nl("are during some events.") - .nl("NPCS", new char[]{'c','l'}) - .nl(" Baker - During New Years") - .nl(" Jerry - While Winter Island is opened") - .nl(" Fear Mongerer - During Spooky Festival") - .apd(" Oringo - During Traveling Zoo") - .build(), - MapHandler.MapIconTypes.NPC - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(135, 142), - new ResourceLocation("skyblockhud", "maps/icons/fairy.png"), - new ComponentBuilder() - .nl("Fairy", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Fairy is where you go when you find fairy souls") - .apd("to trade them in to get permanent stat upgrades.") - .build(), - MapHandler.MapIconTypes.NPC - ) - ); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-2, -34), new ResourceLocation("skyblockhud", "maps/icons/special.png"), new ComponentBuilder().nl("Event Hut", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Event Hut is where special event npcs").nl("are during some events.").nl("NPCS", new char[] { 'c', 'l' }).nl(" Baker - During New Years").nl(" Jerry - While Winter Island is opened").nl(" Fear Mongerer - During Spooky Festival").apd(" Oringo - During Traveling Zoo").build(), MapHandler.MapIconTypes.NPC)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(135, 142), new ResourceLocation("skyblockhud", "maps/icons/fairy.png"), new ComponentBuilder().nl("Fairy", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Fairy is where you go when you find fairy souls").apd("to trade them in to get permanent stat upgrades.").build(), MapHandler.MapIconTypes.NPC)); } private static void setupShopIcons() { - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-50, -22), - new ResourceLocation("skyblockhud", "maps/icons/building.png"), - new ComponentBuilder() - .nl("Builder's House", new char[]{'a','l'}) - .nl("NPCS", new char[]{'c','l'}) - .nl(" Wool Weaver") - .nl(" Builder") - .apd(" Mad Redstone Engineer") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-78, -46), - new ResourceLocation("skyblockhud", "maps/icons/bar.png"), - new ComponentBuilder() - .nl("Tavern", new char[]{'a','l'}) - .nl("NPCS", new char[]{'c','l'}) - .nl(" Bartender") - .nl(" Maddox the slayer") - .nl("Description", 'l') - .nl("The Tavern is where maddox the slayer is located you can") - .nl("start slayer quests with them to unlock") - .apd("new items the more slayer bosses you kill.") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(36, -82), - new ResourceLocation("skyblockhud", "maps/icons/vet.png"), - new ComponentBuilder() - .nl("Vet", new char[]{'a','l'}) - .nl("NPCS", new char[]{'c','l'}) - .nl(" Bea") - .nl(" Zog") - .nl(" Kat") - .nl(" George") - .nl("Description", 'l') - .nl("The Vet is where you go to upgrade your pet") - .nl("at Kat or to buy pet upgrade items from Zog") - .nl("or trade in your pet at George and if you're") - .apd("a new player you can buy a bee pet from Bea.") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(58, -73), - new ResourceLocation("skyblockhud", "maps/icons/fishing_merchant.png"), - new ComponentBuilder() - .nl("Fishing Merchant", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Fishing Merchant allows you to buy") - .nl("fishing related items and he has his friend") - .nl("joe whose in the house hes setup") - .apd("in front of who sells sponges.") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(46, -53), - new ResourceLocation("skyblockhud", "maps/icons/witch.png"), - new ComponentBuilder() - .nl("Alchemist", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Alchemist allows you to buy") - .apd("potion making related items") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-4, -128), - new ResourceLocation("skyblockhud", "maps/icons/metal_merchants.png"), - new ComponentBuilder() - .nl("Blacksmith Merchants", new char[]{'a','l'}) - .nl("Merchants", new char[]{'c','l'}) - .nl(" Weaponsmith - Weapon Related Items") - .nl(" Armorsmith - Armor Related Items") - .apd(" Mine Merchant - Mining Related Items") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-30, -120), - new ResourceLocation("skyblockhud", "maps/icons/blacksmith.png"), - new ComponentBuilder() - .nl("Blacksmith", new char[]{'a','l'}) - .nl("NPCS", new char[]{'c','l'}) - .nl(" Blacksmith") - .nl(" Dusk") - .nl(" Smithmonger") - .nl("Description", 'l') - .nl("The Blacksmith lets you reforge your items") - .nl("while the Smithmonger allows you to buy reforge stones") - .apd("and Dusk allows you to combine and apply runes.") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(124, 180), - new ResourceLocation("skyblockhud", "maps/icons/dark_bar.png"), - new ComponentBuilder() - .nl("Dark Bar", new char[]{'a','l'}) - .nl("NPCS", new char[]{'c','l'}) - .nl(" Shifty") - .nl(" Lucius") - .nl("Description", 'l') - .nl("The Dark Bar is where you can buy special") - .nl("brews from Shifty and you can buy special") - .nl("items from Lucius after buying a certain") - .apd("amount of items from the Dark Auction.") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(92, 185), - new ResourceLocation("skyblockhud", "maps/icons/dark_ah.png"), - new ComponentBuilder() - .nl("Dark Auction", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Dark Auction allows you to buy") - .nl("super special items from Sirius the") - .apd("auctioneer in a special auction.") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-245, 52), - new ResourceLocation("skyblockhud", "maps/icons/scroll.png"), - new ComponentBuilder() - .nl("Lonely Philosopher", new char[]{'a','l'}) - .nl("Shop", new char[]{'6','l'}) - .nl(" Travel Scroll to Hub Castle") - .nl() - .nl(" Cost") - .nl(" 150,000 Coins", '6') - .nl() - .apd(" Requires ") - .apd("MVP", 'b') - .apd("+", 'c') - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(24, -38), - new ResourceLocation("skyblockhud", "maps/icons/tux.png"), - new ComponentBuilder() - .nl("Fashion Shop", new char[]{'a','l'}) - .nl("NPCS", new char[]{'c','l'}) - .nl(" Wool Weaver") - .nl(" Builder") - .apd(" Mad Redstone Engineer") - .build(), - MapHandler.MapIconTypes.SHOPS - ) - ); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-50, -22), new ResourceLocation("skyblockhud", "maps/icons/building.png"), new ComponentBuilder().nl("Builder's House", new char[] { 'a', 'l' }).nl("NPCS", new char[] { 'c', 'l' }).nl(" Wool Weaver").nl(" Builder").apd(" Mad Redstone Engineer").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-78, -46), new ResourceLocation("skyblockhud", "maps/icons/bar.png"), new ComponentBuilder().nl("Tavern", new char[] { 'a', 'l' }).nl("NPCS", new char[] { 'c', 'l' }).nl(" Bartender").nl(" Maddox the slayer").nl("Description", 'l').nl("The Tavern is where maddox the slayer is located you can").nl("start slayer quests with them to unlock").apd("new items the more slayer bosses you kill.").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(36, -82), new ResourceLocation("skyblockhud", "maps/icons/vet.png"), new ComponentBuilder().nl("Vet", new char[] { 'a', 'l' }).nl("NPCS", new char[] { 'c', 'l' }).nl(" Bea").nl(" Zog").nl(" Kat").nl(" George").nl("Description", 'l').nl("The Vet is where you go to upgrade your pet").nl("at Kat or to buy pet upgrade items from Zog").nl("or trade in your pet at George and if you're").apd("a new player you can buy a bee pet from Bea.").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(58, -73), new ResourceLocation("skyblockhud", "maps/icons/fishing_merchant.png"), new ComponentBuilder().nl("Fishing Merchant", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Fishing Merchant allows you to buy").nl("fishing related items and he has his friend").nl("joe whose in the house hes setup").apd("in front of who sells sponges.").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(46, -53), new ResourceLocation("skyblockhud", "maps/icons/witch.png"), new ComponentBuilder().nl("Alchemist", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Alchemist allows you to buy").apd("potion making related items").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-4, -128), new ResourceLocation("skyblockhud", "maps/icons/metal_merchants.png"), new ComponentBuilder().nl("Blacksmith Merchants", new char[] { 'a', 'l' }).nl("Merchants", new char[] { 'c', 'l' }).nl(" Weaponsmith - Weapon Related Items").nl(" Armorsmith - Armor Related Items").apd(" Mine Merchant - Mining Related Items").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-30, -120), new ResourceLocation("skyblockhud", "maps/icons/blacksmith.png"), new ComponentBuilder().nl("Blacksmith", new char[] { 'a', 'l' }).nl("NPCS", new char[] { 'c', 'l' }).nl(" Blacksmith").nl(" Dusk").nl(" Smithmonger").nl("Description", 'l').nl("The Blacksmith lets you reforge your items").nl("while the Smithmonger allows you to buy reforge stones").apd("and Dusk allows you to combine and apply runes.").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(124, 180), new ResourceLocation("skyblockhud", "maps/icons/dark_bar.png"), new ComponentBuilder().nl("Dark Bar", new char[] { 'a', 'l' }).nl("NPCS", new char[] { 'c', 'l' }).nl(" Shifty").nl(" Lucius").nl("Description", 'l').nl("The Dark Bar is where you can buy special").nl("brews from Shifty and you can buy special").nl("items from Lucius after buying a certain").apd("amount of items from the Dark Auction.").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(92, 185), new ResourceLocation("skyblockhud", "maps/icons/dark_ah.png"), new ComponentBuilder().nl("Dark Auction", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Dark Auction allows you to buy").nl("super special items from Sirius the").apd("auctioneer in a special auction.").build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-245, 52), new ResourceLocation("skyblockhud", "maps/icons/scroll.png"), new ComponentBuilder().nl("Lonely Philosopher", new char[] { 'a', 'l' }).nl("Shop", new char[] { '6', 'l' }).nl(" Travel Scroll to Hub Castle").nl().nl(" Cost").nl(" 150,000 Coins", '6').nl().apd(" Requires ").apd("MVP", 'b').apd("+", 'c').build(), MapHandler.MapIconTypes.SHOPS)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(24, -38), new ResourceLocation("skyblockhud", "maps/icons/tux.png"), new ComponentBuilder().nl("Fashion Shop", new char[] { 'a', 'l' }).nl("NPCS", new char[] { 'c', 'l' }).nl(" Wool Weaver").nl(" Builder").apd(" Mad Redstone Engineer").build(), MapHandler.MapIconTypes.SHOPS)); } private static void setupMiscIcons() { - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-24, -53), - new ResourceLocation("skyblockhud", "maps/icons/bank.png"), - new ComponentBuilder() - .nl("Bank", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Bank is where you can store your money on skyblock") - .apd("you can also store some items in the vault.") - .build(), - MapHandler.MapIconTypes.MISC - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-26, -80), - new ResourceLocation("skyblockhud", "maps/icons/ah.png"), - new ComponentBuilder() - .nl("Auction House", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Auction House is where you can auction off your") - .apd("precious items in skyblock to make a profit.") - .build(), - MapHandler.MapIconTypes.MISC - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-38, -66), - new ResourceLocation("skyblockhud", "maps/icons/bazaar.png"), - new ComponentBuilder() - .nl("Bazaar", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Bazaar is where you can sell specific items") - .nl("on a sort of stock market and request and") - .apd("sell items at a specific price.") - .build(), - MapHandler.MapIconTypes.MISC - ) - ); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-24, -53), new ResourceLocation("skyblockhud", "maps/icons/bank.png"), new ComponentBuilder().nl("Bank", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Bank is where you can store your money on skyblock").apd("you can also store some items in the vault.").build(), MapHandler.MapIconTypes.MISC)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-26, -80), new ResourceLocation("skyblockhud", "maps/icons/ah.png"), new ComponentBuilder().nl("Auction House", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Auction House is where you can auction off your").apd("precious items in skyblock to make a profit.").build(), MapHandler.MapIconTypes.MISC)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-38, -66), new ResourceLocation("skyblockhud", "maps/icons/bazaar.png"), new ComponentBuilder().nl("Bazaar", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Bazaar is where you can sell specific items").nl("on a sort of stock market and request and").apd("sell items at a specific price.").build(), MapHandler.MapIconTypes.MISC)); } private static void setupInfoIcons() { - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(8, -95), - new ResourceLocation("skyblockhud", "maps/icons/community.png"), - new ComponentBuilder() - .nl("Community Center", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("The Community Center is where you can vote") - .nl("for your favorite election candidate,") - .nl("access the community shop, upgrade your") - .apd("account, and help with city projects.") - .build(), - MapHandler.MapIconTypes.INFO - ) - ); - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(150, 45), - new ResourceLocation("skyblockhud", "maps/icons/fishing.png"), - new ComponentBuilder() - .nl("Fisherman's Hut", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("This is a spot where people regularly") - .nl("do their fishing, this is one") - .apd("of many spots.") - .build(), - MapHandler.MapIconTypes.INFO - ) - ); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(8, -95), new ResourceLocation("skyblockhud", "maps/icons/community.png"), new ComponentBuilder().nl("Community Center", new char[] { 'a', 'l' }).nl("Description", 'l').nl("The Community Center is where you can vote").nl("for your favorite election candidate,").nl("access the community shop, upgrade your").apd("account, and help with city projects.").build(), MapHandler.MapIconTypes.INFO)); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(150, 45), new ResourceLocation("skyblockhud", "maps/icons/fishing.png"), new ComponentBuilder().nl("Fisherman's Hut", new char[] { 'a', 'l' }).nl("Description", 'l').nl("This is a spot where people regularly").nl("do their fishing, this is one").apd("of many spots.").build(), MapHandler.MapIconTypes.INFO)); } private static void setupQuestIcons() { - hubIcons.add(new MapHandler.MapIcon( - new Vector2f(-8, -10), - new ResourceLocation("skyblockhud", "maps/icons/painter.png"), - new ComponentBuilder() - .nl("Marco", new char[]{'a','l'}) - .nl("Description", 'l') - .nl("Marco is an NPC that has no other uses") - .nl("besides giving you a spray can for") - .apd("completing a quest.") - .build(), - MapHandler.MapIconTypes.QUEST - ) - ); + hubIcons.add(new MapHandler.MapIcon(new Vector2f(-8, -10), new ResourceLocation("skyblockhud", "maps/icons/painter.png"), new ComponentBuilder().nl("Marco", new char[] { 'a', 'l' }).nl("Description", 'l').nl("Marco is an NPC that has no other uses").nl("besides giving you a spray can for").apd("completing a quest.").build(), MapHandler.MapIconTypes.QUEST)); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/EntityTypeRegistry.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/EntityTypeRegistry.java index d45fa1f..40076d9 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/EntityTypeRegistry.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/EntityTypeRegistry.java @@ -2,11 +2,10 @@ package com.thatgravyboat.skyblockhud.handlers.sbentities; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; -import net.minecraft.entity.Entity; -import net.minecraft.entity.monster.EntityEnderman; - import java.util.List; import java.util.Map; +import net.minecraft.entity.Entity; +import net.minecraft.entity.monster.EntityEnderman; public class EntityTypeRegistry { @@ -16,10 +15,9 @@ public class EntityTypeRegistry { entities.put(EntityEnderman.class, ImmutableList.of(SkyBlockEntity.of("zealot", EntityTypeHelper::isZealot))); } - public static String getEntityId(Entity entity){ + public static String getEntityId(Entity entity) { if (!entities.containsKey(entity.getClass())) return null; for (SkyBlockEntity skyBlockEntity : entities.get(entity.getClass())) if (skyBlockEntity.isEntity(entity)) return skyBlockEntity.getName(); return null; } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/SkyBlockEntity.java b/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/SkyBlockEntity.java index ca10b53..ee8c3a7 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/SkyBlockEntity.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/handlers/sbentities/SkyBlockEntity.java @@ -1,24 +1,25 @@ package com.thatgravyboat.skyblockhud.handlers.sbentities; -import net.minecraft.entity.Entity; - import java.util.function.Predicate; +import net.minecraft.entity.Entity; public class SkyBlockEntity { private final String name; private final Predicate<Entity> predicate; - public static SkyBlockEntity of(String name, Predicate<Entity> predicate){ + public static SkyBlockEntity of(String name, Predicate<Entity> predicate) { return new SkyBlockEntity(name, predicate); } - private SkyBlockEntity(String name, Predicate<Entity> predicate){ + private SkyBlockEntity(String name, Predicate<Entity> predicate) { this.name = name; this.predicate = predicate; } - public String getName(){ return name; } + public String getName() { + return name; + } public boolean isEntity(Entity entity) { return predicate.test(entity); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/DwarvenMineHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/DwarvenMineHandler.java index 32f6c80..3b17899 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/DwarvenMineHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/DwarvenMineHandler.java @@ -2,12 +2,11 @@ package com.thatgravyboat.skyblockhud.location; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Arrays; import java.util.Locale; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class DwarvenMineHandler { @@ -19,7 +18,7 @@ public class DwarvenMineHandler { public int x; public String displayName; - Event(int x, String displayName){ + Event(int x, String displayName) { this.x = x; this.displayName = displayName; } @@ -33,53 +32,52 @@ public class DwarvenMineHandler { private static final DecimalFormat formatter = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.CANADA)); - public static String getMithrilFormatted(){ + public static String getMithrilFormatted() { String output = formatter.format(mithril); - if (output.equals(".0")) output = "0.0"; - else if (output.equals(",0")) output = "0,0"; + if (output.equals(".0")) output = "0.0"; else if (output.equals(",0")) output = "0,0"; return output; } - public static void parseMithril(String line){ - try{ + public static void parseMithril(String line) { + try { mithril = Integer.parseInt(line.toLowerCase().replace("mithril powder:", "").trim()); - }catch (Exception ignored){} + } catch (Exception ignored) {} } @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ - if (event.formattedLine.toLowerCase().contains("mithril")){ - try{ - mithril = Integer.parseInt(event.formattedLine.toLowerCase().replace("mithril:","").trim()); - }catch (Exception ignored){} + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { + if (event.formattedLine.toLowerCase().contains("mithril")) { + try { + mithril = Integer.parseInt(event.formattedLine.toLowerCase().replace("mithril:", "").trim()); + } catch (Exception ignored) {} } - if (event.formattedLine.toLowerCase().contains("event")){ - if (event.formattedLine.toLowerCase().contains("raffle")){ + if (event.formattedLine.toLowerCase().contains("event")) { + if (event.formattedLine.toLowerCase().contains("raffle")) { DwarvenMineHandler.currentEvent = Event.TICKET; - }else if (event.formattedLine.toLowerCase().contains("goblin raid")){ + } else if (event.formattedLine.toLowerCase().contains("goblin raid")) { DwarvenMineHandler.currentEvent = Event.GOBLIN; } } - if (DwarvenMineHandler.currentEvent != Event.NONE){ - if (DwarvenMineHandler.currentEvent == Event.TICKET && event.formattedLine.toLowerCase().contains("tickets:")){ - if (event.formattedLine.toLowerCase().contains("pool:")){ - try{ - eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("pool:","").trim().split("/")[0].trim()); - }catch (Exception ignored){} - }else if (event.formattedLine.toLowerCase().contains("tickets:")){ - try{ + if (DwarvenMineHandler.currentEvent != Event.NONE) { + if (DwarvenMineHandler.currentEvent == Event.TICKET && event.formattedLine.toLowerCase().contains("tickets:")) { + if (event.formattedLine.toLowerCase().contains("pool:")) { + try { + eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("pool:", "").trim().split("/")[0].trim()); + } catch (Exception ignored) {} + } else if (event.formattedLine.toLowerCase().contains("tickets:")) { + try { eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("tickets:", "").split("\\(")[0].trim()); - }catch (Exception ignored){} + } catch (Exception ignored) {} } - }else if (DwarvenMineHandler.currentEvent == Event.GOBLIN){ - if (event.formattedLine.toLowerCase().contains("remaining:")){ - try{ - eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("goblins","").replace("remaining:","").trim()); - }catch (Exception ignored){} - }else if (event.formattedLine.toLowerCase().contains("your kills:") && !event.formattedLine.toLowerCase().contains("(")){ - try{ - eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("your kills:","").trim()); - }catch (Exception ignored){} + } else if (DwarvenMineHandler.currentEvent == Event.GOBLIN) { + if (event.formattedLine.toLowerCase().contains("remaining:")) { + try { + eventMax = Integer.parseInt(event.formattedLine.toLowerCase().replace("goblins", "").replace("remaining:", "").trim()); + } catch (Exception ignored) {} + } else if (event.formattedLine.toLowerCase().contains("your kills:") && !event.formattedLine.toLowerCase().contains("(")) { + try { + eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("your kills:", "").trim()); + } catch (Exception ignored) {} } } } @@ -88,7 +86,7 @@ public class DwarvenMineHandler { @SubscribeEvent public void onSidebarPost(SidebarPostEvent event) { String arrayString = Arrays.toString(event.arrayScores); - if (!arrayString.toLowerCase().contains("event:")){ + if (!arrayString.toLowerCase().contains("event:")) { DwarvenMineHandler.currentEvent = Event.NONE; DwarvenMineHandler.eventProgress = 0; DwarvenMineHandler.eventMax = 0; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/EndIslandHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/EndIslandHandler.java index e8be465..505db19 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/EndIslandHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/EndIslandHandler.java @@ -1,6 +1,7 @@ package com.thatgravyboat.skyblockhud.location; public class EndIslandHandler { + public enum dragonTypes { PROTECTOR("Protector Dragon", 9000000), OLD("Old Dragon", 15000000), @@ -14,12 +15,12 @@ public class EndIslandHandler { private final String displayName; private final int maxHealth; - dragonTypes(String displayName, int maxHealth){ + dragonTypes(String displayName, int maxHealth) { this.displayName = displayName; this.maxHealth = maxHealth; } - public String getDisplayName(){ + public String getDisplayName() { return this.displayName; } @@ -27,20 +28,26 @@ public class EndIslandHandler { return this.maxHealth; } - public static dragonTypes findDragon(String input){ - if (input.contains(" ")){ + public static dragonTypes findDragon(String input) { + if (input.contains(" ")) { try { return dragonTypes.valueOf(input.toLowerCase().replace("dragon", "").replace(" ", "").toUpperCase()); - } catch(IllegalArgumentException ignored) { + } catch (IllegalArgumentException ignored) { return NODRAGON; } } else { - try { return dragonTypes.valueOf(input); } catch(IllegalArgumentException ignored) { return NODRAGON; } + try { + return dragonTypes.valueOf(input); + } catch (IllegalArgumentException ignored) { + return NODRAGON; + } } } } private static dragonTypes currentDragon = dragonTypes.NODRAGON; - public static void setCurrentDragon(dragonTypes dragon) { currentDragon = dragon; } + public static void setCurrentDragon(dragonTypes dragon) { + currentDragon = dragon; + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/FarmingIslandHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/FarmingIslandHandler.java index 03a698b..a4abaae 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/FarmingIslandHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/FarmingIslandHandler.java @@ -1,9 +1,8 @@ package com.thatgravyboat.skyblockhud.location; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.util.Arrays; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class FarmingIslandHandler { @@ -16,13 +15,13 @@ public class FarmingIslandHandler { if (isTracking && location == Locations.NONE) { for (int i = 0; i < event.scores.size(); i++) { String line = event.scores.get(i); - if (line.toLowerCase().contains("tracker mob location:") && i > 2){ + if (line.toLowerCase().contains("tracker mob location:") && i > 2) { location = Locations.get(event.scores.get(i - 1).toLowerCase()); break; } } } - if (!isTracking && location != Locations.NONE){ + if (!isTracking && location != Locations.NONE) { location = Locations.NONE; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/IslandHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/IslandHandler.java index d6ab81e..2e2fae1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/IslandHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/IslandHandler.java @@ -5,9 +5,8 @@ import com.thatgravyboat.skyblockhud.api.events.ProfileSwitchedEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; import com.thatgravyboat.skyblockhud.handlers.CurrencyHandler; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.util.Arrays; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class IslandHandler { @@ -15,33 +14,43 @@ public class IslandHandler { public static boolean hadFlightTime; public static int redstone; - public static boolean hadRedstone; + public static boolean hadRedstone; @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { hadFlightTime = checkFlightDuration(event.formattedLine); hadRedstone = checkRestone(event.formattedLine); } @SubscribeEvent - public void onProfileSwitch(ProfileSwitchedEvent event){ + public void onProfileSwitch(ProfileSwitchedEvent event) { flightTime = 0; } - public static boolean checkFlightDuration(String formatedScoreboardLine){ - if (LocationHandler.getCurrentLocation() == Locations.YOURISLAND && Utils.removeColor(formatedScoreboardLine.toLowerCase().trim()).contains("flight duration:")){ + public static boolean checkFlightDuration(String formatedScoreboardLine) { + if (LocationHandler.getCurrentLocation() == Locations.YOURISLAND && Utils.removeColor(formatedScoreboardLine.toLowerCase().trim()).contains("flight duration:")) { String timeString = formatedScoreboardLine.toLowerCase().replace("flight duration:", "").replace(" ", ""); String[] times = timeString.split(":"); - if (times.length == 2){ + if (times.length == 2) { int s = 0; - try { s += Integer.parseInt(times[0]) * 60; } catch (NumberFormatException ignored){} - try { s += Integer.parseInt(times[1]); } catch (NumberFormatException ignored){} + try { + s += Integer.parseInt(times[0]) * 60; + } catch (NumberFormatException ignored) {} + try { + s += Integer.parseInt(times[1]); + } catch (NumberFormatException ignored) {} flightTime = s - 1; - } else if (times.length == 3){ + } else if (times.length == 3) { int s = 0; - try { s += Integer.parseInt(times[0]) * 3600; } catch (NumberFormatException ignored){} - try { s += Integer.parseInt(times[1]) * 60; } catch (NumberFormatException ignored){} - try { s += Integer.parseInt(times[2]); } catch (NumberFormatException ignored){} + try { + s += Integer.parseInt(times[0]) * 3600; + } catch (NumberFormatException ignored) {} + try { + s += Integer.parseInt(times[1]) * 60; + } catch (NumberFormatException ignored) {} + try { + s += Integer.parseInt(times[2]); + } catch (NumberFormatException ignored) {} flightTime = s - 1; } return true; @@ -49,13 +58,12 @@ public class IslandHandler { return false; } - public static boolean checkRestone(String formatedScoreboardLine){ + public static boolean checkRestone(String formatedScoreboardLine) { if (LocationHandler.getCurrentLocation() == Locations.YOURISLAND) { - if (formatedScoreboardLine.toLowerCase().contains("redstone:")) - return true; + if (formatedScoreboardLine.toLowerCase().contains("redstone:")) return true; try { redstone = formatedScoreboardLine.toLowerCase().contains("redstone:") ? Integer.parseInt(Utils.removeWhiteSpaceAndRemoveWord(formatedScoreboardLine, "redstone:")) : 0; - }catch (Exception ignored){} + } catch (Exception ignored) {} } return false; } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/LocationCategory.java b/src/main/java/com/thatgravyboat/skyblockhud/location/LocationCategory.java index 817645d..a337f3d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/LocationCategory.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/LocationCategory.java @@ -1,46 +1,49 @@ package com.thatgravyboat.skyblockhud.location; -import com.thatgravyboat.skyblockhud.handlers.MapHandler; import static com.thatgravyboat.skyblockhud.handlers.MapHandler.Maps; -public enum LocationCategory { +import com.thatgravyboat.skyblockhud.handlers.MapHandler; +public enum LocationCategory { ERROR("error", 34), - ISLAND("island",43), - HUB("hub",34, Maps.HUB), - BARN("barn",67, Maps.BARN), - MUSHROOMDESERT("mushroomdesert",75, Maps.MUSHROOM), - GOLDMINE("gold_mine",83), - DEEPCAVERNS("deepcaverns",91), - SPIDERSDEN("spiders_den",99, Maps.SPIDERS), - PARK("park",51, Maps.PARK), - FORTRESS("fortress",107, Maps.NETHER), - DUNGEONHUB("dungeonhub",115), - JERRY("jerry",59), - THEEND("the_end",123), + ISLAND("island", 43), + HUB("hub", 34, Maps.HUB), + BARN("barn", 67, Maps.BARN), + MUSHROOMDESERT("mushroomdesert", 75, Maps.MUSHROOM), + GOLDMINE("gold_mine", 83), + DEEPCAVERNS("deepcaverns", 91), + SPIDERSDEN("spiders_den", 99, Maps.SPIDERS), + PARK("park", 51, Maps.PARK), + FORTRESS("fortress", 107, Maps.NETHER), + DUNGEONHUB("dungeonhub", 115), + JERRY("jerry", 59), + THEEND("the_end", 123), DWARVENMINES("dwarven_mines", 131, Maps.DWARVEN), CRYSTALHOLLOWS("crystal_hollows", 131); - private final String name; private final int texturePos; private final MapHandler.Maps map; - LocationCategory(String name, int texturePos){ + LocationCategory(String name, int texturePos) { this(name, texturePos, null); } - LocationCategory(String name, int texturePos, MapHandler.Maps map){ + LocationCategory(String name, int texturePos, MapHandler.Maps map) { this.name = name; this.texturePos = texturePos; this.map = map; } - public String getName(){ + public String getName() { return this.name; } - public int getTexturePos(){ + + public int getTexturePos() { return this.texturePos; } - public MapHandler.Maps getMap() { return this.map; } + + public MapHandler.Maps getMap() { + return this.map; + } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/LocationHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/LocationHandler.java index 274baf8..bf55db6 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/LocationHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/LocationHandler.java @@ -1,54 +1,51 @@ package com.thatgravyboat.skyblockhud.location; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.util.ArrayList; import java.util.List; import java.util.Locale; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class LocationHandler { private static Locations currentLocation = Locations.NONE; private static final List<String> UndocumentedLocations = new ArrayList<>(); - @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { if (event.rawLine.contains("\u23E3")) { String objectiveName = event.objective.getDisplayName().replaceAll("(?i)\\u00A7.", ""); - if (objectiveName.toLowerCase(Locale.ENGLISH).endsWith("guest")){ + if (objectiveName.toLowerCase(Locale.ENGLISH).endsWith("guest")) { LocationHandler.setCurrentLocation(Locations.GUESTISLAND); - }else { + } else { LocationHandler.handleLocation(event.formattedLine); } } } - public static void setCurrentLocation(String location){ + public static void setCurrentLocation(String location) { currentLocation = Locations.get(location); } - public static void setCurrentLocation(Locations location){ + public static void setCurrentLocation(Locations location) { currentLocation = location; } - public static Locations getCurrentLocation(){ return currentLocation; } + public static Locations getCurrentLocation() { + return currentLocation; + } - public static void handleLocation(String locationLine){ + public static void handleLocation(String locationLine) { String location = locationLine.replace(" ", "").toUpperCase(Locale.ENGLISH).trim(); - if (location.startsWith("THECATACOMBS")){ + if (location.startsWith("THECATACOMBS")) { currentLocation = Locations.CATACOMBS; - } - else setCurrentLocation(location.replaceAll("[^A-Za-z0-9]", "")); + } else setCurrentLocation(location.replaceAll("[^A-Za-z0-9]", "")); } - - public static void reportUndocumentedLocation(String locationId){ - if (!UndocumentedLocations.contains(locationId)){ + public static void reportUndocumentedLocation(String locationId) { + if (!UndocumentedLocations.contains(locationId)) { UndocumentedLocations.add(locationId); System.out.println("Missing Location value for: " + locationId); } } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/Locations.java b/src/main/java/com/thatgravyboat/skyblockhud/location/Locations.java index 887ac11..74e7ae1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/Locations.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/Locations.java @@ -1,128 +1,126 @@ package com.thatgravyboat.skyblockhud.location; public enum Locations { - //ERROR LOCATIONS - DEFAULT("unknown", "Error", LocationCategory.ERROR), - NONE("none", "Unknown", LocationCategory.ERROR), + DEFAULT("unknown", "Error", LocationCategory.ERROR), + NONE("none", "Unknown", LocationCategory.ERROR), //ISLAND - YOURISLAND("yourisland", "Your Island", LocationCategory.ISLAND), - GUESTISLAND("guestisland", "Guest Island", LocationCategory.ISLAND), - MOULBERRYSISLAND("moulberryisland", "Cool Dude Hub", LocationCategory.ISLAND), + YOURISLAND("yourisland", "Your Island", LocationCategory.ISLAND), + GUESTISLAND("guestisland", "Guest Island", LocationCategory.ISLAND), + MOULBERRYSISLAND("moulberryisland", "Cool Dude Hub", LocationCategory.ISLAND), //HUB - VILLAGE("village", "Village", LocationCategory.HUB), - AUCTIONHOUSE("auctionhouse", "Auction House", LocationCategory.HUB), - BAZAARALLEY("bazaaralley", "Bazaar Alley", LocationCategory.HUB), - BANK("bank", "Bank", LocationCategory.HUB), - FASHIONSHOP("fashionshop", "Fashion Shop", LocationCategory.HUB), - COLOSSEUM("colosseum", "Colosseum", LocationCategory.HUB), - COLOSSEUMARENA("colosseumarena", "Colosseum Arena", LocationCategory.HUB), - MOUNTAIN("mountain", "Mountain", LocationCategory.HUB), - HIGHLEVEL("highlevel", "High Level", LocationCategory.HUB), - WILDERNESS("wilderness", "Wilderness", LocationCategory.HUB), - FISHERMANSHUT("fishermanshut", "Fisherman's Hut", LocationCategory.HUB), - FLOWERHOUSE("flowerhouse", "Flower House", LocationCategory.HUB), - CANVASROOM("canvasroom", "Canvas Room", LocationCategory.HUB), - TAVERN("tavern", "Tavern", LocationCategory.HUB), - FOREST("forest", "Forest", LocationCategory.HUB), - RUINS("ruins", "Ruins", LocationCategory.HUB), - GRAVEYARD("graveyard", "Graveyard", LocationCategory.HUB), - COALMINE("coalmine", "Coal Mine", LocationCategory.HUB), - FARM("farm", "Farm", LocationCategory.HUB), - LIBRARY("library", "Library", LocationCategory.HUB), - COMMUNITYCENTER("communitycenter", "Community Center", LocationCategory.HUB), - ELECTIONROOM("electionroom", "Election Room", LocationCategory.HUB), - BUILDERSHOUSE("buildershouse", "Builder's House", LocationCategory.HUB), - BLACKSMITH("blacksmith", "Blacksmith", LocationCategory.HUB), - FARMHOUSE("farmhouse", "Farmhouse", LocationCategory.HUB), - WIZARDTOWER("wizardtower", "Wizard Tower", LocationCategory.HUB), + VILLAGE("village", "Village", LocationCategory.HUB), + AUCTIONHOUSE("auctionhouse", "Auction House", LocationCategory.HUB), + BAZAARALLEY("bazaaralley", "Bazaar Alley", LocationCategory.HUB), + BANK("bank", "Bank", LocationCategory.HUB), + FASHIONSHOP("fashionshop", "Fashion Shop", LocationCategory.HUB), + COLOSSEUM("colosseum", "Colosseum", LocationCategory.HUB), + COLOSSEUMARENA("colosseumarena", "Colosseum Arena", LocationCategory.HUB), + MOUNTAIN("mountain", "Mountain", LocationCategory.HUB), + HIGHLEVEL("highlevel", "High Level", LocationCategory.HUB), + WILDERNESS("wilderness", "Wilderness", LocationCategory.HUB), + FISHERMANSHUT("fishermanshut", "Fisherman's Hut", LocationCategory.HUB), + FLOWERHOUSE("flowerhouse", "Flower House", LocationCategory.HUB), + CANVASROOM("canvasroom", "Canvas Room", LocationCategory.HUB), + TAVERN("tavern", "Tavern", LocationCategory.HUB), + FOREST("forest", "Forest", LocationCategory.HUB), + RUINS("ruins", "Ruins", LocationCategory.HUB), + GRAVEYARD("graveyard", "Graveyard", LocationCategory.HUB), + COALMINE("coalmine", "Coal Mine", LocationCategory.HUB), + FARM("farm", "Farm", LocationCategory.HUB), + LIBRARY("library", "Library", LocationCategory.HUB), + COMMUNITYCENTER("communitycenter", "Community Center", LocationCategory.HUB), + ELECTIONROOM("electionroom", "Election Room", LocationCategory.HUB), + BUILDERSHOUSE("buildershouse", "Builder's House", LocationCategory.HUB), + BLACKSMITH("blacksmith", "Blacksmith", LocationCategory.HUB), + FARMHOUSE("farmhouse", "Farmhouse", LocationCategory.HUB), + WIZARDTOWER("wizardtower", "Wizard Tower", LocationCategory.HUB), //THE BARN - THEBARN("thebarn", "The Barn", LocationCategory.BARN), - WINDMILL("windmill", "Windmill", LocationCategory.BARN), + THEBARN("thebarn", "The Barn", LocationCategory.BARN), + WINDMILL("windmill", "Windmill", LocationCategory.BARN), //MUSHROOM DESERT - MUSHROOMDESERT("mushroomdesert", "Mushroom Desert", LocationCategory.MUSHROOMDESERT), - DESERTSETTLEMENT("desertsettlement", "Desert Settlement", LocationCategory.MUSHROOMDESERT), - OASIS("oasis", "Oasis", LocationCategory.MUSHROOMDESERT), - MUSHROOMGORGE("mushroomgorge", "Mushroom Gorge", LocationCategory.MUSHROOMDESERT), - SHEPHERDSKEEP("shepherdskeep", "Shepherds Keep", LocationCategory.MUSHROOMDESERT), - JAKESHOUSE("jakeshouse", "Jake's House", LocationCategory.MUSHROOMDESERT), - TREASUREHUNTERCAMP("treasurehuntercamp", "Treasure Hunter Camp", LocationCategory.MUSHROOMDESERT), - GLOWINGMUSHROOMCAVE("glowingmushroomcave", "Glowing Mushroom Cave", LocationCategory.MUSHROOMDESERT), - TRAPPERSDEN("trappersden", "Trappers Den", LocationCategory.MUSHROOMDESERT), - OVERGROWNMUSHROOMCAVE("overgrownmushroomcave", "Overgrown Mushroom Cave", LocationCategory.MUSHROOMDESERT), + MUSHROOMDESERT("mushroomdesert", "Mushroom Desert", LocationCategory.MUSHROOMDESERT), + DESERTSETTLEMENT("desertsettlement", "Desert Settlement", LocationCategory.MUSHROOMDESERT), + OASIS("oasis", "Oasis", LocationCategory.MUSHROOMDESERT), + MUSHROOMGORGE("mushroomgorge", "Mushroom Gorge", LocationCategory.MUSHROOMDESERT), + SHEPHERDSKEEP("shepherdskeep", "Shepherds Keep", LocationCategory.MUSHROOMDESERT), + JAKESHOUSE("jakeshouse", "Jake's House", LocationCategory.MUSHROOMDESERT), + TREASUREHUNTERCAMP("treasurehuntercamp", "Treasure Hunter Camp", LocationCategory.MUSHROOMDESERT), + GLOWINGMUSHROOMCAVE("glowingmushroomcave", "Glowing Mushroom Cave", LocationCategory.MUSHROOMDESERT), + TRAPPERSDEN("trappersden", "Trappers Den", LocationCategory.MUSHROOMDESERT), + OVERGROWNMUSHROOMCAVE("overgrownmushroomcave", "Overgrown Mushroom Cave", LocationCategory.MUSHROOMDESERT), //GOLD MINE - GOLDMINE("goldmine", "Gold Mine", LocationCategory.GOLDMINE), + GOLDMINE("goldmine", "Gold Mine", LocationCategory.GOLDMINE), //DEEP CAVERNS - DEEPCAVERNS("deepcaverns", "Deep Caverns", LocationCategory.DEEPCAVERNS), - GUNPOWDERMINES("gunpowdermines", "Gunpowder Mines", LocationCategory.DEEPCAVERNS), - LAPISQUARRY("lapisquarry", "Lapis Quarry", LocationCategory.DEEPCAVERNS), - PIGMANSDEN("pigmansden", "Pigman's Den", LocationCategory.DEEPCAVERNS), - SLIMEHILL("slimehill", "Slimehill", LocationCategory.DEEPCAVERNS), - DIAMONDRESERVE("diamondreserve", "Diamond Reserve", LocationCategory.DEEPCAVERNS), - OBSIDIANSANCTUARY("obsidiansanctuary", "Obsidian Sanctuary", LocationCategory.DEEPCAVERNS), + DEEPCAVERNS("deepcaverns", "Deep Caverns", LocationCategory.DEEPCAVERNS), + GUNPOWDERMINES("gunpowdermines", "Gunpowder Mines", LocationCategory.DEEPCAVERNS), + LAPISQUARRY("lapisquarry", "Lapis Quarry", LocationCategory.DEEPCAVERNS), + PIGMANSDEN("pigmansden", "Pigman's Den", LocationCategory.DEEPCAVERNS), + SLIMEHILL("slimehill", "Slimehill", LocationCategory.DEEPCAVERNS), + DIAMONDRESERVE("diamondreserve", "Diamond Reserve", LocationCategory.DEEPCAVERNS), + OBSIDIANSANCTUARY("obsidiansanctuary", "Obsidian Sanctuary", LocationCategory.DEEPCAVERNS), //SPIDERS DEN - SPIDERSDEN("spidersden", "Spider's Den", LocationCategory.SPIDERSDEN), + SPIDERSDEN("spidersden", "Spider's Den", LocationCategory.SPIDERSDEN), //THE END - THEEND("theend", "The End", LocationCategory.THEEND), - DRAGONSNEST("dragonsnest", "Dragon's Nest", LocationCategory.THEEND), - VOIDSEPULTURE("voidsepulture", "Void Sepulture", LocationCategory.THEEND), + THEEND("theend", "The End", LocationCategory.THEEND), + DRAGONSNEST("dragonsnest", "Dragon's Nest", LocationCategory.THEEND), + VOIDSEPULTURE("voidsepulture", "Void Sepulture", LocationCategory.THEEND), //PARK - HOWLINGCAVE("howlingcave", "Howling Cave", LocationCategory.PARK), - BIRCHPARK("birchpark", "Birch Park", LocationCategory.PARK), - SPRUCEWOODS("sprucewoods", "Spruce Woods", LocationCategory.PARK), - DARKTHICKET("darkthicket", "Dark Thicket", LocationCategory.PARK), - SAVANNAWOODLAND("savannawoodland", "Savanna Woodland", LocationCategory.PARK), - JUNGLEISLAND("jungleisland", "Jungle Island", LocationCategory.PARK), + HOWLINGCAVE("howlingcave", "Howling Cave", LocationCategory.PARK), + BIRCHPARK("birchpark", "Birch Park", LocationCategory.PARK), + SPRUCEWOODS("sprucewoods", "Spruce Woods", LocationCategory.PARK), + DARKTHICKET("darkthicket", "Dark Thicket", LocationCategory.PARK), + SAVANNAWOODLAND("savannawoodland", "Savanna Woodland", LocationCategory.PARK), + JUNGLEISLAND("jungleisland", "Jungle Island", LocationCategory.PARK), //BLAZING FORTRESS - BLAZINGFORTRESS("blazingfortress", "Blazing Fortress", LocationCategory.FORTRESS), + BLAZINGFORTRESS("blazingfortress", "Blazing Fortress", LocationCategory.FORTRESS), //DUNGEONS - DUNGEONHUB("dungeonhub", "Dungeon Hub", LocationCategory.DUNGEONHUB), - CATACOMBS("catacombs", "The Catacombs", LocationCategory.DUNGEONHUB), - CATACOMBSENTRANCE("catacombsentrance", "Catacombs Entrance", LocationCategory.DUNGEONHUB), + DUNGEONHUB("dungeonhub", "Dungeon Hub", LocationCategory.DUNGEONHUB), + CATACOMBS("catacombs", "The Catacombs", LocationCategory.DUNGEONHUB), + CATACOMBSENTRANCE("catacombsentrance", "Catacombs Entrance", LocationCategory.DUNGEONHUB), //JERRYISLAND - JERRYSWORKSHOP("jerrysworkshop", "Jerry's Workshop", LocationCategory.JERRY), - JERRYPOND("jerrypond", "Jerry Pond", LocationCategory.JERRY), + JERRYSWORKSHOP("jerrysworkshop", "Jerry's Workshop", LocationCategory.JERRY), + JERRYPOND("jerrypond", "Jerry Pond", LocationCategory.JERRY), //DWARVENMINES - THELIFT("thelift", "The Lift", LocationCategory.DWARVENMINES), - DWARVENVILLAGE("dwarvenvillage", "Dwarven Village", LocationCategory.DWARVENMINES), - DWARVENMINES("dwarvenmines", "Dwarven Mines", LocationCategory.DWARVENMINES), - LAVASPRINGS("lavasprings", "Lava Springs", LocationCategory.DWARVENMINES), - PALACEBRIDGE("palacebridge", "Palace Bridge", LocationCategory.DWARVENMINES), - ROYALPALACE("royalpalace", "Royal Palace", LocationCategory.DWARVENMINES), - GRANDLIBRARY("grandlibrary", "Grand Library", LocationCategory.DWARVENMINES), - ROYALQUARTERS("royalquarters", "Royal Quarters", LocationCategory.DWARVENMINES), - BARRACKSOFHEROES("barracksofheroes", "Barracks of Heroes", LocationCategory.DWARVENMINES), - HANGINGCOURT("hangingcourt", "Hanging Court", LocationCategory.DWARVENMINES), - GREATICEWALL("greaticewall", "Great Ice Wall", LocationCategory.DWARVENMINES), - GOBLINBURROWS("goblinburrows", "Goblin Burrows", LocationCategory.DWARVENMINES), - FARRESERVE("farreserve", "Far Reserve", LocationCategory.DWARVENMINES), - CCMINECARTSCO("ccminecartco", "Minecart Co.", LocationCategory.DWARVENMINES), - UPPERMINES("uppermines", "Upper Mines", LocationCategory.DWARVENMINES), - RAMPARTSQUARRY("rampartsquarry", "Ramparts Quarry", LocationCategory.DWARVENMINES), - GATESTOTHEMINES("gatestothemines", "Gates to The Mines", LocationCategory.DWARVENMINES), - FORGEBASIN("forgebasin", "Forge Basin", LocationCategory.DWARVENMINES), - THEFORGE("theforge", "The Forge", LocationCategory.DWARVENMINES), - CLIFFSIDEVEINS("cliffsideveins", "Cliffside Veins", LocationCategory.DWARVENMINES), - DIVANSGATEWAY("divansgateway", "Divan's Gateway", LocationCategory.DWARVENMINES), - THEMIST("themist", "The Mist", LocationCategory.DWARVENMINES), - ROYALMINES("royalmines", "Royal Mines", LocationCategory.DWARVENMINES), - ARISTOCRATPASSAGE("aristocratpassage", "Aristocrat Passage", LocationCategory.DWARVENMINES), - MINERSGUILD("minersguild", "Miner's Guild", LocationCategory.DWARVENMINES), + THELIFT("thelift", "The Lift", LocationCategory.DWARVENMINES), + DWARVENVILLAGE("dwarvenvillage", "Dwarven Village", LocationCategory.DWARVENMINES), + DWARVENMINES("dwarvenmines", "Dwarven Mines", LocationCategory.DWARVENMINES), + LAVASPRINGS("lavasprings", "Lava Springs", LocationCategory.DWARVENMINES), + PALACEBRIDGE("palacebridge", "Palace Bridge", LocationCategory.DWARVENMINES), + ROYALPALACE("royalpalace", "Royal Palace", LocationCategory.DWARVENMINES), + GRANDLIBRARY("grandlibrary", "Grand Library", LocationCategory.DWARVENMINES), + ROYALQUARTERS("royalquarters", "Royal Quarters", LocationCategory.DWARVENMINES), + BARRACKSOFHEROES("barracksofheroes", "Barracks of Heroes", LocationCategory.DWARVENMINES), + HANGINGCOURT("hangingcourt", "Hanging Court", LocationCategory.DWARVENMINES), + GREATICEWALL("greaticewall", "Great Ice Wall", LocationCategory.DWARVENMINES), + GOBLINBURROWS("goblinburrows", "Goblin Burrows", LocationCategory.DWARVENMINES), + FARRESERVE("farreserve", "Far Reserve", LocationCategory.DWARVENMINES), + CCMINECARTSCO("ccminecartco", "Minecart Co.", LocationCategory.DWARVENMINES), + UPPERMINES("uppermines", "Upper Mines", LocationCategory.DWARVENMINES), + RAMPARTSQUARRY("rampartsquarry", "Ramparts Quarry", LocationCategory.DWARVENMINES), + GATESTOTHEMINES("gatestothemines", "Gates to The Mines", LocationCategory.DWARVENMINES), + FORGEBASIN("forgebasin", "Forge Basin", LocationCategory.DWARVENMINES), + THEFORGE("theforge", "The Forge", LocationCategory.DWARVENMINES), + CLIFFSIDEVEINS("cliffsideveins", "Cliffside Veins", LocationCategory.DWARVENMINES), + DIVANSGATEWAY("divansgateway", "Divan's Gateway", LocationCategory.DWARVENMINES), + THEMIST("themist", "The Mist", LocationCategory.DWARVENMINES), + ROYALMINES("royalmines", "Royal Mines", LocationCategory.DWARVENMINES), + ARISTOCRATPASSAGE("aristocratpassage", "Aristocrat Passage", LocationCategory.DWARVENMINES), + MINERSGUILD("minersguild", "Miner's Guild", LocationCategory.DWARVENMINES), //CRYSTALHOLLOWS - JUNGLE("jungle", "Jungle", LocationCategory.CRYSTALHOLLOWS), - MAMGAFIELDS("magmafields", "Magma Fields", LocationCategory.CRYSTALHOLLOWS), - GOBLINHOLDOUT("goblinholdout", "Goblin Holdout", LocationCategory.CRYSTALHOLLOWS), - CRYSTALNUCLEUS("crystalnucleus", "Crystal Nucleus", LocationCategory.CRYSTALHOLLOWS), - PERCURSORREMNANTS("precursorremnants", "Precursor Remnants", LocationCategory.CRYSTALHOLLOWS), - MITHRILDEPOSITS("mithrildeposits", "Mithril Deposits", LocationCategory.CRYSTALHOLLOWS); - + JUNGLE("jungle", "Jungle", LocationCategory.CRYSTALHOLLOWS), + MAMGAFIELDS("magmafields", "Magma Fields", LocationCategory.CRYSTALHOLLOWS), + GOBLINHOLDOUT("goblinholdout", "Goblin Holdout", LocationCategory.CRYSTALHOLLOWS), + CRYSTALNUCLEUS("crystalnucleus", "Crystal Nucleus", LocationCategory.CRYSTALHOLLOWS), + PERCURSORREMNANTS("precursorremnants", "Precursor Remnants", LocationCategory.CRYSTALHOLLOWS), + MITHRILDEPOSITS("mithrildeposits", "Mithril Deposits", LocationCategory.CRYSTALHOLLOWS); private final String name; private final String displayName; private final LocationCategory category; - Locations(String name, String displayName, LocationCategory category){ + Locations(String name, String displayName, LocationCategory category) { this.name = name; this.displayName = displayName; this.category = category; @@ -140,7 +138,7 @@ public enum Locations { return this.category; } - static public Locations get(String id) { + public static Locations get(String id) { try { return Locations.valueOf(id.replace(" ", "").toUpperCase()); } catch (IllegalArgumentException ex) { @@ -149,7 +147,6 @@ public enum Locations { } } - @Override public String toString() { return this.name; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/ParkIslandHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/ParkIslandHandler.java index 2a41391..b9628d0 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/location/ParkIslandHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/ParkIslandHandler.java @@ -7,25 +7,23 @@ public class ParkIslandHandler { private static boolean isRaining = false; private static String rainTime = ""; - public static void parseRain(@Nullable String tabLine){ - if (tabLine == null){ + public static void parseRain(@Nullable String tabLine) { + if (tabLine == null) { isRaining = false; rainTime = ""; - } - else if (tabLine.toLowerCase().contains("rain:")){ - if (tabLine.toLowerCase().contains("no rain")) isRaining = false; - else { + } else if (tabLine.toLowerCase().contains("rain:")) { + if (tabLine.toLowerCase().contains("no rain")) isRaining = false; else { rainTime = tabLine.toLowerCase().replace("rain:", "").replace(" ", ""); isRaining = true; } } } - public static String getRainTime(){ + public static String getRainTime() { return rainTime; } - public static boolean isRaining(){ + public static boolean isRaining() { return isRaining; } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEndermanRenderer.java b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEndermanRenderer.java index 3cdbae5..7363a45 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEndermanRenderer.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEndermanRenderer.java @@ -2,6 +2,7 @@ package com.thatgravyboat.skyblockhud.mixins; import com.thatgravyboat.skyblockhud.SpecialColour; import com.thatgravyboat.skyblockhud.handlers.sbentities.EntityTypeHelper; +import java.awt.*; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.entity.RenderEnderman; import net.minecraft.entity.monster.EntityEnderman; @@ -10,14 +11,12 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.awt.*; - @Mixin(RenderEnderman.class) public class MixinEndermanRenderer { @Inject(method = "doRender(Lnet/minecraft/entity/monster/EntityEnderman;DDDFF)V", at = @At("HEAD")) - public void onRender(EntityEnderman entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci){ - if (EntityTypeHelper.isZealot(entity)){ + public void onRender(EntityEnderman entity, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) { + if (EntityTypeHelper.isZealot(entity)) { Color color = new Color(SpecialColour.specialToChromaRGB("255:255:0:48:255")); GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 255f); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEntityArrow.java b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEntityArrow.java index 93537ea..cc1edaf 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEntityArrow.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinEntityArrow.java @@ -12,11 +12,13 @@ import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(EntityArrow.class) public class MixinEntityArrow { + //Disabled as kill tracker stuff not fully added yet. - @Shadow public Entity shootingEntity; + @Shadow + public Entity shootingEntity; @ModifyVariable(method = "onUpdate", at = @At(value = "STORE", ordinal = 1)) - public MovingObjectPosition onUpdate(MovingObjectPosition position){ + public MovingObjectPosition onUpdate(MovingObjectPosition position) { if (position != null && position.entityHit != null && this.shootingEntity != null && this.shootingEntity.getUniqueID().equals(Minecraft.getMinecraft().thePlayer.getUniqueID())) { KillTrackerHandler.attackedEntities.add(position.entityHit.getUniqueID()); } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinGuiIngameForge.java b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinGuiIngameForge.java index ce7c228..9886ba0 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinGuiIngameForge.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinGuiIngameForge.java @@ -1,5 +1,7 @@ package com.thatgravyboat.skyblockhud.mixins; +import static net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.*; + import com.thatgravyboat.skyblockhud.SkyblockHud; import net.minecraftforge.client.GuiIngameForge; import net.minecraftforge.client.event.RenderGameOverlayEvent; @@ -10,8 +12,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import static net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType.*; - @Mixin(GuiIngameForge.class) public class MixinGuiIngameForge { @@ -19,8 +19,8 @@ public class MixinGuiIngameForge { private RenderGameOverlayEvent eventParent; @Inject(method = "renderArmor", at = @At("HEAD"), cancellable = true, remap = false) - public void onRenderArmor(int width, int height, CallbackInfo ci){ - if (SkyblockHud.config.renderer.hideArmor && SkyblockHud.hasSkyblockScoreboard()){ + public void onRenderArmor(int width, int height, CallbackInfo ci) { + if (SkyblockHud.config.renderer.hideArmor && SkyblockHud.hasSkyblockScoreboard()) { ci.cancel(); if (pre(ARMOR)) return; post(ARMOR); @@ -28,8 +28,8 @@ public class MixinGuiIngameForge { } @Inject(method = "renderHealth", at = @At("HEAD"), cancellable = true, remap = false) - public void onRenderHealth(int width, int height, CallbackInfo ci){ - if (SkyblockHud.config.renderer.hideHearts && SkyblockHud.hasSkyblockScoreboard()){ + public void onRenderHealth(int width, int height, CallbackInfo ci) { + if (SkyblockHud.config.renderer.hideHearts && SkyblockHud.hasSkyblockScoreboard()) { ci.cancel(); if (pre(HEALTH)) return; post(HEALTH); @@ -37,8 +37,8 @@ public class MixinGuiIngameForge { } @Inject(method = "renderAir", at = @At("HEAD"), cancellable = true, remap = false) - public void onRenderAir(int width, int height, CallbackInfo ci){ - if (SkyblockHud.config.renderer.hideAir && SkyblockHud.hasSkyblockScoreboard()){ + public void onRenderAir(int width, int height, CallbackInfo ci) { + if (SkyblockHud.config.renderer.hideAir && SkyblockHud.hasSkyblockScoreboard()) { ci.cancel(); if (pre(AIR)) return; post(AIR); @@ -46,8 +46,8 @@ public class MixinGuiIngameForge { } @Inject(method = "renderHealthMount", at = @At("HEAD"), cancellable = true, remap = false) - public void onRenderHealthMount(int width, int height, CallbackInfo ci){ - if (SkyblockHud.config.renderer.hideAnimalHearts && SkyblockHud.hasSkyblockScoreboard()){ + public void onRenderHealthMount(int width, int height, CallbackInfo ci) { + if (SkyblockHud.config.renderer.hideAnimalHearts && SkyblockHud.hasSkyblockScoreboard()) { ci.cancel(); if (pre(HEALTHMOUNT)) return; post(HEALTHMOUNT); @@ -55,8 +55,8 @@ public class MixinGuiIngameForge { } @Inject(method = "renderExperience", at = @At("HEAD"), cancellable = true, remap = false) - public void onRenderExperience(int width, int height, CallbackInfo ci){ - if (SkyblockHud.config.renderer.hideXpBar && SkyblockHud.hasSkyblockScoreboard()){ + public void onRenderExperience(int width, int height, CallbackInfo ci) { + if (SkyblockHud.config.renderer.hideXpBar && SkyblockHud.hasSkyblockScoreboard()) { ci.cancel(); if (pre(EXPERIENCE)) return; post(EXPERIENCE); @@ -64,8 +64,8 @@ public class MixinGuiIngameForge { } @Inject(method = "renderJumpBar", at = @At("HEAD"), cancellable = true, remap = false) - public void onRenderJumpBar(int width, int height, CallbackInfo ci){ - if (SkyblockHud.config.renderer.hideXpBar && SkyblockHud.hasSkyblockScoreboard()){ + public void onRenderJumpBar(int width, int height, CallbackInfo ci) { + if (SkyblockHud.config.renderer.hideXpBar && SkyblockHud.hasSkyblockScoreboard()) { ci.cancel(); if (pre(JUMPBAR)) return; post(JUMPBAR); @@ -73,20 +73,19 @@ public class MixinGuiIngameForge { } @Inject(method = "renderFood", at = @At("HEAD"), cancellable = true, remap = false) - public void onRenderFood(int width, int height, CallbackInfo ci){ - if (SkyblockHud.config.renderer.hideFood && SkyblockHud.hasSkyblockScoreboard()){ + public void onRenderFood(int width, int height, CallbackInfo ci) { + if (SkyblockHud.config.renderer.hideFood && SkyblockHud.hasSkyblockScoreboard()) { ci.cancel(); if (pre(FOOD)) return; post(FOOD); } } - private boolean pre(RenderGameOverlayEvent.ElementType type) - { + private boolean pre(RenderGameOverlayEvent.ElementType type) { return MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Pre(eventParent, type)); } - private void post(RenderGameOverlayEvent.ElementType type) - { + + private void post(RenderGameOverlayEvent.ElementType type) { MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Post(eventParent, type)); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinNetHandlerPlayClient.java b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinNetHandlerPlayClient.java index 679da20..df36b8f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinNetHandlerPlayClient.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinNetHandlerPlayClient.java @@ -45,9 +45,8 @@ public class MixinNetHandlerPlayClient { */ @Inject(method = "handleTeams", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/server/S3EPacketTeams;getAction()I", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true) - public void handleTeams(S3EPacketTeams packetIn, CallbackInfo ci, Scoreboard scoreboard){ + public void handleTeams(S3EPacketTeams packetIn, CallbackInfo ci, Scoreboard scoreboard) { //This stops Hypixel from being stupid and spamming our logs because they dont have different ids for things. if (scoreboard.getTeam(packetIn.getName()) != null && packetIn.getAction() == 0) ci.cancel(); } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java index 4a3b36f..f8a2e0d 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/DungeonOverlay.java @@ -23,6 +23,7 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class DungeonOverlay extends Gui { + private static final FontRenderer font = Minecraft.getMinecraft().fontRendererObj; private static boolean bossBarVisible = false; @@ -42,27 +43,27 @@ public class DungeonOverlay extends Gui { } } - public void drawDungeonClock(int width, int offset, Minecraft mc){ + public void drawDungeonClock(int width, int offset, Minecraft mc) { GlStateManager.enableBlend(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); int dungeonTime = DungeonHandler.getDungeonTime(); - int dungeonTimeMin = dungeonTime /60; + int dungeonTimeMin = dungeonTime / 60; int dungeonTimeSec = dungeonTime - dungeonTimeMin * 60; - drawTexturedModalRect((width/ 2) - 17, offset + (bossBarVisible ? 17 : 0), 0, 0, 34, 34); + drawTexturedModalRect((width / 2) - 17, offset + (bossBarVisible ? 17 : 0), 0, 0, 34, 34); mc.renderEngine.bindTexture(GuiTextures.dungeon); - drawTexturedModalRect((width/ 2) - 7, offset + (bossBarVisible ? 20 : 3), 16, 50, 3, 8); - drawTexturedModalRect((width/ 2) - 7, offset + (bossBarVisible ? 30 : 13), 19, 50, 3, 8); + drawTexturedModalRect((width / 2) - 7, offset + (bossBarVisible ? 20 : 3), 16, 50, 3, 8); + drawTexturedModalRect((width / 2) - 7, offset + (bossBarVisible ? 30 : 13), 19, 50, 3, 8); String dungeonTimeElapsed = (dungeonTimeMin > 9 ? String.valueOf(dungeonTimeMin) : "0" + dungeonTimeMin) + ":" + (dungeonTimeSec > 9 ? String.valueOf(dungeonTimeSec) : "0" + dungeonTimeSec); - drawCenteredString(font, dungeonTimeElapsed, (width/ 2), offset + (bossBarVisible ? 40 : 23), 0xFFFF55); + drawCenteredString(font, dungeonTimeElapsed, (width / 2), offset + (bossBarVisible ? 40 : 23), 0xFFFF55); //KEYS - drawString(font, (DungeonHandler.hasBloodkey() ? "\u2714" : "x"), (width/ 2), offset + (bossBarVisible ? 19 : 2), (DungeonHandler.hasBloodkey() ? 0x55FF55 : 0xAA0000)); - drawString(font, DungeonHandler.getWitherKeys()+"x", (width/ 2), offset + (bossBarVisible ? 30 : 13), 0x555555); + drawString(font, (DungeonHandler.hasBloodkey() ? "\u2714" : "x"), (width / 2), offset + (bossBarVisible ? 19 : 2), (DungeonHandler.hasBloodkey() ? 0x55FF55 : 0xAA0000)); + drawString(font, DungeonHandler.getWitherKeys() + "x", (width / 2), offset + (bossBarVisible ? 30 : 13), 0x555555); //CLEARED PERCENTAGE GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); int clearPercent = DungeonHandler.getDungeonCleared(); - String clearPercentage = "Dungeon Cleared: \u00A7" + (clearPercent <= 20 ? "4" : clearPercent <= 50 ? "6" : clearPercent <= 80 ? "e" : "a") + clearPercent + "%"; + String clearPercentage = "Dungeon Cleared: \u00A7" + (clearPercent <= 20 ? "4" : clearPercent <= 50 ? "6" : clearPercent <= 80 ? "e" : "a") + clearPercent + "%"; drawTexturedModalRect((width / 2) + 17, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(clearPercentage) + 3, 14); drawTexturedModalRect(((width / 2) + 17) + font.getStringWidth(clearPercentage) + 3, offset + (bossBarVisible ? 20 : 3), 252, 34, 4, 14); drawString(font, clearPercentage, (width / 2) + 18, offset + (bossBarVisible ? 23 : 6), 0xAAAAAA); @@ -83,21 +84,21 @@ public class DungeonOverlay extends Gui { int secrets = DungeonHandler.getSecrets(); int totalSecrets = DungeonHandler.getTotalSecrets(); String secretsText = "Secrets: " + secrets + "/" + maxSecrets + " (" + totalSecrets + ")"; - drawTexturedModalRect((width/ 2) - 17 - (font.getStringWidth(secretsText)) - 4, offset + (bossBarVisible ? 20 : 3), 0, 34, 2, 14); - drawTexturedModalRect(((width/ 2) - 17 - (font.getStringWidth(secretsText))) - 2, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(secretsText) + 2, 14); - drawString(font, secretsText, (width/ 2) - 17 - (font.getStringWidth(secretsText)) , offset + (bossBarVisible ? 23 : 6), 0xAAAAAA); + drawTexturedModalRect((width / 2) - 17 - (font.getStringWidth(secretsText)) - 4, offset + (bossBarVisible ? 20 : 3), 0, 34, 2, 14); + drawTexturedModalRect(((width / 2) - 17 - (font.getStringWidth(secretsText))) - 2, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(secretsText) + 2, 14); + drawString(font, secretsText, (width / 2) - 17 - (font.getStringWidth(secretsText)), offset + (bossBarVisible ? 23 : 6), 0xAAAAAA); //CRYPTS GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); int crypts = DungeonHandler.getCrypts(); String cryptText = "Crypts: " + crypts; - drawTexturedModalRect((width/ 2) - 17 - (font.getStringWidth(cryptText)) - 4, offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); - drawTexturedModalRect(((width/ 2) - 17 - (font.getStringWidth(cryptText))) - 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(cryptText) + 2, 14); - drawString(font, cryptText, (width/ 2) - 17 - (font.getStringWidth(cryptText)) , offset + (bossBarVisible ? 38 : 21), 0xAAAAAA); + drawTexturedModalRect((width / 2) - 17 - (font.getStringWidth(cryptText)) - 4, offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); + drawTexturedModalRect(((width / 2) - 17 - (font.getStringWidth(cryptText))) - 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(cryptText) + 2, 14); + drawString(font, cryptText, (width / 2) - 17 - (font.getStringWidth(cryptText)), offset + (bossBarVisible ? 38 : 21), 0xAAAAAA); } - public void drawUltimateBar(Minecraft mc, ScaledResolution resolution){ + public void drawUltimateBar(Minecraft mc, ScaledResolution resolution) { if (!SkyblockHud.config.dungeon.hideUltimateBar) { float percentage = mc.thePlayer.experience; SBHConfig.DungeonHud dungeonHud = SkyblockHud.config.dungeon; @@ -106,12 +107,7 @@ public class DungeonOverlay extends Gui { int x = position.getAbsX(resolution, 182); int y = position.getAbsY(resolution, 5); - GenericOverlays.drawLargeBar(mc, - x - 91, y, - percentage, 0.999f, - SpecialColour.specialToChromaRGB(dungeonHud.barLoadColor), - SpecialColour.specialToChromaRGB(dungeonHud.barFullColor), - dungeonHud.barStyle); + GenericOverlays.drawLargeBar(mc, x - 91, y, percentage, 0.999f, SpecialColour.specialToChromaRGB(dungeonHud.barLoadColor), SpecialColour.specialToChromaRGB(dungeonHud.barFullColor), dungeonHud.barStyle); } } @@ -125,8 +121,8 @@ public class DungeonOverlay extends Gui { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); if (!SkyblockHud.config.dungeon.hideDungeonPlayers) { - int[] hardCodedPos = new int[]{5, 42, 79, 116}; - Position[] positions = new Position[]{SkyblockHud.config.dungeon.dungeonPlayer1, SkyblockHud.config.dungeon.dungeonPlayer2, SkyblockHud.config.dungeon.dungeonPlayer3, SkyblockHud.config.dungeon.dungeonPlayer4}; + int[] hardCodedPos = new int[] { 5, 42, 79, 116 }; + Position[] positions = new Position[] { SkyblockHud.config.dungeon.dungeonPlayer1, SkyblockHud.config.dungeon.dungeonPlayer2, SkyblockHud.config.dungeon.dungeonPlayer3, SkyblockHud.config.dungeon.dungeonPlayer4 }; for (int i = 0; i < Math.min(DungeonHandler.getDungeonPlayers().values().size(), 4); i++) { DungeonPlayer player = (DungeonPlayer) DungeonHandler.getDungeonPlayers().values().toArray()[i]; int posX; diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java index d987c86..eeb48e1 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/GenericOverlays.java @@ -3,16 +3,14 @@ package com.thatgravyboat.skyblockhud.overlay; import com.thatgravyboat.skyblockhud.GuiTextures; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.core.util.render.RenderUtils; +import java.awt.Color; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; -import java.awt.Color; - - public class GenericOverlays extends Gui { - public static void drawLargeBar(Minecraft mc, int x, int y, float percentage, float max, int fullColor, int loadingColor, int barStyle){ + public static void drawLargeBar(Minecraft mc, int x, int y, float percentage, float max, int fullColor, int loadingColor, int barStyle) { if (SkyblockHud.hasSkyblockScoreboard()) { mc.renderEngine.bindTexture(GuiTextures.bars); Color color = new Color(percentage == max ? fullColor : loadingColor); @@ -27,7 +25,7 @@ public class GenericOverlays extends Gui { } } - public static void drawSmallBar(Minecraft mc, int x, int y, double percentage, double max, int fullColor, int loadingColor, int barStyle){ + public static void drawSmallBar(Minecraft mc, int x, int y, double percentage, double max, int fullColor, int loadingColor, int barStyle) { if (SkyblockHud.hasSkyblockScoreboard()) { mc.renderEngine.bindTexture(GuiTextures.bars); Color color = new Color(percentage == max ? fullColor : loadingColor); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java index 8cdd44c..23b9df0 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/OverlayHud.java @@ -8,8 +8,11 @@ import com.thatgravyboat.skyblockhud.handlers.CurrencyHandler; import com.thatgravyboat.skyblockhud.handlers.SlayerHandler; import com.thatgravyboat.skyblockhud.handlers.TimeHandler; import com.thatgravyboat.skyblockhud.location.*; -import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; import com.thatgravyboat.skyblockhud.seasons.Season; +import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Locale; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -20,19 +23,16 @@ import net.minecraftforge.client.GuiIngameForge; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; -import java.util.Locale; - public class OverlayHud extends Gui { + private static final FontRenderer font = Minecraft.getMinecraft().fontRendererObj; - + //STATS private static boolean eventToggle; public static boolean bossBarVisible = false; - public void drawClock(int width, int offset, Minecraft mc){ + public void drawClock(int width, int offset, Minecraft mc) { GlStateManager.enableBlend(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); @@ -44,10 +44,9 @@ public class OverlayHud extends Gui { int time12Hour = timeHour >= 12 ? timeHour - 12 : timeHour; String normalTime = (time12Hour == 0 ? "00" : String.valueOf(time12Hour)) + ":" + (timeMin == 0 ? "00" : timeMin) + (timeHour >= 12 ? "pm" : "am"); - drawTexturedModalRect((width/ 2) - 17, offset + (bossBarVisible ? 17 : 0), 0, 0, 34, 34); - drawTexturedModalRect((width/ 2) - 4, offset + (bossBarVisible ? 24 : 7), (timeHour > 19 || timeHour < 4) ? 43 : 43 + 8, 0, 8, 8); - if (SkyblockHud.config.main.twelveHourClock) drawScaledString(0.8f, width/ 2, offset + (bossBarVisible ? 38 : 21), normalTime, (timeHour > 19 || timeHour < 4) ? 0xAFB8CC : 0xFFFF55); - else drawCenteredString(font, militaryTime, (width/ 2), offset + (bossBarVisible ? 38 : 21), (timeHour > 19 || timeHour < 4) ? 0xAFB8CC : 0xFFFF55); + drawTexturedModalRect((width / 2) - 17, offset + (bossBarVisible ? 17 : 0), 0, 0, 34, 34); + drawTexturedModalRect((width / 2) - 4, offset + (bossBarVisible ? 24 : 7), (timeHour > 19 || timeHour < 4) ? 43 : 43 + 8, 0, 8, 8); + if (SkyblockHud.config.main.twelveHourClock) drawScaledString(0.8f, width / 2, offset + (bossBarVisible ? 38 : 21), normalTime, (timeHour > 19 || timeHour < 4) ? 0xAFB8CC : 0xFFFF55); else drawCenteredString(font, militaryTime, (width / 2), offset + (bossBarVisible ? 38 : 21), (timeHour > 19 || timeHour < 4) ? 0xAFB8CC : 0xFFFF55); //PURSE drawPurseAndBits(width, offset, mc); @@ -64,27 +63,24 @@ public class OverlayHud extends Gui { //EXTRA SLOT if (LocationHandler.getCurrentLocation().equals(Locations.YOURISLAND)) { if (IslandHandler.flightTime > 0) drawFlightDuration(width, offset, mc); - } - else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.MUSHROOMDESERT)){ + } else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.MUSHROOMDESERT)) { drawTrapperOrPelts(width, offset, mc); - } - else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)) { - if (DwarvenMineHandler.currentEvent != DwarvenMineHandler.Event.NONE){ + } else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)) { + if (DwarvenMineHandler.currentEvent != DwarvenMineHandler.Event.NONE) { drawDwarvenEvent(width, offset, mc); - }else { + } else { drawMithril(width, offset, mc); } - } - else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK) && ParkIslandHandler.isRaining()){ - if (LocationHandler.getCurrentLocation().equals(Locations.HOWLINGCAVE)){ + } else if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK) && ParkIslandHandler.isRaining()) { + if (LocationHandler.getCurrentLocation().equals(Locations.HOWLINGCAVE)) { drawSlayer(width, offset, mc); - }else drawRainDuration(width, offset, mc); - }else if (SlayerHandler.isDoingSlayer){ + } else drawRainDuration(width, offset, mc); + } else if (SlayerHandler.isDoingSlayer) { drawSlayer(width, offset, mc); } } - public void drawSeasonAndDate(int width, int offset, Minecraft mc){ + public void drawSeasonAndDate(int width, int offset, Minecraft mc) { if (SeasonDateHandler.getCurrentSeason() != Season.ERROR) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); if (mc.thePlayer.ticksExisted % 100 == 0 && eventToggle) eventToggle = false; @@ -98,36 +94,31 @@ public class OverlayHud extends Gui { drawString(font, dateText, (width / 2) + 18, offset + (bossBarVisible ? 23 : 6), 0xffffff); } } - - public void drawLocation(int width, int offset, Minecraft mc){ + + public void drawLocation(int width, int offset, Minecraft mc) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); - drawTexturedModalRect((width/ 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName())), offset + (bossBarVisible ? 20 : 3), 0, 34, 2, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()))) + 2, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()) + 14, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()))) + 4, offset + (bossBarVisible ? 23 : 6), LocationHandler.getCurrentLocation().getCategory().getTexturePos(), 8, 8, 8); - drawString(font, - LocationHandler.getCurrentLocation().getDisplayName(), - (width/ 2) - 19 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName())) , - offset + (bossBarVisible ? 23 : 6), - 0xFFFFFF - ); + drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName())), offset + (bossBarVisible ? 20 : 3), 0, 34, 2, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()))) + 2, offset + (bossBarVisible ? 20 : 3), 2, 34, font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()) + 14, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName()))) + 4, offset + (bossBarVisible ? 23 : 6), LocationHandler.getCurrentLocation().getCategory().getTexturePos(), 8, 8, 8); + drawString(font, LocationHandler.getCurrentLocation().getDisplayName(), (width / 2) - 19 - (font.getStringWidth(LocationHandler.getCurrentLocation().getDisplayName())), offset + (bossBarVisible ? 23 : 6), 0xFFFFFF); } - public void drawRedstone(int width, int offset, Minecraft mc){ + public void drawRedstone(int width, int offset, Minecraft mc) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); int redstoneColor = IslandHandler.redstone > 90 ? 0xFF0000 : IslandHandler.redstone > 75 ? 0xC45B00 : IslandHandler.redstone > 50 ? 0xFFFF55 : 0x55FF55; if (IslandHandler.redstone > 0 && Utils.isPlayerHoldingRedstone(mc.thePlayer)) { - drawTexturedModalRect((width/ 2) - 15, offset + (bossBarVisible ? 51 : 34), 0, 48, 30, 18); - drawTexturedModalRect((width/ 2) - 4, offset + (bossBarVisible ? 51 : 34), 59, 0, 8, 8); - drawCenteredString(mc.fontRendererObj, IslandHandler.redstone+"%", (width/ 2), offset + (bossBarVisible ? 58 : 41), redstoneColor); + drawTexturedModalRect((width / 2) - 15, offset + (bossBarVisible ? 51 : 34), 0, 48, 30, 18); + drawTexturedModalRect((width / 2) - 4, offset + (bossBarVisible ? 51 : 34), 59, 0, 8, 8); + drawCenteredString(mc.fontRendererObj, IslandHandler.redstone + "%", (width / 2), offset + (bossBarVisible ? 58 : 41), redstoneColor); } } - public void drawPurseAndBits(int width, int offset, Minecraft mc){ + public void drawPurseAndBits(int width, int offset, Minecraft mc) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); - int xPos = (width/ 2) + 17; + int xPos = (width / 2) + 17; //COINS drawTexturedModalRect(xPos, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(CurrencyHandler.getCoinsFormatted()) + 11, 14); @@ -150,38 +141,34 @@ public class OverlayHud extends Gui { drawTexturedModalRect(xPos, offset + (bossBarVisible ? 35 : 18), 252, 34, 4, 14); } - public void drawFlightDuration(int width, int offset, Minecraft mc ){ - if (LocationHandler.getCurrentLocation().equals(Locations.YOURISLAND)){ + public void drawFlightDuration(int width, int offset, Minecraft mc) { + if (LocationHandler.getCurrentLocation().equals(Locations.YOURISLAND)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); DecimalFormat flightFormat = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); String duration; - if (IslandHandler.flightTime < 60) duration = IslandHandler.flightTime + "s"; - else if (IslandHandler.flightTime < 3600) duration = flightFormat.format((double)IslandHandler.flightTime / 60) + "m"; - else if (IslandHandler.flightTime < 86400) duration = flightFormat.format((double)IslandHandler.flightTime / 3600) + "hr"; - else if (IslandHandler.flightTime < 86460) duration = flightFormat.format((double)IslandHandler.flightTime / 86400) + "day"; - else duration = flightFormat.format((double)IslandHandler.flightTime / 86400) + "days"; + if (IslandHandler.flightTime < 60) duration = IslandHandler.flightTime + "s"; else if (IslandHandler.flightTime < 3600) duration = flightFormat.format((double) IslandHandler.flightTime / 60) + "m"; else if (IslandHandler.flightTime < 86400) duration = flightFormat.format((double) IslandHandler.flightTime / 3600) + "hr"; else if (IslandHandler.flightTime < 86460) duration = flightFormat.format((double) IslandHandler.flightTime / 86400) + "day"; else duration = flightFormat.format((double) IslandHandler.flightTime / 86400) + "days"; mc.renderEngine.bindTexture(GuiTextures.overlay); - drawTexturedModalRect((width/ 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), 67, 0, 8, 8); - drawString(font, duration, (width/ 2) - 19 - (font.getStringWidth(duration)) , offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); + drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), 67, 0, 8, 8); + drawString(font, duration, (width / 2) - 19 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); } } - public void drawRainDuration(int width, int offset, Minecraft mc ){ - if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK)){ + public void drawRainDuration(int width, int offset, Minecraft mc) { + if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.PARK)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); String duration = "Rain: " + ParkIslandHandler.getRainTime(); - drawTexturedModalRect((width/ 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), 83, 0, 8, 8); - drawString(font, duration, (width/ 2) - 19 - (font.getStringWidth(duration)) , offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); + drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), 83, 0, 8, 8); + drawString(font, duration, (width / 2) - 19 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); } } - public void drawSlayer(int width, int offset, Minecraft mc){ - if (SlayerHandler.isDoingSlayer){ + public void drawSlayer(int width, int offset, Minecraft mc) { + if (SlayerHandler.isDoingSlayer) { int kills = SlayerHandler.progress; int maxKills = SlayerHandler.maxKills; int tier = SlayerHandler.slayerTier; @@ -193,13 +180,13 @@ public class OverlayHud extends Gui { stringBuilder.append(EnumChatFormatting.GREEN); stringBuilder.append(Utils.intToRomanNumeral(tier)); stringBuilder.append(" "); - if (SlayerHandler.isKillingBoss){ + if (SlayerHandler.isKillingBoss) { stringBuilder.append(EnumChatFormatting.RED); stringBuilder.append("Slay Boss!"); - } else if (SlayerHandler.bossSlain){ + } else if (SlayerHandler.bossSlain) { stringBuilder.append(EnumChatFormatting.RED); stringBuilder.append("Boss Slain!"); - } else if (kills == 0 && maxKills == 0){ + } else if (kills == 0 && maxKills == 0) { stringBuilder.append(EnumChatFormatting.RED); stringBuilder.append("Not Slaying!"); } else { @@ -215,37 +202,36 @@ public class OverlayHud extends Gui { drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(text))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(text) + 14, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(text))) + 4, offset + (bossBarVisible ? 38 : 21), slayerType.getX(), 24, 8, 8); drawString(font, text, (width / 2) - 19 - (font.getStringWidth(text)), offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); - } } } - public void drawMithril(int width, int offset, Minecraft mc){ - if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)){ + public void drawMithril(int width, int offset, Minecraft mc) { + if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); String mithril = DwarvenMineHandler.getMithrilFormatted(); - drawTexturedModalRect((width/ 2) - 33 - (font.getStringWidth(mithril)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(mithril))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(mithril) + 14, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(mithril))) + 4, offset + (bossBarVisible ? 38 : 21), 91, 0, 8, 8); - drawString(font, mithril, (width/ 2) - 19 - (font.getStringWidth(mithril)) , offset + (bossBarVisible ? 38 : 21), 0x00C896); + drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(mithril)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(mithril))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(mithril) + 14, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(mithril))) + 4, offset + (bossBarVisible ? 38 : 21), 91, 0, 8, 8); + drawString(font, mithril, (width / 2) - 19 - (font.getStringWidth(mithril)), offset + (bossBarVisible ? 38 : 21), 0x00C896); } } - public void drawTrapperOrPelts(int width, int offset, Minecraft mc){ - if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.MUSHROOMDESERT)){ + public void drawTrapperOrPelts(int width, int offset, Minecraft mc) { + if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.MUSHROOMDESERT)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); - String duration = FarmingIslandHandler.location != Locations.NONE ? FarmingIslandHandler.location.getDisplayName() : ""+FarmingIslandHandler.pelts; - drawTexturedModalRect((width/ 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); - drawTexturedModalRect(((width/ 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), FarmingIslandHandler.location != Locations.NONE ? 123 : 115, 0, 8, 8); - drawString(font, duration, (width/ 2) - 19 - (font.getStringWidth(duration)) , offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); + String duration = FarmingIslandHandler.location != Locations.NONE ? FarmingIslandHandler.location.getDisplayName() : "" + FarmingIslandHandler.pelts; + drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); + drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), FarmingIslandHandler.location != Locations.NONE ? 123 : 115, 0, 8, 8); + drawString(font, duration, (width / 2) - 19 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); } } - public void drawDwarvenEvent(int width, int offset, Minecraft mc){ - if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)){ + public void drawDwarvenEvent(int width, int offset, Minecraft mc) { + if (LocationHandler.getCurrentLocation().getCategory().equals(LocationCategory.DWARVENMINES)) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(GuiTextures.overlay); if (DwarvenMineHandler.eventMax > 0) { @@ -254,7 +240,7 @@ public class OverlayHud extends Gui { drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(duration) + 14, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(duration))) + 4, offset + (bossBarVisible ? 38 : 21), DwarvenMineHandler.currentEvent.x, 0, 8, 8); drawString(font, duration, (width / 2) - 19 - (font.getStringWidth(duration)), offset + (bossBarVisible ? 38 : 21), 0xFFFFFF); - }else { + } else { String text = DwarvenMineHandler.currentEvent.displayName; drawTexturedModalRect((width / 2) - 33 - (font.getStringWidth(text)), offset + (bossBarVisible ? 35 : 18), 0, 34, 2, 14); drawTexturedModalRect(((width / 2) - 33 - (font.getStringWidth(text))) + 2, offset + (bossBarVisible ? 35 : 18), 2, 34, font.getStringWidth(text) + 14, 14); @@ -270,17 +256,16 @@ public class OverlayHud extends Gui { bossBarVisible = BossStatus.statusBarTime > 0 && GuiIngameForge.renderBossHealth && BossbarHandler.bossBarRendered; Minecraft mc = Minecraft.getMinecraft(); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - if (LocationHandler.getCurrentLocation() != Locations.CATACOMBS){ + if (LocationHandler.getCurrentLocation() != Locations.CATACOMBS) { drawClock(event.resolution.getScaledWidth(), SkyblockHud.config.main.mainHudPos.getAbsY(event.resolution, 34), mc); } GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); } } - - public void drawScaledString(float factor, int x, int y, String text, int color){ + public void drawScaledString(float factor, int x, int y, String text, int color) { GlStateManager.scale(factor, factor, 1); - drawCenteredString(font, text, (int)(x/factor), (int)(y/factor), color); - GlStateManager.scale(1/factor, 1/factor, 1); + drawCenteredString(font, text, (int) (x / factor), (int) (y / factor), color); + GlStateManager.scale(1 / factor, 1 / factor, 1); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java b/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java index 9356be6..d6a9709 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/overlay/RPGHud.java @@ -5,6 +5,8 @@ import com.thatgravyboat.skyblockhud.GuiTextures; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.core.config.Position; +import java.text.DecimalFormat; +import java.text.NumberFormat; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; @@ -13,30 +15,31 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.text.DecimalFormat; -import java.text.NumberFormat; - public class RPGHud extends Gui { + private static int mana, maxMana, overflow = 0; private static int health, maxHealth = 0; private static int defense = 0; - public static void updateMana(int current, int max){ + public static void updateMana(int current, int max) { mana = current; maxMana = max; } - public static void updateOverflow(int current){ + public static void updateOverflow(int current) { overflow = current; } - public static void updateHealth(int current, int max){ + public static void updateHealth(int current, int max) { health = current; maxHealth = max; } - public static void updateDefense(int input){ defense = input; } - public static void manaPredictionUpdate(boolean isIncrease, int decrease){ + public static void updateDefense(int input) { + defense = input; + } + + public static void manaPredictionUpdate(boolean isIncrease, int decrease) { mana = isIncrease ? Math.min(mana + (maxMana / 50), maxMana) : mana - decrease; } @@ -49,14 +52,13 @@ public class RPGHud extends Gui { @SubscribeEvent public void renderOverlay(RenderGameOverlayEvent.Post event) { - if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), SkyblockHud.config.renderer.hideXpBar)) - MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Post(new RenderGameOverlayEvent(event.partialTicks, event.resolution), RenderGameOverlayEvent.ElementType.EXPERIENCE)); + if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), SkyblockHud.config.renderer.hideXpBar)) MinecraftForge.EVENT_BUS.post(new RenderGameOverlayEvent.Post(new RenderGameOverlayEvent(event.partialTicks, event.resolution), RenderGameOverlayEvent.ElementType.EXPERIENCE)); if (Utils.overlayShouldRender(event.type, SkyblockHud.hasSkyblockScoreboard(), SkyblockHud.config.rpg.showRpgHud)) { Minecraft mc = Minecraft.getMinecraft(); GlStateManager.enableBlend(); - GlStateManager.color(1.0f,1.0f,1.0f,1.0f); + GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); FontRenderer font = mc.fontRendererObj; - if (mc.thePlayer.getHealth() < mc.thePlayer.getMaxHealth()){ + if (mc.thePlayer.getHealth() < mc.thePlayer.getMaxHealth()) { health = Math.max((int) (maxHealth * (mc.thePlayer.getHealth() / mc.thePlayer.getMaxHealth())), health); } @@ -68,13 +70,13 @@ public class RPGHud extends Gui { boolean rightAligned = position.rightAligned(event.resolution, 120); - drawTexturedModalRect(x,y,rightAligned ? 131 : 5,6,120,47); + drawTexturedModalRect(x, y, rightAligned ? 131 : 5, 6, 120, 47); - float manaWidth = Math.min(57 * ((float)mana/(float)maxMana), 57); - drawTexturedModalRect(rightAligned ? x + 16 : 47 + x,17 + y,rightAligned ? 199 : 0,64,(int)manaWidth,4); + float manaWidth = Math.min(57 * ((float) mana / (float) maxMana), 57); + drawTexturedModalRect(rightAligned ? x + 16 : 47 + x, 17 + y, rightAligned ? 199 : 0, 64, (int) manaWidth, 4); - float healthWidth = Math.min(70 * ((float)health/(float)maxHealth), 70); - drawTexturedModalRect(rightAligned ? x + 3 : 47+ x,22+ y,rightAligned ? 186 : 0,68,(int)healthWidth,5); + float healthWidth = Math.min(70 * ((float) health / (float) maxHealth), 70); + drawTexturedModalRect(rightAligned ? x + 3 : 47 + x, 22 + y, rightAligned ? 186 : 0, 68, (int) healthWidth, 5); if (health > maxHealth) { float absorptionWidth = Math.min(70 * ((float) (health - maxHealth) / (float) maxHealth), 70); @@ -82,22 +84,22 @@ public class RPGHud extends Gui { } float xpWidth = 67 * mc.thePlayer.experience; - drawTexturedModalRect(rightAligned ? x + 7 : 45+ x,28+ y,rightAligned ? 189 : 0,73,(int)xpWidth,4); + drawTexturedModalRect(rightAligned ? x + 7 : 45 + x, 28 + y, rightAligned ? 189 : 0, 73, (int) xpWidth, 4); //Air in water NumberFormat myFormat = NumberFormat.getInstance(); myFormat.setGroupingUsed(true); - if (mc.thePlayer.getAir() < 300){ - float airWidth = 60 * ((float)mc.thePlayer.getAir() / 300); - drawTexturedModalRect(rightAligned ? x + 17 : 39 + x,33+ y,rightAligned ? 192 : 0,82,64,6); - drawTexturedModalRect(rightAligned ? x + 19 : 41+ x,33+ y,rightAligned ? 196 : 0,88,(int)airWidth,4); + if (mc.thePlayer.getAir() < 300) { + float airWidth = 60 * ((float) mc.thePlayer.getAir() / 300); + drawTexturedModalRect(rightAligned ? x + 17 : 39 + x, 33 + y, rightAligned ? 192 : 0, 82, 64, 6); + drawTexturedModalRect(rightAligned ? x + 19 : 41 + x, 33 + y, rightAligned ? 196 : 0, 88, (int) airWidth, 4); } GlStateManager.scale(0.75f, 0.75f, 1); - drawCenteredString(mc.fontRendererObj, ""+mc.thePlayer.experienceLevel, (rightAligned ? 130 : 0) + (int)(15+ x/0.75f), (int)(45+ y/0.75f), 8453920); - GlStateManager.scale(1/0.75f, 1/0.75f, 1); + drawCenteredString(mc.fontRendererObj, "" + mc.thePlayer.experienceLevel, (rightAligned ? 130 : 0) + (int) (15 + x / 0.75f), (int) (45 + y / 0.75f), 8453920); + GlStateManager.scale(1 / 0.75f, 1 / 0.75f, 1); GlStateManager.scale(0.75f, 0.75f, 1); - font.drawString( ChatFormatting.RED + " \u2764 " + health +"/"+maxHealth,(rightAligned ? -40 : 0) + (int)(64+ x/0.75f), (int)(8+ y/0.75f), 0xffffff, true); - GlStateManager.scale(1/0.75f, 1/0.75f, 1); - GlStateManager.color(255,255,255); + font.drawString(ChatFormatting.RED + " \u2764 " + health + "/" + maxHealth, (rightAligned ? -40 : 0) + (int) (64 + x / 0.75f), (int) (8 + y / 0.75f), 0xffffff, true); + GlStateManager.scale(1 / 0.75f, 1 / 0.75f, 1); + GlStateManager.color(255, 255, 255); GlStateManager.disableBlend(); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/playerstats/ActionBarParsing.java b/src/main/java/com/thatgravyboat/skyblockhud/playerstats/ActionBarParsing.java index b287ad6..4e895f9 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/playerstats/ActionBarParsing.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/playerstats/ActionBarParsing.java @@ -3,6 +3,8 @@ package com.thatgravyboat.skyblockhud.playerstats; import com.thatgravyboat.skyblockhud.SkyblockHud; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.overlay.RPGHud; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; import net.minecraftforge.client.event.ClientChatReceivedEvent; @@ -10,9 +12,6 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - public class ActionBarParsing { private static String lastActionBar = ""; @@ -38,7 +37,7 @@ public class ActionBarParsing { private static boolean predict = false; @SubscribeEvent - public void tick(TickEvent.ClientTickEvent event){ + public void tick(TickEvent.ClientTickEvent event) { if (predict) { ticksSinceLastPrediction++; if (ticksSinceLastPrediction == 20 && SkyblockHud.config.rpg.showRpgHud) { @@ -49,18 +48,17 @@ public class ActionBarParsing { } @SubscribeEvent(priority = EventPriority.HIGHEST) - public void onStatusBarHigh(ClientChatReceivedEvent event){ - if (event.type == 2 && SkyblockHud.hasSkyblockScoreboard() && SkyblockHud.config.rpg.showRpgHud){ + public void onStatusBarHigh(ClientChatReceivedEvent event) { + if (event.type == 2 && SkyblockHud.hasSkyblockScoreboard() && SkyblockHud.config.rpg.showRpgHud) { parseActionBar(event.message.getUnformattedText()); } } - @SubscribeEvent(priority = EventPriority.LOW) - public void onStatusBarLow(ClientChatReceivedEvent event){ - if (event.type == 2 && SkyblockHud.hasSkyblockScoreboard() && SkyblockHud.config.rpg.showRpgHud){ + public void onStatusBarLow(ClientChatReceivedEvent event) { + if (event.type == 2 && SkyblockHud.hasSkyblockScoreboard() && SkyblockHud.config.rpg.showRpgHud) { String message = event.message.getUnformattedText(); - if (lastLowEditedActionBar == null || !lastLowActionBar.equals(message)){ + if (lastLowEditedActionBar == null || !lastLowActionBar.equals(message)) { lastLowActionBar = message; message = HealthReplaceRegex.matcher(message).replaceAll(""); message = HealthAbsorptionReplaceRegex.matcher(message).replaceAll(""); @@ -74,7 +72,7 @@ public class ActionBarParsing { } } - public static void parseActionBar(String input){ + public static void parseActionBar(String input) { if (!lastActionBar.equals(input)) { lastActionBar = input; String bar = Utils.removeColor(input); @@ -93,31 +91,30 @@ public class ActionBarParsing { boolean manaOverflowFound = ManaOverflowMatcher.find(); boolean xpFound = XpGainMatcher.find(); - if (healthFound) { try { RPGHud.updateHealth(Integer.parseInt(HealthMatcher.group(1)), Integer.parseInt(HealthMatcher.group(2))); - }catch (Exception ignored){} + } catch (Exception ignored) {} } if (defenseFound) { try { RPGHud.updateDefense(Integer.parseInt(DefenseMatcher.group(1))); - }catch (Exception ignored){} - }else if (!xpFound && !manaUseFound){ - RPGHud.updateDefense(0); + } catch (Exception ignored) {} + } else if (!xpFound && !manaUseFound) { + RPGHud.updateDefense(0); } if (manaFound) { try { RPGHud.updateMana(Integer.parseInt(ManaMatcher.group(1)), Integer.parseInt(ManaMatcher.group(2))); - }catch (Exception ignored){} + } catch (Exception ignored) {} } - if (!manaFound && manaOverflowFound){ + if (!manaFound && manaOverflowFound) { try { RPGHud.updateMana(Integer.parseInt(ManaOverflowMatcher.group(1)), Integer.parseInt(ManaOverflowMatcher.group(2))); RPGHud.updateOverflow(Integer.parseInt(ManaOverflowMatcher.group(3))); - }catch (Exception ignored){} + } catch (Exception ignored) {} } - if (!manaFound){ + if (!manaFound) { if (manaUseFound) { try { RPGHud.manaPredictionUpdate(false, Integer.parseInt(ManaUseMatcher.group(1))); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/seasons/Season.java b/src/main/java/com/thatgravyboat/skyblockhud/seasons/Season.java index e55c0fa..da14204 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/seasons/Season.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/seasons/Season.java @@ -15,29 +15,33 @@ public enum Season { LATEWINTER("latewinter", "Late Winter", 58, 341), ERROR("error", "Error", 0, -1); - - - private final String name; private final String displayName; private final int textureX; private final int yearStartDay; - Season(String name, String displayName, int textureX, int yearStartDay){ + Season(String name, String displayName, int textureX, int yearStartDay) { this.name = name; this.displayName = displayName; this.textureX = textureX; this.yearStartDay = yearStartDay; } - public String getName(){ + public String getName() { return this.name; } - public String getDisplayName(){ + + public String getDisplayName() { return this.displayName; } - public int getTextureX() { return this.textureX; } - public int getYearStartDay() { return yearStartDay; } + + public int getTextureX() { + return this.textureX; + } + + public int getYearStartDay() { + return yearStartDay; + } public static Season get(String id) { try { @@ -46,5 +50,4 @@ public enum Season { return ERROR; } } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/seasons/SeasonDateHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/seasons/SeasonDateHandler.java index 1e22afc..bc36b70 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/seasons/SeasonDateHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/seasons/SeasonDateHandler.java @@ -2,9 +2,8 @@ package com.thatgravyboat.skyblockhud.seasons; import com.thatgravyboat.skyblockhud.Utils; import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; - import java.util.regex.Pattern; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class SeasonDateHandler { @@ -13,45 +12,62 @@ public class SeasonDateHandler { private static String currentEvent = ""; private static String eventTime = ""; - @SubscribeEvent - public void onSidebarLineUpdate(SidebarLineUpdateEvent event){ + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { if (Season.get(SeasonDateHandler.removeDate(event.formattedLine.toLowerCase()).toUpperCase()) != Season.ERROR) { SeasonDateHandler.setCurrentDateAndSeason(SeasonDateHandler.removeSeason(Utils.removeColor(event.formattedLine.toLowerCase().trim())), SeasonDateHandler.removeDate(Utils.removeColor(event.formattedLine.toLowerCase().trim())).toUpperCase()); } } - public static void setCurrentDateAndSeason(int date, String season){ + public static void setCurrentDateAndSeason(int date, String season) { currentDate = date; currentSeason = Season.get(season); } - public static void setCurrentEvent(String event, String time){ + + public static void setCurrentEvent(String event, String time) { currentEvent = event; eventTime = time; } + public static Season getCurrentSeason() { + return currentSeason; + } + + public static int getCurrentDate() { + return currentDate; + } - public static Season getCurrentSeason(){ return currentSeason; } - public static int getCurrentDate(){ return currentDate; } private static String getDataSuffix(int date) { if (date > 10 && date < 14) return "th"; - switch (date % 10){ - case 1: return "st"; - case 2: return "nd"; - case 3: return "rd"; - default: return "th"; + switch (date % 10) { + case 1: + return "st"; + case 2: + return "nd"; + case 3: + return "rd"; + default: + return "th"; } } - public static String getFancySeasonAndDate(){ return currentSeason.getDisplayName() + " " + currentDate + getDataSuffix(currentDate); } - public static String getCurrentEvent() { return currentEvent; } - public static String getCurrentEventTime() { return eventTime; } + public static String getFancySeasonAndDate() { + return (currentSeason.getDisplayName() + " " + currentDate + getDataSuffix(currentDate)); + } + + public static String getCurrentEvent() { + return currentEvent; + } + + public static String getCurrentEventTime() { + return eventTime; + } - public static String removeDate(String seasonDate){ + public static String removeDate(String seasonDate) { return Pattern.compile("[^a-zA-Z]").matcher(seasonDate.toLowerCase()).replaceAll("").replaceAll("st|nd|rd|th", "").trim(); } - public static int removeSeason(String seasonDate){ + public static int removeSeason(String seasonDate) { return Integer.parseInt(Pattern.compile("[^0-9]").matcher(seasonDate.toLowerCase()).replaceAll("").trim()); } } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java index 6734283..5d5615f 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java @@ -1,5 +1,8 @@ package com.thatgravyboat.skyblockhud.tracker; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; import net.minecraft.client.Minecraft; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.DamageSource; @@ -8,24 +11,19 @@ import net.minecraftforge.event.entity.living.LivingDeathEvent; import net.minecraftforge.event.entity.player.AttackEntityEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - public class KillTrackerHandler { public static final Set<UUID> attackedEntities = new HashSet<>(); @SubscribeEvent - public void onAttack(AttackEntityEvent event){ + public void onAttack(AttackEntityEvent event) { if (event.target != null) { attackedEntities.add(event.target.getUniqueID()); } } @SubscribeEvent - public void onDeath(LivingDeathEvent event){ - + public void onDeath(LivingDeathEvent event) { if (false) { //Used for testing System.out.println("----------------------------------------------------------------------------------------------------------------"); @@ -41,32 +39,12 @@ public class KillTrackerHandler { attackedEntities.remove(event.entity.getUniqueID()); } - public static String getDamageSourceString(DamageSource source){ - return "{ " + - source.getDamageType() + - ", " + - source.isDamageAbsolute() + - ", " + - source.isDifficultyScaled() + - ", " + - source.isFireDamage() + - ", " + - source.isProjectile() + - ", " + - source.isUnblockable() + - ", " + - source.isExplosion() + - ", " + - source.isMagicDamage() + - ", " + - source.isCreativePlayer() + - ", " + - source.getSourceOfDamage() + - " }"; + public static String getDamageSourceString(DamageSource source) { + return ("{ " + source.getDamageType() + ", " + source.isDamageAbsolute() + ", " + source.isDifficultyScaled() + ", " + source.isFireDamage() + ", " + source.isProjectile() + ", " + source.isUnblockable() + ", " + source.isExplosion() + ", " + source.isMagicDamage() + ", " + source.isCreativePlayer() + ", " + source.getSourceOfDamage() + " }"); } @SubscribeEvent - public void onWorldChange(EntityJoinWorldEvent event){ + public void onWorldChange(EntityJoinWorldEvent event) { if (event.entity != null) { if (event.entity.getUniqueID().equals(Minecraft.getMinecraft().thePlayer.getUniqueID())) { attackedEntities.clear(); diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java index d7f7512..624ca60 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerFileLoader.java @@ -2,6 +2,12 @@ package com.thatgravyboat.skyblockhud.tracker; import com.google.gson.*; import com.thatgravyboat.skyblockhud.location.Locations; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import net.minecraft.client.Minecraft; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -10,30 +16,23 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class TrackerFileLoader { private static final Gson gson = new GsonBuilder().create(); - public static ItemStack getDisplayItem(JsonObject jsonObject){ + public static ItemStack getDisplayItem(JsonObject jsonObject) { int meta = jsonObject.get("meta").getAsInt(); String displayItemId = jsonObject.get("item").getAsString(); Item item = Item.itemRegistry.getObject(new ResourceLocation(displayItemId)); ItemStack stack = new ItemStack(item, 0, meta); - if (jsonObject.has("skullData") && displayItemId.equals("minecraft:skull") && meta == 3){ - stack.setTagInfo("SkullOwner",getSkullTag(jsonObject.getAsJsonObject("skullData"))); + if (jsonObject.has("skullData") && displayItemId.equals("minecraft:skull") && meta == 3) { + stack.setTagInfo("SkullOwner", getSkullTag(jsonObject.getAsJsonObject("skullData"))); } if (jsonObject.has("enchanted") && jsonObject.get("enchanted").getAsBoolean()) stack.setTagInfo("ench", new NBTTagList()); return stack; } - public static NBTBase getSkullTag(JsonObject skullObject){ + public static NBTBase getSkullTag(JsonObject skullObject) { NBTTagCompound skullOwner = new NBTTagCompound(); NBTTagCompound properties = new NBTTagCompound(); NBTTagList textures = new NBTTagList(); @@ -44,22 +43,21 @@ public class TrackerFileLoader { value.setString("Value", skullObject.get("texture").getAsString()); textures.appendTag(value); - properties.setTag("textures",textures); + properties.setTag("textures", textures); skullOwner.setTag("Properties", properties); return skullOwner; } - private static void loadTrackers(JsonObject object){ + private static void loadTrackers(JsonObject object) { for (JsonElement element : object.get("trackers").getAsJsonArray()) { JsonObject tracker = element.getAsJsonObject(); StringBuilder builder = new StringBuilder(); tracker.get("location").getAsJsonArray().forEach(loc -> builder.append(loc.getAsString())); String location = builder.toString(); - Map<String, ItemStack> stacks = new HashMap<>(); - for (JsonElement drop :tracker.get("drops").getAsJsonArray()) { + for (JsonElement drop : tracker.get("drops").getAsJsonArray()) { JsonObject dropObject = drop.getAsJsonObject(); //Display Item Creation @@ -74,9 +72,9 @@ public class TrackerFileLoader { Map<String, Map<String, ItemStack>> events = new HashMap<>(); events.put(event, stacks); - if (TrackerHandler.trackers.containsKey(location)){ + if (TrackerHandler.trackers.containsKey(location)) { TrackerHandler.trackers.get(location).dropTrackers.put(event, stacks); - }else { + } else { TrackerHandler.trackers.putIfAbsent(location, new TrackerHandler.TrackerData(events)); } @@ -84,28 +82,30 @@ public class TrackerFileLoader { } } - private static JsonElement getTrackerFile(){ + private static JsonElement getTrackerFile() { List<JsonObject> trackerStats = new ArrayList<>(); - TrackerHandler.trackers.forEach((locations, trackerData) -> - trackerData.dropTrackers.forEach((event, drops) -> { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("location", locations); - - if (event == null) jsonObject.add("event", new JsonNull()); - else jsonObject.addProperty("event", event); - - JsonObject dropsData = new JsonObject(); - drops.forEach((s, stack) -> dropsData.addProperty(s, stack.stackSize)); - jsonObject.add("drops", dropsData); - trackerStats.add(jsonObject); - } - )); + TrackerHandler.trackers.forEach( + (locations, trackerData) -> + trackerData.dropTrackers.forEach( + (event, drops) -> { + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("location", locations); + + if (event == null) jsonObject.add("event", new JsonNull()); else jsonObject.addProperty("event", event); + + JsonObject dropsData = new JsonObject(); + drops.forEach((s, stack) -> dropsData.addProperty(s, stack.stackSize)); + jsonObject.add("drops", dropsData); + trackerStats.add(jsonObject); + } + ) + ); JsonArray stats = new JsonArray(); trackerStats.forEach(stats::add); return stats; } - public static void loadTrackersFile(){ + public static void loadTrackersFile() { try { ResourceLocation trackers = new ResourceLocation("skyblockhud:data/trackers.json"); InputStream is = Minecraft.getMinecraft().getResourceManager().getResource(trackers).getInputStream(); @@ -113,59 +113,62 @@ public class TrackerFileLoader { try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { loadTrackers(gson.fromJson(reader, JsonObject.class)); } - }catch (Exception ignored){} + } catch (Exception ignored) {} } - public static boolean loadTrackerStatsFile(File configDirectory){ + public static boolean loadTrackerStatsFile(File configDirectory) { File configFile = new File(configDirectory, "sbh-trackers-stats.json"); try { - if (configFile.createNewFile()){ + if (configFile.createNewFile()) { return true; } try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { JsonObject json = gson.fromJson(reader, JsonObject.class); - if (json.has("trackerStats")){ - json.getAsJsonArray("trackerStats").forEach(element -> { - if (element.isJsonObject()){ - JsonObject object = element.getAsJsonObject(); - String location = object.get("location").getAsString(); - Map<String, Map<String, ItemStack>> trackers = TrackerHandler.trackers.get(location).dropTrackers; - - JsonElement event = object.get("event"); - String eventString = event == null || event.isJsonNull() ? null : event.getAsString(); - Map<String, ItemStack> drops = trackers.get(eventString); - - if (drops != null) { - for (Map.Entry <String ,JsonElement> drop :object.getAsJsonObject("drops").entrySet()) { - if (drops.containsKey(drop.getKey())) { - drops.get(drop.getKey()).stackSize = drop.getValue().getAsInt(); + if (json.has("trackerStats")) { + json + .getAsJsonArray("trackerStats") + .forEach( + element -> { + if (element.isJsonObject()) { + JsonObject object = element.getAsJsonObject(); + String location = object.get("location").getAsString(); + Map<String, Map<String, ItemStack>> trackers = TrackerHandler.trackers.get(location).dropTrackers; + + JsonElement event = object.get("event"); + String eventString = event == null || event.isJsonNull() ? null : event.getAsString(); + Map<String, ItemStack> drops = trackers.get(eventString); + + if (drops != null) { + for (Map.Entry<String, JsonElement> drop : object.getAsJsonObject("drops").entrySet()) { + if (drops.containsKey(drop.getKey())) { + drops.get(drop.getKey()).stackSize = drop.getValue().getAsInt(); + } + } + drops = TrackerHandler.sortTrackers(drops); + trackers.put(eventString, drops); } } - drops = TrackerHandler.sortTrackers(drops); - trackers.put(eventString, drops); } - } - }); + ); } } - } catch(Exception ignored) {} + } catch (Exception ignored) {} return false; } - public static void saveTrackerStatsFile(File configDirectory){ + public static void saveTrackerStatsFile(File configDirectory) { File configFile = new File(configDirectory, "sbh-trackers-stats.json"); try { configFile.createNewFile(); - try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { JsonObject json = new JsonObject(); json.add("trackerStats", getTrackerFile()); writer.write(gson.toJson(json)); } - } catch(IOException ignored) {} + } catch (IOException ignored) {} } - } diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java index 9d8261b..fa2bacf 100644 --- a/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/TrackerHandler.java @@ -6,6 +6,7 @@ import com.thatgravyboat.skyblockhud.core.config.Position; import com.thatgravyboat.skyblockhud.location.LocationHandler; import com.thatgravyboat.skyblockhud.location.Locations; import com.thatgravyboat.skyblockhud.seasons.SeasonDateHandler; +import java.util.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; @@ -15,29 +16,28 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import java.util.*; - public class TrackerHandler { public static class TrackerData { - public Map<String, Map<String,ItemStack>> dropTrackers; - public TrackerData(Map<String, Map<String,ItemStack>> trackers) { + public Map<String, Map<String, ItemStack>> dropTrackers; + + public TrackerData(Map<String, Map<String, ItemStack>> trackers) { this.dropTrackers = trackers; } - public String getDropId(String event){ + public String getDropId(String event) { if (event == null || event.isEmpty() || !eventGoing() || !dropTrackers.containsKey(event.toLowerCase().trim())) return null; return event.toLowerCase().trim(); } - private boolean eventGoing(){ + private boolean eventGoing() { return SeasonDateHandler.getCurrentEventTime().trim().toLowerCase().contains("ends in"); } } public static Map<String, TrackerData> trackers = new HashMap<>(); - public static Map<Locations,String> trackerIds = new HashMap<>(); + public static Map<Locations, String> trackerIds = new HashMap<>(); public static Map<String, ItemStack> sortTrackers(Map<String, ItemStack> map) { List<Map.Entry<String, ItemStack>> list = new ArrayList<>(map.entrySet()); @@ -51,18 +51,18 @@ public class TrackerHandler { return result; } - public static void onItemAdded(String id, int amount, String enchant, int level){ - if (SkyblockHud.hasSkyblockScoreboard() && trackerIds.containsKey(LocationHandler.getCurrentLocation())){ + public static void onItemAdded(String id, int amount, String enchant, int level) { + if (SkyblockHud.hasSkyblockScoreboard() && trackerIds.containsKey(LocationHandler.getCurrentLocation())) { String trackerId = trackerIds.get(LocationHandler.getCurrentLocation()); TrackerData tracked = trackers.get(trackerId); String dropTrackerId = tracked.getDropId(SeasonDateHandler.getCurrentEvent()); - Map<String,ItemStack> tracker = tracked.dropTrackers.get(dropTrackerId); + Map<String, ItemStack> tracker = tracked.dropTrackers.get(dropTrackerId); String dropId = id; - if (enchant != null){ + if (enchant != null) { dropId = enchant.toUpperCase() + ";" + level; } - if (tracker != null && tracker.containsKey(dropId)){ + if (tracker != null && tracker.containsKey(dropId)) { ItemStack stack = tracker.get(dropId); stack.stackSize += amount; tracked.dropTrackers.put(dropTrackerId, sortTrackers(tracker)); @@ -71,7 +71,7 @@ public class TrackerHandler { } public static void drawItemStack(ItemStack stack, int x, int y) { - if(stack == null)return; + if (stack == null) return; RenderItem itemRender = Minecraft.getMinecraft().getRenderItem(); RenderHelper.enableGUIStandardItemLighting(); itemRender.zLevel = -145; @@ -119,6 +119,4 @@ public class TrackerHandler { } } } - - } |