# Basic usage of Config API

## What is it?

Along with YACL's primary functionality, the GUI, this mod also provides a super easy way to manage your mod's config. It can be a tedious part of every mod you make, this is why the Config API was created!

All you need to do is create a class, add some fields and tell YACL *how* to save and load your config.&#x20;

## An example...

<pre class="language-java"><code class="lang-java">public class MyConfig {
    public static ConfigClassHandler&#x3C;MyConfig> HANDLER = ConfigClassHandler.createBuilder(MyConfig.class)
            .id(new ResourceLocation("<a data-footnote-ref href="#user-content-fn-1">mymod</a>", "my_config"))
            .serializer(config -> GsonConfigSerializerBuilder.create(config)
                    .setPath(FabricLoader.getInstance().getConfigDir().resolve("my_mod.json5"))
                    .appendGsonBuilder(GsonBuilder::setPrettyPrint) // not needed, pretty print by default
                    .setJson5(true)
                    .build())
            .build();
            
    @SerialEntry
    public boolean myCoolBoolean = true;
    
    @SerialEntry
    public int myCoolInteger = 5;
    
    @SerialEntry<a data-footnote-ref href="#user-content-fn-2">(comment = "This string is amazing")</a>
    public String myCoolString = "How amazing!";
    
}
</code></pre>

That is it! That's all the setup you need for your config.

In this example, you can see that we told the config handler to use GSON to serialize your fields, meaning not just primitive/basic types work, but any! You can even see me modifying the GSON builder. **Only fields annotated with `@SerialEntry` are considered.**&#x20;

## Saving and loading

In the above example, you can see we specified the serializer like so:

```java
.serializer(config -> GsonConfigSerializerBuilder.create(config)
        .setPath(YACLPlatform.getConfigDir().resolve("my_mod.json5"))
        .appendGsonBuilder(GsonBuilder::setPrettyPrint) // not needed, pretty print by default
        .setJson5(true)
        .build())
```

You can see we specified the GSON serializer, set its path, configured GSON, and specified to use JSON5 spec. Currently, GSON is the only serializer made available to you. You can create your own, more on that later.

To save and load use the respected methods:

```java
MyConfig.HANDLER.save();
MyConfig.HANDLER.load();
```

[^1]: This should be your mod ID

[^2]: You can add comments!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.isxander.dev/yet-another-config-lib/config-api/basic-usage-of-config-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
