isXander / YetAnotherConfigLib

YetAnotherConfigLib (yacl) is just that. A builder-based configuration library for Minecraft.
GNU Lesser General Public License v3.0
91 stars 34 forks source link

[API Request] Allow `AutoGen` Config to Set `OptionFlag` #147

Open Phoupraw opened 5 months ago

Phoupraw commented 5 months ago

Now there is no way to set OptionFlag for AutoGen config.

I wrote a mixin for temporary use. (It's cumbersome to open a PR for a new project.)

@Mixin(SimpleOptionFactory.class)
abstract class MSimpleOptionFactory<A extends Annotation, T> implements OptionFactory<A, T> {
    @Inject(method = "flags", at = @At("RETURN"), cancellable = true)
    private void setFlags(A annotation, ConfigField<T> field, OptionAccess storage, CallbackInfoReturnable<Set<OptionFlag>> cir) {
        if (field.access().getAnnotation(GameRestart.class).isPresent()) {
            var set = new HashSet<>(cir.getReturnValue());
            set.add(OptionFlag.GAME_RESTART);
            cir.setReturnValue(set);
        }
    }
}
public class PSEConfig {
    @AutoGen(category = Categories.MAIN)
    @SerialEntry
    @IntField(min = 1, max = 64, format = "%d")
    @GameRestart
    public int potionMaxStack = 1
}