diff options
author | Cephetir <silyichev@gmail.com> | 2022-05-06 12:41:54 +0300 |
---|---|---|
committer | Cephetir <silyichev@gmail.com> | 2022-05-06 12:41:54 +0300 |
commit | b5002d403246d91b8276791c1d16847abbbadab9 (patch) | |
tree | c011350cd8b1e29252edf672c68bbcb7cbc2a28d /src/main/kotlin/cc/woverflow/chatting/utils | |
parent | d3b3d5273d6754c991d6ba9a69884071a8e56c91 (diff) | |
download | Chatting-b5002d403246d91b8276791c1d16847abbbadab9.tar.gz Chatting-b5002d403246d91b8276791c1d16847abbbadab9.tar.bz2 Chatting-b5002d403246d91b8276791c1d16847abbbadab9.zip |
Timestamp on hover
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chatting/utils')
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt | 12 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt | 47 |
2 files changed, 51 insertions, 8 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt index 8f73f2c..39455ae 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt @@ -1,12 +1,12 @@ package cc.woverflow.chatting.utils -import club.sk1er.patcher.config.PatcherConfig -import com.llamalad7.betterchat.BetterChat import cc.woverflow.chatting.Chatting.isBetterChat import cc.woverflow.chatting.Chatting.isPatcher import cc.woverflow.chatting.config.ChattingConfig.textRenderType import cc.woverflow.chatting.hook.GuiNewChatHook import cc.woverflow.onecore.utils.drawBorderedString +import club.sk1er.patcher.config.PatcherConfig +import com.llamalad7.betterchat.BetterChat import net.minecraft.client.Minecraft import net.minecraft.client.gui.FontRenderer @@ -35,12 +35,8 @@ object ModCompatHooks { @JvmStatic fun redirectDrawString(text: String, x: Float, y: Float, color: Int): Int { return when (textRenderType) { - 0 -> { - fontRenderer.drawString(text, x, y, color, false) - } - 2 -> { - fontRenderer.drawBorderedString(text, x.toInt(), y.toInt(), color, (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity) - } + 0 -> fontRenderer.drawString(text, x, y, color, false) + 2 -> fontRenderer.drawBorderedString(text, x.toInt(), y.toInt(), color, (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).textOpacity) else -> fontRenderer.drawString(text, x, y, color, true) } } diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt index 393cc74..bf11c3b 100644 --- a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt +++ b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt @@ -3,9 +3,17 @@ package cc.woverflow.chatting.utils import cc.woverflow.chatting.config.ChattingConfig +import cc.woverflow.chatting.mixin.GuiNewChatAccessor +import cc.woverflow.chatting.utils.ModCompatHooks.fontRenderer +import gg.essential.universal.UMouse +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.ChatLine +import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.texture.TextureUtil import net.minecraft.client.shader.Framebuffer +import net.minecraft.util.ChatComponentText +import net.minecraft.util.MathHelper import org.apache.commons.lang3.SystemUtils import org.lwjgl.BufferUtils import org.lwjgl.opengl.GL11 @@ -19,7 +27,10 @@ import java.lang.reflect.Field import java.lang.reflect.Method import java.nio.ByteBuffer import java.nio.ByteOrder +import java.text.SimpleDateFormat +import java.util.* import javax.imageio.ImageIO +import kotlin.math.roundToInt /** * Taken from https://github.com/Moulberry/HyChat @@ -206,4 +217,40 @@ fun Framebuffer.screenshot(file: File): BufferedImage { } } return bufferedimage +} + +private val sdf: SimpleDateFormat = SimpleDateFormat("HH:mm:ss") + +@JvmField +val messages: Map<ChatLine, Long> = mutableMapOf() +var lastMessage: ChatLine? = null +fun showTimestamp() { + if (!ChattingConfig.showTimestamp) return + val chatLine = getChatLineOverMouse(UMouse.Raw.x.roundToInt(), UMouse.Raw.y.roundToInt()) + if (chatLine != null) { + val long = messages[chatLine] + if (long != null) chatLine.chatComponent.appendText(" §7[${sdf.format(Date(long))}]§r") + } + val long = messages[lastMessage] + if (long != null) lastMessage?.chatComponent?.siblings?.remove(ChatComponentText(" §7[${sdf.format(Date(long))}]§r")) + lastMessage = chatLine +} + +private fun getChatLineOverMouse(mouseX: Int, mouseY: Int): ChatLine? { + val chat = Minecraft.getMinecraft().ingameGUI.chatGUI + if (!chat.chatOpen) return null + val scaledResolution = ScaledResolution(Minecraft.getMinecraft()) + val i = scaledResolution.scaleFactor + val f = chat.chatScale + val j = MathHelper.floor_float((mouseX / i - 3).toFloat() / f) + val k = MathHelper.floor_float((mouseY / i - 27).toFloat() / f) + if (j < 0 || k < 0) return null + val drawnChatLines = (chat as GuiNewChatAccessor).drawnChatLines + val l = chat.lineCount.coerceAtMost(drawnChatLines.size) + if (j <= MathHelper.floor_float(chat.chatWidth.toFloat() / f) && k < fontRenderer.FONT_HEIGHT * l + l) { + val m = k / Minecraft.getMinecraft().fontRendererObj.FONT_HEIGHT + chat.scrollPos + if (m >= 0 && m < drawnChatLines.size) + return drawnChatLines[m] + } + return null }
\ No newline at end of file |