Using - Glass-Series/glass-config-api GitHub Wiki

Quick Usage
Categories
Annotations
Multiplayer Syncing
Multiple Config Pages
IMPORTANT NOTES

Quick Usage

  1. Create an empty non-static class somewhere in your project. We will be using this later.
  2. Create an instantiated public static final field for your first config screen and annotate it with @GConfig, make sure the field's type is the class you just created. Do not put it inside your newly made class. (e.g. public static final ExampleConfigClass config = new ExampleConfigClass())
  3. Fill out the required value and visibleName parameters on the annotation. Value is the name of your config file. (e.g. @GConfig(value = "config", visibleName = "My Config GUI"))
  4. Go into your fabric.mod.json and add the snippet below inside your entrypoints section:
"gcapi": [
  "<path.to.the.class.containing.the.field.here>"
]
  1. Now let's go back to the empty class you made earlier.
  2. Create some fields with the type you want (Valid Types) and annotate them with @ConfigName, filling out the value parameter with what you'd like the user to see your option called in the config GUI. (e.g. @ConfigName("My Config Field") public String myField = "")
  3. Done! You can use the field in your code, GCAPI will handle loading and syncing logic for you.

Categories

To make a category, you will need to:

  1. Create a class that will represent your category and fill it with fields like normal, including the required annotations.
  2. In the class where you want the category, add a @ConfigCategory annotation, and fill out the required value parameter.
  3. Done! You can have categories inside of categories if you so wish to.

Annotations

Annotation Description Required
@GConfig Used by GCAPI to find your mod configs in a class.
  • (config class fields)
@ConfigName Holds the name of a config entry.
  • (config fields)
@ConfigCategory Holds the name of a config category, and indicates to the parser that it's a category.
  • (categories)
@MultiplayerSynced Indicates to the parser that the field or category should be set to server-side values when joining a server. Doesn't work on servers without GCAPI.
@blue.endless.jankson.Comment Holds the description of a config entry. Shown underneath the value in grey, and as comments in the JSON files themselves.
@MaxLength Tells the parser the maximum length of a config entry. Default is 32. !!Note that also applies to numeric field values, so by default, all floats and ints are limited to being 32 in value!!
@DefaultOnVanillaServer Temporarily resets the field to the default value on joining a vanilla server.
@ValueOnVanillaServer Temporarily resets the field to the specified value on joining a vanilla server. You can specify stringValue, integerValue, floatValue and booleanValue. Only one should be specified, and it should match the type of your field.

Multiplayer Syncing

Just add @MultiplayerSynced to the field or categories you want synced with the server.

Multiple Config Pages

Just add another @GConfig field, and if it's in a different class from the first one, add it's class to the entrypoints section in fabric.mod.json too.

Buttons will be added at the top of the config page for your mod for navigating these.

Enums

In 2.0.0, you can now use enums to create cycling config values.

The catch is that you need to create your enum type, and provide a set of simple config factories.

See ExampleConfigEnum and ExampleConfigEnumFactories on how to do it.

Generated Configs

In 2.0.0, you can now dynamically supply config categories and fields.

Make your config category class, implement GeneratedConfig.

IMPORTANT NOTES

  • Use GCAPI.reloadConfig to manually set config values. This is to ensure mods are notified properly and can post-process things.
  • The config.json files are not sanitised or checked when loaded. This will be fixed in a later update once I figure out a good way to handle it. This is low on my list.
  • Servers are able to send whatever configs they want, so long as the config field on the client is MP syncable. The server doesn't even need to have the mod installed. This would require emulating GCAPI's config export code to do so, though. I'm not sure if I'll patch this. It seems like it would have its uses.
⚠️ **GitHub.com Fallback** ⚠️