diff options
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
6 files changed, 142 insertions, 81 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java index ab81cd75..d4f7fec5 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/DungeonBlaze.java @@ -1,6 +1,7 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon; import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import me.xmrvizzy.skyblocker.utils.Utils; import me.xmrvizzy.skyblocker.utils.color.QuadColor; import me.xmrvizzy.skyblocker.utils.RenderUtils; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; @@ -14,13 +15,15 @@ public class DungeonBlaze { static Entity lowestBlaze = null; static boolean renderHooked = false; - public static void DungeonBlaze() { + public static void update() { + if (!Utils.isInDungeons) return; MinecraftClient client = MinecraftClient.getInstance(); if(!renderHooked){ WorldRenderEvents.END.register(DungeonBlaze::blazeRenderer); renderHooked = true; } + assert client.world != null; Iterable<Entity> entities = client.world.getEntities(); int highestHealth = 0; int lowestHealth = 99999999; diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java index 69278023..65b9648f 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/Reparty.java @@ -1,5 +1,6 @@ package me.xmrvizzy.skyblocker.skyblock.dungeon; +import me.xmrvizzy.skyblocker.SkyblockerMod; import me.xmrvizzy.skyblocker.chat.ChatListener; import me.xmrvizzy.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; @@ -11,8 +12,9 @@ import java.util.regex.Pattern; public class Reparty extends ChatListener { private static final MinecraftClient client = MinecraftClient.getInstance(); + private static final SkyblockerMod skyblocker = SkyblockerMod.getInstance(); public static final Pattern PLAYER = Pattern.compile(" ([a-zA-Z0-9_]{2,16}) ●"); - private static final int SLEEP_TIME = 600; + private static final int BASE_DELAY = 20; private String[] players; private int playersSoFar; @@ -23,7 +25,7 @@ public class Reparty extends ChatListener { repartying = false; ClientCommandManager.DISPATCHER.register( ClientCommandManager.literal("rp").executes(context -> { - if (!Utils.isSkyblock || repartying) + if (!Utils.isOnSkyblock || repartying) return 0; assert client.player != null; repartying = true; @@ -53,45 +55,31 @@ public class Reparty extends ChatListener { return false; } if (playersSoFar == players.length) - new Thread(this::reparty).start(); + reparty(); return false; } private void reparty() { ClientPlayerEntity playerEntity = client.player; assert playerEntity != null; - StringBuilder sb = new StringBuilder("/p disband"); - for (int i = 0; i < players.length; i++) { - if (i % 5 == 0) { - sleep(); - playerEntity.sendChatMessage(sb.toString()); - sb.setLength(0); - sb.append("/p invite"); + sendCommand(playerEntity, "/p disband", 1); + StringBuilder sb = new StringBuilder(); + int invites = (players.length - 1) / 5 + 1; + for(int i = 0; i < invites; i++) { + sb.setLength(0); + sb.append("/p invite"); + for(int j = 0; j < 5 && i * 5 + j < players.length; j++) { + sb.append(' '); + sb.append(players[i * 5 + j]); } - sb.append(' '); - sb.append(players[i]); + sendCommand(playerEntity, sb.toString(), i + 2); } - if (players.length % 5 != 0) { - sleep(); - playerEntity.sendChatMessage(sb.toString()); - } - repartying = false; + skyblocker.scheduler.schedule(() -> repartying = false, invites + 2); } - private void sleep() { - long sleepStart = System.currentTimeMillis(); - boolean interrupted = false; - long sleepLeft = SLEEP_TIME; - do { - if (interrupted) { - sleepLeft = sleepStart + SLEEP_TIME - System.currentTimeMillis(); - interrupted = false; - } - try { - Thread.sleep(sleepLeft); - } catch (InterruptedException e) { - interrupted = true; - } - } while (interrupted); + private void sendCommand(ClientPlayerEntity player, String command, int delay) { + skyblocker.scheduler.schedule(() -> + player.sendChatMessage(command), delay * BASE_DELAY + ); } } diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java index c6b5be9e..266006b4 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Fetchur.java @@ -33,7 +33,7 @@ public class Fetchur extends ChatListener { static { answers = new HashMap<>(); answers.put("red and soft", new TranslatableText("block.minecraft.red_wool").getString()); - answers.put("yellow and see-through", new TranslatableText("block.minecraft.yellow_stained_glass").getString()); + answers.put("yellow and see through", new TranslatableText("block.minecraft.yellow_stained_glass").getString()); answers.put("circular and sometimes moves", new TranslatableText("item.minecraft.compass").getString()); answers.put("expensive minerals", "Mithril"); answers.put("useful during celebrations", new TranslatableText("item.minecraft.firework_rocket").getString()); diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java index e95a7507..3e117955 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dwarven/Puzzler.java @@ -21,7 +21,6 @@ public class Puzzler extends ChatListener { public boolean onMessage(String[] groups) { int x = 181; int z = 135; - System.out.println(groups[1]); for (char c : groups[1].toCharArray()) { if (c == '▲') z++; else if (c == '▼') z--; 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..daad1d26 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,104 @@ 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) { + int count = stack.getCount(); 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("%-21s", "NPC Price:")) + .formatted(Formatting.YELLOW) + .append(getCoinsMessage(npcPricesJson.get(name).getAsDouble(), count))); } - 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) { + lines.add(new LiteralText(String.format("%-19s", "Lowest BIN Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(lowestPricesJson.get(name).getAsDouble(), count))); } - 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(":", "-"); + } + + // has(name) check because Skytils keeps old data but Moulberry not + if (SkyblockerConfig.get().general.itemTooltip.enableAvgBIN && avgPricesJson.has(name)) { + lines.add(new LiteralText(String.format("%-21s", "Avg. BIN Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(avgPricesJson.get(name).getAsDouble(), count))); } + } 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("%-18s", "Bazaar buy Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("buyPrice").getAsDouble(), count))); + lines.add(new LiteralText(String.format("%-19s", "Bazaar sell Price:")) + .formatted(Formatting.GOLD) + .append(getCoinsMessage(getItem.get("sellPrice").getAsDouble(), count))); } - 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"; + case "Weapons" -> "%-18s"; + case "Armor" -> "%-19s"; + default -> "%-20s"; }; - 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("%-22s", "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 +150,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; } } @@ -117,20 +167,42 @@ public class PriceInfoTooltip { return internalName; } - private static Text getCoinsMessage(double price) { - String priceString = String.format(Locale.ENGLISH, "%1$,.0f", price); - return new LiteralText(priceString + " Coins").formatted(Formatting.DARK_AQUA); + private static Text getCoinsMessage(double price, int count) { + if (count == 1) { + String priceString = String.format(Locale.ENGLISH, "%1$,.0f", price); + return new LiteralText(priceString + " Coins").formatted(Formatting.DARK_AQUA); + } else { + String priceString = String.format(Locale.ENGLISH, "%1$,.0f", price * count); + LiteralText priceText = (LiteralText) new LiteralText(priceString + " Coins ").formatted(Formatting.DARK_AQUA); + priceString = String.format(Locale.ENGLISH, "%1$,.0f", price); + LiteralText priceText2 = (LiteralText) new LiteralText( "(" + priceString + " each)").formatted(Formatting.GRAY); + return priceText.append(priceText2); + } } + 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 +216,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 +231,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 +240,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 +252,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/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java index a0788126..4e5e7f32 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/item/WikiLookup.java @@ -5,7 +5,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import me.xmrvizzy.skyblocker.utils.Utils; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.option.KeyBinding; @@ -49,7 +48,7 @@ public class WikiLookup { } public static void openWiki(Slot slot){ - if (Utils.isSkyblock){ + if (Utils.isOnSkyblock){ id = getSkyblockId(slot); try { //Setting up a connection with the repo |