YetAnotherConfigLib

YetAnotherConfigLib

13M Downloads

Use Supplier<Text> instead of Text for option names

Qendolin opened this issue ยท 0 comments

commented

Currently all options are passed a fixed Text for their name. Sometimes, especially in the case of buttons, it would be nice to change their text. I propose updating the option implementations and builders to use a Supplier<Text> instead. This change would also easily be backwards compatible.

To demonstrate take this simple example:

This is currently possible:

AtomicBoolean added = new AtomicBoolean(false);
ButtonOption.createBuilder()
    .name(Text.literal("Add or Remove"))
    .action((scr, opt) -> {
        if(added.get()) {
            added.set(false);
        } else {
            added.set(true);
        }
    });

This would be possible with the proposal:

AtomicBoolean added = new AtomicBoolean(false);
ButtonOption.createBuilder()
    .name(() => added.get() ? Text.literal("Remove") : Text.literal("Add"))
    .action((scr, opt) -> {
        if(added.get()) {
            added.set(false);
        } else {
            added.set(true);
        }
    });