Temperature Attributes (Mods) - TheDeathlyCow/thermoo GitHub Wiki

[!WARNING] This page has been moved to https://thermoo.thedeathlycow.com/entity_attributes/

Thermoo provides four attributes related to temperature, two for each 'form' of temperature (cooling/heating). They are Minimum Temperature (thermoo:min_temperature), Maximum Temperature (thermoo:max_temperature), Frost Resistance (thermoo:frost_resistance), and Heat Resistance (thermoo:heat_resistance).

[!NOTE] In Thermoo 4.x and below (for Minecraft 1.21.1 and below) all Thermoo attributes had a generic prefix in their name. For example, thermoo:generic.frost_resistance. In Thermoo 5.0 and above (for Minecraft 1.21.2+), this was removed. Please use the appropriate ID for your version!

Minimum and Maximum

The minimum and maximum temperature attributes set the temperature bounds for a TemperatureAware entity, and control the result of LivingEntity#thermoo$getMinTemperature and Living#thermoo$getMaxTemperature respectively. More specifically, the value of the bound is 140 times the sum total value of the attribute (base + all modifiers). The reason why 140 was chosen specifically, was because 140 is the vanilla maximum value of the TicksFrozen data piece that is associated with powder snow, so you can think of these bounds as being some multiple of the maximum freezing of powder snow.

Resistances

The attributes of Frost- and Heat Resistance both control how temperature changes (applied with TemperatureAware#thermoo$addTemperature) are, as the name implies, resisted. Frost Resistance deals with negative changes in temperature, while Heat Resistance deals with positive changes in temperature. Frost and Heat Resistance control the return value of TemperautreAware#thermoo$getColdResistance and TemperatureAware#thermoo$getHeatResistance, respectively. More about how resistance works can be found in the next section.

Setting the base values for these attributes

By default, all attributes have a base value of 0. If you wish to set a different value for this, you may register a listener for that attribute's base value event, obtained from ThermooAttributes#baseValueEvent(RegistryEntry<EntityAttribute>). Note that the attributes for this method argument must be one of Thermoo's (generic) attributes, an exception will be thrown if it isn't, as this event only applies for those attributes.

Examples

Example: Setting a base Minimum Temperature for all mobs

public class ExampleMod implements ModInitializer {
    private static final double MOB_MIN_TEMPERATURE = 40;
    
    @Override
    public void onInitialize() {
        ThermooAttributes.baseValueEvent(ThermooAttributes.MIN_TEMPERATURE).register((entity, baseValue) -> {
            // baseValue is set by the other listeners, so it is recommended to modify it rather than override it,
            // and return it as a fallback rather than some other fixed value like 0
            if (entity instanceof MobEntity) {
                return baseValue + MOB_MIN_TEMPERATURE;
            } else {
                return baseValue;
            }
        );
    }
}

Example: Get the Resistances of an Entity

LivingEntity entity;

double coldResistance = entity.thermoo$getColdResistance(); // get cold (or frost) resistance
double heatResistance = entity.thermoo$getHeatResistance(); // get heat resistance

➡️ Next: Temperature Changes