From 406f308cc92378a7812ea429f414a6f770798564 Mon Sep 17 00:00:00 2001 From: joe Date: Thu, 7 Mar 2024 21:19:51 +0000 Subject: [PATCH] Remember the old max chat length before changing it, fixing VFP incompatibility --- .../clientcommands/mixin/MixinChatScreen.java | 15 +++++++++++++-- src/main/resources/clientcommands.aw | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java index 86c43e4e4..f391aaf7b 100644 --- a/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java +++ b/src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java @@ -4,8 +4,10 @@ import net.earthcomputer.clientcommands.command.VarCommand; import net.minecraft.client.gui.components.EditBox; import net.minecraft.client.gui.screens.ChatScreen; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; @@ -13,9 +15,12 @@ @Mixin(ChatScreen.class) public class MixinChatScreen { - @Shadow protected EditBox input; + @Unique + @Nullable + private Integer oldMaxLength = null; + // replace the text before the Fabric Command API executes it, // but ensure the message is added to the history in its raw form. @ModifyVariable(method = "handleChatInput", at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z", remap = false), argsOnly = true) @@ -30,10 +35,16 @@ private String onHandleChatInput(String message) { @Inject(method = "onEdited", at = @At("HEAD")) private void onEdited(String value, CallbackInfo ci) { if (value.startsWith("/") && ClientCommands.isClientcommandsCommand(value.substring(1).split(" ")[0])) { + if (oldMaxLength == null) { + oldMaxLength = input.maxLength; + } input.setMaxLength(32767); } else { // TODO: what if other mods try to do the same thing? - input.setMaxLength(256); + if (oldMaxLength != null) { + input.setMaxLength(oldMaxLength); + oldMaxLength = null; + } } } } diff --git a/src/main/resources/clientcommands.aw b/src/main/resources/clientcommands.aw index c2bb3f5b4..3ebc898e2 100644 --- a/src/main/resources/clientcommands.aw +++ b/src/main/resources/clientcommands.aw @@ -13,6 +13,8 @@ accessible method net/minecraft/client/Minecraft openChatScreen (Ljava/lang/Stri accessible method net/minecraft/network/chat/HoverEvent (Lnet/minecraft/network/chat/HoverEvent$TypedHoverEvent;)V accessible class net/minecraft/network/chat/HoverEvent$TypedHoverEvent +accessible field net/minecraft/client/gui/components/EditBox maxLength I + accessible field net/minecraft/network/ConnectionProtocol flows Ljava/util/Map; accessible field net/minecraft/network/ConnectionProtocol$CodecData packetSet Lnet/minecraft/network/ConnectionProtocol$PacketSet; accessible field net/minecraft/network/ConnectionProtocol$PacketSet classToId Lit/unimi/dsi/fastutil/objects/Object2IntMap;