diff options
Diffstat (limited to 'src')
3 files changed, 64 insertions, 55 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/events/MinionOpenEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/MinionOpenEvent.kt new file mode 100644 index 000000000..5d577b6ee --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/MinionOpenEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events + +import net.minecraft.item.ItemStack + +class MinionOpenEvent(val inventoryName: String, val inventoryItems: Map<Int, ItemStack>) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt index d6f971ec3..177a0016e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionCollectLogic.kt @@ -1,13 +1,10 @@ package at.hannibal2.skyhanni.features.minion import at.hannibal2.skyhanni.api.CollectionAPI -import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.MinionOpenEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NEUItems import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -15,19 +12,7 @@ class MinionCollectLogic { private var oldMap = mapOf<String, Int>() @SubscribeEvent - fun onInventoryOpen(event: InventoryOpenEvent) { - if (!LorenzUtils.inSkyBlock) return - if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return - if (!event.inventoryName.contains(" Minion ")) return - - event.inventoryItems[48]?.let { - if ("§aCollect All" == it.name) { - openMinion() - } - } - } - - private fun openMinion() { + fun onMinionOpen(event: MinionOpenEvent) { if (oldMap.isNotEmpty()) return oldMap = count() } diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt index b836fb315..887b17a2a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionFeatures.kt @@ -4,7 +4,10 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.Storage import at.hannibal2.skyhanni.data.IslandType import at.hannibal2.skyhanni.data.ProfileStorageData +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.events.MinionOpenEvent import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -83,50 +86,66 @@ class MinionFeatures { } @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!LorenzUtils.inSkyBlock) return if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return - val minions = minions ?: return + if (!event.inventoryName.contains(" Minion ")) return - val openInventory = InventoryUtils.currentlyOpenInventory() - if (openInventory.contains("Minion")) { - lastClickedEntity?.let { - val name = getMinionName(openInventory) - if (!minions.contains(it)) { - minions[it] = Storage.ProfileSpecific.MinionConfig().apply { - displayName = name - lastClicked = 0 - } - } else { - if (minions[it]!!.displayName != name) { - minions[it]!!.displayName = name - } - } - lastMinion = it - lastClickedEntity = null - minionInventoryOpen = true - lastMinionOpened = 0 + event.inventoryItems[48]?.let { + if ("§aCollect All" == it.name) { + MinionOpenEvent(event.inventoryName, event.inventoryItems).postAndCatch() + } + } + } + + @SubscribeEvent + fun onMinionOpen(event: MinionOpenEvent) { + val minions = minions ?: return + val entity = lastClickedEntity ?: return + + val openInventory = event.inventoryName + val name = getMinionName(openInventory) + if (!minions.contains(entity)) { + minions[entity] = Storage.ProfileSpecific.MinionConfig().apply { + displayName = name + lastClicked = 0 } } else { - if (minionInventoryOpen) { - minionInventoryOpen = false - lastMinionOpened = System.currentTimeMillis() - - val location = lastMinion - if (location != null) { - - if (System.currentTimeMillis() - lastCoinsRecived < 2_000) { - minions[location]!!.lastClicked = System.currentTimeMillis() - } - if (location !in minions) { - minions[location]!!.lastClicked = 0 - } - - if (System.currentTimeMillis() - lastMinionPickedUp < 2_000) { - minions.remove(location) - } - } + if (minions[entity]!!.displayName != name) { + minions[entity]!!.displayName = name } } + lastMinion = entity + lastClickedEntity = null + minionInventoryOpen = true + lastMinionOpened = 0 + } + + @SubscribeEvent + fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { + if (!minionInventoryOpen) return + val minions = minions ?: return + + minionInventoryOpen = false + lastMinionOpened = System.currentTimeMillis() + + val location = lastMinion ?: return + + if (System.currentTimeMillis() - lastCoinsRecived < 2_000) { + minions[location]!!.lastClicked = System.currentTimeMillis() + } + if (location !in minions) { + minions[location]!!.lastClicked = 0 + } + + if (System.currentTimeMillis() - lastMinionPickedUp < 2_000) { + minions.remove(location) + } + } + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (LorenzUtils.skyBlockIsland != IslandType.PRIVATE_ISLAND) return if (config.hopperProfitDisplay) { coinsPerDay = if (minionInventoryOpen) { |