Skip to content

Commit

Permalink
Fix parsing float config values.
Browse files Browse the repository at this point in the history
Fixes #137.
Fixes #138.
  • Loading branch information
fnuecke committed Sep 22, 2023
1 parent 10a39ae commit 18ccb75
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions common/src/main/java/li/cil/scannable/util/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,15 @@ private static ConfigFieldPair<?> parseLongField(final Object instance, final Fi
}

private static ConfigFieldPair<?> parseFloatField(final Object instance, final Field field, final Builder builder) throws IllegalAccessException {
final float defaultValue = field.getFloat(instance);
final float minValue = (float) getMin(field);
final float maxValue = (float) getMax(field);
// Forge config does not natively support floats, so we map float fields to double config values.
final double defaultValue = field.getFloat(instance);
final double minValue = getMin(field);
final double maxValue = getMax(field);

final var configValue = withCommonAttributes(field, builder)
.defineInRange(getPath(field), defaultValue, minValue, maxValue, Float.class);
.defineInRange(getPath(field), defaultValue, minValue, maxValue, Double.class);

return new SetFieldConfigItem<>(field, configValue);
return new SetFieldConfigItem<>(field, configValue, value -> (float) (double) value);
}

private static ConfigFieldPair<?> parseDoubleField(final Object instance, final Field field, final Builder builder) throws IllegalAccessException {
Expand Down

0 comments on commit 18ccb75

Please sign in to comment.