Quick Start

This library is in the active development and it's API might change.

The wiki is up to date with version 0.1.0-beta.4

Introduction

Before we start, a bit of terminology: Every command config consists of nodes, which can be categories, options or a super-secret custom node that will shown later. Command starts with a base node, with all other branching from it.

Where to start?

First, lets make a simple config state class to operate on.

ExampleConfig.java
public class ExampleConfig {
    private static ExampleConfig instance;
    public int intOpt = 0;
    public String strOpt = "";

    public static ExampleConfig getInstance() {
        if (instance == null) {
            instance = new ExampleConfig();
        }
        return instance;
    }

    public static void reset() {
        instance = new ExampleConfig();
    }

    public void save() {
        // Command Config Lib currently doesn't provide config saving.
        // Implementation is left to the user.
    }
}

Next create a client-side config builder in mod's initializer class.

ExampleMod.java
public class ExampleMod implements ClientModInitializer {
    @Override
    public void onInitializeClient() {
        createConfig();
    }

    private void createConfig() {
        // CommandConfigBuilder<FabricClientCommandSource> is long
        var configBuilder = CommandConfigBuilder.client("example-mod");
        // Config setup

        ClientCommandRegistrationCallback.EVENT.register(
                (dispatcher, access) -> dispatcher.register(configBuilder.build())
        );
        
        /*
        For Minecraft <1.19 use
        ClientCommandManager.DISPATCHER.register(configBuilder.build);
         */
    }
}

This creates a base command named "example-mod", which so far does nothing. See following sections for a detailed guide.

Last updated