From 3faf4f2e23ee6d7dccaa9bd724b9fd6d2ecbfb0c Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Fri, 17 May 2024 17:11:03 -0400 Subject: [PATCH] Add cultivating counter --- .../skyblock/garden/FarmingHud.java | 51 +++++++++++++++---- .../skyblock/garden/FarmingHudWidget.java | 2 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java index 201e6716ed..9f7f5ac9cf 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHud.java @@ -33,8 +33,8 @@ public class FarmingHud { private static final Logger LOGGER = LoggerFactory.getLogger(FarmingHud.class); public static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US); - private static final Pattern COUNTER = Pattern.compile("Counter: (?[\\d,]+) .+"); private static final Pattern FARMING_XP = Pattern.compile("ยง3\\+(?\\d+.?\\d*) Farming \\((?[\\d,]+.?\\d*)%\\)"); + private static CounterType counterType; private static final Deque counter = new ArrayDeque<>(); private static final LongPriorityQueue blockBreaks = new LongArrayFIFOQueue(); private static final Queue farmingXp = new ArrayDeque<>(); @@ -54,16 +54,12 @@ public static void init() { } ItemStack stack = MinecraftClient.getInstance().player.getMainHandStack(); - Matcher matcher = ItemUtils.getLoreLineIfMatch(stack, FarmingHud.COUNTER); - if (matcher != null) { - try { - int count = NUMBER_FORMAT.parse(matcher.group("count")).intValue(); - if (counter.isEmpty() || counter.peekLast().leftInt() != count) { - counter.offer(IntLongPair.of(count, System.currentTimeMillis())); - } - } catch (ParseException e) { - LOGGER.error("[Skyblocker Farming HUD] Failed to parse counter", e); - } + if (tryParseCounter(stack, CounterType.CULTIVATING.pattern)) { + counterType = CounterType.CULTIVATING; + } else if (tryParseCounter(stack, CounterType.COUNTER.pattern)) { + counterType = CounterType.COUNTER; + } else { + counterType = CounterType.NONE; } FarmingHudWidget.INSTANCE.update(); @@ -92,10 +88,29 @@ public static void init() { .executes(Scheduler.queueOpenScreenCommand(() -> new FarmingHudConfigScreen(null))))))); } + private static boolean tryParseCounter(ItemStack stack, Pattern counterPattern) { + Matcher matcher = ItemUtils.getLoreLineIfMatch(stack, counterPattern); + if (matcher == null) return false; + try { + int count = NUMBER_FORMAT.parse(matcher.group("count")).intValue(); + if (counter.isEmpty() || counter.peekLast().leftInt() != count) { + counter.offer(IntLongPair.of(count, System.currentTimeMillis())); + } + return true; + } catch (ParseException e) { + LOGGER.error("[Skyblocker Farming HUD] Failed to parse counter", e); + return false; + } + } + private static boolean shouldRender() { return SkyblockerConfigManager.get().farming.garden.farmingHud.enableHud && Utils.getLocation() == Location.GARDEN; } + public static String counterText() { + return counterType.text; + } + public static int counter() { return counter.isEmpty() ? 0 : counter.peekLast().leftInt(); } @@ -120,4 +135,18 @@ public static float farmingXpPercentProgress() { public static double farmingXpPerHour() { return farmingXp.stream().mapToDouble(FloatLongPair::leftFloat).sum() * blockBreaks() * 1800; // Hypixel only sends xp updates around every half a second } + + public enum CounterType { + NONE(Pattern.compile(""), "No Counter: "), + COUNTER(Pattern.compile("Counter: (?[\\d,]+) .+"), "Counter: "), + CULTIVATING(Pattern.compile("Cultivating (?[IVXLCDM]+) (?[\\d,]+)"), "Cultivating Counter: "); + + private final Pattern pattern; + private final String text; + + CounterType(Pattern pattern, String text) { + this.pattern = pattern; + this.text = text; + } + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java index d9e0902b1c..143567d42a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/garden/FarmingHudWidget.java @@ -60,7 +60,7 @@ public void updateContent() { if (client.player == null) return; ItemStack farmingTool = client.player.getMainHandStack(); - addSimpleIcoText(farmingTool, "Counter: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format(FarmingHud.counter())); + addSimpleIcoText(farmingTool, FarmingHud.counterText(), Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format(FarmingHud.counter())); float cropsPerMinute = FarmingHud.cropsPerMinute(); addSimpleIcoText(farmingTool, "Crops/min: ", Formatting.YELLOW, FarmingHud.NUMBER_FORMAT.format((int) cropsPerMinute / 10 * 10)); DoubleBooleanPair itemPrice = ItemUtils.getItemPrice(FARMING_TOOLS.get(ItemUtils.getItemId(farmingTool)));