Base command

Configuration

Before we proceed to options and categories, there's some configuration to add in the base command.

category()

Adds a category to the node. Can be called multiple times to add more categories.

See Categories section for more details.

option()

Adds an option to the node. Can be called multiple times to add more options.

See Options section for more details.

printFunc()

Print function defines how command responses are sent to the player. Once specified in a node it will propagate to all branches that don't have their own function.

If you're using CommandConfigBuilder.client() or server(), print function is already specified to default one, but can be overridden.

saveFunc()

Save function saves your config upon setting an option value. Saving implementation is up to you. Similarly to the print function, once specified in a top level node it will apply to all other ones.

helpFunc()

Help function provides a response aimed to explain node usage and give other helpful information. Unlike print and save functions this doesn't propagate to other nodes and has to be set individually.

When any node has a help function a "help" node will be created at the base command, which will include all specified helper nodes.

build()

Builds all nested categories, options and their helper functions in a command argument to be registered.

Example

Following the config setup example shown in previous section, here's what these configurations look like:

private void createConfig() {
    // CommandConfigBuilder<FabricClientCommandSource> is long
    var configBuilder = CommandConfigBuilder.client("example-mod");
    configBuilder.helpFunc(() -> Text.of("This is a config for ExampleMod!"));
    configBuilder.saveFunc(ExampleConfig.getInstance()::save);

    ClientCommandRegistrationCallback.EVENT.register(
            (dispatcher, access) -> dispatcher.register(configBuilder.build())
    );

    /*
    For Minecraft <1.19 use
    ClientCommandManager.DISPATCHER.register(configBuilder.build);
     */
}

Last updated