aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/features/misc/KuudraReady.kt
blob: 469d6fedc66c38d220b718b56bca144744fb73e7 (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
package com.ambientaddons.features.misc

import AmbientAddons.Companion.config
import AmbientAddons.Companion.mc
import com.ambientaddons.utils.Area
import com.ambientaddons.utils.Extensions.chest
import com.ambientaddons.utils.Extensions.items
import com.ambientaddons.utils.Extensions.lore
import com.ambientaddons.utils.Extensions.stripControlCodes
import com.ambientaddons.utils.SkyBlock
import com.ambientaddons.utils.dungeon.DungeonPlayers
import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object KuudraReady {
    private var hasClickedReady = false

    @SubscribeEvent
    fun onWorldUnload(event: WorldEvent.Unload) {
        hasClickedReady = false
    }

    @SubscribeEvent
    fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent) {
        if (!config.kuudraReady || SkyBlock.area != Area.Kuudra) return
        val chest = event.gui?.chest ?: return
        val chestName = chest.lowerChestInventory.name
        if (chestName == "Ready Up" && !hasClickedReady) {
            val clickIndex = chest.lowerChestInventory.items.takeIf { it.last() != null }?.indexOfFirst {
                it?.lore?.getOrNull(0)?.stripControlCodes()?.startsWith("Click to mark yourself") == true
            } ?: return
            hasClickedReady = true
            mc.playerController.windowClick(chest.windowId, clickIndex, 2, 3, mc.thePlayer)
        }
    }
}