aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiChatHook.kt
blob: 354707f8569a591ab3b00725f86617c869d2af5f (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
package at.hannibal2.skyhanni.mixins.hooks

import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChatStyle
import net.minecraft.util.IChatComponent

object GuiChatHook {

    lateinit var replacement: ChatComponentText

    fun replaceEntireComponent(title: String, chatStyle: ChatStyle) {
        if (!this::replacement.isInitialized) return

        // Initialise new component
        val newComponent = ChatComponentText(title)
        newComponent.setChatStyle(chatStyle)

        replacement = newComponent
    }

    fun replaceOnlyHoverEvent(hoverEvent: HoverEvent) {
        if (!this::replacement.isInitialized) return

        // Initialise new component
        val newComponent = ChatComponentText(replacement.chatComponentText_TextValue)
        newComponent.setChatStyle(replacement.chatStyle)
        newComponent.chatStyle.chatHoverEvent = hoverEvent

        replacement = newComponent
    }

    fun getReplacementAsIChatComponent(): IChatComponent {
        if (!this::replacement.isInitialized) {
            // Return an extremely basic chat component as to not error downstream
            return ChatComponentText("Original component was not set")
        }
        return replacement
    }
}