aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCephetir <silyichev@gmail.com>2022-05-06 12:41:54 +0300
committerCephetir <silyichev@gmail.com>2022-05-06 12:41:54 +0300
commitb5002d403246d91b8276791c1d16847abbbadab9 (patch)
treec011350cd8b1e29252edf672c68bbcb7cbc2a28d
parentd3b3d5273d6754c991d6ba9a69884071a8e56c91 (diff)
downloadChatting-b5002d403246d91b8276791c1d16847abbbadab9.tar.gz
Chatting-b5002d403246d91b8276791c1d16847abbbadab9.tar.bz2
Chatting-b5002d403246d91b8276791c1d16847abbbadab9.zip
Timestamp on hover
-rw-r--r--.gitignore3
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java9
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt8
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/utils/ModCompatHooks.kt12
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt47
5 files changed, 70 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 36367f5..74b86e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,4 +26,5 @@ build
# other
run
.DS_Store
-Thumbs.db \ No newline at end of file
+Thumbs.db
+.vscode \ No newline at end of file
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java
index e9acce1..6cf58ef 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java
@@ -72,6 +72,14 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
handleChatTabMessage(chatComponent, chatLineId, updateCounter, displayOnly, ci);
}
+ @Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V"), slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;scroll(I)V"), to = @At(value = "INVOKE", target = "Ljava/util/List;size()I")), cancellable = true)
+ private void handleAddDrawnLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) {
+ ci.cancel();
+ ChatLine chatLine = new ChatLine(updateCounter, chatComponent, chatLineId);
+ RenderUtils.messages.put(chatLine, System.currentTimeMillis());
+ this.drawnChatLines.add(0, chatLine);
+ }
+
@Inject(method = "drawChat", at = @At("HEAD"))
private void checkScreenshotKeybind(int j2, CallbackInfo ci) {
if (Chatting.INSTANCE.getKeybind().isPressed()) {
@@ -133,6 +141,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
@Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I"))
private int redirectDrawString(FontRenderer instance, String text, float x, float y, int color) {
+ RenderUtils.showTimestamp();
return ModCompatHooks.redirectDrawString(text, x, y, color);
}
diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
index 93a8723..e80fa94 100644
--- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
@@ -80,6 +80,14 @@ object ChattingConfig :
@Property(
type = PropertyType.SWITCH,
+ name = "Show Timestamp",
+ description = "Show message timestamp on hover.",
+ category = "General"
+ )
+ var showTimestamp = false
+
+ @Property(
+ type = PropertyType.SWITCH,
name = "Custom Chat Height",
description = "Allows you to change the height of chat to heights greater than before.",
category = "Chat Window"
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