From 7fd26d14e742c974ec50686c375ccdfd9c968faf Mon Sep 17 00:00:00 2001 From: Roman / Linnea Gräf Date: Mon, 19 Jun 2023 18:37:26 +0200 Subject: Fix hot potato book being parsed as potato (#722) --- .../miscfeatures/DungeonNpcProfitOverlay.java | 6 ++++-- .../notenoughupdates/util/ItemResolutionQuery.java | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'src/main/java/io') diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java index 96e0765d..8bd5e84d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java @@ -361,8 +361,10 @@ public class DungeonNpcProfitOverlay { return new SkyblockItem(internalName, amount); } else { // Remove Book (from hot potato book), as a perf optimization since "book" is a very common phrase - String id = ItemResolutionQuery.findInternalNameByDisplayName( - line.trim().replace("Book", ""), true); + String trimmedLine = line.trim(); + String id = + ItemResolutionQuery.filterInternalNameCandidates(ItemResolutionQuery.findInternalNameCandidatesForDisplayName( + trimmedLine.replace("Book", "")), trimmedLine, true); if (id == null) return null; return new SkyblockItem(id, 1); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java index 5dacf7ef..cf508a33 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java @@ -37,6 +37,7 @@ import net.minecraft.nbt.NBTTagCompound; import javax.annotation.Nullable; import java.util.Arrays; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -201,11 +202,24 @@ public class ItemResolutionQuery { * @return the internal neu item id of that item, or null */ public static String findInternalNameByDisplayName(String displayName, boolean mayBeMangled) { + var cleanDisplayName = StringUtils.cleanColour(displayName); + return filterInternalNameCandidates( + findInternalNameCandidatesForDisplayName(cleanDisplayName), + displayName, + mayBeMangled + ); + } + + public static String filterInternalNameCandidates( + Collection candidateInternalNames, + String displayName, + boolean mayBeMangled + ) { var cleanDisplayName = StringUtils.cleanColour(displayName); var manager = NotEnoughUpdates.INSTANCE.manager; String bestMatch = null; int bestMatchLength = -1; - for (String internalName : findInternalNameCandidatesForDisplayName(cleanDisplayName)) { + for (String internalName : candidateInternalNames) { var cleanItemDisplayName = StringUtils.cleanColour(manager.getDisplayName(internalName)); if (cleanItemDisplayName.length() == 0) continue; if (mayBeMangled -- cgit