aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/features/DungeonLeap.kt
blob: b8ce75e15c5cfc8c0f503ae2b3d47b496f25f7cc (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
package dulkirmod.features

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

class DungeonLeap {


    private var lastGuiOpenEvent : Long = 0
    @SubscribeEvent
    fun onTick(event: TickEvent.ClientTickEvent) {
        val lastInLeap = inLeapMenuBool

        if (!Config.highlightLeap) return
        if (mc.currentScreen == null || !(mc.currentScreen is GuiChest)) {
            inLeapMenuBool = false
            return
        }
        inLeapMenuBool = (ContainerNameUtil.currentGuiChestName == "Spirit Leap")

        if (inLeapMenuBool && !lastInLeap) {
            lastGuiOpenEvent = System.currentTimeMillis()
        }

        if (inLeapMenuBool && System.currentTimeMillis() - lastGuiOpenEvent < 300) {
            for (i in 11..15) {
                boolArray[i-11] = false
                val slotIn = DulkirMod.mc.thePlayer.openContainer.getSlot(i)

                if (slotIn.stack == null) continue
                val stack = slotIn.stack
                if (Utils.stripColorCodes(stack.displayName) == Config.highlightLeapName) boolArray[i-11] = true
            }
        }
    }
    companion object {
        var inLeapMenuBool : Boolean = false
        var boolArray = BooleanArray(5) {false}

        fun inLeapMenu(): Boolean {
            return inLeapMenuBool
        }

        fun isHighlightedLeapPlayer(slotIn: Slot): Boolean {
            if (!inLeapMenuBool) return false
            if(slotIn.inventory == mc.thePlayer.inventory) return false
            val slotIndex = slotIn.slotIndex
            if (slotIndex !in 11..15) return false
            return boolArray[slotIndex - 11]
        }
    }
}