From a2f20b5399a0ff2862ef882183d733223570e7c7 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sun, 30 Jul 2023 22:38:30 +0200 Subject: renamed collection tracker --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 +- .../hannibal2/skyhanni/config/commands/Commands.kt | 4 +- .../skyhanni/features/misc/CollectionCounter.kt | 198 -------------------- .../skyhanni/features/misc/CollectionTracker.kt | 200 +++++++++++++++++++++ .../features/misc/tabcomplete/TabComplete.kt | 4 +- 5 files changed, 205 insertions(+), 203 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index d27201ee4..a59a45963 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -241,7 +241,7 @@ class SkyHanniMod { loadModule(GriffinBurrowHelper) loadModule(GriffinBurrowParticleFinder()) loadModule(BurrowWarpHelper()) - loadModule(CollectionCounter()) + loadModule(CollectionTracker()) loadModule(HighlightBonzoMasks()) loadModule(DungeonLevelColor()) loadModule(BazaarCancelledBuyOrderClipboard()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index b2023d7aa..4c8c455fd 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -19,7 +19,7 @@ import at.hannibal2.skyhanni.features.garden.fortuneguide.CaptureFarmingGear import at.hannibal2.skyhanni.features.garden.fortuneguide.FFGuideGUI import at.hannibal2.skyhanni.features.minion.MinionFeatures import at.hannibal2.skyhanni.features.misc.CityProjectFeatures -import at.hannibal2.skyhanni.features.misc.CollectionCounter +import at.hannibal2.skyhanni.features.misc.CollectionTracker import at.hannibal2.skyhanni.features.misc.MarkedPlayerManager import at.hannibal2.skyhanni.features.misc.discordrpc.DiscordRPCManager import at.hannibal2.skyhanni.features.misc.ghostcounter.GhostUtil @@ -107,7 +107,7 @@ object Commands { "shmarkplayer", "Add a highlight effect to a player for better visibility" ) { MarkedPlayerManager.command(it) } - registerCommand("shtrackcollection", "Tracks your collection gain over time") { CollectionCounter.command(it) } + registerCommand("shtrackcollection", "Tracks your collection gain over time") { CollectionTracker.command(it) } registerCommand( "shcroptime", "Calculates with your current crop per second speed how long you need to farm a crop to collect this amount of items" diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt deleted file mode 100644 index ff860b3b5..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionCounter.kt +++ /dev/null @@ -1,198 +0,0 @@ -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.LorenzTickEvent -import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_new -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUItems -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems -import at.hannibal2.skyhanni.utils.StringUtils.removeColor -import net.minecraft.client.Minecraft -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.* - -class CollectionCounter { - - private val RECENT_GAIN_TIME = 1_500 - - companion object { - - private var display = emptyList>() - - private var itemName = "" - private var internalName: NEUInternalName? = null - private var itemAmount = -1L - - private var lastAmountInInventory = -1 - - private var recentGain = 0 - private var lastGainTime = -1L - - fun command(args: Array) { - if (args.isEmpty()) { - if (internalName == null) { - LorenzUtils.chat("§c/shtrackcollection ") - return - } - LorenzUtils.chat("§e[SkyHanni] Stopped collection tracker.") - resetData() - return - } - - val rawName = fixTypo(args.joinToString(" ").lowercase().replace("_", " ")) - 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 - } - -// val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) ?: rawName.replace(" ", "_") - val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) - if (foundInternalName == null) { - LorenzUtils.chat("§c[SkyHanni] Item '$rawName' does not exist!") - return - } - - 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) { - "carrots" -> "carrot" - "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" - "caducous" -> "caducous stem" - "agaricus" -> "agaricus cap" - - else -> rawName - } - - private fun setNewCollection(internalName: NEUInternalName, 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 - } - this.internalName = internalName - itemName = name - itemAmount = foundAmount - - lastAmountInInventory = countCurrentlyInInventory() - updateDisplay() - LorenzUtils.chat("§e[SkyHanni] Started tracking $itemName §ecollection.") - } - - private fun resetData() { - itemAmount = -1 - internalName = null - - lastAmountInInventory = -1 - display = emptyList() - - recentGain = 0 - } - - private fun updateDisplay() { - val format = LorenzUtils.formatInteger(itemAmount) - - var gainText = "" - if (recentGain != 0) { - gainText = "§a+" + LorenzUtils.formatInteger(recentGain) - } - - display = Collections.singletonList(buildList { - internalName?.let { - add(NEUItems.getItemStack(it)) - } - add("$itemName collection: §e$format $gainText") - }) - } - - private fun countCurrentlyInInventory() = - InventoryUtils.countItemsInLowerInventory { it.getInternalName_new() == internalName } - - fun handleTabComplete(command: String): List? { - if (command != "shtrackcollection") return null - - return CollectionAPI.collectionValue.keys.mapNotNull { NEUItems.getItemStackOrNull(it) } - .map { it.displayName.removeColor().replace(" ", "_") } - } - } - - @SubscribeEvent - fun onTick(event: LorenzTickEvent) { - val thePlayer = Minecraft.getMinecraft().thePlayer ?: return - thePlayer.worldObj ?: return - - compareInventory() - updateGain() - } - - private fun compareInventory() { - if (lastAmountInInventory == -1) return - if (Minecraft.getMinecraft().currentScreen != null) return - - val currentlyInInventory = countCurrentlyInInventory() - val diff = currentlyInInventory - lastAmountInInventory - if (diff != 0) { - if (diff > 0) { - gainItems(diff) - } - } - - lastAmountInInventory = currentlyInInventory - } - - private fun updateGain() { - if (recentGain != 0) { - if (System.currentTimeMillis() > lastGainTime + RECENT_GAIN_TIME) { - recentGain = 0 - updateDisplay() - } - } - } - - private fun gainItems(amount: Int) { - itemAmount += amount - - if (System.currentTimeMillis() > lastGainTime + RECENT_GAIN_TIME) { - recentGain = 0 - } - lastGainTime = System.currentTimeMillis() - recentGain += amount - - updateDisplay() - } - - @SubscribeEvent - fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { - if (!LorenzUtils.inSkyBlock) return - - SkyHanniMod.feature.misc.collectionCounterPos.renderStringsAndItems(display, posLabel = "Collection Counter") - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt new file mode 100644 index 000000000..af01ca68b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/CollectionTracker.kt @@ -0,0 +1,200 @@ +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.LorenzTickEvent +import at.hannibal2.skyhanni.utils.InventoryUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName_new +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.* + +class CollectionTracker { + + private val RECENT_GAIN_TIME = 1_500 + + companion object { + + private var display = emptyList>() + + private var itemName = "" + private var internalName: NEUInternalName? = null + private var itemAmount = -1L + + private var lastAmountInInventory = -1 + + private var recentGain = 0 + private var lastGainTime = -1L + + fun command(args: Array) { + if (args.isEmpty()) { + if (internalName == null) { + LorenzUtils.chat("§c/shtrackcollection ") + return + } + LorenzUtils.chat("§e[SkyHanni] Stopped collection tracker.") + resetData() + return + } + + val rawName = fixTypo(args.joinToString(" ").lowercase().replace("_", " ")) + 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 + } + +// val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) ?: rawName.replace(" ", "_") + val foundInternalName = NEUItems.getInternalNameOrNullIgnoreCase(rawName) + if (foundInternalName == null) { + LorenzUtils.chat("§c[SkyHanni] Item '$rawName' does not exist!") + return + } + + 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) { + "carrots" -> "carrot" + "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" + "caducous" -> "caducous stem" + "agaricus" -> "agaricus cap" + "quartz" -> "nether quartz" + "glowstone" -> "glowstone dust" + + else -> rawName + } + + private fun setNewCollection(internalName: NEUInternalName, 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 + } + this.internalName = internalName + itemName = name + itemAmount = foundAmount + + lastAmountInInventory = countCurrentlyInInventory() + updateDisplay() + LorenzUtils.chat("§e[SkyHanni] Started tracking $itemName §ecollection.") + } + + private fun resetData() { + itemAmount = -1 + internalName = null + + lastAmountInInventory = -1 + display = emptyList() + + recentGain = 0 + } + + private fun updateDisplay() { + val format = LorenzUtils.formatInteger(itemAmount) + + var gainText = "" + if (recentGain != 0) { + gainText = "§a+" + LorenzUtils.formatInteger(recentGain) + } + + display = Collections.singletonList(buildList { + internalName?.let { + add(NEUItems.getItemStack(it)) + } + add("$itemName collection: §e$format $gainText") + }) + } + + private fun countCurrentlyInInventory() = + InventoryUtils.countItemsInLowerInventory { it.getInternalName_new() == internalName } + + fun handleTabComplete(command: String): List? { + if (command != "shtrackcollection") return null + + return CollectionAPI.collectionValue.keys.mapNotNull { NEUItems.getItemStackOrNull(it) } + .map { it.displayName.removeColor().replace(" ", "_") } + } + } + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + val thePlayer = Minecraft.getMinecraft().thePlayer ?: return + thePlayer.worldObj ?: return + + compareInventory() + updateGain() + } + + private fun compareInventory() { + if (lastAmountInInventory == -1) return + if (Minecraft.getMinecraft().currentScreen != null) return + + val currentlyInInventory = countCurrentlyInInventory() + val diff = currentlyInInventory - lastAmountInInventory + if (diff != 0) { + if (diff > 0) { + gainItems(diff) + } + } + + lastAmountInInventory = currentlyInInventory + } + + private fun updateGain() { + if (recentGain != 0) { + if (System.currentTimeMillis() > lastGainTime + RECENT_GAIN_TIME) { + recentGain = 0 + updateDisplay() + } + } + } + + private fun gainItems(amount: Int) { + itemAmount += amount + + if (System.currentTimeMillis() > lastGainTime + RECENT_GAIN_TIME) { + recentGain = 0 + } + lastGainTime = System.currentTimeMillis() + recentGain += amount + + updateDisplay() + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { + if (!LorenzUtils.inSkyBlock) return + + SkyHanniMod.feature.misc.collectionCounterPos.renderStringsAndItems(display, posLabel = "Collection Tracker") + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt index 08ec84c52..8e13d3a1d 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/tabcomplete/TabComplete.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.features.misc.tabcomplete -import at.hannibal2.skyhanni.features.misc.CollectionCounter +import at.hannibal2.skyhanni.features.misc.CollectionTracker object TabComplete { @@ -22,7 +22,7 @@ object TabComplete { private fun customTabComplete(command: String): List? { WarpTabComplete.handleTabComplete(command)?.let { return it } PlayerTabComplete.handleTabComplete(command)?.let { return it } - CollectionCounter.handleTabComplete(command)?.let { return it } + CollectionTracker.handleTabComplete(command)?.let { return it } return null } -- cgit