Untitled Duck Mod (Fabric)

Untitled Duck Mod (Fabric)

1M Downloads

Crashes due to trying to get a float value from config when it's actually double

Prunoideae opened this issue · 2 comments

commented

Describe the bug
Crash due to config type casting

To Reproduce
Steps to reproduce the behavior:

  1. Have a duck with food
  2. Wait for a long time till it will eat food
  3. Crash

Expected behavior
Won't crash

Version
1.21.1 Neoforge 21.1.114

Error Log
https://gist.github.com/Prunoideae/5780a35a80de6ac3277d6ac9237d0245

commented

Had the same issue and dug into the source code to potentially find a fix. My suggestion would be to edit this function at UntitledConfigImpl.java:

public static float foodHealingValue() {
try {
return FOOD_HEALING_VALUE.get().floatValue(); // Added explicit cast to float
} catch (Exception e) {
return 0.5F; // Default value to prevent crashes
}
}

This issue likely occurs because Forge's config system stores numerical values as Double by default, even when defining them as Float. Since defineInRange tries to enforce type safety but may still store the value as Double, the .get() method returns a Double instead of a Float, leading to a ClassCastException when used directly in foodHealingValue(). At least, that's my guess.

commented

The issue originates from the Double parsing mechanism in Forge's configuration system.
Final solution:
ConfigValue<Double> → get().floatValue()
Thanks for providing the investigation direction.

Had the same issue and dug into the source code to potentially find a fix. My suggestion would be to edit this function at UntitledConfigImpl.java:

public static float foodHealingValue() { try { return FOOD_HEALING_VALUE.get().floatValue(); // Added explicit cast to float } catch (Exception e) { return 0.5F; // Default value to prevent crashes } }

This issue likely occurs because Forge's config system stores numerical values as Double by default, even when defining them as Float. Since defineInRange tries to enforce type safety but may still store the value as Double, the .get() method returns a Double instead of a Float, leading to a ClassCastException when used directly in foodHealingValue(). At least, that's my guess.