Cloth Config API (Fabric/Forge/NeoForge)

Cloth Config API (Fabric/Forge/NeoForge)

169M Downloads

Can't get multi file partitioning to work.

ShetiPhian opened this issue ยท 1 comments

commented

I hesitate to post this because I'm sure it's something obvious I'm missing, but I'm stuck and can't see the error.

I'm using ClothConfig 4.11.26 and this example: https://shedaniel.gitbook.io/cloth-config/auto-config/partitioning-the-config

First test:

@Config(name = "tester")
public class ConfigTest extends PartitioningSerializer.GlobalData
{
    @ConfigEntry.Category("client")
    @ConfigEntry.Gui.TransitiveObject
    public ClientFile CLIENT = new ClientFile();

    @ConfigEntry.Category("common")
    @ConfigEntry.Gui.TransitiveObject
    public CommonFile COMMON = new CommonFile();

    @Config(name = "client")
    public static class ClientFile implements ConfigData
    {
        boolean client_boolean = true;
    }

    @Config(name = "common")
    public static class CommonFile implements ConfigData
    {
        boolean common_boolean = true;
    }
}
AutoConfig.register(ConfigTest.class, JanksonConfigSerializer::new);
ConfigTest configs = AutoConfig.getConfigHolder(ConfigTest.class).getConfig();

Results in a single tester.json5 file

{
    "CLIENT": {
        "client_boolean": true
    },
    "COMMON": {
        "common_boolean": true
    }
}

Making the inner classes non static results in a stack overflow.

Taking a second look at the example, I noticed the modules where not inner classes to the main one, so I reconfigured them.

public class ConfigTest
{
    @Config(name = "tester")
    public static class Base extends PartitioningSerializer.GlobalData
    {
        @ConfigEntry.Category("client")
        @ConfigEntry.Gui.TransitiveObject
        public ClientFile CLIENT = new ClientFile();

        @ConfigEntry.Category("common")
        @ConfigEntry.Gui.TransitiveObject
        public CommonFile COMMON = new CommonFile();
    }

    @Config(name = "client")
    public static class ClientFile implements ConfigData
    {
        boolean client_boolean = true;
    }

    @Config(name = "common")
    public static class CommonFile implements ConfigData
    {
        boolean common_boolean = true;
    }
}
AutoConfig.register(ConfigTest.Base.class, JanksonConfigSerializer::new);
ConfigTest.Base configs = AutoConfig.getConfigHolder(ConfigTest.Base.class).getConfig();

But the output was the same.

I tried making the classes non static, but that throws a NoSuchMethodException for ConfigTest$Base.<init>() and creating a constructor doesn't fix it.

commented

100% me being dumb.
It finally clicked, while reading the code here with java docs, (don't have them in IntelliJ)
The PartitioningSerializer docs note "This serializer wraps another serializer", and I started thinking 'but my serializer isn't wrapped.'

I was still using
AutoConfig.register(ConfigTest.Base.class, JanksonConfigSerializer::new);
and should have changed it to
AutoConfig.register(ConfigTest.Base.class, PartitioningSerializer.wrap(JanksonConfigSerializer::new));
The real kick is its right there in the example, and I overlooked it multiple times.