From 142ec00be57eb7caa38dde7bd9503104a8151de9 Mon Sep 17 00:00:00 2001 From: ev chang Date: Tue, 25 Jun 2024 14:49:15 +0700 Subject: [PATCH] Fix MC chat scale not being linked with Chatting's --- .../chatting/mixin/GameSettingsMixin.java | 21 +++++++++++++++++++ .../kotlin/org/polyfrost/chatting/Chatting.kt | 10 +++++++++ .../org/polyfrost/chatting/chat/ChatWindow.kt | 15 +++++++++++++ .../chatting/config/ChattingConfig.kt | 2 +- src/main/resources/mixins.chatting.json | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/polyfrost/chatting/mixin/GameSettingsMixin.java diff --git a/src/main/java/org/polyfrost/chatting/mixin/GameSettingsMixin.java b/src/main/java/org/polyfrost/chatting/mixin/GameSettingsMixin.java new file mode 100644 index 0000000..dd607dc --- /dev/null +++ b/src/main/java/org/polyfrost/chatting/mixin/GameSettingsMixin.java @@ -0,0 +1,21 @@ +package org.polyfrost.chatting.mixin; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.GameSettings; +import org.objectweb.asm.Opcodes; +import org.polyfrost.chatting.config.ChattingConfig; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(GameSettings.class) +public class GameSettingsMixin { + @Shadow protected Minecraft mc; + + @Inject(method = "setOptionFloatValue", at = @At(value = "FIELD", target = "Lnet/minecraft/client/settings/GameSettings;chatScale:F", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER)) + private void onChatScaleChange(GameSettings.Options settingsOption, float value, CallbackInfo ci) { + ChattingConfig.INSTANCE.getChatWindow().updateMCChatScale(); + } +} diff --git a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt index 45b1bcd..42a7a69 100644 --- a/src/main/kotlin/org/polyfrost/chatting/Chatting.kt +++ b/src/main/kotlin/org/polyfrost/chatting/Chatting.kt @@ -74,6 +74,16 @@ object Chatting { @Mod.EventHandler fun onInitialization(event: FMLInitializationEvent) { ChattingConfig + if (!ChattingConfig.enabled) { + ChattingConfig.enabled = true + ChattingConfig.save() + } + if (!ChattingConfig.chatWindow.transferOverScale) { + ChattingConfig.chatWindow.normalScale = ChattingConfig.chatWindow.scale + ChattingConfig.chatWindow.transferOverScale = true + ChattingConfig.save() + } + ChattingConfig.chatWindow.updateMCChatScale() CommandManager.INSTANCE.registerCommand(ChattingCommand()) ClientRegistry.registerKeyBinding(keybind) EVENT_BUS.register(this) diff --git a/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt b/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt index 2a84154..c0934f9 100644 --- a/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt +++ b/src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt @@ -69,6 +69,10 @@ class ChatWindow : BasicHud(true, 2f, 1080 - 27f - 45f - 12f, @Exclude var wasInChatGui = false + var normalScale = 1f + var lastChatGuiScale = -1f + var transferOverScale = false + @Switch( name = "Custom Chat Height", description = "Set a custom height for the chat window. Allows for more customization than the vanilla chat height options." @@ -279,4 +283,15 @@ class ChatWindow : BasicHud(true, 2f, 1080 - 27f - 45f - 12f, bgColor = color } + override fun setScale(scale: Float, example: Boolean) { + super.setScale(scale, example) + normalScale = scale + } + + fun updateMCChatScale() { + if (ChattingConfig.chatWindow.lastChatGuiScale != mc.gameSettings.chatScale) { + ChattingConfig.chatWindow.scale = ChattingConfig.chatWindow.normalScale * mc.gameSettings.chatScale + } + } + } \ No newline at end of file diff --git a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt b/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt index c270ed7..7cc1f81 100644 --- a/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/org/polyfrost/chatting/config/ChattingConfig.kt @@ -26,7 +26,7 @@ object ChattingConfig : Config( ModType.UTIL_QOL, "/chatting_dark.svg", VigilanceMigrator(File(Chatting.oldModDir, Chatting.ID + ".toml").toPath().toString()) - ), "chatting.json" + ), "chatting.json", true, false ) { @Dropdown( diff --git a/src/main/resources/mixins.chatting.json b/src/main/resources/mixins.chatting.json index 5f47765..6b7d1a3 100644 --- a/src/main/resources/mixins.chatting.json +++ b/src/main/resources/mixins.chatting.json @@ -9,6 +9,7 @@ "ClientCommandHandlerMixin", "EntityPlayerSPMixin", "EntityRendererMixin", + "GameSettingsMixin", "GuiChatMixin", "GuiIngameForgeAccessor", "GuiIngameForgeMixin",