41 lines
1.6 KiB
Kotlin
41 lines
1.6 KiB
Kotlin
package com.github.itzilly.sbt.util
|
|
|
|
import net.minecraft.client.Minecraft
|
|
import net.minecraft.entity.player.EntityPlayer
|
|
import net.minecraft.util.ChatComponentText
|
|
import net.minecraft.util.ChatStyle
|
|
import net.minecraft.util.EnumChatFormatting
|
|
import net.minecraft.util.IChatComponent
|
|
|
|
object Chatterbox {
|
|
private const val prefixString = "[SBT] "
|
|
private val prefixColorStyle = ChatStyle().setColor(EnumChatFormatting.AQUA)
|
|
private val prefixComponent = ChatComponentText(prefixString).setChatStyle(prefixColorStyle)
|
|
private val player = Minecraft.getMinecraft().thePlayer
|
|
|
|
private fun copy(component: IChatComponent): IChatComponent {
|
|
val newComponent = ChatComponentText(component.unformattedTextForChat)
|
|
newComponent.chatStyle = component.chatStyle.createShallowCopy()
|
|
component.siblings.forEach { sibling ->
|
|
newComponent.appendSibling(copy(sibling))
|
|
}
|
|
return newComponent
|
|
}
|
|
|
|
fun say(msg: String) {
|
|
val messageComponent = ChatComponentText(msg).setChatStyle(ChatStyle().setColor(EnumChatFormatting.RESET))
|
|
player.addChatMessage(prefixComponent.createCopy().appendSibling(messageComponent))
|
|
}
|
|
|
|
fun say(component: ChatComponentText) {
|
|
player.addChatMessage(copy(prefixComponent).appendSibling(copy(component)))
|
|
}
|
|
|
|
fun say(component: IChatComponent) {
|
|
player.addChatMessage(copy(prefixComponent).appendSibling(copy(component)))
|
|
}
|
|
|
|
fun say(player: EntityPlayer, component: IChatComponent) {
|
|
player.addChatMessage(copy(prefixComponent).appendSibling(copy(component)))
|
|
}
|
|
} |