Cold Sweat

Cold Sweat

3M Downloads

[Question] Compatibility with EnhancedVisuals

CreativeMD opened this issue ยท 8 comments

commented

Hey there,

I'm the author of EnhancedVisuals. I would like to add support for your mod. I already support other similar mods. My question would be what is the best way to get the current temperature from the player. Is it stored in the persistent data somewhere?

In Regards
CreativeMD

commented

Looks good! But there are a couple things to note.

Temperatures for the world, like biomes and dimensions, are in MC units, but body temperature is on a scale of -100 to 100. 0 is neutral, -100 is freezing, and 100 is burning. This means that in this method, the temperature does not need to be converted.

The values for coldestTemperature, hypothermiaTemperature, warmTemperature, etc. would probably need to be adjusted for this.

commented

Thanks for your detailed instructions. I have finally got around and added supported. I have no tested it hope, it works: CreativeMD/EnhancedVisuals@146e8af
I guess by default you get the mc unit?

commented

Hey! Thanks for being interested in adding support. You can find documentation on that stuff here:
https://mikul.gitbook.io/cold-sweat/
Basically, you call Temperature.get(player, trait), where "trait" can be any temperature statistic on the player. You'd probably be most interested in the WORLD and BODY traits.

commented

Hey thanks for your quick response. Sorry for not being as fast. Would it be possible to make use of the persistent data? Because that way I could around using classes from your mod. For example every time you the temperature changes you could set it in the persistent data of the player as well. Just an idea, if that's not your type of tea I can also make use of your provided solution. For example this is how it looks for the addon of Survive:

https://github.com/CreativeMD/EnhancedVisuals/blob/1.20/src/main/java/team/creative/enhancedvisuals/common/addon/survive/TemperatureHandler.java#L51

        return PlayerUtils.getPersistentData(player).getCompound("survive:PlayerData").getCompound("TemperatureStats").getDouble("temperatureLevel");
commented

I could see about that, but I would still suggest the other method. Last time I tried, writing to NBT 11 times per tick, per player/entity, introduced more performance overhead than I'd like.

I implement inter-mod compat by using a dedicated class that handles all compat-related tasks. This way, classes from other mods are sandboxed and won't be called upon unless it is certain that their respective mods are loaded. For example:

// Method in some other class in your mod
if (CompatHelper.getBodyTemp(player) > 50)
{
      // do things when the player is hot
}
// Method in a dedicated mod compat class
public static double getBodyTempCS(Player player)
{
    if (isModLoaded("cold_sweat"))
    {
        return Temperature.get(player, Temperature.Trait.BODY);
    }
    // Default value in case Cold Sweat isn't loaded
    return 0;
}

// I like to have a method that makes it easy to check if mods are loaded
// This can also be stored as a static boolean field for each mod you want compat for
public static boolean isModLoaded(String mod)
{
    return ModList.get().getModFileById(modID) != null;
}

You can check my implementation for some real examples:
https://github.com/Momo-Softworks/Cold-Sweat/blob/1.20.1-FG/src/main/java/com/momosoftworks/coldsweat/util/compat/CompatManager.java

This enables much more in-depth compat with other mods, rather than being limited to Vanilla conventions. I'd suggest giving this a try for now, but I can look into storing basic temperature data on the player's NBT.

commented

Alright thanks. I have adjusted the config. Not sure if that fits, but effects start to appear at a temperature of 50/-50 and get more intense towards 100/-100:
CreativeMD/EnhancedVisuals@4ce4bdf
Does this seem like a good solution?

commented

Hello, sorry for the delay. Been busy lately. These changes look perfect.

commented

Perfect. Thanks again for your help! Will close this issue now.