QuiltMC / quilt-config

Quilt Config (aka "haven king's metadata of madness") is a library designed to facilitate the creation and management of config files.
Apache License 2.0
21 stars 8 forks source link

add public methods for getting min and max on ranges #47

Closed ix0rai closed 4 months ago

ix0rai commented 5 months ago

without this, it's impossible for you to check the min and max of a tracked value

context: this method in my mod

    private static Option<Double> createOptional(TrackedValue<Float> trackedValue) {
        Constraint.Range<?> range = null;

        for (Constraint<?> c : trackedValue.constraints()) {
            if (c instanceof Constraint.Range<?> constraintRange) {
                range = constraintRange;
            }
        }

        if (range == null) {
            throw new RuntimeException("value must have float range constraint " + trackedValue);
        }

        return new Option<>(
                trackedValue.key().toString(),
                Option.constantTooltip(Text.empty()),
                (text, value) -> GameOptions.getGenericValueText(text, Text.translatable("options.multiplier", value)),
                new Option.IntRangeValueSet((int) range.min() * 10, (int) range.max() * 10).withModifier(i -> (double) i / 10.0, double_ -> (int) (double_ * 10.0)),
                Codec.doubleRange(range.min(), range.max()),
                (double) trackedValue.getDefaultValue(),
                value -> {
                    trackedValue.setValue(value.floatValue());
                }
        );
    }

requires an access widener to work, and there should be a proper way to do this