diff options
author | Fix3dll <serhanduzce@gmail.com> | 2022-02-19 02:10:08 +0300 |
---|---|---|
committer | Fix3dll <serhanduzce@gmail.com> | 2022-02-19 02:10:08 +0300 |
commit | a15e9811418c3c1d6cc632db3aede3cb4e8112c2 (patch) | |
tree | abb8d2ad48f9c52f932ffe56d633c23c8c2bfea5 | |
parent | deccbf3fd4d14577effd5d58180e45ee7d64d079 (diff) | |
download | Skyblocker-a15e9811418c3c1d6cc632db3aede3cb4e8112c2.tar.gz Skyblocker-a15e9811418c3c1d6cc632db3aede3cb4e8112c2.tar.bz2 Skyblocker-a15e9811418c3c1d6cc632db3aede3cb4e8112c2.zip |
customizable and improved item tooltip
-rw-r--r-- | gradle.properties | 6 | ||||
-rwxr-xr-x | gradlew | 2 | ||||
-rw-r--r-- | gradlew.bat | 2 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java | 12 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java | 137 | ||||
-rw-r--r-- | src/main/resources/assets/skyblocker/lang/en_us.json | 6 |
6 files changed, 122 insertions, 43 deletions
diff --git a/gradle.properties b/gradle.properties index 41a9c7fc..f1e32644 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -org.gradle.jvmargs=-Xmx1G +org.gradle.jvmargs=-Xmx1G -Dfile.encoding=UTF-8 -Duser.language=en -Duser.country=US # Fabric Properties (https://fabricmc.net/versions.html) minecraft_version=1.18.1 @@ -10,9 +10,9 @@ fabric_version=0.44.0+1.18 # Dependencies ## Cloth Api (https://www.curseforge.com/minecraft/mc-mods/cloth-config/files) -clothconfig_version=6.1.48 +clothconfig_version=6.1.50 ## Mod Menu (https://www.curseforge.com/minecraft/mc-mods/modmenu/files) -mod_menu_version=3.0.0 +mod_menu_version=3.0.1 # Mod Properties mod_version = 1.5.0 @@ -44,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m" "-Dfile.encoding=UTF-8" "-Duser.language=en" "-Duser.country=US"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/gradlew.bat b/gradlew.bat index 107acd32..afa9efaa 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -33,7 +33,7 @@ set APP_HOME=%DIRNAME% for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" "-Dfile.encoding=UTF-8" "-Duser.language=en" "-Duser.country=US" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java index 9471620b..231ee697 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java +++ b/src/main/java/me/xmrvizzy/skyblocker/config/SkyblockerConfig.java @@ -42,6 +42,10 @@ public class SkyblockerConfig implements ConfigData { @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) public Quicknav quicknav = new Quicknav(); + @ConfigEntry.Category("itemTooltip") + @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) + public ItemTooltip itemTooltip = new ItemTooltip(); + @ConfigEntry.Gui.Excluded public List<Integer> lockedSlots = new ArrayList<>(); } @@ -66,6 +70,14 @@ public class SkyblockerConfig implements ConfigData { public boolean enableQuicknav = true; } + public static class ItemTooltip { + public boolean enableNPCPrice = true; + public boolean enableAvgBIN = true; + public boolean enableLowestBIN = true; + public boolean enableBazaarPrice = true; + public boolean enableMuseumDate = true; + } + public static class Locations { @ConfigEntry.Category("dungeons") @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java index ab24ff27..9bf3f851 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/PriceInfoTooltip.java @@ -1,8 +1,8 @@ package me.xmrvizzy.skyblocker.skyblock.item; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; import net.minecraft.item.ItemStack; @@ -20,55 +20,101 @@ import java.net.URL; import java.time.Month; import java.util.List; import java.util.Locale; +import java.util.Timer; +import java.util.TimerTask; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; public class PriceInfoTooltip { - private static JsonObject shopPricesJson; + private static JsonObject npcPricesJson; private static JsonObject bazaarPricesJson; - private static JsonObject auctionPricesJson; - private static JsonObject lbAuctionPricesJson; + private static JsonObject avgPricesJson; + private static JsonObject lowestPricesJson; private static JsonObject isMuseumJson; - public static void onInjectTooltip(ItemStack stack, TooltipContext context, List<Text> list) { + public static void onInjectTooltip(ItemStack stack, TooltipContext context, List<Text> lines) { String name = getInternalNameFromNBT(stack); String timestamp = getTimestamp(stack); - List<String> listString = list.stream() + List<String> listString = lines.stream() .map(Text::getString) .collect(Collectors.toList()); + try { - if (!listString.contains("NPC Price") && shopPricesJson != null && shopPricesJson.has(name)) { - JsonElement getPrice = shopPricesJson.get(name); - list.add(new LiteralText(String.format("%-23s", "NPC Price:")).formatted(Formatting.YELLOW).append(getCoinsMessage(getPrice.getAsDouble()))); + if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice + && !listString.contains("NPC Price") && npcPricesJson != null && npcPricesJson.has(name)) { + + lines.add(new LiteralText(String.format("%-23s", "NPC Price:")) + .formatted(Formatting.YELLOW) + .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble()))); } - if ((!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price")) && bazaarPricesJson != null && bazaarPricesJson.has(name)) { - JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); - list.add(new LiteralText(String.format("%-19s", "Bazaar buy Price:")).formatted(Formatting.GOLD).append(getCoinsMessage(getItem.get("buyPrice").getAsDouble()))); - list.add(new LiteralText(String.format("%-20s", "Bazaar sell Price:")).formatted(Formatting.GOLD).append(getCoinsMessage(getItem.get("sellPrice").getAsDouble()))); - } else if ((!listString.contains("Avg. BIN Price") && auctionPricesJson != null && auctionPricesJson.has(name)) || (!listString.contains("Lowest BIN Price") && lbAuctionPricesJson != null && lbAuctionPricesJson.has(name))) { - if (!listString.contains("Lowest BIN Price") && lbAuctionPricesJson != null && lbAuctionPricesJson.has(name)) { - JsonElement getPrice = lbAuctionPricesJson.get(name); - list.add(new LiteralText(String.format("%-21s", "Lowest BIN Price:")).formatted(Formatting.GOLD).append(getCoinsMessage(getPrice.getAsDouble()))); + + if ((!listString.contains("Avg. BIN Price") && avgPricesJson != null && avgPricesJson.has(name)) + || (!listString.contains("Lowest BIN Price") && lowestPricesJson != null && lowestPricesJson.has(name))) { + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN && lowestPricesJson != null) { + lines.add(new LiteralText(String.format("%-21s", "Lowest BIN Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble()))); } - if (!listString.contains("Avg. BIN Price") && auctionPricesJson != null && auctionPricesJson.has(name)) { - JsonElement getPrice = auctionPricesJson.get(name); - list.add(new LiteralText(String.format("%-22s", "Avg. BIN Price:")).formatted(Formatting.GOLD).append(getCoinsMessage(getPrice.getAsDouble()))); + + // Change format from Skytils to Moulberry's for Avg. BIN + if (name.contains("PET-")) { + name = name.replace("PET-", "") + .replace("0", "COMMON") + .replace("1", "UNCOMMON") + .replace("2", "RARE") + .replace("3", "EPIC") + .replace("4", "LEGENDARY") + .replace("5", "MYTHIC") + .replace("-", ";"); + } else if (name.contains("ENCHANTED_BOOK-")) { + name = name.replace("ENCHANTED_BOOK-", "").replace("-", ";"); + } else { + name = name.replace(":", "-"); + } + + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && avgPricesJson != null) { + lines.add(new LiteralText(String.format("%-22s", "Avg. BIN Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(avgPricesJson.get(name).getAsDouble()))); } + } else if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice + && (!listString.contains("Bazaar buy Price") || !listString.contains("Bazaar sell Price")) + && bazaarPricesJson != null && bazaarPricesJson.has(name)) { + + JsonObject getItem = bazaarPricesJson.getAsJsonObject(name); + lines.add(new LiteralText(String.format("%-19s", "Bazaar buy Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("buyPrice").getAsDouble()))); + lines.add(new LiteralText(String.format("%-20s", "Bazaar sell Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("sellPrice").getAsDouble()))); } - if (!listString.contains("Museum") && isMuseumJson != null && isMuseumJson.has(name)) { + if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate + && !listString.contains("Museum") && isMuseumJson != null && isMuseumJson.has(name)) { + String itemCategory = isMuseumJson.get(name).toString().replaceAll("\"", ""); String format = switch (itemCategory) { case "Weapons" -> "%-19s"; case "Armor" -> "%-20s"; default -> "%-21s"; }; - list.add(new LiteralText(String.format(format, "Museum: (" + itemCategory + ")")).formatted(Formatting.LIGHT_PURPLE).append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED))); - } else if (!listString.contains("Obtained") && timestamp != null) { - list.add(new LiteralText(String.format("%-23s", "Obtained: ")).formatted(Formatting.LIGHT_PURPLE).append(new LiteralText(timestamp).formatted(Formatting.RED))); + + lines.add(new LiteralText(String.format(format, "Museum: (" + itemCategory + ")")) + .formatted(Formatting.LIGHT_PURPLE) + .append(new LiteralText(timestamp != null ? timestamp : "").formatted(Formatting.RED))); + } else if (!listString.contains("Obtained") && timestamp != null + && SkyblockerConfig.get().general.itemTooltip.enableMuseumDate) { + + lines.add(new LiteralText(String.format("%-23s", "Obtained: ")) + .formatted(Formatting.LIGHT_PURPLE) + .append(new LiteralText(timestamp).formatted(Formatting.RED))); } } catch (Exception e) { - assert MinecraftClient.getInstance().player != null; + if (MinecraftClient.getInstance().player == null) { + throw new RuntimeException("[Skyblocker] client.player cannot be null!"); + } MinecraftClient.getInstance().player.sendMessage(new LiteralText(e.toString()), false); } @@ -101,15 +147,16 @@ public class PriceInfoTooltip { NbtCompound ea = tag.getCompound("ExtraAttributes"); if (ea.contains("id", 8)) { - internalName = ea.getString("id").replaceAll(":", "-"); + internalName = ea.getString("id"); } else { return null; } + if ("ENCHANTED_BOOK".equals(internalName)) { NbtCompound enchants = ea.getCompound("enchantments"); for (String enchName : enchants.getKeys()) { - internalName = enchName.toUpperCase() + ";" + enchants.getInt(enchName); + internalName += "-" + enchName.toUpperCase() + "-" + enchants.getInt(enchName); break; } } @@ -122,15 +169,29 @@ public class PriceInfoTooltip { return new LiteralText(priceString + " Coins").formatted(Formatting.DARK_AQUA); } + public static boolean firstRun = true; public static void init() { - new Thread(PriceInfoTooltip::downloadPrices).start(); - new Thread(PriceInfoTooltip::downloadLBPrices).start(); - new Thread(PriceInfoTooltip::downloadBazaarPrices).start(); - new Thread(PriceInfoTooltip::downloadShopPrices).start(); - new Thread(PriceInfoTooltip::downloadIsMuseum).start(); + TimerTask repeatedTask = new TimerTask() { + public void run() { + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN || PriceInfoTooltip.firstRun) + CompletableFuture.runAsync(PriceInfoTooltip::downloadAvgPrices); + if (SkyblockerConfig.get().general.itemTooltip.enableLowestBIN || PriceInfoTooltip.firstRun) + CompletableFuture.runAsync(PriceInfoTooltip::downloadLowestPrices); + if (SkyblockerConfig.get().general.itemTooltip.enableBazaarPrice || PriceInfoTooltip.firstRun) + CompletableFuture.runAsync(PriceInfoTooltip::downloadBazaarPrices); + if (SkyblockerConfig.get().general.itemTooltip.enableNPCPrice || PriceInfoTooltip.firstRun) + CompletableFuture.runAsync(PriceInfoTooltip::downloadNPCPrices); + if (SkyblockerConfig.get().general.itemTooltip.enableMuseumDate || PriceInfoTooltip.firstRun) + CompletableFuture.runAsync(PriceInfoTooltip::downloadIsMuseum); + } + }; + + firstRun = false; + Timer timer = new Timer("PriceInfoDownloader"); + timer.scheduleAtFixedRate(repeatedTask, 0L, 1000L * 60L); } - private static void downloadPrices() { + private static void downloadAvgPrices() { JsonObject result = null; try { URL apiAddr = new URL("https://moulberry.codes/auction_averages_lbin/3day.json.gz"); @@ -144,7 +205,7 @@ public class PriceInfoTooltip { } catch (IOException e) { LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download auction item prices!", e); } - auctionPricesJson = result; + avgPricesJson = result; } private static void downloadBazaarPrices() { @@ -159,7 +220,7 @@ public class PriceInfoTooltip { bazaarPricesJson = result; } - private static void downloadLBPrices() { + private static void downloadLowestPrices() { JsonObject result = null; try { URL apiAddr = new URL("https://sbe-stole-skytils.design/api/auctions/lowestbins"); @@ -168,10 +229,10 @@ public class PriceInfoTooltip { } catch (IOException e) { LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download lb item prices!", e); } - lbAuctionPricesJson = result; + lowestPricesJson = result; } - private static void downloadShopPrices() { + private static void downloadNPCPrices() { JsonObject result = null; try { URL apiAddr = new URL("https://hysky.de/api/npcprice"); @@ -180,7 +241,7 @@ public class PriceInfoTooltip { } catch (IOException e) { LogManager.getLogger(PriceInfoTooltip.class.getName()).warn("[Skyblocker] Failed to download shop item prices!", e); } - shopPricesJson = result; + npcPricesJson = result; } private static void downloadIsMuseum() { diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 4e7d88bb..66b1c17e 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -10,6 +10,12 @@ "text.autoconfig.skyblocker.option.general.bars.enableBars": "Enable Bars", "text.autoconfig.skyblocker.option.general.quicknav": "Quicknav", "text.autoconfig.skyblocker.option.general.quicknav.enableQuicknav": "Enable Quicknav", + "text.autoconfig.skyblocker.option.general.itemTooltip": "Item Tooltip", + "text.autoconfig.skyblocker.option.general.itemTooltip.enableNPCPrice": "Enable NPC Price", + "text.autoconfig.skyblocker.option.general.itemTooltip.enableAvgBIN": "Enable Avg. BIN Price", + "text.autoconfig.skyblocker.option.general.itemTooltip.enableLowestBIN": "Enable Lowest BIN Price", + "text.autoconfig.skyblocker.option.general.itemTooltip.enableBazaarPrice": "Enable Bazaar buy/sell Price", + "text.autoconfig.skyblocker.option.general.itemTooltip.enableMuseumDate": "Enable Museum & Date", "text.autoconfig.skyblocker.category.richPresence": "Discord Rich Presence", "text.autoconfig.skyblocker.option.richPresence.info": "Skyblock Info", |