File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
mod/src/main/kotlin/gg/skytils/skytilsmod/utils/multiplatform Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1919package gg.skytils.skytilsmod.utils.multiplatform
2020
2121import gg.essential.universal.UMinecraft
22+ import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorChatState
23+ import net.minecraft.client.gui.hud.ChatHudLine
2224import net.minecraft.text.ClickEvent
2325import net.minecraft.text.HoverEvent
2426import net.minecraft.text.MutableText
@@ -43,6 +45,25 @@ fun MCTextComponent.map(action: Text.() -> Unit) {
4345fun MCTextComponent.chat () =
4446 UMinecraft .getMinecraft().inGameHud.chatHud.addMessage(this )
4547
48+ fun MCTextComponent.edit (newComponent : MCTextComponent ) {
49+ val oldState = UMinecraft .getMinecraft().inGameHud.chatHud.toChatState()
50+ val accessor = (oldState as AccessorChatState )
51+ val messages = accessor.messages
52+ val oldLine = messages.find { message ->
53+ this == message.content
54+ } ? : return
55+ messages.remove(oldLine)
56+ messages.add(ChatHudLine (
57+ UMinecraft .getMinecraft().inGameHud.ticks,
58+ newComponent,
59+ oldLine.signature,
60+ oldLine.indicator
61+ ))
62+ UMinecraft .getMinecraft().inGameHud.chatHud.restoreChatState(
63+ oldState
64+ )
65+ }
66+
4667fun MutableMCTextComponent.setHoverText (text : String ) = apply {
4768 setStyle(style.withHoverEvent(HoverEvent .ShowText (Text .literal(text))))
4869}
You can’t perform that action at this time.
0 commit comments