aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorRoman / Linnea Gräf <roman.graef@gmail.com>2023-06-19 18:37:26 +0200
committerGitHub <noreply@github.com>2023-06-19 18:37:26 +0200
commit7fd26d14e742c974ec50686c375ccdfd9c968faf (patch)
tree0ceb5fbb46d6619b912f8136f3ff7fb4f8848d25 /src/main
parentf7168033b41ee84a58adbd005b6ba8898b38cb5a (diff)
downloadNotEnoughUpdates-7fd26d14e742c974ec50686c375ccdfd9c968faf.tar.gz
NotEnoughUpdates-7fd26d14e742c974ec50686c375ccdfd9c968faf.tar.bz2
NotEnoughUpdates-7fd26d14e742c974ec50686c375ccdfd9c968faf.zip
Fix hot potato book being parsed as potato (#722)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/DungeonNpcProfitOverlay.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java16
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt12
3 files changed, 27 insertions, 7 deletions
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;
@@ -202,10 +203,23 @@ public class ItemResolutionQuery {
*/
public static String findInternalNameByDisplayName(String displayName, boolean mayBeMangled) {
var cleanDisplayName = StringUtils.cleanColour(displayName);
+ return filterInternalNameCandidates(
+ findInternalNameCandidatesForDisplayName(cleanDisplayName),
+ displayName,
+ mayBeMangled
+ );
+ }
+
+ public static String filterInternalNameCandidates(
+ Collection<String> 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
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
index 58da635e..3292a9cf 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
@@ -31,10 +31,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.Custom
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager
import io.github.moulberry.notenoughupdates.miscgui.pricegraph.GuiPriceGraph
-import io.github.moulberry.notenoughupdates.util.ApiCache
-import io.github.moulberry.notenoughupdates.util.PronounDB
-import io.github.moulberry.notenoughupdates.util.SBInfo
-import io.github.moulberry.notenoughupdates.util.TabListUtils
+import io.github.moulberry.notenoughupdates.util.*
import io.github.moulberry.notenoughupdates.util.brigadier.*
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiScreen
@@ -109,6 +106,13 @@ class DevTestCommand {
requires {
canPlayerExecute(it)
}
+ thenLiteral("testsearch") {
+ thenArgument("name", RestArgumentType) { arg ->
+ thenExecute {
+ reply("Resolved ID: ${ItemResolutionQuery.findInternalNameByDisplayName(get(arg), true)}")
+ }
+ }.withHelp("Search for an item id by name")
+ }
thenLiteralExecute("garden") {
val player = Minecraft.getMinecraft().thePlayer
reply("Is in Garden: ${SBInfo.getInstance().getLocation() == "garden"}")