Skip to content

Commit

Permalink
mc
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jun 5, 2024
1 parent 2f94633 commit 77111bf
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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, 16777215 + (chatting$getOpacity(0, chatLine) << 24), chatLine, false);
ModCompatHooks.redirectDrawString(string, chatting$config().getFade() ? 0 : 3, -q - 8, 16777215 + (chatting$getOpacity(chatting$updateCounter, chatLine) << 24), chatLine, false);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
}
Expand Down
26 changes: 10 additions & 16 deletions src/main/kotlin/org/polyfrost/chatting/Chatting.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package org.polyfrost.chatting

import cc.polyfrost.oneconfig.events.EventManager
import cc.polyfrost.oneconfig.events.event.InitializationEvent
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe
import cc.polyfrost.oneconfig.libs.universal.UDesktop
import cc.polyfrost.oneconfig.libs.universal.UMinecraft
import cc.polyfrost.oneconfig.utils.Notifications
import cc.polyfrost.oneconfig.utils.commands.CommandManager
import cc.polyfrost.oneconfig.utils.dsl.browseLink
import cc.polyfrost.oneconfig.utils.dsl.mc
import cc.polyfrost.oneconfig.utils.dsl.runAsync
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.*
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.OpenGlHelper
Expand Down Expand Up @@ -70,7 +64,7 @@ object Chatting {

private val fileFormatter: SimpleDateFormat = SimpleDateFormat("yyyy-MM-dd_HH.mm.ss'.png'")

val oldModDir = File(File(Minecraft.getMinecraft().mcDataDir, "W-OVERFLOW"), NAME)
val oldModDir = File(File(mc.mcDataDir, "W-OVERFLOW"), NAME)

@Mod.EventHandler
fun onInitialization(event: FMLInitializationEvent) {
Expand Down Expand Up @@ -158,7 +152,7 @@ object Chatting {

@SubscribeEvent
fun onTickEvent(event: TickEvent.ClientTickEvent) {
if (event.phase == TickEvent.Phase.START && Minecraft.getMinecraft().theWorld != null && Minecraft.getMinecraft().thePlayer != null && (Minecraft.getMinecraft().currentScreen == null || Minecraft.getMinecraft().currentScreen is GuiChat)) {
if (event.phase == TickEvent.Phase.START && mc.theWorld != null && mc.thePlayer != null && (mc.currentScreen == null || mc.currentScreen is GuiChat)) {
if (doTheThing) {
screenshotChat()
doTheThing = false
Expand Down Expand Up @@ -205,15 +199,15 @@ object Chatting {
}

fun screenshotLine(line: ChatLine): BufferedImage? {
val hud = Minecraft.getMinecraft().ingameGUI
val hud = mc.ingameGUI
val chat = hud.chatGUI
val i = MathHelper.floor_float(getChatWidth() / chat.chatScale)
return screenshot(
hashMapOf<ChatLine, String>().also {
GuiUtilRenderComponents.splitText(
line.chatComponent,
i,
Minecraft.getMinecraft().fontRendererObj,
mc.fontRendererObj,
false,
false
).map { it.formattedText }.reversed().forEach { string ->
Expand All @@ -228,7 +222,7 @@ object Chatting {
}

fun screenshotChat(scrollPos: Int) {
val hud = Minecraft.getMinecraft().ingameGUI
val hud = mc.ingameGUI
val chat = hud.chatGUI
val chatLines = LinkedHashMap<ChatLine, String>()
ChatSearchingManager.filterMessages(
Expand All @@ -237,7 +231,7 @@ object Chatting {
)?.let { drawnLines ->
val chatHeight =
if (ChattingConfig.chatWindow.customChatHeight) getChatHeight(true) / 9 else GuiNewChat.calculateChatboxHeight(
Minecraft.getMinecraft().gameSettings.chatHeightFocused / 9
mc.gameSettings.chatHeightFocused / 9
)
for (i in scrollPos until drawnLines.size.coerceAtMost(scrollPos + chatHeight)) {
chatLines[drawnLines[i]] = drawnLines[i].chatComponent.formattedText
Expand All @@ -263,18 +257,18 @@ object Chatting {
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 file = File(Minecraft.getMinecraft().mcDataDir, "screenshots/chat/" + fileFormatter.format(Date()))
val file = File(mc.mcDataDir, "screenshots/chat/" + fileFormatter.format(Date()))

GlStateManager.scale(2f, 2f, 1f)
val scale = Minecraft.getMinecraft().gameSettings.chatScale
val scale = mc.gameSettings.chatScale
GlStateManager.scale(scale, scale, 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)
}

val image = fb.screenshot(file)
Minecraft.getMinecraft().entityRenderer.setupOverlayRendering()
Minecraft.getMinecraft().framebuffer.bindFramebuffer(true)
mc.entityRenderer.setupOverlayRendering()
mc.framebuffer.bindFramebuffer(true)
Notifications.INSTANCE.send(
"Chatting",
"Chat screenshotted successfully." + (if (ChattingConfig.copyMode != 1) "\nClick to open." else ""),
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/polyfrost/chatting/chat/ChatTab.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.polyfrost.chatting.chat

import cc.polyfrost.oneconfig.libs.universal.ChatColor
import cc.polyfrost.oneconfig.utils.dsl.mc
import org.polyfrost.chatting.gui.components.TabButton
import com.google.gson.annotations.SerializedName
import net.minecraft.client.Minecraft
Expand Down Expand Up @@ -40,7 +41,7 @@ data class ChatTab(
fun initialize() {
compiledRegex = ChatRegexes(uncompiledRegex)
compiledIgnoreRegex = ChatRegexes(uncompiledIgnoreRegex)
val width = Minecraft.getMinecraft().fontRendererObj.getStringWidth(name)
val width = mc.fontRendererObj.getStringWidth(name)
button = TabButton(653452, run {
val returnValue = x - 2
x += 6 + width
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/org/polyfrost/chatting/chat/ChatTabs.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.polyfrost.chatting.chat

import cc.polyfrost.oneconfig.config.core.ConfigUtils
import cc.polyfrost.oneconfig.utils.dsl.mc
import org.polyfrost.chatting.Chatting
import org.polyfrost.chatting.gui.components.TabButton
import com.google.gson.GsonBuilder
Expand All @@ -19,8 +20,8 @@ object ChatTabs {
var currentTabs: ArrayList<ChatTab> = object : ArrayList<ChatTab>() {
override fun add(element: ChatTab): Boolean {
val returnValue = super.add(element)
if (Minecraft.getMinecraft().theWorld != null && returnValue) {
Minecraft.getMinecraft().ingameGUI.chatGUI.refreshChat()
if (mc.theWorld != null && returnValue) {
mc.ingameGUI.chatGUI.refreshChat()
}
return returnValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cc.polyfrost.oneconfig.config.data.Mod
import cc.polyfrost.oneconfig.config.data.ModType
import cc.polyfrost.oneconfig.config.migration.VigilanceMigrator
import cc.polyfrost.oneconfig.libs.universal.UKeyboard
import cc.polyfrost.oneconfig.libs.universal.UMinecraft
import cc.polyfrost.oneconfig.utils.dsl.mc
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils
import org.polyfrost.chatting.Chatting
import org.polyfrost.chatting.chat.*
Expand Down Expand Up @@ -399,7 +399,7 @@ object ChattingConfig : Config(
"chatTabs"
).forEach {
addListener(it) {
UMinecraft.getMinecraft().currentScreen?.let { screen ->
mc.currentScreen?.let { screen ->
if (screen is GuiChatHook) {
screen.`chatting$triggerButtonReset`()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ open class CleanButton(
((xPosition + width / 2) - (fontrenderer.getStringWidth(displayString) / 2)).toFloat(),
(yPosition + (height - 8) / 2).toFloat(),
j,
(Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).`chatting$getTextOpacity`()
(mc.ingameGUI.chatGUI as GuiNewChatHook).`chatting$getTextOpacity`()
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cc.polyfrost.oneconfig.libs.universal.ChatColor
import cc.polyfrost.oneconfig.libs.universal.UChat
import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.polyfrost.oneconfig.utils.Multithreading
import cc.polyfrost.oneconfig.utils.dsl.mc
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
Expand All @@ -23,7 +24,7 @@ class ClearButton :
++times
if (times > 1) {
times = 0
Minecraft.getMinecraft().ingameGUI.chatGUI.clearChatMessages()
mc.ingameGUI.chatGUI.clearChatMessages()
} else {
UChat.chat(ChatColor.RED + ChatColor.BOLD.toString() + "Click again to clear the chat!")
Multithreading.runAsync {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.polyfrost.chatting.gui.components

import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.polyfrost.oneconfig.libs.universal.UScreen
import cc.polyfrost.oneconfig.utils.dsl.mc
import org.polyfrost.chatting.Chatting
import org.polyfrost.chatting.mixin.GuiNewChatAccessor
import net.minecraft.client.Minecraft
Expand All @@ -18,9 +19,8 @@ class ScreenshotButton :
{ RenderType.NONE }) {

override fun onMousePress() {
val chat = Minecraft.getMinecraft().ingameGUI.chatGUI
if (UScreen.currentScreen is GuiChat) {
Chatting.screenshotChat((chat as GuiNewChatAccessor).scrollPos)
Chatting.screenshotChat((mc.ingameGUI.chatGUI as GuiNewChatAccessor).scrollPos)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.polyfrost.chatting.gui.components

import cc.polyfrost.oneconfig.config.core.OneColor
import cc.polyfrost.oneconfig.libs.universal.UResolution
import cc.polyfrost.oneconfig.utils.dsl.mc
import org.polyfrost.chatting.Chatting
import org.polyfrost.chatting.chat.ChatSearchingManager
import net.minecraft.client.Minecraft
Expand Down Expand Up @@ -54,7 +55,7 @@ class SearchButton() :

inner class SearchTextField : GuiTextField(
69420,
Minecraft.getMinecraft().fontRendererObj,
mc.fontRendererObj,
UResolution.scaledWidth * 4 / 5 - 60,
UResolution.scaledHeight - 26,
UResolution.scaledWidth / 5,
Expand Down
30 changes: 13 additions & 17 deletions src/main/kotlin/org/polyfrost/chatting/utils/ModCompatHooks.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package org.polyfrost.chatting.utils

import cc.polyfrost.oneconfig.platform.Platform
import cc.polyfrost.oneconfig.renderer.TextRenderer
import cc.polyfrost.oneconfig.utils.dsl.getAlpha
import cc.polyfrost.oneconfig.utils.dsl.mc
import org.polyfrost.chatting.Chatting.isBetterChat
import org.polyfrost.chatting.Chatting.isPatcher
import org.polyfrost.chatting.config.ChattingConfig.offsetNonPlayerMessages
import org.polyfrost.chatting.config.ChattingConfig.showChatHeads
import org.polyfrost.chatting.config.ChattingConfig.textRenderType
import club.sk1er.patcher.config.PatcherConfig
import com.llamalad7.betterchat.BetterChat
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ChatLine
import net.minecraft.client.gui.FontRenderer
import net.minecraft.client.gui.Gui
import net.minecraft.client.renderer.GlStateManager
import org.polyfrost.chatting.Chatting.isBetterChat
import org.polyfrost.chatting.Chatting.isPatcher
import org.polyfrost.chatting.config.ChattingConfig
import org.polyfrost.chatting.config.ChattingConfig.offsetNonPlayerMessages
import org.polyfrost.chatting.config.ChattingConfig.showChatHeads
import org.polyfrost.chatting.hook.ChatLineHook
import org.polyfrost.chatting.hook.GuiNewChatHook
import org.polyfrost.chatting.mixin.GuiNewChatAccessor

// This exists because mixin doesn't like dummy classes
Expand All @@ -44,15 +42,15 @@ object ModCompatHooks {

@JvmStatic
val fontRenderer: FontRenderer
get() = Minecraft.getMinecraft().fontRendererObj
get() = mc.fontRendererObj

@JvmStatic
val chatLines: List<ChatLine>
get() = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).chatLines
get() = (mc.ingameGUI.chatGUI as GuiNewChatAccessor).chatLines

@JvmStatic
val drawnChatLines: List<ChatLine>
get() = (Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines
get() = (mc.ingameGUI.chatGUI as GuiNewChatAccessor).drawnChatLines

@JvmStatic
val chatHeadOffset
Expand All @@ -65,6 +63,7 @@ object ModCompatHooks {
@JvmStatic
val chatInputLimit
get() = if (isPatcher && PatcherConfig.extendedChatLength) 256 else 100

@JvmStatic
val shouldDrawInputBox
get() = !isPatcher || !PatcherConfig.transparentChatInputField
Expand Down Expand Up @@ -112,13 +111,10 @@ object ModCompatHooks {
GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f)
}
}
return when (textRenderType) {
0 -> fontRenderer.drawString(text, actualX, y, color, false)
2 -> TextRenderer.drawBorderedText(text,
actualX,
y,
color,
(Minecraft.getMinecraft().ingameGUI.chatGUI as GuiNewChatHook).`chatting$getTextOpacity`())
return when (ChattingConfig.textRenderType) {
0 -> Platform.getGLPlatform().drawText(text, actualX, y, color, false).toInt()
1 -> Platform.getGLPlatform().drawText(text, actualX, y, color, true).toInt()
2 -> TextRenderer.drawBorderedText(text, actualX, y, color, color.getAlpha())
else -> fontRenderer.drawString(text, actualX, y, color, true)
}
}
Expand Down

0 comments on commit 77111bf

Please sign in to comment.