diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-07 00:31:50 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-07 00:31:50 +0200 |
commit | 99773d6a593c444151503de315f127bea6f74d49 (patch) | |
tree | 9ee1ae505e5f82aba62f10c882af85a3acd6e483 /src/main/java/com/thatgravyboat/skyblockhud/location | |
download | skyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.gz skyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.bz2 skyhanni-99773d6a593c444151503de315f127bea6f74d49.zip |
init lorenz mod
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/location')
9 files changed, 669 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/EndIslandHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/EndIslandHandler.java new file mode 100644 index 000000000..505db19d2 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/EndIslandHandler.java @@ -0,0 +1,53 @@ +package com.thatgravyboat.skyblockhud.location; + +public class EndIslandHandler { + + public enum dragonTypes { + PROTECTOR("Protector Dragon", 9000000), + OLD("Old Dragon", 15000000), + WISE("Wise Dragon", 9000000), + UNSTABLE("Unstable Dragon", 9000000), + YOUNG("Young Dragon", 7500000), + STRONG("Strong Dragon", 9000000), + SUPERIOR("Superior Dragon", 12000000), + NODRAGON("", 0); + + private final String displayName; + private final int maxHealth; + + dragonTypes(String displayName, int maxHealth) { + this.displayName = displayName; + this.maxHealth = maxHealth; + } + + public String getDisplayName() { + return this.displayName; + } + + public int getMaxHealth() { + return this.maxHealth; + } + + public static dragonTypes findDragon(String input) { + if (input.contains(" ")) { + try { + return dragonTypes.valueOf(input.toLowerCase().replace("dragon", "").replace(" ", "").toUpperCase()); + } catch (IllegalArgumentException ignored) { + return NODRAGON; + } + } else { + try { + return dragonTypes.valueOf(input); + } catch (IllegalArgumentException ignored) { + return NODRAGON; + } + } + } + } + + private static dragonTypes currentDragon = dragonTypes.NODRAGON; + + public static void setCurrentDragon(dragonTypes dragon) { + currentDragon = dragon; + } +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/FarmHouseHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/FarmHouseHandler.java new file mode 100644 index 000000000..005d9ff8c --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/FarmHouseHandler.java @@ -0,0 +1,41 @@ +package com.thatgravyboat.skyblockhud.location; + +import com.thatgravyboat.skyblockhud.api.events.ProfileSwitchedEvent; +import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; +import java.util.Arrays; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class FarmHouseHandler { + + public enum Medal { + BRONZE, + SILVER, + GOLD + } + + private static final int[] medals = new int[Medal.values().length]; + + @SubscribeEvent + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { + if (event.formattedLine.contains("medals:")) { + for (Medal value : Medal.values()) { + if (event.formattedLine.contains(value.name())) { + try { + medals[value.ordinal()] = Integer.parseInt(event.formattedLine.replace("medals:", "").replace(value.name(), "").trim()); + } catch (Exception ignored) {} + break; + } + } + } + } + + @SubscribeEvent + public void onProfileSwitch(ProfileSwitchedEvent event) { + Arrays.fill(medals, 0); + } + + public static String getFormattedMedals(Medal medal) { + if (medal == null) return "0"; + return String.valueOf(medals[medal.ordinal()]); + } +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/FarmingIslandHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/FarmingIslandHandler.java new file mode 100644 index 000000000..a4abaaec8 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/FarmingIslandHandler.java @@ -0,0 +1,28 @@ +package com.thatgravyboat.skyblockhud.location; + +import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; +import java.util.Arrays; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class FarmingIslandHandler { + + public static Locations location = Locations.NONE; + public static int pelts; + + @SubscribeEvent + public void onSidebarPost(SidebarPostEvent event) { + boolean isTracking = Arrays.toString(event.arrayScores).toLowerCase().contains("tracker mob location:"); + 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) { + location = Locations.get(event.scores.get(i - 1).toLowerCase()); + break; + } + } + } + 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 new file mode 100644 index 000000000..cc6668a17 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/IslandHandler.java @@ -0,0 +1,67 @@ +package com.thatgravyboat.skyblockhud.location; + +import com.thatgravyboat.skyblockhud.api.events.ProfileSwitchedEvent; +import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; +import com.thatgravyboat.skyblockhud.utils.Utils; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class IslandHandler { + + public static int flightTime; + public static boolean hadFlightTime; + + public static int redstone; + public static boolean hadRedstone; + + @SubscribeEvent + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { + hadFlightTime = checkFlightDuration(event.formattedLine); + hadRedstone = checkRestone(event.formattedLine); + } + + @SubscribeEvent + 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:")) { + String timeString = formatedScoreboardLine.toLowerCase().replace("flight duration:", "").replace(" ", ""); + String[] times = timeString.split(":"); + 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) {} + flightTime = s - 1; + } 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) {} + flightTime = s - 1; + } + return true; + } + return false; + } + + public static boolean checkRestone(String formatedScoreboardLine) { + if (LocationHandler.getCurrentLocation() == Locations.YOURISLAND) { + if (formatedScoreboardLine.toLowerCase().contains("redstone:")) return true; + try { + redstone = formatedScoreboardLine.toLowerCase().contains("redstone:") ? Integer.parseInt(Utils.removeWhiteSpaceAndRemoveWord(formatedScoreboardLine, "redstone:")) : 0; + } 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 new file mode 100644 index 000000000..b6ef6fbac --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/LocationCategory.java @@ -0,0 +1,54 @@ +package com.thatgravyboat.skyblockhud.location; + +import static com.thatgravyboat.skyblockhud.handlers.MapHandler.Maps; + +import com.thatgravyboat.skyblockhud.SkyblockHud; +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), + DWARVENMINES("dwarven_mines", 131, Maps.DWARVEN), + CRYSTALHOLLOWS("crystal_hollows", 139, Maps.CRYSTAL); + + private final String name; + private final int texturePos; + private final MapHandler.Maps map; + + LocationCategory(String name, int texturePos) { + this(name, texturePos, null); + } + + LocationCategory(String name, int texturePos, MapHandler.Maps map) { + this.name = name; + this.texturePos = texturePos; + this.map = map; + } + + public String getName() { + return this.name; + } + + public int getTexturePos() { + return this.texturePos; + } + + public MapHandler.Maps getMap() { + if (this.map != null && SkyblockHud.config.map.mapLocations.contains(this.ordinal() - 2)) return this.map; else return null; + } + + public boolean isMiningCategory() { + return this == LocationCategory.DWARVENMINES || this == LocationCategory.CRYSTALHOLLOWS; + } +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/LocationHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/LocationHandler.java new file mode 100644 index 000000000..cfbfdc324 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/LocationHandler.java @@ -0,0 +1,44 @@ +package com.thatgravyboat.skyblockhud.location; + +import com.thatgravyboat.skyblockhud.api.events.LocationChangeEvent; +import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; +import java.util.Locale; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class LocationHandler { + + private static Locations currentLocation = Locations.NONE; + + @SubscribeEvent + 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")) { + LocationHandler.setCurrentLocation(Locations.GUESTISLAND); + } else { + LocationHandler.handleLocation(event.formattedLine); + } + } + } + + public static void setCurrentLocation(Locations location) { + currentLocation = location; + } + + public static Locations getCurrentLocation() { + return currentLocation; + } + + public static void handleLocation(String locationLine) { + String location = locationLine.replace(" ", "").toUpperCase(Locale.ENGLISH).trim(); + if (location.startsWith("THECATACOMBS")) { + MinecraftForge.EVENT_BUS.post(new LocationChangeEvent(currentLocation, Locations.CATACOMBS)); + currentLocation = Locations.CATACOMBS; + } else { + Locations locations = Locations.get(location.replaceAll("[^A-Za-z0-9]", "")); + MinecraftForge.EVENT_BUS.post(new LocationChangeEvent(currentLocation, locations)); + currentLocation = locations; + } + } +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/Locations.java b/src/main/java/com/thatgravyboat/skyblockhud/location/Locations.java new file mode 100644 index 000000000..5077bce99 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/Locations.java @@ -0,0 +1,161 @@ +package com.thatgravyboat.skyblockhud.location; + +public enum Locations { + //ERROR LOCATIONS + 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), + //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), + //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), + //GOLD MINE + 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), + PIGMENSDEN("pigmensden", "Pigmen'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), + + //THE END + 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), + //BLAZING 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), + //JERRYISLAND + 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), + DWARVENTAVERN("dwarvemtavern", "Dwarven Tavern", 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), + JUNGLETEMPLE("jungletemple", "Jungle Temple", LocationCategory.CRYSTALHOLLOWS), + MITHRILDEPOSITS("mithrildeposits", "Mithril Deposits", LocationCategory.CRYSTALHOLLOWS), + MINESOFDIVAN("minesofdivan", "Mines of Divan", LocationCategory.CRYSTALHOLLOWS), + MAGMAFIELDS("magmafields", "Magma Fields", LocationCategory.CRYSTALHOLLOWS), + KHAZADDM("khzaddm", "Khazad-d\u00FBm", LocationCategory.CRYSTALHOLLOWS), + GOBLINHOLDOUT("goblinholdout", "Goblin Holdout", LocationCategory.CRYSTALHOLLOWS), + GOBLINQUEENSDEN("goblinqueensden", "Goblin Queens Den", LocationCategory.CRYSTALHOLLOWS), + PRECURSORREMNANTS("precursorremnants", "Precursor Remnants", LocationCategory.CRYSTALHOLLOWS), + LOSTPRECURSORCITY("lostprecursorcity", "Lost Precursor City", LocationCategory.CRYSTALHOLLOWS), + CRYSTALNUCLEUS("crystalnucleus", "Crystal Nucleus", LocationCategory.CRYSTALHOLLOWS), + CRYSTALHOLLOWS("crystalhollows", "Crystal Hollows", LocationCategory.CRYSTALHOLLOWS), + FAIRYGROTTO("fairygrotto", "Fairy Grotto", LocationCategory.CRYSTALHOLLOWS); + + private final String name; + private final String displayName; + private final LocationCategory category; + + Locations(String name, String displayName, LocationCategory category) { + this.name = name; + this.displayName = displayName; + this.category = category; + } + + public String getName() { + return this.name; + } + + public String getDisplayName() { + return this.displayName; + } + + public LocationCategory getCategory() { + return this.category; + } + + public static Locations get(String id) { + try { + return Locations.valueOf(id.replace(" ", "").toUpperCase()); + } catch (IllegalArgumentException ex) { + return DEFAULT; + } + } + + @Override + public String toString() { + return this.name; + } +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/MinesHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/MinesHandler.java new file mode 100644 index 000000000..ebde7dba7 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/MinesHandler.java @@ -0,0 +1,192 @@ +package com.thatgravyboat.skyblockhud.location; + +import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent; +import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent; +import com.thatgravyboat.skyblockhud.overlay.MiningHud; +import com.thatgravyboat.skyblockhud.utils.Utils; +import java.lang.ref.WeakReference; +import java.math.RoundingMode; +import java.text.DecimalFormat; +import java.text.DecimalFormatSymbols; +import java.util.Arrays; +import java.util.Locale; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class MinesHandler { + + public enum Event { + NONE(0, "Unknown", false, false), + TICKET(107, "Raffle", true, true), + GOBLIN(99, "Goblin Raid", true, true), + WIND(0, "Gone With The Wind", false, false), + TOGETHER(171, "Better Together", false, true); + + public int x; + public String displayName; + public boolean needsMax; + public boolean display; + + Event(int x, String displayName, boolean needsMax, boolean display) { + this.x = x; + this.displayName = displayName; + this.needsMax = needsMax; + this.display = display; + } + } + + public static int mithril; + public static int gemstone; + + public static int eventMax; + public static int eventProgress; + public static Event currentEvent; + + private static final DecimalFormat NORMAL_FORMATTER = new DecimalFormat("#,###", DecimalFormatSymbols.getInstance(Locale.CANADA)); + private static final DecimalFormat SHORT_FORMATTER = new DecimalFormat("#.#", DecimalFormatSymbols.getInstance(Locale.CANADA)); + + static { + SHORT_FORMATTER.setRoundingMode(RoundingMode.FLOOR); + } + + public static String getMithrilFormatted() { + String output = NORMAL_FORMATTER.format(mithril); + if (output.equals(".0")) output = "0.0"; else if (output.equals(",0")) output = "0,0"; + return output; + } + + public static String getMithrilShortFormatted() { + return mithril > 999 ? SHORT_FORMATTER.format((double) mithril / 1000) + "k" : String.valueOf(mithril); + } + + public static String getGemstoneFormatted() { + String output = NORMAL_FORMATTER.format(gemstone); + if (output.equals(".0")) output = "0.0"; else if (output.equals(",0")) output = "0,0"; + return output; + } + + public static String getGemstoneShortFormatted() { + return gemstone > 999 ? SHORT_FORMATTER.format((double) gemstone / 1000) + "k" : String.valueOf(gemstone); + } + + public static void parseMithril(String line) { + try { + mithril = Integer.parseInt(line.toLowerCase().replace("mithril powder:", "").trim()); + } catch (Exception ignored) {} + } + + public static void parseGemstone(String line) { + try { + gemstone = Integer.parseInt(line.toLowerCase().replace("gemstone powder:", "").trim()); + } catch (Exception ignored) {} + } + + @SubscribeEvent + public void onSidebarLineUpdate(SidebarLineUpdateEvent event) { + if (event.formattedLine.toLowerCase().contains("heat")) { + try { + MiningHud.setHeat(Integer.parseInt(event.formattedLine.toLowerCase().replace("heat:", "").trim())); + } catch (Exception ignored) {} + } + if (event.formattedLine.toLowerCase().contains("mithril")) { + try { + mithril = Integer.parseInt(event.formattedLine.toLowerCase().replace("mithril:", "").trim()); + } catch (Exception ignored) {} + } + if (event.formattedLine.toLowerCase().contains("gemstone")) { + try { + gemstone = Integer.parseInt(event.formattedLine.toLowerCase().replace("gemstone:", "").trim()); + } catch (Exception ignored) {} + } + if (event.formattedLine.toLowerCase().contains("event")) { + if (event.formattedLine.toLowerCase().contains("raffle")) { + MinesHandler.currentEvent = Event.TICKET; + } else if (event.formattedLine.toLowerCase().contains("goblin raid")) { + MinesHandler.currentEvent = Event.GOBLIN; + } + } + if (event.formattedLine.equalsIgnoreCase("wind compass")) { + MinesHandler.currentEvent = Event.WIND; + } + if (event.formattedLine.toLowerCase(Locale.ENGLISH).contains("nearby players")) { + MinesHandler.currentEvent = Event.TOGETHER; + try { + MinesHandler.eventProgress = Integer.parseInt(event.formattedLine.toLowerCase().replace("nearby players:", "").trim()); + } catch (Exception ignored) {} + } + + if (MinesHandler.currentEvent != Event.NONE) { + if (MinesHandler.currentEvent == Event.TICKET) { + 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) {} + } + } else if (MinesHandler.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) {} + } + } + } + } + + @SubscribeEvent + public void onSidebarPost(SidebarPostEvent event) { + String arrayString = Arrays.toString(event.arrayScores); + boolean hasEvent = arrayString.toLowerCase().contains("event:"); + boolean hasWind = arrayString.toLowerCase().contains("wind compass"); + boolean hasNearbyPlayers = arrayString.toLowerCase().contains("nearby players"); + + if (!hasEvent && !hasWind && !hasNearbyPlayers) { + MinesHandler.currentEvent = Event.NONE; + MinesHandler.eventProgress = 0; + MinesHandler.eventMax = 0; + } + if (!arrayString.toLowerCase().contains("heat:")) { + MiningHud.setHeat(0); + } + } + + public static WeakReference<PrehistoricEggProgress> getEggColorAndProgress(ItemStack stack) { + String id = Utils.getItemCustomId(stack); + if (id == null || !id.equals("PREHISTORIC_EGG")) return null; + NBTTagCompound extraAttributes = stack.getTagCompound().getCompoundTag("ExtraAttributes"); + if (!extraAttributes.hasKey("blocks_walked")) return null; + PrehistoricEggProgress progress = new PrehistoricEggProgress(); + int walked = extraAttributes.getInteger("blocks_walked"); + if (walked < 4000) { + progress.currentColor = 0xffffff; + progress.progress = walked / 4000f; + } else if (walked < 10000) { + progress.currentColor = 0x55FF55; + progress.progress = (walked - 4000f) / 6000f; + } else if (walked < 20000) { + progress.currentColor = 0x5555FF; + progress.progress = (walked - 10000f) / 10000f; + } else if (walked < 40000) { + progress.currentColor = 0xAA00AA; + progress.progress = (walked - 20000f) / 20000f; + } else if (walked < 100000) { + progress.currentColor = 0xFFAA00; + progress.progress = (walked - 40000f) / 60000f; + } + return new WeakReference<>(progress); + } + + public static class PrehistoricEggProgress { + + public float progress; + public int currentColor; + } +} diff --git a/src/main/java/com/thatgravyboat/skyblockhud/location/ParkIslandHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/location/ParkIslandHandler.java new file mode 100644 index 000000000..b9628d008 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/location/ParkIslandHandler.java @@ -0,0 +1,29 @@ +package com.thatgravyboat.skyblockhud.location; + +import javax.annotation.Nullable; + +public class ParkIslandHandler { + + private static boolean isRaining = false; + private static String rainTime = ""; + + 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 { + rainTime = tabLine.toLowerCase().replace("rain:", "").replace(" ", ""); + isRaining = true; + } + } + } + + public static String getRainTime() { + return rainTime; + } + + public static boolean isRaining() { + return isRaining; + } +} |