aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLulonaut <lulonaut@tutanota.de>2022-12-27 14:53:51 +0100
committerLulonaut <lulonaut@tutanota.de>2022-12-27 14:53:51 +0100
commitb064aa64f82bb58047d7e50799b6199094a276ce (patch)
tree16d572c8efef0f808035c96903d9783ff1724ae0
parent3a84ab3535e0472829fbe890ed603a4062689145 (diff)
downloadNotEnoughUpdates-b064aa64f82bb58047d7e50799b6199094a276ce.tar.gz
NotEnoughUpdates-b064aa64f82bb58047d7e50799b6199094a276ce.tar.bz2
NotEnoughUpdates-b064aa64f82bb58047d7e50799b6199094a276ce.zip
improvements to armor detection
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java2
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt95
2 files changed, 35 insertions, 62 deletions
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 ea5e13ab..e5c1b9ad 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/ItemResolutionQuery.java
@@ -201,7 +201,7 @@ public class ItemResolutionQuery {
return null;
}
- private String getInternalNameByDisplayName(String displayName) {
+ public static String getInternalNameByDisplayName(String displayName) {
String cleanDisplayName = StringUtils.cleanColour(displayName);
for (Map.Entry<String, JsonObject> entry : NotEnoughUpdates.INSTANCE.manager
.getItemInformation()
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt
index 1526513e..72f88e6d 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/MuseumCheapestItemOverlay.kt
@@ -23,6 +23,7 @@ import io.github.moulberry.notenoughupdates.NEUManager
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.core.util.ArrowPagesUtils
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer
+import io.github.moulberry.notenoughupdates.util.ItemResolutionQuery
import io.github.moulberry.notenoughupdates.util.Utils
import io.github.moulberry.notenoughupdates.util.stripControlCodes
import net.minecraft.client.Minecraft
@@ -36,6 +37,7 @@ import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.client.event.GuiScreenEvent.BackgroundDrawnEvent
+import net.minecraftforge.client.event.GuiScreenEvent.KeyboardInputEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.input.Mouse
import org.lwjgl.opengl.GL11
@@ -81,7 +83,7 @@ object MuseumCheapestItemOverlay {
val guiTop = (event.gui as AccessorGuiContainer).guiTop
drawBackground(guiLeft, xSize, guiTop)
- drawLines(guiLeft, xSize, guiTop)
+ drawLines(guiLeft, guiTop)
}
@SubscribeEvent
@@ -101,7 +103,7 @@ object MuseumCheapestItemOverlay {
}
- private fun drawLines(guiLeft: Int, xSize: Int, guiTop: Int) {
+ private fun drawLines(guiLeft: Int, guiTop: Int) {
//render
val lines = buildLines()
lines.forEachIndexed { index, line ->
@@ -114,14 +116,12 @@ object MuseumCheapestItemOverlay {
)
} else {
Utils.renderAlignedString(
- "${EnumChatFormatting.BLUE}${line.name}",
- "${EnumChatFormatting.BLUE}${
- if (line.value == Double.MAX_VALUE) "${EnumChatFormatting.RED}Unknown" else "${EnumChatFormatting.AQUA}${
- Utils.shortNumberFormat(
- line.value,
- 0
- )
- }"
+ "${EnumChatFormatting.RESET}${EnumChatFormatting.BLUE}${line.name}",
+ if (line.value == Double.MAX_VALUE) "${EnumChatFormatting.RED}Unknown" else "${EnumChatFormatting.AQUA}${
+ Utils.shortNumberFormat(
+ line.value,
+ 0
+ )
}",
(guiLeft + 187).toFloat(),
(guiTop + 5 + (index * 10)).toFloat(),
@@ -145,6 +145,7 @@ object MuseumCheapestItemOverlay {
return list
}
+
private fun parseItems(slots: List<Slot>) {
//iterate upper chest with 56 slots
val time = System.currentTimeMillis()
@@ -168,7 +169,11 @@ object MuseumCheapestItemOverlay {
if (totalValue == 0.0) {
totalValue = Double.MAX_VALUE
}
- itemsToDonate.add(MuseumItem(name, totalValue, time))
+
+ //make sure this item does not already exist
+ if (itemsToDonate.none { it.name == name }) {
+ itemsToDonate.add(MuseumItem(name, totalValue, time))
+ }
}
}
}
@@ -182,69 +187,37 @@ object MuseumCheapestItemOverlay {
}
}
+ @SubscribeEvent
+ fun onKey(event: KeyboardInputEvent) {
+ println(guessInternalNames("Mushroom Armor", true))
+ }
+
+
private fun guessInternalNames(itemName: String, armor: Boolean): List<String> {
return if (armor) {
- //TODO: convert this to use titlewordmap as well
- val suffixes = listOf(
- "HELMET",
- "CHESTPLATE",
- "LEGGINGS",
- "BOOTS",
- "ARMOR_HELMET",
- "ARMOR_CHESTPLATE",
- "ARMOR_LEGGINGS",
- "ARMOR_BOOTS"
- )
-
- val prefixes = listOf(
+ val mustHaves = arrayOf(
"HELMET",
"LEGGINGS",
"CHESTPLATE",
"BOOTS"
)
- val validNames = mutableListOf<String>()
- val name = itemName
- .replace(" Armor", "")
- .replace("Armor ", "")
- .replace("'s", "")
- .replace(" ", "_")
- .uppercase()
-
- for (suffix in suffixes) {
- val possibleName = name + "_" + suffix
- if (NotEnoughUpdates.INSTANCE.manager.isValidInternalName(possibleName)) {
- validNames.add(possibleName)
- } else {
- //catch for example: ARMOR_OF_YOG_LEGGINGS, where "Armor" does not need to be replaced to get a valid internalname
- val unchangedName = itemName.replace(" ", "_").uppercase() + "_" + suffix
- if (NotEnoughUpdates.INSTANCE.manager.isValidInternalName(unchangedName)) {
- validNames.add(unchangedName)
- }
- }
- }
-
- for (prefix in prefixes) {
- val possibleName = prefix + "_" + name
- if (NotEnoughUpdates.INSTANCE.manager.isValidInternalName(possibleName)) {
- validNames.add(possibleName)
- }
-
- }
-
- validNames
- } else {
val monochromeName = NEUManager.cleanForTitleMapSearch(itemName)
- val internalName = monochromeName.split(" ")
- .asSequence()
+ val candidates = monochromeName.split(" ")
.mapNotNull { NotEnoughUpdates.INSTANCE.manager.titleWordMap[it]?.keys }
.flatten()
.filter {
- val item = NotEnoughUpdates.INSTANCE.manager.createItem(it) ?: return@filter false
- item.displayName != null && item.displayName.isNotEmpty() && NEUManager.cleanForTitleMapSearch(item.displayName) in monochromeName
+ val item = NotEnoughUpdates.INSTANCE.manager.createItem(it)
+ val name = NEUManager.cleanForTitleMapSearch(item.displayName)
+ monochromeName.replace("armor", "") in name
+ }.filter { item ->
+ mustHaves.any {
+ item.contains(it)
+ }
}
- .firstOrNull() ?: return emptyList()
- listOf(internalName)
+ return candidates
+ } else {
+ listOf(ItemResolutionQuery.getInternalNameByDisplayName(itemName))
}
}