aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCephetir <silyichev@gmail.com>2022-05-07 15:58:07 +0300
committerCephetir <silyichev@gmail.com>2022-05-07 15:58:07 +0300
commit5a7c1803dfeeda9a88dc4c290d60e907a43aeebd (patch)
tree62c69c0bfedc453db258c59d85fcc471b871459f
parent8dcd0270b25df0437fd583b8221f59943cfe4372 (diff)
downloadChatting-5a7c1803dfeeda9a88dc4c290d60e907a43aeebd.tar.gz
Chatting-5a7c1803dfeeda9a88dc4c290d60e907a43aeebd.tar.bz2
Chatting-5a7c1803dfeeda9a88dc4c290d60e907a43aeebd.zip
FINALLY fixed timestamps
-rw-r--r--src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java32
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt11
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt2
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt41
4 files changed, 57 insertions, 29 deletions
diff --git a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java
index 6cf58ef..8f92e1e 100644
--- a/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java
+++ b/src/main/java/cc/woverflow/chatting/mixin/GuiNewChatMixin.java
@@ -12,10 +12,7 @@ import gg.essential.universal.UMouse;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.*;
import net.minecraft.client.renderer.GlStateManager;
-import net.minecraft.util.EnumChatFormatting;
-import net.minecraft.util.IChatComponent;
-import net.minecraft.util.MathHelper;
-import net.minecraft.util.ResourceLocation;
+import net.minecraft.util.*;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@@ -30,6 +27,8 @@ import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
import java.util.Locale;
@@ -72,12 +71,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);
+ @Unique
+ private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
+ @ModifyArg(method = "setChatLine", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/ChatLine;<init>(ILnet/minecraft/util/IChatComponent;I)V"))
+ private IChatComponent handleAddDrawnLine(IChatComponent iChatComponent) {
+ if (!ChattingConfig.INSTANCE.getShowTimestamp()) return iChatComponent;
+ String time = " §7["+ sdf.format(new Date(System.currentTimeMillis())) + "]§r";
+ iChatComponent.appendSibling(new ChatComponentText(time));
+ return iChatComponent;
}
@Inject(method = "drawChat", at = @At("HEAD"))
@@ -139,9 +140,18 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
return chatting$textOpacity = (int) (((float) (getChatOpen() ? 255 : value)) * (mc.gameSettings.chatOpacity * 0.9F + 0.1F));
}
+ @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;scale(FFF)V"))
+ private void drawPre(int updateCounter, CallbackInfo ci) {
+ RenderUtils.timestampPre();
+ }
+
+ @Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;popMatrix()V"))
+ private void drawPost(int updateCounter, CallbackInfo ci) {
+ RenderUtils.timestampPost();
+ }
+
@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 d1a6ae9..2b163c5 100644
--- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt
@@ -107,13 +107,21 @@ object ChattingConfig :
@Property(
type = PropertyType.SWITCH,
name = "Show Timestamp",
- description = "Show message timestamp on hover.",
+ description = "Show message timestamp.",
category = "General"
)
var showTimestamp = false
@Property(
type = PropertyType.SWITCH,
+ name = "Timestamp Only On Hover",
+ description = "Show timestamp only on mouse hover.",
+ category = "General"
+ )
+ var showTimestampHover = true
+
+ @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"
@@ -243,6 +251,7 @@ object ChattingConfig :
chatShortcuts = funny
ChatShortcuts.initialize()
}
+ addDependency("showTimestampHover", "showTimestamp")
}
private object ConfigSorting : SortingBehavior() {
diff --git a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt
index b22673b..61f1ea1 100644
--- a/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/gui/components/ScreenshotButton.kt
@@ -11,7 +11,7 @@ import net.minecraft.client.renderer.GlStateManager
import net.minecraft.util.ResourceLocation
class ScreenshotButton :
- CleanButton(448318, { UResolution.scaledWidth - 28 }, { UResolution.scaledHeight - 26 }, 12, 12, "",
+ CleanButton(448318, { UResolution.scaledWidth - 42 }, { UResolution.scaledHeight - 26 }, 12, 12, "",
{ RenderType.NONE }) {
override fun onMousePress() {
diff --git a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt
index dc6a1e6..7a5f5d4 100644
--- a/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt
+++ b/src/main/kotlin/cc/woverflow/chatting/utils/renderutils.kt
@@ -5,6 +5,7 @@ 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.ChatColor
import gg.essential.universal.UMouse
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ChatLine
@@ -12,7 +13,6 @@ 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
@@ -27,8 +27,6 @@ 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
@@ -219,21 +217,32 @@ 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
+private val timePattern = Regex("\\[\\d+:\\d+:\\d+]")
+private var lastLines = mutableListOf<ChatLine>()
+fun timestampPre() {
+ if (!ChattingConfig.showTimestampHover) return
+ val drawnChatLines = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines
val chatLine = getChatLineOverMouse(UMouse.getTrueX().roundToInt(), UMouse.getTrueY().roundToInt())
- if (chatLine != null) {
- val long = messages[chatLine]
- if (long != null) chatLine.chatComponent.appendText(" §7[${sdf.format(Date(long))}]§r")
+
+ lastLines.clear()
+ for (line in drawnChatLines) {
+ val chatComponent = line.chatComponent.createCopy()
+ val newline = ChatLine(line.updatedCounter, chatComponent, line.chatLineID)
+ lastLines.add(newline)
}
- val long = messages[lastMessage]
- if (long != null) lastMessage?.chatComponent?.siblings?.remove(ChatComponentText(" §7[${sdf.format(Date(long))}]§r"))
- lastMessage = chatLine
+
+ drawnChatLines.map {
+ if (it != chatLine) it.chatComponent.siblings.removeAll { itt ->
+ timePattern.find(ChatColor.stripControlCodes(itt.unformattedText)!!) != null
+ }
+ }
+}
+
+fun timestampPost() {
+ if (!ChattingConfig.showTimestampHover) return
+ val drawnChatLines = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines
+ drawnChatLines.clear()
+ drawnChatLines.addAll(lastLines)
}
private fun getChatLineOverMouse(mouseX: Int, mouseY: Int): ChatLine? {