Skip to content

feat: support slash-prefixed Baritone commands (e.g. /#goto)#5060

Open
CompileRider wants to merge 1 commit into
cabaletta:1.19.4from
CompileRider:feat/slash-prefix-support
Open

feat: support slash-prefixed Baritone commands (e.g. /#goto)#5060
CompileRider wants to merge 1 commit into
cabaletta:1.19.4from
CompileRider:feat/slash-prefix-support

Conversation

@CompileRider

Copy link
Copy Markdown
Contributor

Summary

Adds support for Baritone command prefixes that start with / (e.g. /#). When the prefix is set to /#, typing /#goto 100 64 100 in chat now correctly executes as a Baritone command instead of being sent to the server as an unknown vanilla command.

Problem

When a user sets prefix to a string starting with / (like /#), Minecraft's ChatScreen intercepts the message, strips the leading /, and routes it to sendCommand() instead of sendChat(). Baritone's existing mixin only hooks into sendChat(), so slash-prefixed commands were never seen by Baritone.
This is useful for privacy — if Baritone is inactive, /#goto becomes an unknown server command (only visible to the user), whereas #goto would be broadcast as regular chat to all players.

Solution

Added a new @Inject mixin in MixinClientPlayNetHandler targeting ClientPacketListener.sendCommand(String):

  • Checks if the configured prefix starts with /
  • Compares the command (without /) against the prefix (without /)
  • If matched, reconstructs the full message with / and dispatches a ChatEvent
  • ExampleBaritoneControl handles it normally from there

What's NOT affected

  • Default prefix # — new mixin returns early (no / prefix)
  • Vanilla commands (/tp, /give, etc.) — don't match the Baritone prefix
  • FORCE_COMMAND_PREFIX — goes through sendChat(), untouched
  • Tab completion — already worked via MixinCommandSuggestionHelper

Testing

Video attached demonstrating:

  1. Setting prefix to /# via #set prefix /#
  2. Executing /#goto — Baritone intercepts correctly
  3. Vanilla commands like /tp still work normally
    Fixes Suggest about command prefix #5045
video-compressed.mp4

Add a sendCommand() mixin to ClientPacketListener so that when the
Baritone prefix starts with '/' (like '/#'), commands typed as
'/#goto 100 64 100' are intercepted before Minecraft routes them
as vanilla commands.

ChatScreen strips the leading '/' and calls sendCommand() instead
of sendChat(), so the existing sendChat() mixin never saw these
messages. The new mixin compares the command (without '/') against
the prefix (without '/') and reconstructs the full message for
ExampleBaritoneControl to process.

Fixes cabaletta#5045
@CompileRider

Copy link
Copy Markdown
Contributor Author

Yes, vanilla /tp still works too. No, I didn't record that part because I forgot. You'll just have to trust me on this one. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggest about command prefix

1 participant