From 38af8a31a642fa3112ceb7651dd673e1de58851e Mon Sep 17 00:00:00 2001 From: XThe <101992755+SirXThe@users.noreply.github.com> Date: Sun, 26 Feb 2023 18:22:35 +0100 Subject: fix: fix: resolve duplicated lines are missing in chat screenshots (#21) --- src/main/kotlin/cc/woverflow/chatting/Chatting.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/main/kotlin/cc/woverflow/chatting') diff --git a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt index ae5f8a1..882be98 100644 --- a/src/main/kotlin/cc/woverflow/chatting/Chatting.kt +++ b/src/main/kotlin/cc/woverflow/chatting/Chatting.kt @@ -195,7 +195,7 @@ object Chatting { val chat = hud.chatGUI val i = MathHelper.floor_float(chat.chatWidth / chat.chatScale) return screenshot( - hashMapOf().also { + hashMapOf().also { GuiUtilRenderComponents.splitText( line.chatComponent, i, @@ -203,7 +203,7 @@ object Chatting { false, false ).map { it.formattedText }.reversed().forEach { string -> - it[string] = line + it[line] = string } } ) @@ -216,7 +216,7 @@ object Chatting { fun screenshotChat(scrollPos: Int) { val hud = Minecraft.getMinecraft().ingameGUI val chat = hud.chatGUI - val chatLines = LinkedHashMap() + val chatLines = LinkedHashMap() ChatSearchingManager.filterMessages( ChatSearchingManager.lastSearch, (chat as GuiNewChatAccessor).drawnChatLines @@ -226,14 +226,14 @@ object Chatting { Minecraft.getMinecraft().gameSettings.chatHeightFocused / 9 ) for (i in scrollPos until drawnLines.size.coerceAtMost(scrollPos + chatHeight)) { - chatLines[drawnLines[i].chatComponent.formattedText] = drawnLines[i] + chatLines[drawnLines[i]] = drawnLines[i].chatComponent.formattedText } screenshot(chatLines)?.copyToClipboard() } } - private fun screenshot(messages: HashMap): BufferedImage? { + private fun screenshot(messages: HashMap): BufferedImage? { if (messages.isEmpty()) { Notifications.INSTANCE.send("Chatting", "Chat window is empty.") return null @@ -247,15 +247,15 @@ object Chatting { } val fr: FontRenderer = ModCompatHooks.fontRenderer - val width = messages.maxOf { fr.getStringWidth(it.key) + (if (ChattingConfig.showChatHeads && ((it.value as ChatLineHook).hasDetected() || ChattingConfig.offsetNonPlayerMessages)) 10 else 0) } + 4 + val width = messages.maxOf { fr.getStringWidth(it.value) + (if (ChattingConfig.showChatHeads && ((it.key as ChatLineHook).hasDetected() || ChattingConfig.offsetNonPlayerMessages)) 10 else 0) } + 4 val fb: Framebuffer = createBindFramebuffer(width * 2, (messages.size * 9) * 2) val file = File(Minecraft.getMinecraft().mcDataDir, "screenshots/chat/" + fileFormatter.format(Date())) GlStateManager.scale(2f, 2f, 1f) val scale = Minecraft.getMinecraft().gameSettings.chatScale GlStateManager.scale(scale, scale, 1f) - messages.entries.forEachIndexed { i: Int, entry: MutableMap.MutableEntry -> - ModCompatHooks.redirectDrawString(entry.key, 0f, (messages.size - 1 - i) * 9f, 0xffffff, entry.value, true) + messages.entries.forEachIndexed { i: Int, entry: MutableMap.MutableEntry -> + ModCompatHooks.redirectDrawString(entry.value, 0f, (messages.size - 1 - i) * 9f, 0xffffff, entry.key, true) } val image = fb.screenshot(file) -- cgit