aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/features/Croesus.kt
blob: e38616ce925b8f5ef7789bd75b71e370727d7219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package dulkirmod.features

import dulkirmod.DulkirMod.Companion.mc
import dulkirmod.config.Config
import dulkirmod.utils.ContainerNameUtil
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.Slot
import net.minecraft.nbt.NBTTagList
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent

class Croesus {

    var lastGuiOpenEvent: Long = 0

    @SubscribeEvent
    fun onTick(event: TickEvent.ClientTickEvent) {
        val lastInCroesus = inCroesusBool

        if (!Config.hideOpenedChests) return
        if (mc.currentScreen == null || !(mc.currentScreen is GuiChest)) {
            inCroesusBool = false
            return
        }
        inCroesusBool = (ContainerNameUtil.currentGuiChestName == "Croesus")

        if (inCroesusBool && !lastInCroesus) {
            lastGuiOpenEvent = System.currentTimeMillis()
        }

        if (inCroesusBool && System.currentTimeMillis() - lastGuiOpenEvent < 300) {
            for (i in 9..44) {
                boolArray[i - 9] = false
                val slotIn = mc.thePlayer.openContainer.getSlot(i)

                if (slotIn.stack == null) continue
                val stack = slotIn.stack
                if (stack.getSubCompound("display", true)?.getTagList("Lore", 8) == null) continue

                val tagList: NBTTagList = stack.getSubCompound("display", true).getTagList("Lore", 8)
                for (j in 0 until tagList.tagCount()) {
                    if (tagList.getStringTagAt(j) == "§aChests have been opened!") boolArray[i - 9] = true
                }
            }
        }
    }

    companion object {
        var inCroesusBool: Boolean = false
        var boolArray = BooleanArray(36) { false }

        fun inCroesus(): Boolean {
            return inCroesusBool
        }

        fun isChestOpened(slotIn: Slot): Boolean {
            if (!inCroesusBool) return false
            if (slotIn.inventory == mc.thePlayer.inventory) return false
            val slotindex = slotIn.slotIndex
            if (slotindex !in 9..44) return false
            return boolArray[slotindex - 9]
        }
    }
}