> For the complete documentation index, see [llms.txt](https://walksy.gitbook.io/walksylib-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://walksy.gitbook.io/walksylib-docs/using/creating-a-config.md).

# Creating a Config

A WalksyLib config is a class that implements `WalksyLibApi` and returns a `Config` from `define()`.

## The config class

```java
import main.walksy.lib.api.WalksyLibApi;
import main.walksy.lib.core.config.Config;
import main.walksy.lib.core.config.option.Category;
import main.walksy.lib.core.config.option.OptionGroup;
import main.walksy.lib.core.config.option.Options;
import main.walksy.lib.core.utils.PathUtils;

public final class MyModConfig implements WalksyLibApi {
    public static boolean enabled = true;
    public static int range = 8;

    @Override
    public Config define() {
        return Config.builder()
            .path(PathUtils.ofConfigDir("mymod"))
            .category(Category.builder("General")
                .group(OptionGroup.builder("General")
                    .option(Options.ofBoolean("Enabled", () -> enabled, true, value -> enabled = value).build())
                    .option(Options.ofNumber("Range", () -> range, 8, value -> range = value).range(1, 32, 1).build())
                    .build())
                .build())
            .build();
    }
}
```

Then register it under the `walksylib` entrypoint in `fabric.mod.json` (see [Adding WalksyLib to Gradle](https://walksy.gitbook.io/walksylib-docs/using/pages/d77a4b8fb4b5b5efd83167de2ce2371ab7c1ffca#declare-it-in-fabric.mod.json)).

## How options hold values

WalksyLib doesn't store your values. Each option takes a **getter** and a **setter** that read and write your own fields:

```java
Options.ofBoolean("Enabled", () -> enabled, true, value -> enabled = value)
//                 name      getter          default setter
```

Your mod reads `MyModConfig.enabled` directly, and there's no lookup at runtime. When the user changes the option, or when the config loads from disk, WalksyLib calls your setter.

## The config builder

| Method                             | What it does                                                                                                 |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `.path(Path)`                      | **Required.** Where the JSON file is saved. Use `PathUtils.ofConfigDir("name")` for `config/name.json`.      |
| `.category(Category)`              | Adds a category (a tab in the config screen).                                                                |
| `.onSave(Runnable)`                | Runs after the user saves the config from the screen.                                                        |
| `.movedFrom(Path)`                 | Imports values from an old config file once, then renames the old file to `.moved.bak`.                      |
| `.sharedFile()`                    | Merges into an existing file instead of overwriting it, so several configs can share one file.               |
| `.checkForUpdatesViaModrinth(url)` | Shows an update notice when a newer version is on your Modrinth page.                                        |
| `.allowOptOutFromServer(...)`      | Lets servers disable your mod or features. See [Server Opt-Out](/walksylib-docs/advanced/server-opt-out.md). |

## Getting the config instance

`getConfig()` returns the one shared `Config` built from your class:

```java
Config config = new MyModConfig().getConfig();
```
