Skip to content

Commit

Permalink
fixed screenshot head rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jul 29, 2024
1 parent 60b1a6d commit ddd9e46
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions src/main/kotlin/org/polyfrost/chatting/Chatting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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<ChatLine, String> ->
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)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ddd9e46

Please sign in to comment.