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

import dulkirmod.config.Config
import dulkirmod.utils.TextUtils
import dulkirmod.utils.Utils
import dulkirmod.utils.WorldRenderUtils
import net.minecraft.util.Vec3
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ArachneTimer {
    private var startmillis: Long = -1
    private var endmillis: Long = -1
    private var spawnmillis: Long = -1
    private var bigboy: Boolean = false

    @SubscribeEvent(receiveCanceled = true, priority = EventPriority.LOW)
    fun onChat(event: ClientChatReceivedEvent) {
        if (!Config.arachneKillTimer) return

        var killtime: Float = -1f

        if (event.type == 2.toByte()) {
            return
        }

        val unformatted = Utils.stripColorCodes(event.message.unformattedText)
        if (unformatted == "[BOSS] Arachne: With your sacrifice." || unformatted == "[BOSS] Arachne: A befitting welcome!") {
            bigboy = false
            startmillis = System.currentTimeMillis()
        } else if (unformatted.startsWith('☄') && unformatted.contains("Something is awakening!")) {
            if (unformatted.contains("Arachne Crystal!")) bigboy = true
            spawnmillis = System.currentTimeMillis()
        }

        if (unformatted.startsWith("                           Runecrafting:")) {
            endmillis = System.currentTimeMillis()
            if (startmillis > -1) {
                killtime = (endmillis - startmillis).toFloat() / 1000
                TextUtils.info("§6Arachne took §7$killtime §6seconds to kill.")
            }
        }
    }

    @SubscribeEvent
    fun onWorldRenderLast(event: RenderWorldLastEvent) {
        if (!Config.arachneSpawnTimer) return

        if (spawnmillis > startmillis) {
            val color = Utils.getColorString(Config.bestiaryNotifColor)
            var time: Int
            time = if (bigboy) {
                (40 - (System.currentTimeMillis() - spawnmillis) / 1000).toInt()
            } else {
                (18 - (System.currentTimeMillis() - spawnmillis) / 1000).toInt()
            }
            if (time < 0) time = 0
            WorldRenderUtils.render(Vec3(-282.5, 50.8, -178.5), "${color}${time}", false)
        }
    }
}