-
Notifications
You must be signed in to change notification settings - Fork 3
Temperature Unit API
For mods that prefer to deal with ambient temperature changes in terms of normal units of temperature like Celsius or Fahrenheit, this API is for you! This API helps to convert between temperature units and passive temperature point changes per tick.
The javadoc of the TemperatureConverter
class provides a lot of the details, but the gist is that conversions are based on a linear scale where temperatures of 15C - 24C are 0 points per tick, and adding or removing 10C adds or removes 1 temperature point respectively. However, you can configure both the scale and the unit through settings. This desmos graph provides a nice visualization of the scale: https://www.desmos.com/calculator/z1tqbiol9l
The temperature unit enum also provides a general way of converting between temperature units - so this could be helpful outside of Thermoo temperatures, too.
For example:
@Test
void room_temp_is_20c() {
double roomTempC = 20.0;
int tempChange = TemperatureConverter.ambientTemperatureToTemperatureTick(roomTempC, TemperatureConverter.Settings.DEFAULT);
assertEquals(0, tempChange);
}
@Test
void room_temp_is_68f() {
double roomTempF = 68.0;
var settings = new TemperatureConverter.Settings(TemperatureUnit.FAHRENHEIT, 1.0, 0.0);
int tempChange = TemperatureConverter.ambientTemperatureToTemperatureTick(roomTempF, settings);
assertEquals(0, tempChange);
}
@Test
void convert_f_to_c() {
double roomTempF = 68.0;
double roomTempC = TemperatureUnit.FAHRENHEIT.convertTemperature(roomTempF, TemperatureUnit.CELSIUS);
assertEquals(20.0, roomTempC);
}