Skip to content

Commit 406f308

Browse files
committed
Remember the old max chat length before changing it, fixing VFP incompatibility
1 parent 719bd9f commit 406f308

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/main/java/net/earthcomputer/clientcommands/mixin/MixinChatScreen.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
44
import net.earthcomputer.clientcommands.command.VarCommand;
55
import net.minecraft.client.gui.components.EditBox;
66
import net.minecraft.client.gui.screens.ChatScreen;
7+
import org.jetbrains.annotations.Nullable;
78
import org.spongepowered.asm.mixin.Mixin;
89
import org.spongepowered.asm.mixin.Shadow;
10+
import org.spongepowered.asm.mixin.Unique;
911
import org.spongepowered.asm.mixin.injection.At;
1012
import org.spongepowered.asm.mixin.injection.Inject;
1113
import org.spongepowered.asm.mixin.injection.ModifyVariable;
1214
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1315

1416
@Mixin(ChatScreen.class)
1517
public class MixinChatScreen {
16-
1718
@Shadow protected EditBox input;
1819

20+
@Unique
21+
@Nullable
22+
private Integer oldMaxLength = null;
23+
1924
// replace the text before the Fabric Command API executes it,
2025
// but ensure the message is added to the history in its raw form.
2126
@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) {
3035
@Inject(method = "onEdited", at = @At("HEAD"))
3136
private void onEdited(String value, CallbackInfo ci) {
3237
if (value.startsWith("/") && ClientCommands.isClientcommandsCommand(value.substring(1).split(" ")[0])) {
38+
if (oldMaxLength == null) {
39+
oldMaxLength = input.maxLength;
40+
}
3341
input.setMaxLength(32767);
3442
} else {
3543
// TODO: what if other mods try to do the same thing?
36-
input.setMaxLength(256);
44+
if (oldMaxLength != null) {
45+
input.setMaxLength(oldMaxLength);
46+
oldMaxLength = null;
47+
}
3748
}
3849
}
3950
}

src/main/resources/clientcommands.aw

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ accessible method net/minecraft/client/Minecraft openChatScreen (Ljava/lang/Stri
1313
accessible method net/minecraft/network/chat/HoverEvent <init> (Lnet/minecraft/network/chat/HoverEvent$TypedHoverEvent;)V
1414
accessible class net/minecraft/network/chat/HoverEvent$TypedHoverEvent
1515

16+
accessible field net/minecraft/client/gui/components/EditBox maxLength I
17+
1618
accessible field net/minecraft/network/ConnectionProtocol flows Ljava/util/Map;
1719
accessible field net/minecraft/network/ConnectionProtocol$CodecData packetSet Lnet/minecraft/network/ConnectionProtocol$PacketSet;
1820
accessible field net/minecraft/network/ConnectionProtocol$PacketSet classToId Lit/unimi/dsi/fastutil/objects/Object2IntMap;

0 commit comments

Comments
 (0)