Glass Config API

Glass Config API an API for mod authors to create configs, GUIs with Mod Menu integration along with other benefits for multiplayer, servers AND client configs.

Glass Config API Developer Wiki Source

Dependencies: StationAPI, Cursed Legacy API (for their respective environments) and Mod Menu is optional though 90% recommended.

Glass Repo Description:
Adds in the ability for mod authors to easily create config GUIs with ModMenu integration.

Heavily hackable and extendable while still remaining almost braindead easy to use.

Can sync in multiplayer as well, allowing servers to give clients configs that they should use.

Can be installed on client or server without requiring the other to install the API, provided no mods require it.

Source: https://github.com/calmilamsy/glass-config-api

Adding
You want to use GCAPI to handle your mod config? Great!

Go into your gradle.properties and add a new line: gcapi_version=1.0.0

Go into your build.gradle and go into your dependencies block, and add modImplementation "com.github.calmilamsy:glass-config-api:${project.gcapi_version}" to it.

(IntelliJ) Open the gradle tab in the top right, and press the circle Reload All Gradle Projects button.

You have added GCAPI to your workspace. For the next steps, see Using.

To-Do
Mostly for me. In rough order of priority weighted with estimated difficulty.

1.Get people to actually use this and report issues and suggestions to me.

2.Add the ability to easily and cleanly edit config fields programmatically.

3.Clean up the UI some.

4.Add support for fixed-length lists. I already know how I want to do this.

5.Redo part of the data storage in GCAPI, cause it's messy at best right now.

6.Add support for colours with an ingame colour picker. Adding an actual colour picker might be a pain the the arse. I have a couple of ideas on how to do this.

7.Add field validation on game load. JSON files are not validated on load, currently.

8.Add block and item selection support. Should be easy enough with StAPI registries. I currently cannot think of a good use for this config option yet, though.

Using
Quick Links on Developer Wiki not this Wiki (the quick links for this wiki are available at the top of the page taking the user to the appropriate headings below): Quick Usage Categories Annotations Multiplayer Syncing Multiple Config Pages

Create an empty non-static class somewhere in your project. We will be using this later.

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)

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"))

Go into your fabric.mod.json and add the snippet below inside your entrypoints section:

"gcapi": [ "" ]

Now let's go back to the empty class you made earlier.

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 = "")

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:

Create a class that will represent your category and fill it with fields like normal, including the required annotations.

In the class where you want the category, add a @ConfigCategory annotation, and fill out the required value parameter.

Done! You can have categories inside of categories if you so wish to.

Annotation
Annotation 	Description 	Required @GConfig 	Used by GCAPI to find your mod configs in a class.

@ConfigName 	Holds the name of a config entry.

@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.

@Description 	Holds the description of a config entry. Shown underneath the value in grey.

@MaxLength 	Tells the parser the maximum length of a config entry. Default is 32.



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.

Important Notes
Do not modify contents of your config fields during runtime. They will get reset once the user closes the game or reopens the config GUI. There is a way to do this, but it's convoluted, so a proper way to do this is coming in a later update. This is pretty high on my list, and may come as soon as 1.1.0.

The config.json files are not sanitised or checked. 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 mixining into 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.