From ddd9e469f3802440965d764b44a87ffefa977875 Mon Sep 17 00:00:00 2001 From: ImToggle <98242902+ImToggle@users.noreply.github.com> Date: Tue, 30 Jul 2024 01:25:46 +0800 Subject: [PATCH] fixed screenshot head rendering --- .../polyfrost/chatting/mixin/GuiNewChatMixin.java | 2 +- .../mixin/GuiNewChatMixin_TextRendering.java | 2 +- src/main/kotlin/org/polyfrost/chatting/Chatting.kt | 12 ++++++------ .../kotlin/org/polyfrost/chatting/chat/ChatWindow.kt | 2 +- .../org/polyfrost/chatting/utils/ModCompatHooks.kt | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java index 7555aee..d19c520 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java @@ -107,7 +107,7 @@ private void drawClosing(int updateCounter, CallbackInfo ci) { int q = m * 9; String string = chatLine.getChatComponent().getFormattedText(); GlStateManager.enableBlend(); - ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 0xFFFFFFFF, chatLine, false); + ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 0xFFFFFFFF, chatLine); GlStateManager.disableAlpha(); GlStateManager.disableBlend(); } diff --git a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java index aff102c..c636e2c 100644 --- a/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java +++ b/src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin_TextRendering.java @@ -24,6 +24,6 @@ private void captureChatLine(int updateCounter, CallbackInfo ci, int i, boolean @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) { - return ModCompatHooks.redirectDrawString(text, x, y, color, chatting$drawingLine, false); + return ModCompatHooks.redirectDrawString(text, x, y, color, chatting$drawingLine); } } diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 3e17063..1d61570 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -9,7 +9,6 @@ import net.minecraft.client.gui.* import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.OpenGlHelper import net.minecraft.client.settings.KeyBinding -import net.minecraft.client.shader.Framebuffer import net.minecraftforge.common.MinecraftForge.EVENT_BUS import net.minecraftforge.fml.client.registry.ClientRegistry import net.minecraftforge.fml.common.Loader @@ -18,7 +17,6 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent import net.minecraftforge.fml.common.event.FMLLoadCompleteEvent import net.minecraftforge.fml.common.event.FMLPostInitializationEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.input.Keyboard import org.lwjgl.input.Mouse @@ -262,14 +260,16 @@ object Chatting { return null } - val fr: FontRenderer = ModCompatHooks.fontRenderer - val width = messages.maxOf { fr.getStringWidth(it.value) + (if (ChattingConfig.showChatHeads && ((it.key as ChatLineHook).`chatting$hasDetected`() || ChattingConfig.offsetNonPlayerMessages)) 10 else 0) } + 4 - val fb: Framebuffer = createBindFramebuffer(width * 2, (messages.size * 9) * 2) + val fr = ModCompatHooks.fontRenderer + val border = ChattingConfig.textRenderType == 2 + val offset = if (border) 1 else 0 + val width = messages.maxOf { fr.getStringWidth(it.value) + (if (ChattingConfig.showChatHeads && ((it.key as ChatLineHook).`chatting$hasDetected`() || ChattingConfig.offsetNonPlayerMessages)) 10 else 0) } + if (border) 2 else 1 + val fb = createBindFramebuffer(width * 2, (messages.size * 9 + offset) * 2) val file = File(mc.mcDataDir, "screenshots/chat/" + fileFormatter.format(Date())) GlStateManager.scale(2f, 2f, 1f) messages.entries.forEachIndexed { i: Int, entry: MutableMap.MutableEntry -> - ModCompatHooks.redirectDrawString(entry.value, 0f, (messages.size - 1 - i) * 9f, 0xffffff, entry.key, true) + ModCompatHooks.redirectDrawString(entry.value, offset.toFloat(), (messages.size - 1 - i) * 9f + offset.toFloat(), 0xFFFFFFFF.toInt(), entry.key) } val image = fb.screenshot(file) diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt index 48fd709..597f910 100644 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt @@ -162,7 +162,7 @@ class ChatWindow : BasicHud(true, 2f, 1080 - 27f - 45f - 12f, GL.translate(x, y + scale, 0f) GL.scale(scale, scale, 1f) for (chat in exampleList) { - ModCompatHooks.redirectDrawString(chat.chatComponent.formattedText, 0f, 0f, -1, chat, false) + ModCompatHooks.redirectDrawString(chat.chatComponent.formattedText, 0f, 0f, -1, chat) GL.translate(0f, 9f, 0f) } GL.popMatrix() diff --git a/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt b/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt index e9419ff..5183432 100644 --- a/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt +++ b/src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt @@ -69,9 +69,9 @@ object ModCompatHooks { get() = !isPatcher || !PatcherConfig.transparentChatInputField @JvmStatic - fun redirectDrawString(text: String, x: Float, y: Float, color: Int, chatLine: ChatLine, screenshot: Boolean): Int { + fun redirectDrawString(text: String, x: Float, y: Float, color: Int, chatLine: ChatLine): Int { var actualX = x - if (showChatHeads && !screenshot) { + if (showChatHeads) { val hook = chatLine as ChatLineHook if (hook.`chatting$hasDetected`() || offsetNonPlayerMessages) { actualX += 10f