Super secret node

Here be dragons!

Technical details

First, a few details of the config builder implementation. When you have set up your config and call build() method in the base command builder, it traverses all categories, options and converts them to ArgumentBuilder-s provided by Brigadier - Minecraft's command library. Base command builder also scans for all helpFunc()-s you specified to add them to a separate branch.

Because of this mechanic, the entire config provided by this library can be recreated with vanilla commands and no other dependency, although with much more effort. But this also means there can be a pinch of freedom added to the config.

This is done with a node() method, which adds a custom LiteralArgumentBuilder node to the specified option, category or the base command. If you don't know how commands are built, its highly encouraged to check out Brigadier and try adding your own command with Fabric API.

Be warned: although custom nodes provide powerful functionality, they can cause issues if not configured properly.

Example

configBuilder.node((command) -> {
    LiteralArgumentBuilder<FabricClientCommandSource> node = literal("reset");
    node.executes(context -> {
        ExampleConfig.reset();
        return configBuilder.print(context, Text.of("Resetting config!"));
    });
    command.then(node);
});

In this example custom node is used to add an ability to reset config. It uses a print() method to send a response, which is provided by base command, category or option builder. Similar to help() and save() methods it simply runs the function you've set.

Result

/example-mod reset -> reset ExampleConfig

Last updated