From c3caf0b538747d46d02f38a2d2182c821ef1b0f0 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 11 May 2023 12:43:44 +0200 Subject: Added support for lower case names and common typos in /shtrackcollection --- .../skyhanni/features/bingo/BingoNextStepHelper.kt | 2 +- .../skyhanni/features/misc/CollectionCounter.kt | 57 +++++++++++++++++----- 2 files changed, 47 insertions(+), 12 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features') 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() { -- cgit