Skip to content

Commit

Permalink
Increase max length of chat field when typing a clientcommands command.
Browse files Browse the repository at this point in the history
Closes #579
  • Loading branch information
Earthcomputer committed Mar 7, 2024
1 parent 74e536f commit 8c81b2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public static void sendCommandExecutionToServer(String command) {
}
}

public static boolean isClientcommandsCommand(String commandName) {
return clientcommandsCommands.contains(commandName);
}

public static void registerCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandBuildContext context) {
Set<String> existingCommands = getCommands(dispatcher);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

import net.earthcomputer.clientcommands.ClientCommands;
import net.earthcomputer.clientcommands.command.VarCommand;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.ChatScreen;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ChatScreen.class)
public class MixinChatScreen {

@Shadow protected EditBox input;

// 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 @@ -20,4 +26,14 @@ private String onHandleChatInput(String message) {
}
return command;
}

@Inject(method = "onEdited", at = @At("HEAD"))
private void onEdited(String value, CallbackInfo ci) {
if (value.startsWith("/") && ClientCommands.isClientcommandsCommand(value.substring(1).split(" ")[0])) {
input.setMaxLength(32767);
} else {
// TODO: what if other mods try to do the same thing?
input.setMaxLength(256);
}
}
}

0 comments on commit 8c81b2e

Please sign in to comment.