From c5713a37374fb140ff1120d9569f32c32f91fdbf Mon Sep 17 00:00:00 2001 From: Fallen_Breath Date: Fri, 22 Mar 2024 23:42:26 +0800 Subject: [PATCH] Added mc tweak `keepMessageHistoryOnReconfiguration` resolved #57, closed #58 --- docs/document-en_us.md | 18 ++++++ docs/document-zh_cn.md | 18 ++++++ .../config/TweakerMoreConfigs.java | 3 + ...MessageHistoryOnReconfigurationHelper.java | 26 ++++++++ .../InGameHudMixin.java | 30 +++++++++ .../MinecraftClientMixin.java | 29 +++++++++ .../assets/tweakermore/lang/en_us.yml | 7 +++ .../assets/tweakermore/lang/zh_cn.yml | 7 +++ src/main/resources/tweakermore.mixins.json | 2 + .../InGameHudMixin.java | 53 ++++++++++++++++ .../MinecraftClientMixin.java | 61 +++++++++++++++++++ 11 files changed, 254 insertions(+) create mode 100644 src/main/java/me/fallenbreath/tweakermore/impl/mc_tweaks/keepMessageHistoryOnReconfiguration/KeepMessageHistoryOnReconfigurationHelper.java create mode 100644 src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java create mode 100644 src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java create mode 100644 versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java create mode 100644 versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java diff --git a/docs/document-en_us.md b/docs/document-en_us.md index 394ac11b..e95ce837 100644 --- a/docs/document-en_us.md +++ b/docs/document-en_us.md @@ -1450,6 +1450,24 @@ With this option, no more need to worry about item tooltips covering too much in - Default value: `false` +### keepMessageHistoryOnReconfiguration + +Prevent the chat messages in the chat hud from being cleared when then client enters the reconfiguration network state + +Proxy servers like BungeeCord and Velocity might let the client enter the reconfiguration network state + +when the client is switching between different backend Minecraft servers. + +With this option, you can keep your chat history with switching between different servers + +- Category: MC Tweaks +- Type: boolean (Generic) +- Default value: `false` +- Mod restrictions: + - Required mods: + - Minecraft (`minecraft`) `>=1.20.2` + + ### legacyF3NLogic Modify the logic of hotkey F3 + N back to 1.15 and before diff --git a/docs/document-zh_cn.md b/docs/document-zh_cn.md index 1239ef11..9088e58d 100644 --- a/docs/document-zh_cn.md +++ b/docs/document-zh_cn.md @@ -1446,6 +1446,24 @@ Format error: 修复使用原版聊天缩放设置来缩放聊天信息HUD中的 - 默认值: `false` +### 在重配置网络阶段保留消息历史 (keepMessageHistoryOnReconfiguration) + +防止聊天记录在客户端进入重新配置网络状态时被清除 + +像BungeeCord和Velocity这样的代理服务器,可能会在客户端在不同的 + +后端Minecraft服务器之间切换时,让客户端进入重新配置网络状态 + +借助该选项,你可以在切换服务器的时候保留你的聊天信息 + +- 分类: MC修改 +- 类型: 布尔值 (通用) +- 默认值: `false` +- 模组约束: + - 依赖模组: + - Minecraft (`minecraft`) `>=1.20.2` + + ### 旧版F3+N逻辑 (legacyF3NLogic) 修改快捷键F3+N的逻辑至1.15及之前的逻辑 diff --git a/src/main/java/me/fallenbreath/tweakermore/config/TweakerMoreConfigs.java b/src/main/java/me/fallenbreath/tweakermore/config/TweakerMoreConfigs.java index f6cf1fb1..e812730f 100644 --- a/src/main/java/me/fallenbreath/tweakermore/config/TweakerMoreConfigs.java +++ b/src/main/java/me/fallenbreath/tweakermore/config/TweakerMoreConfigs.java @@ -488,6 +488,9 @@ public class TweakerMoreConfigs @Config(type = Config.Type.GENERIC, category = Config.Category.MC_TWEAKS) public static final TweakerMoreConfigBoolean ITEM_TOOLTIP_HIDE_UNTIL_MOUSE_MOVE = newConfigBoolean("itemTooltipHideUntilMouseMove", false); + @Config(type = Config.Type.GENERIC, restriction = @Restriction(require = @Condition(value = minecraft, versionPredicates = ">=1.20.2")), category = Config.Category.MC_TWEAKS) + public static final TweakerMoreConfigBoolean KEEP_MESSAGE_HISTORY_ON_RECONFIGURATION = newConfigBoolean("keepMessageHistoryOnReconfiguration", false); + @Config(type = Config.Type.GENERIC, restriction = @Restriction(require = @Condition(value = minecraft, versionPredicates = ">=1.16")), category = Config.Category.MC_TWEAKS) public static final TweakerMoreConfigBoolean LEGACY_F3_N_LOGIC = newConfigBoolean("legacyF3NLogic", false); diff --git a/src/main/java/me/fallenbreath/tweakermore/impl/mc_tweaks/keepMessageHistoryOnReconfiguration/KeepMessageHistoryOnReconfigurationHelper.java b/src/main/java/me/fallenbreath/tweakermore/impl/mc_tweaks/keepMessageHistoryOnReconfiguration/KeepMessageHistoryOnReconfigurationHelper.java new file mode 100644 index 00000000..c3720c04 --- /dev/null +++ b/src/main/java/me/fallenbreath/tweakermore/impl/mc_tweaks/keepMessageHistoryOnReconfiguration/KeepMessageHistoryOnReconfigurationHelper.java @@ -0,0 +1,26 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.impl.mc_tweaks.keepMessageHistoryOnReconfiguration; + +public class KeepMessageHistoryOnReconfigurationHelper +{ + public static final ThreadLocal isReconfiguring = ThreadLocal.withInitial(() -> false); +} diff --git a/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java b/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java new file mode 100644 index 00000000..1fe20c91 --- /dev/null +++ b/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java @@ -0,0 +1,30 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.keepMessageHistoryOnReconfiguration; + +import me.fallenbreath.tweakermore.util.mixin.DummyClass; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(DummyClass.class) +public abstract class InGameHudMixin +{ + // mc1.20.2+ +} diff --git a/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java b/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java new file mode 100644 index 00000000..60985dd6 --- /dev/null +++ b/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java @@ -0,0 +1,29 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.keepMessageHistoryOnReconfiguration; + +import net.minecraft.client.MinecraftClient; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(MinecraftClient.class) +public abstract class MinecraftClientMixin +{ +} diff --git a/src/main/resources/assets/tweakermore/lang/en_us.yml b/src/main/resources/assets/tweakermore/lang/en_us.yml index fe0eb8a6..810e5df3 100644 --- a/src/main/resources/assets/tweakermore/lang/en_us.yml +++ b/src/main/resources/assets/tweakermore/lang/en_us.yml @@ -558,6 +558,13 @@ tweakermore: comment: |- Hide item tooltips in container screens until the mouse has moved With this option, no more need to worry about item tooltips covering too much information in container screens + keepMessageHistoryOnReconfiguration: + .: keepMessageHistoryOnReconfiguration + comment: |- + Prevent the chat messages in the chat hud from being cleared when then client enters the reconfiguration network state + Proxy servers like BungeeCord and Velocity might let the client enter the reconfiguration network state + when the client is switching between different backend Minecraft servers. + With this option, you can keep your chat history with switching between different servers legacyF3NLogic: .: legacyF3NLogic comment: |- diff --git a/src/main/resources/assets/tweakermore/lang/zh_cn.yml b/src/main/resources/assets/tweakermore/lang/zh_cn.yml index 929d83a9..1f839075 100644 --- a/src/main/resources/assets/tweakermore/lang/zh_cn.yml +++ b/src/main/resources/assets/tweakermore/lang/zh_cn.yml @@ -558,6 +558,13 @@ tweakermore: comment: |- 在容器GUI中隐藏物品的悬浮文本,直至鼠标移动 借此,无需再担心物品的悬浮文本遮挡过多容器GUI中的物品图标信息 + keepMessageHistoryOnReconfiguration: + .: 在重配置网络阶段保留消息历史 + comment: |- + 防止聊天记录在客户端进入重新配置网络状态时被清除 + 像BungeeCord和Velocity这样的代理服务器,可能会在客户端在不同的 + 后端Minecraft服务器之间切换时,让客户端进入重新配置网络状态 + 借助该选项,你可以在切换服务器的时候保留你的聊天信息 legacyF3NLogic: .: 旧版F3+N逻辑 comment: |- diff --git a/src/main/resources/tweakermore.mixins.json b/src/main/resources/tweakermore.mixins.json index adf0518b..0340b580 100644 --- a/src/main/resources/tweakermore.mixins.json +++ b/src/main/resources/tweakermore.mixins.json @@ -117,6 +117,8 @@ "tweaks.mc_tweaks.fixHoverTextScale.HoverTextRendererClassMixin", "tweaks.mc_tweaks.flyDrag.LivingEntityMixin", "tweaks.mc_tweaks.itemTooltipHideUntilMouseMove.ContainerScreenMixin", + "tweaks.mc_tweaks.keepMessageHistoryOnReconfiguration.InGameHudMixin", + "tweaks.mc_tweaks.keepMessageHistoryOnReconfiguration.MinecraftClientMixin", "tweaks.mc_tweaks.legacyF3NLogic.KeyboardMixin", "tweaks.mc_tweaks.maxChatHudHeight.ChatHudMixin", "tweaks.mc_tweaks.multiplayerForcedEnabled.MinecraftClientMixin", diff --git a/versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java b/versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java new file mode 100644 index 00000000..612e5d84 --- /dev/null +++ b/versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/InGameHudMixin.java @@ -0,0 +1,53 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.keepMessageHistoryOnReconfiguration; + +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import me.fallenbreath.tweakermore.config.TweakerMoreConfigs; +import me.fallenbreath.tweakermore.impl.mc_tweaks.keepMessageHistoryOnReconfiguration.KeepMessageHistoryOnReconfigurationHelper; +import net.minecraft.client.gui.hud.ChatHud; +import net.minecraft.client.gui.hud.InGameHud; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(InGameHud.class) +public abstract class InGameHudMixin +{ + @SuppressWarnings("RedundantIfStatement") + @WrapWithCondition( + method = "clear", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/hud/ChatHud;clear(Z)V" + ) + ) + private boolean keepMessageOnReconfiguration_dontClearChatHud(ChatHud instance, boolean clearHistory) + { + if (TweakerMoreConfigs.KEEP_MESSAGE_HISTORY_ON_RECONFIGURATION.getBooleanValue()) + { + if (KeepMessageHistoryOnReconfigurationHelper.isReconfiguring.get()) + { + return false; + } + } + return true; + } +} diff --git a/versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java b/versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java new file mode 100644 index 00000000..b22929af --- /dev/null +++ b/versions/1.20.2/src/main/java/me/fallenbreath/tweakermore/mixins/tweaks/mc_tweaks/keepMessageHistoryOnReconfiguration/MinecraftClientMixin.java @@ -0,0 +1,61 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.mixins.tweaks.mc_tweaks.keepMessageHistoryOnReconfiguration; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import me.fallenbreath.tweakermore.config.TweakerMoreConfigs; +import me.fallenbreath.tweakermore.impl.mc_tweaks.keepMessageHistoryOnReconfiguration.KeepMessageHistoryOnReconfigurationHelper; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.hud.InGameHud; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(MinecraftClient.class) +public abstract class MinecraftClientMixin +{ + @WrapOperation( + method = "enterReconfiguration", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/gui/hud/InGameHud;clear()V" + ) + ) + private void keepMessageOnReconfiguration_markIsReconfiguring(InGameHud instance, Operation original) + { + boolean optionEnabled = TweakerMoreConfigs.KEEP_MESSAGE_HISTORY_ON_RECONFIGURATION.getBooleanValue(); + if (optionEnabled) + { + KeepMessageHistoryOnReconfigurationHelper.isReconfiguring.set(true); + } + try + { + original.call(instance); + } + finally + { + if (optionEnabled) + { + KeepMessageHistoryOnReconfigurationHelper.isReconfiguring.remove(); + } + } + } +}