diff options
author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-02-19 13:29:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-19 13:29:45 +0100 |
commit | 7d9a6a101071c75773668e0881b37466506307dd (patch) | |
tree | 0f46abdd4375d2eeb1a5c8154a2cb72046fb7621 /src/main/java/at | |
parent | 4bb1419b90e424ac824042188f67a371a5c276da (diff) | |
download | skyhanni-7d9a6a101071c75773668e0881b37466506307dd.tar.gz skyhanni-7d9a6a101071c75773668e0881b37466506307dd.tar.bz2 skyhanni-7d9a6a101071c75773668e0881b37466506307dd.zip |
Item name rewrite and cache #1016
Diffstat (limited to 'src/main/java/at')
20 files changed, 149 insertions, 76 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java index 9de854ba3..927ef8676 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java @@ -47,6 +47,11 @@ public class DebugConfig { public boolean showItemCategory = false; @Expose + @ConfigOption(name = "Show Item Name", desc = "Show the SkyHanni item name for an item.") + @ConfigEditorBoolean + public boolean showItemName = false; + + @Expose @ConfigOption(name = "Copy Internal Name", desc = "Copies the internal name of an item on key press in the clipboard.") @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) public int copyInternalName = Keyboard.KEY_NONE; diff --git a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt index 824b895bb..2bc9cf3c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OwnInventoryData.kt @@ -11,7 +11,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.SimpleTimeMark @@ -109,7 +109,7 @@ class OwnInventoryData { fun onChat(event: LorenzChatEvent) { sackToInventoryChatPattern.matchMatcher(event.message) { val name = group("name") - ignoreItem(500.milliseconds) { it.getItemName().contains(name) } + ignoreItem(500.milliseconds) { it.itemName.contains(name) } } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt index f422c0b12..d5efd3735 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/PetAPI.kt @@ -1,13 +1,23 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern object PetAPI { - private val petMenuPattern by RepoPattern.pattern( - "misc.pet.menu.title", + private val patternGroup = RepoPattern.group("misc.pet") + private val petMenuPattern by patternGroup.pattern( + "menu.title", "Pets(?: \\(\\d+/\\d+\\) )?" ) + private val petItemName by patternGroup.pattern( + "item.name", + "§.\\[Lvl (?<level>\\d)] (?<name>.*)" + ) + private val neuRepoPetItemName by patternGroup.pattern( + "item.name.neu.format", + "(§f§f)?§7\\[Lvl 1➡(100|200)] (?<name>.*)" + ) fun isPetMenu(inventoryTitle: String): Boolean = petMenuPattern.matches(inventoryTitle) @@ -19,4 +29,15 @@ object PetAPI { } fun isCurrentPet(petName: String): Boolean = currentPet?.contains(petName) ?: false + + fun getCleanName(nameWithLevel: String): String? { + petItemName.matchMatcher(nameWithLevel) { + return group("name") + } + neuRepoPetItemName.matchMatcher(nameWithLevel) { + return group("name") + } + + return null + } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt index 64d1f6206..296e2db65 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/SlayerAPI.kt @@ -8,10 +8,9 @@ import at.hannibal2.skyhanni.events.SlayerProgressChangeEvent import at.hannibal2.skyhanni.events.SlayerQuestCompleteEvent import at.hannibal2.skyhanni.features.slayer.SlayerType import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter -import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUItems.getItemStack import at.hannibal2.skyhanni.utils.NEUItems.getNpcPriceOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil @@ -46,7 +45,7 @@ object SlayerAPI { } val amountFormat = if (amount != 1) "§7${amount}x §r" else "" - val displayName = getNameWithEnchantmentFor(internalName) + val displayName = internalName.itemName val price = internalName.getPrice() val npcPrice = internalName.getNpcPriceOrNull() ?: 0.0 @@ -61,13 +60,6 @@ object SlayerAPI { return result } - private fun getNameWithEnchantmentFor(internalName: NEUInternalName): String { - if (internalName.asString() == "WISP_POTION") { - return "§fWisp's Ice-Flavored Water" - } - return internalName.getItemStack().nameWithEnchantment ?: error("Could not find name for $internalName") - } - @SubscribeEvent fun onDebugDataCollect(event: DebugDataCollectEvent) { event.title("Slayer") diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt index 770c06ba9..3e409b0c6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt @@ -6,7 +6,7 @@ import at.hannibal2.skyhanni.events.InventoryCloseEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi.Companion.getBazaarData import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getNameWithEnchantment +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NumberUtil @@ -59,7 +59,7 @@ class BazaarBestSellMethod { val totalDiff = (data.buyPrice - data.sellPrice) * having val result = NumberUtil.format(totalDiff.toInt()) - val name = internalName.getNameWithEnchantment() + val name = internalName.itemName return "$name§7 sell difference: §6$result coins" } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt index dbdf73535..7ada19315 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/MinionCraftHelper.kt @@ -7,8 +7,8 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName import at.hannibal2.skyhanni.utils.ItemUtils.hasEnchantments +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName @@ -210,7 +210,7 @@ class MinionCraftHelper { val needAmount = need * multiplier val have = otherItems.getOrDefault(itemId, 0) val percentage = have.toDouble() / needAmount - val itemName = rawId.getItemName() + val itemName = rawId.itemName val isTool = itemId.startsWith("WOOD_") if (percentage >= 1) { val color = if (isTool) "§7" else "§a" diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt index 42d417a5a..217b01259 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropTimeCommand.kt @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.sorted -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber @@ -45,10 +45,10 @@ object GardenCropTimeCommand { val map = mutableMapOf<String, Long>() for (entry in multipliers) { val internalName = entry.key - val itemName = internalName.getItemName() + val itemName = internalName.itemName if (itemName.removeColor().lowercase().contains(searchName)) { val (baseId, baseAmount) = NEUItems.getMultiplier(internalName) - val baseName = baseId.getItemName() + val baseName = baseId.itemName val crop = CropType.getByName(baseName.removeColor()) val fullAmount = baseAmount.toLong() * amount diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropsInCommand.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropsInCommand.kt index 4bf34a5ae..8523a7a58 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropsInCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropsInCommand.kt @@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.features.garden.farming.CropMoneyDisplay import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed.getSpeed import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.sorted -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -44,10 +44,10 @@ object GardenCropsInCommand { val map = mutableMapOf<String, Long>() for (entry in multipliers) { val internalName = entry.key - val itemName = internalName.getItemName() + val itemName = internalName.itemName if (itemName.removeColor().lowercase().contains(searchName)) { val (baseId, baseAmount) = NEUItems.getMultiplier(internalName) - val baseName = baseId.getItemName() + val baseName = baseId.itemName val crop = CropType.getByName(baseName.removeColor()) val speed = crop.getSpeed() diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index c592b7837..771c1df2a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -24,7 +24,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getItemNameOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName @@ -37,7 +37,6 @@ import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getReforgeName -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import kotlinx.coroutines.launch import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -209,7 +208,7 @@ object CropMoneyDisplay { } if (!config.compact) { - val itemName = internalName.getItemNameOrNull()?.removeColor() ?: continue + val itemName = internalName.itemNameWithoutColor val currentColor = if (isCurrent) "§e" else "§7" val contestFormat = if (GardenNextJacobContest.isNextCrop(crop)) "§n" else "" list.add("$currentColor$contestFormat$itemName§7: ") @@ -408,7 +407,7 @@ object CropMoneyDisplay { if (!internalName.isBazaarItem()) continue val (newId, amount) = NEUItems.getMultiplier(internalName) - val itemName = newId.getItemNameOrNull()?.removeColor() ?: continue + val itemName = newId.itemNameWithoutColor val crop = getByNameOrNull(itemName) crop?.let { map[internalName] = amount diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt index f137651a0..2d33fd9b1 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/fortuneguide/FortuneUpgrades.kt @@ -12,8 +12,8 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI.Companion.currentPet import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI.Companion.getItem import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrCommon +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil.addSuffix import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments @@ -84,7 +84,7 @@ object FortuneUpgrades { val nextTalisman = CropAccessory.entries[currentTalismanTier + 1] genericUpgrades.add( FortuneUpgrade( - "§7Upgrade your talisman to ${nextTalisman.internalName?.getItemName()}", + "§7Upgrade your talisman to ${nextTalisman.internalName?.itemName}", null, nextTalisman.upgradeCost?.first!!, nextTalisman.upgradeCost.second, 10.0 ) ) diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index d32b8e75d..4b659e9bf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -33,9 +33,9 @@ import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemBlink import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName -import at.hannibal2.skyhanni.utils.ItemUtils.getItemNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.itemName +import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzLogger import at.hannibal2.skyhanni.utils.LorenzUtils @@ -179,7 +179,7 @@ class GardenVisitorFeatures { var totalPrice = 0.0 addAsSingletonList("§7Visitor Shopping List:") for ((internalName, amount) in shoppingList) { - val name = internalName.getItemName() + val name = internalName.itemName val itemStack = internalName.getItemStack() val list = mutableListOf<Any>() @@ -410,7 +410,7 @@ class GardenVisitorFeatures { if (!readingShoppingList) continue val multiplier = NEUItems.getMultiplier(internalName) - val rawName = multiplier.first.getItemNameOrNull()?.removeColor() ?: continue + val rawName = multiplier.first.itemNameWithoutColor val cropType = getByNameOrNull(rawName) ?: continue val cropAmount = multiplier.second.toLong() * amount diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt index 35222706e..506f53b5b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ChestValue.kt @@ -16,6 +16,7 @@ import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.ConfigUtils import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addButton import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland @@ -129,12 +130,12 @@ class ChestValue { if (total < config.hideBelow) continue val textAmount = " §7x$amount:" val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(textAmount) - val name = "${stack.displayName.reduceStringLength((config.nameLength - width), ' ')} $textAmount" + val name = "${stack.itemName.reduceStringLength((config.nameLength - width), ' ')} $textAmount" val price = "§6${(total).formatPrice()}" val text = if (config.alignedDisplay) "$name $price" else - "${stack.displayName} §7x$amount: §6${total.formatPrice()}" + "${stack.itemName} §7x$amount: §6${total.formatPrice()}" newDisplay.add(buildList { val renderable = Renderable.hoverTips( text, diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt index d0e1a80a3..bd97c298f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/PowerStoneGuideFeatures.kt @@ -7,8 +7,8 @@ import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent import at.hannibal2.skyhanni.events.LorenzToolTipEvent import at.hannibal2.skyhanni.features.bazaar.BazaarApi import at.hannibal2.skyhanni.utils.CollectionUtils.nextAfter -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUInternalName @@ -65,7 +65,7 @@ class PowerStoneGuideFeatures { if (!inInventory) return val internalName = missing[event.slotId] ?: return - BazaarApi.searchForBazaarItem(internalName.getItemName(), 9) + BazaarApi.searchForBazaarItem(internalName.itemName, 9) } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt index d0c0d74f2..8ea9195f8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValueCalculator.kt @@ -4,10 +4,11 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.getItemName import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.isRune +import at.hannibal2.skyhanni.utils.ItemUtils.itemName +import at.hannibal2.skyhanni.utils.ItemUtils.itemNameWithoutColor import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment import at.hannibal2.skyhanni.utils.LorenzRarity @@ -47,7 +48,6 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.hasJalapenoBook import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.hasWoodSingularity import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated import at.hannibal2.skyhanni.utils.StringUtils.allLettersFirstUppercase -import at.hannibal2.skyhanni.utils.StringUtils.removeColor import com.google.gson.JsonObject import io.github.moulberry.notenoughupdates.recipes.Ingredient import io.github.moulberry.notenoughupdates.util.Constants @@ -173,7 +173,7 @@ object EstimatedItemValueCalculator { if (rawReforgeName == reforgeName.lowercase() || rawReforgeName == rawInternalName.lowercase()) { val internalName = rawInternalName.asInternalName() val reforgeStonePrice = internalName.getPrice() - val reforgeStoneName = internalName.getItemName() + val reforgeStoneName = internalName.itemName val reforgeCosts = stoneJson.get("reforgeCosts").asJsonObject val applyCost = getReforgeStoneApplyCost(stack, reforgeCosts, internalName) ?: return 0.0 @@ -412,7 +412,7 @@ object EstimatedItemValueCalculator { var totalPrice = 0.0 val map = mutableMapOf<String, Double>() for (internalName in drillUpgrades) { - val name = internalName.getItemName() + val name = internalName.itemName val price = internalName.getPriceOrNull() ?: continue totalPrice += price @@ -430,7 +430,7 @@ object EstimatedItemValueCalculator { val internalName = stack.getPowerScroll() ?: return 0.0 val price = internalName.getPrice() - val name = internalName.getItemName().removeColor() + val name = internalName.itemNameWithoutColor list.add("§7$name: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") return price } @@ -469,7 +469,7 @@ object EstimatedItemValueCalculator { val internalName = "TALISMAN_ENRICHMENT_$enrichmentName".asInternalName() val price = internalName.getPrice() - val name = internalName.getItemName() + val name = internalName.itemName list.add("§7Enrichment: $name §7(§6" + NumberUtil.format(price) + "§7)") return price } @@ -492,7 +492,7 @@ object EstimatedItemValueCalculator { var totalPrice = 0.0 val map = mutableMapOf<String, Double>() for (internalName in abilityScrolls) { - val name = internalName.getItemName() + val name = internalName.itemName val price = internalName.getPriceOrNull() ?: continue totalPrice += price @@ -513,7 +513,7 @@ object EstimatedItemValueCalculator { price = 0.0 } - val name = internalName.getItemName() + val name = internalName.itemName if (internalName.startsWith("ENCHANTED_BOOK_BUNDLE_")) { list.add("§7Base item: $name") return 0.0 @@ -627,7 +627,7 @@ object EstimatedItemValueCalculator { val priceMap = mutableMapOf<String, Double>() for ((internalName, amount) in counterMap) { - val name = internalName.getItemName() + val name = internalName.itemName val price = internalName.getPrice() * amount totalPrice += price diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt index c7a73afcc..adc1b234d 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt @@ -22,6 +22,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getInternalNameOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemCategoryOrNull import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld import at.hannibal2.skyhanni.utils.LocationUtils @@ -415,7 +416,7 @@ class SkyHanniDebugsAndTests { } @SubscribeEvent - fun onSHowNpcPrice(event: LorenzToolTipEvent) { + fun onShowNpcPrice(event: LorenzToolTipEvent) { if (!LorenzUtils.inSkyBlock) return if (!debugConfig.showNpcPrice) return val internalName = event.itemStack.getInternalNameOrNull() ?: return @@ -425,6 +426,20 @@ class SkyHanniDebugsAndTests { } @SubscribeEvent + fun onShowItemName(event: LorenzToolTipEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!debugConfig.showItemName) return + val itemStack = event.itemStack + val internalName = itemStack.getInternalName() + if (internalName == NEUInternalName.NONE) { + event.toolTip.add("Item name: no item.") + return + } + val name = internalName.itemName + event.toolTip.add("Item name: '$name'") + } + + @SubscribeEvent fun onRenderLocation(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (LorenzUtils.inSkyBlock && Minecraft.getMinecraft().gameSettings.showDebugInfo && debugConfig.currentAreaDebug) { config.debugLocationPos.renderString( diff --git a/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt b/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt index e22f1cba5..ca9f11cc6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/CachedItemData.kt @@ -17,10 +17,14 @@ data class CachedItemData( var riftExportable: Boolean? = null, // null = not loaded - var itemRarityLastCheck: Long = 0L, // Cant use SimpleTimeMark here + var itemRarityLastCheck: Long = 0L, // Can't use SimpleTimeMark here // null = not loaded var itemRarity: LorenzRarity? = null, var itemCategory: ItemCategory? = null, + + var lastInternalName: NEUInternalName? = null, + + var lastInternalNameFetchTime: Long = 0L, // Still can't use SimpleTimeMark here ) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 6b52d1eb2..ab0d695fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -1,8 +1,9 @@ package at.hannibal2.skyhanni.utils +import at.hannibal2.skyhanni.data.PetAPI import at.hannibal2.skyhanni.test.command.ErrorManager import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName -import at.hannibal2.skyhanni.utils.NEUItems.getItemStack +import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.cachedData @@ -26,6 +27,8 @@ import kotlin.time.Duration.Companion.seconds object ItemUtils { + private val itemNameCache = mutableMapOf<NEUInternalName, String>() // internal name -> item name + private val ignoredPetStrings = listOf( "Archer", "Berserk", @@ -122,13 +125,22 @@ object ItemUtils { fun ItemStack.getInternalName() = getInternalNameOrNull() ?: NEUInternalName.NONE - fun ItemStack.getInternalNameOrNull() = getRawInternalName()?.asInternalName() + fun ItemStack.getInternalNameOrNull(): NEUInternalName? { + val data = cachedData + if (data.lastInternalNameFetchTime.asTimeMark().passedSince() < 1.seconds) { + return data.lastInternalName + } + val internalName = grabInternalNameOrNull() + data.lastInternalName = internalName + data.lastInternalNameFetchTime = SimpleTimeMark.now().toMillis() + return internalName + } - private fun ItemStack.getRawInternalName(): String? { + private fun ItemStack.grabInternalNameOrNull(): NEUInternalName? { if (name == "§fWisp's Ice-Flavored Water I Splash Potion") { - return "WISP_POTION" + return NEUInternalName.WISP_POTION } - return NEUItems.getInternalName(this) + return NEUItems.getInternalName(this)?.asInternalName() } fun ItemStack.isVanilla() = NEUItems.isVanillaItem(this) @@ -297,12 +309,9 @@ object ItemUtils { setStackDisplayName(value) } + @Deprecated("outdated", ReplaceWith("itemName")) val ItemStack.nameWithEnchantment: String? - get() = name?.let { - if (it.endsWith("Enchanted Book")) { - getLore()[0] - } else it - } + get() = getInternalNameOrNull()?.itemName fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName()?.equals("SKYBLOCK_MENU") ?: false @@ -348,17 +357,6 @@ object ItemUtils { return pair } - fun NEUInternalName.getItemNameOrNull() = getItemStack().name - - fun NEUInternalName.getItemName() = getItemNameOrNull() ?: error("No item name found for $this") - - fun NEUInternalName.getNameWithEnchantment(): String { - if (equals("WISP_POTION")) { - return "§fWisp's Ice-Flavored Water" - } - return getItemStack().nameWithEnchantment ?: error("Could not find item name for $this") - } - private fun getPetRarity(pet: ItemStack): LorenzRarity? { val rarityId = pet.getInternalName().asString().split(";").last().toInt() val rarity = LorenzRarity.getById(rarityId) @@ -377,4 +375,40 @@ object ItemUtils { } fun NEUInternalName.isRune(): Boolean = contains("_RUNE;") + + val ItemStack.itemName: String + get() = getInternalName().itemName + + val ItemStack.itemNameWithoutColor: String get() = itemName.removeColor() + + val NEUInternalName.itemName: String + get() = itemNameCache.getOrPut(this) { grabItemName() } + + val NEUInternalName.itemNameWithoutColor: String get() = itemName.removeColor() + + private fun NEUInternalName.grabItemName(): String { + if (this == NEUInternalName.WISP_POTION) { + return "§fWisp's Ice-Flavored Water" + } + if (this == NEUInternalName.SKYBLOCK_COIN) { + return "§6Coins" + } + if (this == NEUInternalName.NONE) { + error("NEUInternalName.NONE has no name!") + } + + val itemStack = getItemStackOrNull() + val name = itemStack?.name ?: error("Could not find item name for $this") + + // show enchanted book name + if (name.endsWith("Enchanted Book")) { + return itemStack.getLore()[0] + } + + // hide pet level + PetAPI.getCleanName(name)?.let { + return "$it Pet" + } + return name + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt index 26bfcc799..73fc82622 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUInternalName.kt @@ -9,6 +9,9 @@ class NEUInternalName private constructor(private val internalName: String) { val NONE = "NONE".asInternalName() val MISSING_ITEM = "MISSING_ITEM".asInternalName() + val WISP_POTION = "WISP_POTION".asInternalName() + val SKYBLOCK_COIN = "SKYBLOCK_COIN".asInternalName() + fun String.asInternalName(): NEUInternalName { val internalName = uppercase() return map.getOrPut(internalName) { NEUInternalName(internalName) } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 06901f239..c96fb36a3 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -158,7 +158,7 @@ object NEUItems { fun NEUInternalName.getNpcPrice() = getNpcPriceOrNull() ?: -1.0 fun NEUInternalName.getNpcPriceOrNull(): Double? { - if (equals("WISP_POTION")) { + if (this == NEUInternalName.WISP_POTION) { return 20_000.0 } return BazaarDataHolder.getNpcPrice(this) @@ -168,7 +168,7 @@ object NEUItems { manager.auctionManager.transformHypixelBazaarToNEUItemId(hypixelId).asInternalName() fun NEUInternalName.getPriceOrNull(useSellingPrice: Boolean = false): Double? { - if (equals("WISP_POTION")) { + if (this == NEUInternalName.WISP_POTION) { return 20_000.0 } val result = manager.auctionManager.getBazaarOrBin(asString(), useSellingPrice) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt index 6c6ca77ff..e2e7b5ae2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt @@ -8,12 +8,11 @@ import at.hannibal2.skyhanni.test.PriceSource import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.CollectionUtils.addAsSingletonList import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc -import at.hannibal2.skyhanni.utils.ItemUtils.getNameWithEnchantment +import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.KeyboardManager import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.addSelector import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -29,7 +28,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( companion object { - val SKYBLOCK_COIN by lazy { "SKYBLOCK_COIN".asInternalName() } + val SKYBLOCK_COIN = NEUInternalName.SKYBLOCK_COIN } private var lastClickDelay = 0L @@ -106,7 +105,7 @@ class SkyHanniItemTracker<Data : ItemTrackerData>( val cleanName = if (internalName == SKYBLOCK_COIN) { data.getCoinName(itemProfit) } else { - internalName.getNameWithEnchantment() + internalName.itemName } val priceFormat = NumberUtil.format(price) |