aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-01 17:31:22 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-05-01 17:31:22 +0200
commita004600ace92bd722e289c06864eac1ad103d477 (patch)
treeed2ce32066da4369c12b4bac9d0f367bea22151e
parent390b674e5eaaeeacb4c804c606678b82d3594f64 (diff)
downloadskyhanni-a004600ace92bd722e289c06864eac1ad103d477.tar.gz
skyhanni-a004600ace92bd722e289c06864eac1ad103d477.tar.bz2
skyhanni-a004600ace92bd722e289c06864eac1ad103d477.zip
Using InventoryOpenEvent to read bingo card data
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt44
1 files changed, 6 insertions, 38 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
index 8971cc3d3..681b422fe 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/bingo/BingoCardDisplay.kt
@@ -3,10 +3,10 @@ package at.hannibal2.skyhanni.features.bingo
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.bingo.card.CommunityGoal
import at.hannibal2.skyhanni.features.bingo.card.PersonalGoal
-import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.ItemUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
@@ -16,19 +16,16 @@ import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiChat
-import net.minecraft.client.gui.inventory.GuiChest
-import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import net.minecraftforge.fml.common.gameevent.TickEvent
class BingoCardDisplay {
+ private val config get() = SkyHanniMod.feature.bingo.bingoCard
private val MAX_PERSONAL_GOALS = 20
private val MAX_COMMUNITY_GOALS = 5
private var tick = 0
private var display = listOf<String>()
- private val config get() = SkyHanniMod.feature.bingo.bingoCard
private val goalCompletePattern = "§6§lBINGO GOAL COMPLETE! §r§e(?<name>.*)".toPattern()
init {
@@ -39,8 +36,6 @@ class BingoCardDisplay {
val personalGoals = mutableListOf<PersonalGoal>()
private val communityGoals = mutableListOf<CommunityGoal>()
- private var dirty = true
-
fun command() {
reload()
}
@@ -48,39 +43,18 @@ class BingoCardDisplay {
private fun reload() {
personalGoals.clear()
communityGoals.clear()
- dirty = true
}
}
@SubscribeEvent
- fun onTick(event: TickEvent.ClientTickEvent) {
+ fun onInventoryOpen(event: InventoryOpenEvent) {
if (!LorenzUtils.isBingoProfile) return
if (!config.enabled) return
- if (event.phase != TickEvent.Phase.START) return
-
- tick++
- if (tick % 5 != 0) return
-
- val gui = Minecraft.getMinecraft().currentScreen
- if (gui !is GuiChest) {
- dirty = true
- return
- }
-
- val chest = gui.inventorySlots as ContainerChest
- if (chest.getInventoryName() == "Bingo Card") {
- if (dirty) {
- readBingoCard(gui)
- }
- }
- }
+ if (event.inventoryName != "Bingo Card") return
- private fun readBingoCard(gui: GuiChest) {
personalGoals.clear()
communityGoals.clear()
-
- for (slot in gui.inventorySlots.inventorySlots) {
- val stack = slot?.stack ?: continue
+ for (stack in event.inventoryItems.values) {
val personalGoal = stack.getLore().any { it.endsWith("Personal Goal") }
val communityGoal = stack.getLore().any { it.endsWith("Community Goal") }
if (!personalGoal && !communityGoal) continue
@@ -112,13 +86,7 @@ class BingoCardDisplay {
}
}
- val a = personalGoals.size
- val b = communityGoals.size
- if (a == MAX_PERSONAL_GOALS && b == MAX_COMMUNITY_GOALS) {
- dirty = false
-
- update()
- }
+ update()
}
private fun update() {