Skip to content

Commit

Permalink
Fix MC chat scale not being linked with Chatting's
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Jun 25, 2024
1 parent 9cabe5f commit 142ec00
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/main/java/org/polyfrost/chatting/mixin/GameSettingsMixin.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/org/polyfrost/chatting/Chatting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions src/main/kotlin/org/polyfrost/chatting/chat/ChatWindow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.chatting.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"ClientCommandHandlerMixin",
"EntityPlayerSPMixin",
"EntityRendererMixin",
"GameSettingsMixin",
"GuiChatMixin",
"GuiIngameForgeAccessor",
"GuiIngameForgeMixin",
Expand Down

0 comments on commit 142ec00

Please sign in to comment.