aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThatGravyBoat <thatgravyboat@gmail.com>2021-12-26 09:51:37 -0330
committerGitHub <noreply@github.com>2021-12-26 20:21:37 +0700
commitb4db7af1bf1019a187c1b5f71bd2bc4a37afcf46 (patch)
tree9ef0760b8a375ce40f14d62579bddf94d7a12592 /src
parent641e50e9c509981df6a7d3fb5a29ff7e3dbe4d47 (diff)
downloadChatting-b4db7af1bf1019a187c1b5f71bd2bc4a37afcf46.tar.gz
Chatting-b4db7af1bf1019a187c1b5f71bd2bc4a37afcf46.tar.bz2
Chatting-b4db7af1bf1019a187c1b5f71bd2bc4a37afcf46.zip
Made custom chat height, fixed screenshots not taking into account scale and made screenshots 3x the size, also added entry point for font renderer. (#3)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java6
-rw-r--r--src/main/kotlin/com/raeids/stratus/Stratus.kt46
-rw-r--r--src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt36
-rw-r--r--src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt5
4 files changed, 68 insertions, 25 deletions
diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
index 06e25be..4e79cac 100644
--- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
+++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java
@@ -22,6 +22,7 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import java.awt.datatransfer.StringSelection;
@@ -119,6 +120,11 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook {
}
}
+ @Inject(method = "getChatHeight", at = @At("HEAD"), cancellable = true)
+ private void customHeight_getChatHeight(CallbackInfoReturnable<Integer> cir) {
+ if (StratusConfig.INSTANCE.getCustomChatHeight()) cir.setReturnValue(Stratus.INSTANCE.getChatHeight(this.getChatOpen()));
+ }
+
@Override
public int getRight() {
return stratus$right;
diff --git a/src/main/kotlin/com/raeids/stratus/Stratus.kt b/src/main/kotlin/com/raeids/stratus/Stratus.kt
index 57ef565..b998d88 100644
--- a/src/main/kotlin/com/raeids/stratus/Stratus.kt
+++ b/src/main/kotlin/com/raeids/stratus/Stratus.kt
@@ -8,11 +8,14 @@ import com.raeids.stratus.config.StratusConfig
import com.raeids.stratus.hook.GuiNewChatHook
import com.raeids.stratus.mixin.GuiNewChatAccessor
import com.raeids.stratus.updater.Updater
+import com.raeids.stratus.utils.ModCompatHooks
import com.raeids.stratus.utils.RenderHelper
import gg.essential.api.EssentialAPI
import gg.essential.universal.UDesktop
+import gg.essential.universal.UResolution
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.*
+import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.settings.KeyBinding
import net.minecraft.client.shader.Framebuffer
import net.minecraft.util.MathHelper
@@ -89,19 +92,21 @@ object Stratus {
}
}
+ fun getChatHeight(opened: Boolean): Int {
+ var height = if (opened) StratusConfig.focusedHeight else StratusConfig.unfocusedHeight
+ height = (height * Minecraft.getMinecraft().gameSettings.chatScale).toInt()
+ val chatY = ModCompatHooks.yOffset + ModCompatHooks.chatPosition
+ if (height + chatY + 27 > (UResolution.scaledHeight / Minecraft.getMinecraft().gameSettings.chatScale).toInt() - 27 - chatY) {
+ height = (UResolution.scaledHeight / Minecraft.getMinecraft().gameSettings.chatScale).toInt() - 27 - chatY
+ }
+ return height
+ }
+
fun screenshotLine(line: ChatLine): BufferedImage? {
val hud = Minecraft.getMinecraft().ingameGUI
val chat = hud.chatGUI
val i = MathHelper.floor_float(chat.chatWidth / chat.chatScale)
- return screenshot(
- GuiUtilRenderComponents.splitText(
- line.chatComponent,
- i,
- Minecraft.getMinecraft().fontRendererObj,
- false,
- false
- ).map { it.formattedText }.reversed(), chat.chatWidth
- )
+ return screenshot(GuiUtilRenderComponents.splitText(line.chatComponent, i, Minecraft.getMinecraft().fontRendererObj, false, false).map { it.formattedText }.reversed(), chat.chatWidth)
}
private fun screenshotChat() {
@@ -112,15 +117,9 @@ object Stratus {
val hud = Minecraft.getMinecraft().ingameGUI
val chat = hud.chatGUI
val chatLines = ArrayList<String>()
- ChatSearchingManager.filterMessages(
- (chat as GuiNewChatHook).prevText,
- (chat as GuiNewChatAccessor).drawnChatLines
- )?.let { drawnLines ->
- for (i in scrollPos until drawnLines.size.coerceAtMost(
- scrollPos + GuiNewChat.calculateChatboxHeight(
- Minecraft.getMinecraft().gameSettings.chatHeightFocused
- ) / 9
- )) {
+ ChatSearchingManager.filterMessages((chat as GuiNewChatHook).prevText, (chat as GuiNewChatAccessor).drawnChatLines)?.let { drawnLines ->
+ val chatHeight = if (StratusConfig.customChatHeight) getChatHeight(true) / 9 else GuiNewChat.calculateChatboxHeight(Minecraft.getMinecraft().gameSettings.chatHeightFocused / 9)
+ for (i in scrollPos until drawnLines.size.coerceAtMost(scrollPos + chatHeight)) {
chatLines.add(drawnLines[i].chatComponent.formattedText)
}
@@ -136,11 +135,16 @@ object Stratus {
return null
}
- val fr: FontRenderer = Minecraft.getMinecraft().fontRendererObj
- val fb: Framebuffer = RenderHelper.createBindFramebuffer(width, messages.size * 9)
+ val fr: FontRenderer = ModCompatHooks.fontRenderer
+ val fb: Framebuffer = RenderHelper.createBindFramebuffer(width * 3, (messages.size * 9) * 3)
val file = File(Minecraft.getMinecraft().mcDataDir, "screenshots/chat/" + fileFormatter.format(Date()))
- for (i in messages.indices) fr.drawStringWithShadow(messages[i], 0f, (messages.size - 1 - i) * 9f, 0xffffff)
+ GlStateManager.scale(3f, 3f, 1f)
+ val scale = Minecraft.getMinecraft().gameSettings.chatScale
+ GlStateManager.scale(scale, scale, 1f)
+ for (i in messages.indices) {
+ fr.drawStringWithShadow(messages[i], 0f, (messages.size - 1 - i) * 9f, 0xffffff)
+ }
val image = RenderHelper.screenshotFramebuffer(fb, file)
Minecraft.getMinecraft().entityRenderer.setupOverlayRendering()
diff --git a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt
index d67bfd0..de26dcb 100644
--- a/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt
+++ b/src/main/kotlin/com/raeids/stratus/config/StratusConfig.kt
@@ -17,11 +17,31 @@ object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stra
@Property(
type = PropertyType.SWITCH,
- name = "Chat Searching",
- description = "Add a chat search bar.",
- category = "Searching"
+ name = "Custom Chat Height",
+ description = "Allows you to change the height of chat to heights greater than before.",
+ category = "Chat Window"
)
- var chatSearch = true
+ var customChatHeight = true
+
+ @Property(
+ type = PropertyType.SLIDER,
+ min = 180,
+ max = 10000,
+ name = "Focused Height",
+ description = "Height in pixels.",
+ category = "Chat Window"
+ )
+ var focusedHeight = 180
+
+ @Property(
+ type = PropertyType.SLIDER,
+ min = 180,
+ max = 10000,
+ name = "Unfocused Height",
+ description = "Height in pixels.",
+ category = "Chat Window"
+ )
+ var unfocusedHeight = 180
@Property(
type = PropertyType.SELECTOR,
@@ -38,6 +58,14 @@ object StratusConfig : Vigilant(File(Stratus.modDir, "${Stratus.ID}.toml"), Stra
@Property(
type = PropertyType.SWITCH,
+ name = "Chat Searching",
+ description = "Add a chat search bar.",
+ category = "Searching"
+ )
+ var chatSearch = true
+
+ @Property(
+ type = PropertyType.SWITCH,
name = "Chat Tabs",
description = "Add chat tabs.",
category = "Tabs"
diff --git a/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt b/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt
index 48463a6..b28e9ea 100644
--- a/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt
+++ b/src/main/kotlin/com/raeids/stratus/utils/ModCompatHooks.kt
@@ -4,6 +4,8 @@ import club.sk1er.patcher.config.PatcherConfig
import com.llamalad7.betterchat.BetterChat
import com.raeids.stratus.Stratus.isBetterChat
import com.raeids.stratus.Stratus.isPatcher
+import net.minecraft.client.Minecraft
+import net.minecraft.client.gui.FontRenderer
// This exists because mixin doesn't like dummy classes
object ModCompatHooks {
@@ -23,4 +25,7 @@ object ModCompatHooks {
val extendedChatLength
get() = if (isPatcher) 32667 else 0
+ @JvmStatic
+ val fontRenderer: FontRenderer
+ get() = Minecraft.getMinecraft().fontRendererObj
}