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

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

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

	private var lastGuiOpenEvent = 0L

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

		if (!Config.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(Config.highlightLeapName, true)) {
                    leapPlayers[i - 11] = true
                }
			}
		}
	}
	@JvmStatic
	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]
	}
}