ClientCommandManager

public final class ClientCommandManager

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 net.fabricmc.api.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 net.minecraft.server.command.CommandManager: literal and argument.

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
{@code * ClientCommandManager.DISPATCHER.register( * ClientCommandManager.literal("hello").executes(context -> { * context.getSource().sendFeedback(new LiteralText("Hello, world!")); * return 0; * }) * ); * }
 

Functions

argument
Link copied to clipboard
static RequiredArgumentBuilder<FabricClientCommandSource, Targument<T>(String name, ArgumentType<T> type)
Creates a required argument builder.
literal
Link copied to clipboard
static LiteralArgumentBuilder<FabricClientCommandSourceliteral(String name)
Creates a literal argument builder.

Properties

DISPATCHER
Link copied to clipboard
public final static CommandDispatcher<FabricClientCommandSourceDISPATCHER
The command dispatcher that handles client command registration and execution.

Sources

jvm source
Link copied to clipboard