Bawnorton / Configurable

Compile/Runtime config library that allows decentralised settings in a mod
4 stars 0 forks source link

Clamped constraint being applied for boolean options #2

Closed skycatminepokie closed 2 months ago

skycatminepokie commented 2 months ago

Hi, I'm back :) When using a boolean option, the game crashes with IllegalConfigException: Default value "true" for "shouldRecord" in "ShootPlayerClip" does not conform to it's constraints

Using this part for a config:

@Configurable("shoot_player_clip")
public class ShootPlayerClip extends Clip {
    public static final Identifier ID = Identifier.of(Autocut.MOD_ID, "shoot_player");
    @Configurable(value = "default_start_offset", min = 0)
    public static long defaultStartOffset = 100;
    @Configurable(value = "default_end_offset", min = 0)
    public static long defaultEndOffset = 100;
    @Configurable("should_record")
    public static boolean shouldRecord = true;
    //...
}

Generates this:


package com.bawnorton.configurable.client.autocut;

import java.lang.Long;
import java.lang.Boolean;
import com.skycatdev.autocut.clips.ShootPlayerClip;

import com.bawnorton.configurable.generated.GeneratedConfig;
import com.bawnorton.configurable.ref.constraint.*;
import com.bawnorton.configurable.ref.Reference;

public final class Config implements GeneratedConfig {
    public final ShootPlayerClipConfig shoot_player_clip = new ShootPlayerClipConfig();

    public static class ShootPlayerClipConfig {
        public final Reference<Long> default_end_offset = new Reference<>("defaultEndOffset", ShootPlayerClip.class, long.class, ConstraintSet.builder().addClamped(0.0, 100.0));
        public final Reference<Long> default_start_offset = new Reference<>("defaultStartOffset", ShootPlayerClip.class, long.class, ConstraintSet.builder().addClamped(0.0, 100.0));
        public final Reference<Boolean> should_record = new Reference<>("shouldRecord", ShootPlayerClip.class, boolean.class, ConstraintSet.builder().addClamped(0.0, 100.0));
    }

}

It looks like the crash is because of the ConstraintSet.build().addClamped(...) not liking the boolean.

Log: https://mclo.gs/5oItJYq Crash log: https://mclo.gs/zVWBA38

Let me know if you would like any more information 👍

Bawnorton commented 2 months ago

hmm, looks like it's accidentally inheriting the constraint. I'll look into

Bawnorton commented 2 months ago

Fixed in 1.1.1, I adjusted the default max and min in 1.1.0 but forgot to change how the clamped constraint checks for it