Class ClientCommandManager

java.lang.Object
net.fabricmc.fabric.api.client.command.v2.ClientCommandManager

@Environment(CLIENT) public final class ClientCommandManager extends Object
Manages client-sided commands and provides some related helper methods.

Client-sided commands are fully executed on the client, so players can use them in both singleplayer and multiplayer.

Registrations can be done in the DISPATCHER during a ClientModInitializer's initialization. (See example below.)

The commands are run on the client game thread by default. Avoid doing any heavy calculations here as that can freeze the game's rendering. For example, you can move heavy code to another thread.

This class also has alternatives to the server-side helper methods in CommandManager: literal(String) and argument(String, ArgumentType).

The precedence rules of client-sided and server-sided commands with the same name are an implementation detail that is not guaranteed to remain the same in future versions. The aim is to make commands from the server take precedence over client-sided commands in a future version of this API.

Example command

 
 ClientCommandManager.DISPATCHER.register(
 	ClientCommandManager.literal("hello").executes(context -> {
 		context.getSource().sendFeedback(new LiteralText("Hello, world!"));
 		return 0;
 	})
 );
 
 
  • Field Details

    • DISPATCHER

      public static final com.mojang.brigadier.CommandDispatcher<FabricClientCommandSource> DISPATCHER
      The command dispatcher that handles client command registration and execution.
  • Method Details

    • literal

      public static com.mojang.brigadier.builder.LiteralArgumentBuilder<FabricClientCommandSource> literal(String name)
      Creates a literal argument builder.
      Parameters:
      name - the literal name
      Returns:
      the created argument builder
    • argument

      public static <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<FabricClientCommandSource,T> argument(String name, com.mojang.brigadier.arguments.ArgumentType<T> type)
      Creates a required argument builder.
      Type Parameters:
      T - the type of the parsed argument value
      Parameters:
      name - the name of the argument
      type - the type of the argument
      Returns:
      the created argument builder