t-affeldt / climate_api

An expansive weather engine for Minetest
https://forum.minetest.net/viewtopic.php?f=9&t=24569
Other
9 stars 4 forks source link

Positional Weather #7

Closed HeyITGuyFixIt closed 1 year ago

HeyITGuyFixIt commented 1 year ago

I am trying to get the rainbarrels mod to support climate_api for my server. However, it looks like weather is dependent on the player and not the position, so I can't get the position of a barrel and check if its raining independent of a player.

I'm looking for a way to check if it's raining at a barrel's position whenever the timer is triggered. If there isn't a built in way to do this, can there be? Or do you have any ideas of how I can check for this? So basically I am looking for some way to or a function that checks for a specified weather at a given position.

t-affeldt commented 1 year ago

At this point in time, it is not possible to get the active weather effects directly as they are tied to the players. However, you can use climate_api.environment.get_humidity to get the current humidity value at any position of your choice. Regional_weather will spawn rain / snow if this value reaches 50.

You might also want to check that the barrel is outside. For that you can check the daylight value of the node above it.

The following (untested) function will return whether or not it is raining / snowing at a given position:

function is_raining(pos)
    humidity = climate_api.environment.get_humidity(pos)
    above = vector.add(pos, {x = 0, y = 1, z = 0})
    daylight = minetest.get_node_light(above, 0.5) or 0
    return humidity >= 50 and daylight >= 15
end