A Minecraft mod. Downloads can be found on CurseForge.
!!! Forge Config API Port is in no way affiliated with the Forge project !!!
The sole purpose of this library is to enable usage of the Forge config api on the Fabric mod loader. This is done in the hopes of removing one more obstacle for developers wishing to maintain their mods on both loaders.
This is a direct port from Forge, all package names are the same, so you don't even have to readjust imports when porting from Forge. As Fabric is a whole different mod loader, there obviously have to be some differences, even though they're quite small.
For more information regarding the licensing of this project check the LICENSING.md file.
This project is still in development. Implementing it in your workspace is not yet recommended. Therefore, no maven repository exists at the moment.
In case you're eager to test this project, it can be included via the Curse Maven (Note: project name is merely a descriptor, you should be able to choose it freely; project id is found in the info box of a project page, file id is found at the end of the file url). This is how adding a Curse Maven dependency is generally done:
repositories {
maven { url = "https://cursemaven.com" }
}
dependencies {
modImplementation "curse.maven:<projectName>-<projectId>:<fileId>"
}
Since the Curse Maven generally isn't aware of any maven dependencies, you might have to add those manually, too. They are only required within your workspace, in a production environment those dependencies are shipped with Forge Config API Port.
repositories {
mavenCentral()
}
dependencies {
implementation 'com.electronwill.night-config:core:3.6.3'
implementation 'com.electronwill.night-config:toml:3.6.3'
}
There's also one more thing that might have to be done: Depending on how you have enabled Forge Config API Port in your environment, the mod might not be able to recognize the required Night Config libraries. You'll know that is the case when upon running the game instance, you'll be greeted by this message:
net.fabricmc.loader.impl.FormattedException: net.fabricmc.loader.impl.discovery.ModResolutionException: Mod resolution encountered an incompatible mod set!
A potential solution has been determined:
- Install com_electronwill_night-config_core, any version.
- Install com_electronwill_night-config_toml, any version.
To resolve this issue, what you need to do is add dependency overrides (check the Fabric Wiki for more information on this topic) for your configuration. Do that by creating a new file at run/config/fabric_loader_dependencies.json
, in which you put the following contents:
{
"version": 1,
"overrides": {
"forgeconfigapiport": {
"-depends": {
"com_electronwill_night-config_core": "",
"com_electronwill_night-config_toml": ""
}
}
}
}
Also don't forget to manually add this file to your VCS, since the whole run
directory is usually ignored by default.
The recommended point for registering your configs is directly in your ModInitializer::onInitialize
method.
Registering your configs still works via a class called net.minecraftforge.api.ModLoadingContext
, though the name is only for mimicking Forge, as this is really only used for registering configs.
You'll have to provide the mod id of your mod, as there is no context which would be aware of the current mod.
public static void registerConfig(String modId, ModConfig.Type type, IConfigSpec<?> spec)
And as on Forge there is also a version which supports a custom file name.
public static void registerConfig(String modId, ModConfig.Type type, IConfigSpec<?> spec, String fileName)
As Forge's mod loading process is split into multiple stages, configs aren't loaded immediately upon being registered. On Fabric though, no such mod loading stages exist. Therefore, Forge Config API Port loads all registered configs immediately.
Forge's ModConfigEvent.Loading
and ModConfigEvent.Reloading
events are both adapted for Fabric's callback event style. They can be accessed from the net.minecraftforge.api.fml.event.config.ModConfigEvent
class.
As on Forge, all these events provide is the config that is loading / reloading. But unlike on Forge, when processing that config, you'll have to make sure it actually comes from your mod. This is important, as there is no mod specific event bus on Fabric, meaning all events are fired for all mods subscribed to them.
As an example, a complete implementation of the reloading callback looks something like this:
ModConfigEvent.RELOADING.register((ModConfig config) -> {
if (config.getModId().equals(<modId>)) {
...
}
});