diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-06 02:26:03 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-06 02:26:03 +0100 |
commit | 1e24f52201a7ced89c1298c466824dcc0eb13096 (patch) | |
tree | 9a17905ae9b45216254809a288dd52df2c55d42a /src/main/java/at/hannibal2 | |
parent | ac3a1ccc0e77da14870a9be8fa041ae083284ac1 (diff) | |
download | skyhanni-1e24f52201a7ced89c1298c466824dcc0eb13096.tar.gz skyhanni-1e24f52201a7ced89c1298c466824dcc0eb13096.tar.bz2 skyhanni-1e24f52201a7ced89c1298c466824dcc0eb13096.zip |
Added collection data to the bingo step helper.
Diffstat (limited to 'src/main/java/at/hannibal2')
7 files changed, 146 insertions, 75 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index f683e0436..3ffa9fc00 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni; +import at.hannibal2.skyhanni.api.CollectionAPI; import at.hannibal2.skyhanni.config.ConfigManager; import at.hannibal2.skyhanni.config.Features; import at.hannibal2.skyhanni.config.commands.Commands; @@ -118,6 +119,7 @@ public class SkyHanniMod { // APIs loadModule(new BazaarApi()); loadModule(new GardenAPI()); + loadModule(new CollectionAPI()); // features loadModule(new BazaarOrderHelper()); diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt new file mode 100644 index 000000000..e79e60dfb --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt @@ -0,0 +1,104 @@ +package at.hannibal2.skyhanni.api + +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent +import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class CollectionAPI { + private val counterPattern = Pattern.compile("(?:.*) §e(.*)§6\\/(?:.*)") + private val singleCounterPattern = Pattern.compile("§7Total Collected: §e(.*)") + + @SubscribeEvent + fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { + val profileData = event.profileData + for ((rawName, rawCounter) in profileData["collection"].asJsonObject.entrySet()) { + val counter = rawCounter.asLong + var itemName = BazaarApi.getBazaarDataForInternalName(rawName)?.itemName + if (rawName == "MUSHROOM_COLLECTION") { + itemName = "Mushroom" + } + if (rawName == "MELON") { + itemName = "Melon" + } + if (rawName == "GEMSTONE_COLLECTION") { + itemName = "Gemstone" + } + // Hypixel moment + if (rawName == "WOOL" || rawName == "CORRUPTED_FRAGMENT") { + continue + } + if (itemName == null) { + println("collection name is null for '$rawName'") + continue + } + collectionValue[itemName] = counter + } + } + + @SubscribeEvent + fun onProfileJoin(event: ProfileJoinEvent) { + collectionValue.clear() + } + + @SubscribeEvent + fun onTick(event: InventoryOpenEvent) { + val inventoryName = event.inventoryName + if (inventoryName.endsWith(" Collection")) { + val stack = event.inventoryItems[4] ?: return + for (line in stack.getLore()) { + val matcher = singleCounterPattern.matcher(line) + if (matcher.matches()) { + val counter = matcher.group(1).replace(",", "").toLong() + val name = inventoryName.split(" ").dropLast(1).joinToString(" ") + collectionValue[name] = counter + } + } + } + + if (inventoryName.endsWith(" Collections")) { + if (inventoryName == "Boss Collections") return + + for ((_, stack) in event.inventoryItems) { + var name = stack.name?.removeColor() ?: continue + if (name.contains("Collections")) continue + + val lore = stack.getLore() + if (!lore.any { it.contains("Click to view!") }) continue + + if (!isCollectionTier0(lore)) { + name = name.split(" ").dropLast(1).joinToString(" ") + } + + for (line in lore) { + val matcher = counterPattern.matcher(line) + if (matcher.matches()) { + val counter = matcher.group(1).replace(",", "").toLong() + collectionValue[name] = counter + } + } + } + } + } + + companion object { + private val collectionValue = mutableMapOf<String, Long>() + private val collectionTier0Pattern = Pattern.compile("§7Progress to .* I: .*") + + fun isCollectionTier0(lore: List<String>) = lore.map { collectionTier0Pattern.matcher(it) }.any { it.matches() } + + fun getCollectionCounter(searchName: String): Pair<String, Long>? { + for ((collectionName, counter) in collectionValue) { + if (collectionName.equals(searchName, true)) { + return Pair(collectionName, counter) + } + } + return null + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt index f8139e3b9..28ac37849 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -34,6 +34,9 @@ class BazaarApi { return null } + fun getBazaarDataForInternalName(internalName: String) = + bazaarMap.values.firstOrNull { it.apiName == internalName } + fun isBazaarItem(stack: ItemStack): Boolean { val internalName = stack.getInternalName() return bazaarMap.any { it.value.apiName == internalName } 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 35d318652..75c755de3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoNextStepHelper.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.bingo import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.CollectionAPI import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.SkillExperience import at.hannibal2.skyhanni.events.LorenzChatEvent @@ -149,6 +150,16 @@ class BingoNextStepHelper { updateResult() } } + if (step is CollectionStep) { + val counter = CollectionAPI.getCollectionCounter(step.collectionName)?.second ?: 0 + if (step.amountHaving != counter) { + step.amountHaving = counter + if (counter >= step.amountNeeded) { + step.done() + } + updateResult() + } + } } } @@ -288,7 +299,10 @@ class BingoNextStepHelper { ).apply { createItemIslandRequirement(itemName, this) } redstoneForThys requires IslandType.DEEP_CAVERNS.getStep() IslandType.DWARVEN_MINES.getStep() requires redstoneForThys - IslandType.DWARVEN_MINES.getStep() requires SkillLevelStep("Mining", 12).also { it requires IslandType.THE_FARMING_ISLANDS.getStep() } + IslandType.DWARVEN_MINES.getStep() requires SkillLevelStep( + "Mining", + 12 + ).also { it requires IslandType.THE_FARMING_ISLANDS.getStep() } IslandType.CRYSTAL_HOLLOWS.getStep() requires IslandType.DWARVEN_MINES.getStep() // TODO add skyblock level requirement @@ -301,7 +315,10 @@ class BingoNextStepHelper { IslandType.DWARVEN_MINES.getStep().also { finalSteps.add(it) } ChatMessageStep("Get Ender Armor").also { finalSteps.add(it) } requires IslandType.THE_END.getStep() - IslandType.THE_END.getStep() requires SkillLevelStep("Combat", 12).also { it requires IslandType.DEEP_CAVERNS.getStep() } + IslandType.THE_END.getStep() requires SkillLevelStep( + "Combat", + 12 + ).also { it requires IslandType.DEEP_CAVERNS.getStep() } // enchantedCharcoal(7) // compactor(7) diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/nextstep/CollectionStep.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/nextstep/CollectionStep.kt index 0ba7dbe8e..065f92f9b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bingo/nextstep/CollectionStep.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/nextstep/CollectionStep.kt @@ -2,5 +2,5 @@ package at.hannibal2.skyhanni.features.bingo.nextstep import at.hannibal2.skyhanni.utils.NumberUtil -class CollectionStep(val itemName: String, amountNeeded: Int) : - NextStep(NumberUtil.format(amountNeeded) + " $itemName Collection")
\ No newline at end of file +class CollectionStep(val collectionName: String, amountNeeded: Int) : + ProgressionStep(NumberUtil.format(amountNeeded) + " $collectionName Collection", amountNeeded.toLong())
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt index 4bbd64276..e77865a35 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/ItemDisplayOverlayFeatures.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.features.inventory import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.CollectionAPI import at.hannibal2.skyhanni.events.RenderItemTipEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils @@ -18,7 +19,6 @@ import java.util.regex.Pattern class ItemDisplayOverlayFeatures { private val wishingCompassPattern = Pattern.compile("§7Remaining Uses: §e(.*)§8/§e3") - private val collectionTier0Pattern = Pattern.compile("§7Progress to .* I: .*") @SubscribeEvent fun onRenderItemTip(event: RenderItemTipEvent) { @@ -138,7 +138,7 @@ class ItemDisplayOverlayFeatures { val lore = item.getLore() if (lore.any { it.contains("Click to view!") }) { item.name?.let { - if (isCollectionTier0(lore)) return "0" + if (CollectionAPI.isCollectionTier0(lore)) return "0" if (it.startsWith("§e")) { val text = it.split(" ").last() return "" + text.romanToDecimalIfNeeded() @@ -150,8 +150,6 @@ class ItemDisplayOverlayFeatures { return "" } - private fun isCollectionTier0(lore: List<String>) = lore.map { collectionTier0Pattern.matcher(it) }.any { it.matches() } - private fun grabSackName(name: String): String { val split = name.split(" ") val text = split[0] 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 9da10beeb..95289ac0e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt @@ -1,14 +1,12 @@ package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.api.CollectionAPI import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent -import at.hannibal2.skyhanni.events.ProfileJoinEvent -import at.hannibal2.skyhanni.features.bazaar.BazaarApi -import at.hannibal2.skyhanni.features.bazaar.BazaarData import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.RenderUtils.renderString import net.minecraft.client.Minecraft import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -24,15 +22,13 @@ class CollectionCounter { private var itemName = "" private var itemApiName = "" - private var itemAmount = -1 + private var itemAmount = -1L private var lastAmountInInventory = -1 private var recentGain = 0 private var lastGainTime = -1L - private val apiCollectionData = mutableMapOf<String, Int>() - fun command(args: Array<String>) { if (args.isEmpty()) { if (itemName == "") { @@ -40,44 +36,26 @@ class CollectionCounter { return } LorenzUtils.chat("§e[SkyHanni] Stopped collection tracker.") - apiCollectionData[itemApiName] = itemAmount resetData() return } - var name = args.joinToString(" ") - - var data: BazaarData? = null - for (bazaarData in BazaarApi.bazaarMap.values) { - if (bazaarData.itemName.equals(name, ignoreCase = true)) { - data = bazaarData - break - } - } - - if (data == null) { - LorenzUtils.chat("§c[SkyHanni] Item '$name' not found!") - return - } - name = data.itemName - - val apiName = data.apiName - if (!apiCollectionData.contains(apiName)) { - if (apiCollectionData.isEmpty()) { - LorenzUtils.chat("§c[SkyHanni] No Collection Data! Is the collection API disabled? Is the API down?") - } else { - LorenzUtils.chat("§c[SkyHanni] Item $name is not in the collection data!") - } + val name = args.joinToString(" ") + val pair = CollectionAPI.getCollectionCounter(name) + if (pair == null) { + LorenzUtils.chat("§c[SkyHanni] Item $name is not in the collection data! (API disabled or open the collection inventory)") return } - if (itemAmount != -1) { - resetData() + itemName = pair.first + itemApiName = if (itemName == "Mushroom" || itemName == "Gemstone") { + LorenzUtils.chat("§7Mushroom and Gemstone items are not fully supported for the counter!") + "" + } else { + NEUItems.getInternalName(itemName) } - itemName = name - itemApiName = apiName - itemAmount = apiCollectionData[apiName]!! + itemAmount = pair.second lastAmountInInventory = countCurrentlyInInventory() updateDisplay() @@ -128,8 +106,6 @@ class CollectionCounter { if (diff != 0) { if (diff > 0) { gainItems(diff) -// } else { -// LorenzUtils.debug("Collection counter! Negative collection change: $diff") } } @@ -158,35 +134,6 @@ class CollectionCounter { } @SubscribeEvent - fun onProfileJoin(event: ProfileJoinEvent) { - apiCollectionData.clear() - } - - @SubscribeEvent - fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { - val profileData = event.profileData - - //new profiles don't have any collections or collection api is disabled - val collection = profileData["collection"]?.asJsonObject ?: return - - apiCollectionData.clear() - for (entry in collection.entrySet()) { - val name = entry.key - val value = entry.value.asInt - apiCollectionData[name] = value - if (name == itemApiName) { - val diff = value - itemAmount - if (diff != 0) { - LorenzUtils.debug("Collection counter was wrong by $diff items. (Compared against API data)") - } - itemAmount = value - recentGain = 0 - updateDisplay() - } - } - } - - @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { if (!LorenzUtils.inSkyBlock) return |