Skip to content

Commit

Permalink
Remember the old max chat length before changing it, fixing VFP incom…
Browse files Browse the repository at this point in the history
…patibility
  • Loading branch information
Earthcomputer committed Mar 7, 2024
1 parent 719bd9f commit 406f308
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@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)
Expand All @@ -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;
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/clientcommands.aw
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ accessible method net/minecraft/client/Minecraft openChatScreen (Ljava/lang/Stri
accessible method net/minecraft/network/chat/HoverEvent <init> (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;

0 comments on commit 406f308

Please sign in to comment.