diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java | 181 |
1 files changed, 133 insertions, 48 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java index 6fa03816..4446c1a7 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/DwarvenHud.java @@ -3,7 +3,10 @@ package de.hysky.skyblocker.skyblock.dwarven; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.tabhud.util.Colors; import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudCommsWidget; +import de.hysky.skyblocker.skyblock.tabhud.widget.hud.HudPowderWidget; +import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.scheduler.Scheduler; +import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.IntIntPair; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; @@ -25,6 +28,9 @@ public class DwarvenHud { public static final MinecraftClient client = MinecraftClient.getInstance(); public static List<Commission> commissionList = new ArrayList<>(); + public static String mithrilPowder = "0"; + public static String gemStonePowder = "0"; + public static final List<Pattern> COMMISSIONS = Stream.of( "(?:Titanium|Mithril|Hard Stone) Miner", "(?:Ice Walker|Golden Goblin|(?<!Golden )Goblin|Goblin Raid|Automaton|Sludge|Team Treasurite Member|Yog|Boss Corleone|Thyst) Slayer", @@ -39,6 +45,8 @@ public class DwarvenHud { "(?:Amber|Sapphire|Jade|Amethyst|Topaz) Crystal Hunter", "Chest Looter").map(s -> Pattern.compile("^.*(" + s + "): (\\d+\\.?\\d*%|DONE)")) .collect(Collectors.toList()); + public static final Pattern MITHRIL_PATTERN = Pattern.compile("Mithril Powder: [0-9,]+"); + public static final Pattern GEMSTONE_PATTERN = Pattern.compile("Gemstone Powder: [0-9,]+"); public static void init() { ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(ClientCommandManager.literal("skyblocker") @@ -47,94 +55,162 @@ public class DwarvenHud { .executes(Scheduler.queueOpenScreenCommand(DwarvenHudConfigScreen::new)))))); HudRenderCallback.EVENT.register((context, tickDelta) -> { - if (!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabled + if ((!SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions && !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) || client.options.playerListKey.isPressed() || client.player == null - || commissionList.isEmpty()) { + || (!Utils.isInDwarvenMines() && !Utils.isInCrystalHollows())) { return; } - render(HudCommsWidget.INSTANCE, context, SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y, commissionList); + + render(HudCommsWidget.INSTANCE, HudPowderWidget.INSTANCE, context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.x, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.y, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderX, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.powderY, + commissionList); }); } - public static IntIntPair getDimForConfig(List<Commission> commissions) { + /** + * Gets the dimensions (width, height) for the commissions hud and the powder hud + * @param commissions what commissions to get the dimensions for + * @return a {@link Pair} of {@link IntIntPair} with the first pair being for the commissions hud and the second pair being for the powder hud + */ + public static Pair<IntIntPair,IntIntPair> getDimForConfig(List<Commission> commissions) { return switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) { case SIMPLE -> { HudCommsWidget.INSTANCE_CFG.updateData(commissions, false); - yield IntIntPair.of( - HudCommsWidget.INSTANCE_CFG.getWidth(), - HudCommsWidget.INSTANCE_CFG.getHeight()); + yield Pair.of( + IntIntPair.of( + HudCommsWidget.INSTANCE_CFG.getWidth(), + HudCommsWidget.INSTANCE_CFG.getHeight()), + IntIntPair.of( + HudPowderWidget.INSTANCE_CFG.getWidth(), + HudPowderWidget.INSTANCE_CFG.getHeight()) + ); } case FANCY -> { HudCommsWidget.INSTANCE_CFG.updateData(commissions, true); - yield IntIntPair.of( - HudCommsWidget.INSTANCE_CFG.getWidth(), - HudCommsWidget.INSTANCE_CFG.getHeight()); + yield Pair.of( + IntIntPair.of( + HudCommsWidget.INSTANCE_CFG.getWidth(), + HudCommsWidget.INSTANCE_CFG.getHeight()), + IntIntPair.of( + HudPowderWidget.INSTANCE_CFG.getWidth(), + HudPowderWidget.INSTANCE_CFG.getHeight()) + ); } - default -> IntIntPair.of(200, 20 * commissions.size()); + default -> Pair.of( + IntIntPair.of( + 200, + 20 * commissions.size()), + IntIntPair.of( + 200, + 40) + ); }; } - public static void render(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List<Commission> commissions) { + public static void render(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) { switch (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.style) { - case SIMPLE -> renderSimple(hcw, context, hudX, hudY, commissions); - case FANCY -> renderFancy(hcw, context, hudX, hudY, commissions); - case CLASSIC -> renderClassic(context, hudX, hudY, commissions); + case SIMPLE -> renderSimple(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions); + case FANCY -> renderFancy(hcw,hpw, context, comHudX, comHudY,powderHudX,powderHudY, commissions); + case CLASSIC -> renderClassic(context, comHudX, comHudY,powderHudX,powderHudY, commissions); } } - public static void renderClassic(DrawContext context, int hudX, int hudY, List<Commission> commissions) { + /** + * Renders hud to window without using the widget rendering + * @param context DrawContext to draw the hud to + * @param comHudX X coordinate of the commissions hud + * @param comHudY Y coordinate of the commissions hud + * @param powderHudX X coordinate of the powder hud + * @param powderHudY Y coordinate of the powder hud + * @param commissions the commissions to render to the commissions hud + */ + public static void renderClassic(DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) { if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground) { - context.fill(hudX, hudY, hudX + 200, hudY + (20 * commissions.size()), 0x64000000); + context.fill(comHudX, comHudY, comHudX + 200, comHudY + (20 * commissions.size()), 0x64000000); + context.fill(powderHudX, powderHudY, powderHudX + 200, powderHudY + 40, 0x64000000); } + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { + int y = 0; + for (Commission commission : commissions) { + float percentage; + if (!commission.progression().contains("DONE")) { + percentage = Float.parseFloat(commission.progression().substring(0, commission.progression().length() - 1)); + } else { + percentage = 100f; + } - int y = 0; - for (Commission commission : commissions) { - float percentage; - if (!commission.progression().contains("DONE")) { - percentage = Float.parseFloat(commission.progression().substring(0, commission.progression().length() - 1)); - } else { - percentage = 100f; + context + .drawTextWithShadow(client.textRenderer, + Text.literal(commission.commission + ": ").formatted(Formatting.AQUA) + .append(Text.literal(commission.progression).formatted(Colors.hypixelProgressColor(percentage))), + comHudX + 5, comHudY + y + 5, 0xFFFFFFFF); + y += 20; } - + } + if(SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) { + //render mithril powder then gemstone + context + .drawTextWithShadow(client.textRenderer, + Text.literal("Mithril: " + mithrilPowder).formatted(Formatting.AQUA), + powderHudX + 5, powderHudY + 5, 0xFFFFFFFF); context .drawTextWithShadow(client.textRenderer, - Text.literal(commission.commission + ": ") - .styled(style -> style.withColor(Formatting.AQUA)) - .append(Text.literal(commission.progression) - .styled(style -> style.withColor(Colors.hypixelProgressColor(percentage)))), - hudX + 5, hudY + y + 5, 0xFFFFFFFF); - y += 20; + Text.literal("Gemstone: " + gemStonePowder).formatted(Formatting.DARK_PURPLE), + powderHudX + 5, powderHudY + 25, 0xFFFFFFFF); } } - public static void renderSimple(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List<Commission> commissions) { - hcw.updateData(commissions, false); - hcw.update(); - hcw.setX(hudX); - hcw.setY(hudY); - hcw.render(context, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + public static void renderSimple(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) { + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { + hcw.updateData(commissions, false); + hcw.update(); + hcw.setX(comHudX); + hcw.setY(comHudY); + hcw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) { + hpw.update(); + hpw.setX(powderHudX); + hpw.setY(powderHudY); + hpw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } } - public static void renderFancy(HudCommsWidget hcw, DrawContext context, int hudX, int hudY, List<Commission> commissions) { - hcw.updateData(commissions, true); - hcw.update(); - hcw.setX(hudX); - hcw.setY(hudY); - hcw.render(context, - SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + public static void renderFancy(HudCommsWidget hcw, HudPowderWidget hpw, DrawContext context, int comHudX, int comHudY, int powderHudX, int powderHudY, List<Commission> commissions) { + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions) { + hcw.updateData(commissions, true); + hcw.update(); + hcw.setX(comHudX); + hcw.setY(comHudY); + hcw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } + if (SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledPowder) { + hpw.update(); + hpw.setX(powderHudX); + hpw.setY(powderHudY); + hpw.render(context, + SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enableBackground); + } } public static void update() { - commissionList = new ArrayList<>(); - if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabled) + if (client.player == null || client.getNetworkHandler() == null || !SkyblockerConfigManager.get().locations.dwarvenMines.dwarvenHud.enabledCommissions || (!Utils.isInCrystalHollows() + && !Utils.isInDwarvenMines())) return; + commissionList = new ArrayList<>(); + client.getNetworkHandler().getPlayerList().forEach(playerListEntry -> { if (playerListEntry.getDisplayName() != null) { + //find commissions for (Pattern pattern : COMMISSIONS) { Matcher matcher = pattern.matcher(playerListEntry.getDisplayName().getString()); if (matcher.find()) { @@ -142,6 +218,15 @@ public class DwarvenHud { } } + //find powder + Matcher mithrilMatcher = MITHRIL_PATTERN.matcher(playerListEntry.getDisplayName().getString()); + if (mithrilMatcher.find()){ + mithrilPowder = mithrilMatcher.group(0).split(": ")[1]; + } + Matcher gemstoneMatcher = GEMSTONE_PATTERN.matcher(playerListEntry.getDisplayName().getString()); + if (gemstoneMatcher.find()){ + gemStonePowder = gemstoneMatcher.group(0).split(": ")[1]; + } } }); } |