diff options
4 files changed, 84 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt index 08010207a..80ff8659f 100644 --- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -17,17 +17,6 @@ class CollectionAPI { private val counterPattern = "(?:.*) §e(?<amount>.*)§6\\/(?:.*)".toPattern() private val singleCounterPattern = "§7Total Collected: §e(?<amount>.*)".toPattern() -// private val hypixelApiHasWrongItems = listOf( -// "WOOL", -// "CORRUPTED_FRAGMENT", -// "EGG", -// "POISONOUS_POTATO", -// "REDSTONE_BLOCK", -// "MUSHROOM_COLLECTION", -// "RAW_SOULFLOW", -// "GEMSTONE_COLLECTION", -// ) - @SubscribeEvent fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { val profileData = event.profileData @@ -36,14 +25,10 @@ class CollectionAPI { for ((hypixelId, rawCounter) in asJsonObject.entrySet()) { val counter = rawCounter.asLong val neuItemId = NEUItems.transHypixelNameToInternalName(hypixelId) - val itemName = BazaarApi.getBazaarDataByInternalName(neuItemId)?.displayName - // Hypixel moment -// if (hypixelApiHasWrongItems.contains(neuItemId)) continue - if (itemName == null) { -// LorenzUtils.debug("collection name is null for '$neuItemId'") - continue - } + // MUSHROOM_COLLECTION, GEMSTONE_COLLECTION + BazaarApi.getBazaarDataByInternalName(neuItemId)?.displayName ?: continue + collectionValue[neuItemId] = counter } @@ -101,10 +86,10 @@ class CollectionAPI { fun isCollectionTier0(lore: List<String>) = lore.map { collectionTier0Pattern.matcher(it) }.any { it.matches() } - fun getCollectionCounter(searchName: String): Pair<String, Long>? { + fun getCollectionCounter(searchName: String): Long? { for ((collectionName, counter) in collectionValue) { if (collectionName.equals(searchName, true)) { - return Pair(collectionName, counter) + return counter } } return null diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt index d181caa3a..d5b1c5144 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt @@ -183,7 +183,7 @@ class BingoNextStepHelper { } } if (step is CollectionStep) { - val counter = CollectionAPI.getCollectionCounter(step.collectionName)?.second ?: 0 + val counter = CollectionAPI.getCollectionCounter(step.collectionName) ?: 0 if (step.amountHaving != counter) { step.amountHaving = counter if (counter >= step.amountNeeded) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt index b7d7b52f1..8915ff071 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent @@ -41,25 +42,59 @@ class CollectionCounter { return } - val name = args.joinToString(" ").replace(" ", "_") - val pair = CollectionAPI.getCollectionCounter(name) - if (pair == null) { - LorenzUtils.chat("§c[SkyHanni] Item $name is not in the collection data! (Maybe the API is disabled or try to open the collection inventory)") + val rawName = fixTypo(args.joinToString(" ").lowercase()) + if (rawName == "gemstone") { + LorenzUtils.chat("§c[SkyHanni] Gemstone collection is not supported!") +// setNewCollection("GEMSTONE_COLLECTION", "Gemstone") + return + } else if (rawName == "mushroom") { + LorenzUtils.chat("§c[SkyHanni] Mushroom collection is not supported!") +// setNewCollection("MUSHROOM_COLLECTION", "Mushroom") return } - internalName = pair.first - if (internalName.contains("MUSHROOM") || internalName.endsWith("_GEM")) { - LorenzUtils.chat("§7Mushroom and Gemstone items are not fully supported for the counter!") - internalName = "" + val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) ?: rawName.replace(" ", "_") + val stack = NEUItems.getItemStackOrNull(foundInternalName) + if (stack == null) { + LorenzUtils.chat("§c[SkyHanni] Item '$rawName' does not exist!") + return + } + setNewCollection(foundInternalName, stack.name!!.removeColor()) + } + + private fun fixTypo(rawName: String) = when (rawName) { + "carrot" -> "carrots" + "melons" -> "melon" + "seed" -> "seeds" + "iron" -> "iron ingot" + "gold" -> "gold ingot" + "sugar" -> "sugar cane" + "cocoa bean", "cocoa" -> "cocoa beans" + "lapis" -> "lapis lazuli" + "cacti" -> "cactus" + "pumpkins" -> "pumpkin" + "potatoes" -> "potato" + "nether warts", "wart", "warts" -> "nether wart" + "stone" -> "cobblestone" + "red mushroom", "brown mushroom", "mushrooms" -> "mushroom" + "gemstones" -> "gemstone" + + else -> rawName + } + + private fun setNewCollection(internalName: String, name: String) { + val foundAmount = CollectionAPI.getCollectionCounter(internalName) + if (foundAmount == null) { + LorenzUtils.chat("§c[SkyHanni] Item $name is not in the collection data! (Maybe the API is disabled or try to open the collection inventory)") return } - itemName = NEUItems.getItemStack(internalName).name!! - itemAmount = pair.second + this.internalName = internalName + itemName = name + itemAmount = foundAmount lastAmountInInventory = countCurrentlyInInventory() updateDisplay() - LorenzUtils.chat("§e[SkyHanni] Started tracking $itemName collection.") + LorenzUtils.chat("§e[SkyHanni] Started tracking $itemName §ecollection.") } private fun resetData() { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index ac9b2da2b..69687535b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import io.github.moulberry.notenoughupdates.NEUManager import io.github.moulberry.notenoughupdates.NEUOverlay import io.github.moulberry.notenoughupdates.NotEnoughUpdates @@ -26,14 +27,42 @@ object NEUItems { private val multiplierCache = mutableMapOf<String, Pair<String, Int>>() private val recipesCache = mutableMapOf<String, Set<NeuRecipe>>() private val enchantmentNamePattern = Pattern.compile("^(?<format>(?:§.)+)(?<name>[^§]+) (?<level>[IVXL]+)$") + private var allItemsCache = mapOf<String, String>() // item name -> internal name fun getInternalName(itemName: String): String { return getInternalNameOrNull(itemName) ?: throw Error("getInternalName is null for '$itemName'") } + fun getInternalNameOrNullIgnoreCase(itemName: String): String? { + val lowercase = itemName.removeColor().lowercase() + if (itemNameCache.containsKey(lowercase)) { + return itemNameCache[lowercase]!! + } + + if (allItemsCache.isEmpty()) { + allItemsCache = readAllNeuItems() + } + allItemsCache[lowercase]?.let { + itemNameCache[lowercase] = it + return it + } + + return null + } + + private fun readAllNeuItems(): Map<String, String> { + val map = mutableMapOf<String, String>() + for (internalName in manager.itemInformation.keys) { + val name = manager.createItem(internalName).displayName.removeColor().lowercase() + map[name] = internalName + } + return map + } + fun getInternalNameOrNull(itemName: String): String? { - if (itemNameCache.containsKey(itemName)) { - return itemNameCache[itemName]!! + val lowercase = itemName.lowercase() + if (itemNameCache.containsKey(lowercase)) { + return itemNameCache[lowercase]!! } resolveEnchantmentByName(itemName)?.let { @@ -48,7 +77,7 @@ object NEUItems { internalName = "HAY_BLOCK" } - itemNameCache[itemName] = internalName + itemNameCache[lowercase] = internalName return internalName } |