Skip to content

Commit

Permalink
fix precision errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed May 22, 2024
1 parent 4409e37 commit 978ef7f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/java/io/ix0rai/ramel/client/RamelConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public RamelConfigScreen(@Nullable Screen parent) {
}

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

for (Constraint<?> c : trackedValue.constraints()) {
Expand All @@ -39,13 +39,20 @@ private static Option<Double> createOptional(TrackedValue<Float> trackedValue) {
throw new RuntimeException("value must have float range constraint " + trackedValue);
}

return new Option<>(
float min = (float) range.min();
float max = (float) range.max();

return new Option<Float>(
"ramel.config." + trackedValue.key().toString(),
Option.constantTooltip(Text.translatable("ramel.config.tooltip." + trackedValue.key().toString())),
(text, value) -> GameOptions.getGenericValueText(text, Text.translatable("ramel.config.value." + trackedValue.key().toString(), value)),
new Option.IntRangeValueSet((int) ((float) range.min() * 10), (int) ((float) range.max() * 10)).withModifier(i -> (double) i / 10.0, double_ -> (int) (double_ * 10.0)),
Codec.doubleRange((float) range.min(), (float) range.max()),
(double) trackedValue.value(),
(new Option.IntRangeValueSet((int) (min * 10), (int) (max * 10))).withModifier((i) -> {
return (float) (i / 10.0);
}, (double_) -> {
return (int) (double_ * 10.0);
}),
Codec.floatRange(min, max),
trackedValue.value(),
value -> {
trackedValue.setValue(value.floatValue());
}
Expand Down

0 comments on commit 978ef7f

Please sign in to comment.