Skip to content

Configurable API

Bawnorton edited this page Oct 13, 2024 · 7 revisions

Configurable provides an api for various other tasks

Registering

I am using Fabric

Inside your fabric.mod.json you will need to add the following entrypoint:

  "entrypoints": {
    "configurable": [
      "com.example.mod.YourModConfigurableApiImpl"
    ]
  }

I am using NeoForge or anything else

You will need to declare a service called com.bawnorton.configurable.api.ConfigurableApi inside the META-INF/services/ directory.
The content of this file will need to be a reference to your ConfigurableApi implementation(s):

com.example.mod.YourModConfigurableApiImpl

Using

Type Adapters

Registering additional type adapters may be desired for serialising and deserialising complex objects, such as Blocks. Implementing getTypeAdapters() allows you to provide additional type adapters to the internal serialiser.

Config Loading/Saving

You can modify the saved / loaded config by implementing beforeSave or afterLoad which both accept and return the generated config. You can also apply datafixing to the config that is about to be loaded by implementing beforeLoad

Server Enforcement

You can override serverEnforces to set the default value for all @Configurable's serverEnforces attribute.

Field Naming

Implementing defaultFieldNamingStrategy allows you to change how field names map to keys by default

⚠️ Required for Non-Fabric ⚠️

Configurable cannot tell which mod a service is provided from, thus, non-fabric users must implement getConfigName() in their api impl and return the name of their config (Should be your modid on NeoForge)