Skip to content

Creating A Simple Registry Config Object

ItsMeNotJames edited this page Oct 23, 2023 · 1 revision

Note

This page will show you how to make a SIMPLE registry config object. If you want more control, implement ConfigObject instead of extending RegistryConfigObject

Creating Your Class

To start creating the class for your new config object, create a class that implements net.vakror.jamesconfig.config.config.object.default_objects.registry.RegistryConfigObject. You end up with something like this:

package net.example;

import net.vakror.jamesconfig.config.config.object.ConfigObject;

public class ExampleObject extends RegistryConfigObject {
}

Now, you are required to implement serialize() and deserialize(JsonElement). These methods will serialize and deserialize from/to JSON. Custom objects HAVE to return a JsonObject from its serialize() method, or it will throw an exception. You will also have to create a constructor matching super. This is a simple constructor which sets the name of the object, as well as its type

Registering Your Type

Types are used in registry configs to identify your objects. All registry config objects, except for primitives, need to have a type FIELD inside their JsonObject. To register your type (gotten from getType(), MUST be unique), you can use multiple options. The most simple is the SimpleConfigObjectManager.

SimpleConfigObjectManager

In your mod constructor, call

SimpleConfigObjectManager.INSTANCE#register(ConfigObject)

For the parameter, pass in a default instance of your object. This instance is where deserialize is called from. this will automatically use the event system to register your type.

TODO

Object Register Event

A more complex, but flexible way to register config objects is the event system.