@Environment(value=CLIENT) public final class ClientCommandManager extends Object
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.
ClientCommandManager.DISPATCHER.register(
ClientCommandManager.literal("hello").executes(context -> {
context.getSource().sendFeedback(new LiteralText("Hello, world!"));
return 0;
})
);
Modifier and Type | Field and Description |
---|---|
static com.mojang.brigadier.CommandDispatcher<FabricClientCommandSource> |
DISPATCHER
The command dispatcher that handles client command registration and execution.
|
Modifier and Type | Method and Description |
---|---|
static <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<FabricClientCommandSource,T> |
argument(String name,
com.mojang.brigadier.arguments.ArgumentType<T> type)
Creates a required argument builder.
|
static com.mojang.brigadier.builder.LiteralArgumentBuilder<FabricClientCommandSource> |
literal(String name)
Creates a literal argument builder.
|
public static final com.mojang.brigadier.CommandDispatcher<FabricClientCommandSource> DISPATCHER
public static com.mojang.brigadier.builder.LiteralArgumentBuilder<FabricClientCommandSource> literal(String name)
name
- the literal namepublic static <T> com.mojang.brigadier.builder.RequiredArgumentBuilder<FabricClientCommandSource,T> argument(String name, com.mojang.brigadier.arguments.ArgumentType<T> type)
T
- the type of the parsed argument valuename
- the name of the argumenttype
- the type of the argument