diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-18 12:21:55 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-18 12:21:55 +0100 |
commit | c45868df4087b736d43c78668546f9cab4b7dee8 (patch) | |
tree | 4546cc612ec8b499a190bc12fa4952ca929dc24a /src/main/java | |
parent | d3e24d497102d4223052699197473dd394f4bb32 (diff) | |
download | skyhanni-c45868df4087b736d43c78668546f9cab4b7dee8.tar.gz skyhanni-c45868df4087b736d43c78668546f9cab4b7dee8.tar.bz2 skyhanni-c45868df4087b736d43c78668546f9cab4b7dee8.zip |
Fixed crimson isle reputation helper not detecting town board inventory instantly
Diffstat (limited to 'src/main/java')
2 files changed, 50 insertions, 56 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt index 9b4d6f882..da2a7965f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/DailyQuestHelper.kt @@ -2,9 +2,7 @@ package at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent +import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.features.nether.reputationhelper.CrimsonIsleReputationHelper import at.hannibal2.skyhanni.features.nether.reputationhelper.FactionType import at.hannibal2.skyhanni.features.nether.reputationhelper.dailykuudra.KuudraTier @@ -30,29 +28,37 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { private val townBoardBarbarian = LorenzVec(-572, 100, -687) private var tick = 0 - private val loader = QuestLoader(this) + private val questLoader = QuestLoader(this) val quests = mutableListOf<Quest>() private val sacksCache = mutableMapOf<String, Long>() private var latestTrophyFishInInventory = 0 + + @SubscribeEvent + fun onInventoryOpen(event: InventoryOpenEvent) { + if (!isEnabled()) return + + questLoader.checkInventory(event) + } + + @SubscribeEvent + fun onTabListUpdate(event: TabListUpdateEvent) { + if (!isEnabled()) return + + questLoader.loadFromTabList() + } + @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { - if (!LorenzUtils.inSkyBlock) return - if (LorenzUtils.skyBlockIsland != IslandType.CRIMSON_ISLE) return - if (!SkyHanniMod.feature.misc.crimsonIsleReputationHelper) return + if (!isEnabled()) return + tick++ if (tick % 20 == 0) { - loader.checkInventory() checkInventoryForTrophyFish() } if (tick % 60 == 0) { checkInventoryForFetchItem() - loader.loadFromTabList() - - if (quests.size > 5) { - reputationHelper.reset() - } } } @@ -74,9 +80,7 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { @SubscribeEvent fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { - if (!LorenzUtils.inSkyBlock) return - if (LorenzUtils.skyBlockIsland != IslandType.CRIMSON_ISLE) return - if (!SkyHanniMod.feature.misc.crimsonIsleReputationHelper) return + if (!isEnabled()) return if (event.gui !is GuiChest) return val chest = event.gui.inventorySlots as ContainerChest @@ -132,9 +136,7 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { @SubscribeEvent fun onChat(event: LorenzChatEvent) { - if (!LorenzUtils.inSkyBlock) return - if (LorenzUtils.skyBlockIsland != IslandType.CRIMSON_ISLE) return - if (!SkyHanniMod.feature.misc.crimsonIsleReputationHelper) return + if (!isEnabled()) return val message = event.message if (message == "§aYou completed your Dojo quest! Visit the Town Board to claim the rewards.") { @@ -191,9 +193,7 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { @SubscribeEvent fun onRenderWorld(event: RenderWorldLastEvent) { - if (!LorenzUtils.inSkyBlock) return - if (LorenzUtils.skyBlockIsland != IslandType.CRIMSON_ISLE) return - if (!SkyHanniMod.feature.misc.crimsonIsleReputationHelper) return + if (!isEnabled()) return if (!SkyHanniMod.feature.misc.crimsonIsleReputationLocation) return for (quest in quests) { @@ -321,7 +321,7 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { fun load() { reset() - loader.loadConfig() + questLoader.loadConfig() latestTrophyFishInInventory = SkyHanniMod.feature.hidden.crimsonIsleLatestTrophyFishInInventory } @@ -351,4 +351,7 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) { SkyHanniMod.feature.hidden.crimsonIsleLatestTrophyFishInInventory = latestTrophyFishInInventory } + + private fun isEnabled() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland != IslandType.CRIMSON_ISLE && + SkyHanniMod.feature.misc.crimsonIsleReputationHelper }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt index 2444cb0be..82b83105a 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/nether/reputationhelper/dailyquest/QuestLoader.kt @@ -1,14 +1,11 @@ package at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.features.nether.reputationhelper.dailyquest.quest.* -import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.TabListData -import net.minecraft.client.Minecraft -import net.minecraft.client.gui.inventory.GuiChest -import net.minecraft.inventory.ContainerChest class QuestLoader(private val dailyQuestHelper: DailyQuestHelper) { @@ -63,7 +60,7 @@ class QuestLoader(private val dailyQuestHelper: DailyQuestHelper) { val state = if (green) QuestState.READY_TO_COLLECT else QuestState.NOT_ACCEPTED dailyQuestHelper.update() - dailyQuestHelper.quests.add(addQuest(name, state, needAmount)) + addQuest(addQuest(name, state, needAmount)) } private fun addQuest(name: String, state: QuestState, needAmount: Int): Quest { @@ -111,43 +108,30 @@ class QuestLoader(private val dailyQuestHelper: DailyQuestHelper) { return dailyQuestHelper.quests.firstOrNull { it.internalName == name } } - fun checkInventory() { + fun checkInventory(event: InventoryOpenEvent) { val inMageRegion = LorenzUtils.skyBlockArea == "Community Center" val inBarbarianRegion = LorenzUtils.skyBlockArea == "Dragontail" if (!inMageRegion && !inBarbarianRegion) return - val gui = Minecraft.getMinecraft().currentScreen - if (gui !is GuiChest) return - val chest = gui.inventorySlots as ContainerChest - val name = chest.getInventoryName() - + val name = event.inventoryName for (quest in dailyQuestHelper.quests) { val categoryName = quest.category.name if (!categoryName.equals(name, ignoreCase = true)) continue + val stack = event.inventoryItems[22] ?: continue - for (slot in chest.inventorySlots) { - if (slot == null) continue - if (slot.slotNumber != slot.slotIndex) continue - - // Only checking the middle slot - if (slot.slotNumber != 22) continue - - val stack = slot.stack ?: continue - - val completed = stack.getLore().any { it.contains("Completed!") } - if (completed) { - if (quest.state != QuestState.COLLECTED) { - quest.state = QuestState.COLLECTED - dailyQuestHelper.update() - } + val completed = stack.getLore().any { it.contains("Completed!") } + if (completed) { + if (quest.state != QuestState.COLLECTED) { + quest.state = QuestState.COLLECTED + dailyQuestHelper.update() } + } - val accepted = !stack.getLore().any { it.contains("Click to start!") } - if (accepted) { - if (quest.state == QuestState.NOT_ACCEPTED) { - quest.state = QuestState.ACCEPTED - dailyQuestHelper.update() - } + val accepted = !stack.getLore().any { it.contains("Click to start!") } + if (accepted) { + if (quest.state == QuestState.NOT_ACCEPTED) { + quest.state = QuestState.ACCEPTED + dailyQuestHelper.update() } } } @@ -171,7 +155,14 @@ class QuestLoader(private val dailyQuestHelper: DailyQuestHelper) { } } } - dailyQuestHelper.quests.add(quest) + addQuest(quest) + } + } + + private fun addQuest(element: Quest) { + dailyQuestHelper.quests.add(element) + if (dailyQuestHelper.quests.size > 5) { + dailyQuestHelper.reputationHelper.reset() } } }
\ No newline at end of file |