diff options
Diffstat (limited to 'src/main/java')
5 files changed, 168 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index a88ef4696..ba48a5103 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -163,6 +163,7 @@ public class SkyHanniMod { registerEvent(new GriffinBurrowHelper()); registerEvent(new GriffinBurrowParticleFinder()); registerEvent(new BurrowWarpHelper()); + registerEvent(new CollectionCounter()); registerEvent(new HighlightBonzoMasks()); registerEvent(new DungeonLevelColor()); registerEvent(new BazaarCancelledBuyOrderClipboard()); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 0f7f0fd6c..976a0d9da 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -37,6 +37,11 @@ public class Features extends Config { return; } + if (runnableId.equals("collectionCounter")) { + editOverlay(activeConfigCategory, 200, 16, misc.collectionCounterPos); + return; + } + if (runnableId.equals("debugPos")) { editOverlay(activeConfigCategory, 200, 16, dev.debugPos); return; 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 5d94d850c..e51f9d92c 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.ConfigEditor import at.hannibal2.skyhanni.config.commands.SimpleCommand.ProcessCommandRunnable import at.hannibal2.skyhanni.config.core.GuiScreenElementWrapper +import at.hannibal2.skyhanni.features.CollectionCounter import at.hannibal2.skyhanni.features.MarkedPlayerManager import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import at.hannibal2.skyhanni.test.LorenzTest @@ -37,6 +38,7 @@ object Commands { registerCommand("togglepacketlog") { LorenzTest.togglePacketLog() } registerCommand("shreloadlisteners") { LorenzTest.reloadListeners() } registerCommand("shresetburrowwarps") { BurrowWarpHelper.resetDisabledWarps() } + registerCommand("shtrackcollection") { CollectionCounter.command(it) } } private fun registerCommand(name: String, function: (Array<String>) -> Unit) { diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index 5420aec36..a47b7979e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -134,4 +134,9 @@ public class Misc { @ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.") @ConfigEditorBoolean public boolean configButtonOnPause = true; + + @Expose + @ConfigOption(name = "Collection Counter Position", desc = "Tracking the number of items you collect. §cDoes not work with sacks.") + @ConfigEditorButton(runnableId = "collectionCounter", buttonText = "Edit") + public Position collectionCounterPos = new Position(10, 10, false, true); }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/CollectionCounter.kt b/src/main/java/at/hannibal2/skyhanni/features/CollectionCounter.kt new file mode 100644 index 000000000..4124762b8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/CollectionCounter.kt @@ -0,0 +1,155 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent +import at.hannibal2.skyhanni.features.bazaar.BazaarApi +import at.hannibal2.skyhanni.features.bazaar.BazaarData +import at.hannibal2.skyhanni.test.GriffinJavaUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import net.minecraft.client.Minecraft +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +class CollectionCounter { + + companion object { + + private var textToRender = "" + private var itemName = "" + private var itemApiName = "" + private var itemAmount = -1 + + private var lastAmountInInventory = -1 + + private val apiCollectionData = mutableMapOf<String, Int>() + + fun command(args: Array<String>) { + if (args.isEmpty()) { + if (itemName == "") { + LorenzUtils.chat("§c/shtrackcollection <item name>") + return + } + LorenzUtils.chat("§e[SkyHanni] Disabled collection tracking for $itemName") + 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.error("Item '$name' not found!") + return + } + name = data.itemName + + val apiName = data.apiName + if (!apiCollectionData.contains(apiName)) { + LorenzUtils.error("Item '$name' not in collection data!") + return + } + + if (itemAmount != -1) { + resetData() + } + + itemName = name + itemApiName = apiName + itemAmount = apiCollectionData[apiName]!! + + lastAmountInInventory = countCurrentlyInInventory() + update() + LorenzUtils.chat("§e[SkyHanni] Enabled collection tracking for $itemName") + } + + private fun resetData() { + itemAmount = -1 + itemName = "" + itemApiName = "" + + lastAmountInInventory = -1 + textToRender = "" + } + + private fun update() { + val format = GriffinJavaUtils.formatInteger(itemAmount) + textToRender = "$itemName collection: $format" + } + + private fun countCurrentlyInInventory(): Int { + var currentlyInInventory = 0 + val player = Minecraft.getMinecraft().thePlayer + for (stack in player.inventory.mainInventory) { + if (stack == null) continue + val internalName = stack.getInternalName() + if (internalName == itemApiName) { + currentlyInInventory += stack.stackSize + } + } + return currentlyInInventory + } + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + val thePlayer = Minecraft.getMinecraft().thePlayer ?: return + thePlayer.worldObj ?: return + + if (lastAmountInInventory == -1) return + + if (Minecraft.getMinecraft().currentScreen != null) return + + val currentlyInInventory = countCurrentlyInInventory() + val diff = currentlyInInventory - lastAmountInInventory + if (diff != 0) { + if (diff > 0) { + itemAmount += diff + update() + } else { + LorenzUtils.debug("Collection counter! Negative collection change: $diff") + } + } + + lastAmountInInventory = currentlyInInventory + } + + @SubscribeEvent + fun onProfileDataLoad(event: ProfileApiDataLoadedEvent) { + val profileData = event.profileData + val collection = profileData["collection"].asJsonObject + + 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 + update() + } + } + } + + @SubscribeEvent + fun onRenderOverlay(event: RenderGameOverlayEvent.Post) { + if (event.type != RenderGameOverlayEvent.ElementType.ALL) return + if (!LorenzUtils.inSkyblock) return + + SkyHanniMod.feature.misc.collectionCounterPos.renderString(textToRender) + } +}
\ No newline at end of file |