From 4cd130f140655f8741da93b1aa6c7bc7a2ce6d41 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 11 Apr 2024 10:20:28 +0200 Subject: Fix forge overlay not working when empty forges are hidden (#1079) --- .../notenoughupdates/overlays/MiningOverlay.java | 28 +++++++++++++++++----- .../miscfeatures/tablisttutorial/TablistAPI.kt | 2 +- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java index aefe8ff8..8b12026d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/MiningOverlay.java @@ -44,9 +44,11 @@ import org.lwjgl.util.vector.Vector2f; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -230,8 +232,8 @@ public class MiningOverlay extends TextTabOverlay { "\\xA77Time Remaining: \\xA7a((?Completed!)|(((?[0-9]+)d)? ?((?[0-9]+)h)? ?((?[0-9]+)m)? ?((?[0-9]+)s)?))"); private static final Pattern timeRemainingTab = Pattern.compile( ".*[1-5]\\) (?.*): ((?Ready!)|(((?[0-9]+)d)? ?((?[0-9]+)h)? ?((?[0-9]+)m)? ?((?[0-9]+)s)?))"); - private static final Pattern forgesHeaderPattern = Pattern.compile( - "\\xa7r\\xa79\\xa7lForges \\xa7r(?:\\xa7f\\(\\+1 more\\)\\xa7r)?"); + private static final Pattern forgeIntPattern = Pattern.compile( + "[^)]*([1-5])\\).*"); @Override public boolean isEnabled() { @@ -280,8 +282,6 @@ public class MiningOverlay extends TextTabOverlay { String gemstonePowder = ""; String glacitePowder = ""; - int forgeInt = 0; - List powderLines = getTabLinesOrAddWarning(1, TablistAPI.WidgetNames.POWDER); getTabLinesOrAddWarning(2, TablistAPI.WidgetNames.POWDER); getTabLinesOrAddWarning(6, TablistAPI.WidgetNames.POWDER); @@ -300,6 +300,8 @@ public class MiningOverlay extends TextTabOverlay { List tabForgeLines = getTabLinesOrAddWarning(3, TablistAPI.WidgetNames.FORGE); + Set foundForges = new HashSet<>(); + for (String name : tabForgeLines) { String cleanName = StringUtils.cleanColour(name); if (cleanName.startsWith(" ") && profileConfig != null) { @@ -307,7 +309,14 @@ public class MiningOverlay extends TextTabOverlay { if (firstChar < '0' || firstChar > '9') { break; } else { - + int forgeInt; + Matcher forgeIntMatcher = forgeIntPattern.matcher(cleanName); + if (forgeIntMatcher.matches()) { + forgeInt = Integer.parseInt(forgeIntMatcher.group(1)) - 1; + foundForges.add(forgeInt); + } else { + continue; + } if (name.contains("LOCKED")) { ForgeItem item = new ForgeItem(forgeInt, 1, true); replaceForgeOrAdd(item, profileConfig.forgeItems, true); @@ -354,10 +363,17 @@ public class MiningOverlay extends TextTabOverlay { } } } - forgeInt++; } } } + + if (profileConfig != null) + for (int i = 0; i < 5; i++) { + if (foundForges.contains(i)) continue; + ForgeItem item = new ForgeItem(i, 0, true); + replaceForgeOrAdd(item, profileConfig.forgeItems, true); + } + List tabCommissionLines = getTabLinesOrAddWarning(0, TablistAPI.WidgetNames.COMMISSIONS); for (String name : tabCommissionLines) { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt index 5c493108..7ff2f3a3 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/tablisttutorial/TablistAPI.kt @@ -124,7 +124,7 @@ object TablistAPI { COMMISSIONS(null), SKILLS(null), TRAPPER(null), - FORGE(Regex.fromLiteral("Forges:")), + FORGE(Regex("Forges:( \\(\\d/\\d\\))?")), POWDER(Regex.fromLiteral("Powders:")), PROFILE(Regex("Profile: ([A-Za-z]+)( .*)?")) ; -- cgit