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

import dulkirmod.DulkirMod.Companion.mc
import dulkirmod.config.DulkirConfig
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

object DungeonLeap {
    var inLeapMenu = false
    var leapPlayers = BooleanArray(5) { false }

	private var lastGuiOpenEvent = 0L

	@SubscribeEvent
	fun onTick(event: TickEvent.ClientTickEvent) {
		val lastInLeap = inLeapMenu

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

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

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

				if (slotIn.stack == null) continue
				val stack = slotIn.stack
				if (Utils.stripColorCodes(stack.displayName).equals(DulkirConfig.highlightLeapName, true)) {
                    leapPlayers[i - 11] = true
                }
			}
		}
	}

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