2021-03-16 19:43:32 +03:00
|
|
|
local get_connected_players = minetest.get_connected_players
|
|
|
|
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.snow = {}
|
2017-02-20 21:05:26 +03:00
|
|
|
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.snow.particles_count = 15
|
|
|
|
mcl_weather.snow.init_done = false
|
2017-02-20 21:05:26 +03:00
|
|
|
|
|
|
|
-- calculates coordinates and draw particles for snow weather
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.snow.add_snow_particles = function(player)
|
|
|
|
mcl_weather.rain.last_rp_count = 0
|
|
|
|
for i=mcl_weather.snow.particles_count, 1,-1 do
|
|
|
|
local random_pos_x, random_pos_y, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player)
|
2019-02-01 08:33:07 +03:00
|
|
|
random_pos_y = math.random() + math.random(player:get_pos().y - 1, player:get_pos().y + 7)
|
2017-02-20 21:05:26 +03:00
|
|
|
if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1
|
2017-02-20 21:05:26 +03:00
|
|
|
minetest.add_particle({
|
|
|
|
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
|
2020-04-11 05:06:37 +03:00
|
|
|
velocity = {x = math.random(-100,100)*0.001, y = math.random(-300,-100)*0.004, z = math.random(-100,100)*0.001},
|
|
|
|
acceleration = {x = 0, y=0, z = 0},
|
|
|
|
expirationtime = 8.0,
|
|
|
|
size = 1,
|
2017-02-20 21:05:26 +03:00
|
|
|
collisiondetection = true,
|
|
|
|
collision_removal = true,
|
2020-04-11 05:06:37 +03:00
|
|
|
object_collision = false,
|
|
|
|
vertical = false,
|
2017-11-21 03:35:31 +03:00
|
|
|
texture = mcl_weather.snow.get_texture(),
|
2017-02-20 21:05:26 +03:00
|
|
|
playername = player:get_player_name()
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.snow.set_sky_box = function()
|
|
|
|
mcl_weather.skycolor.add_layer(
|
2017-12-01 18:02:29 +03:00
|
|
|
"weather-pack-snow-sky",
|
2017-02-20 21:05:26 +03:00
|
|
|
{{r=0, g=0, b=0},
|
2017-11-22 04:59:09 +03:00
|
|
|
{r=85, g=86, b=86},
|
|
|
|
{r=135, g=135, b=135},
|
|
|
|
{r=85, g=86, b=86},
|
|
|
|
{r=0, g=0, b=0}})
|
|
|
|
mcl_weather.skycolor.active = true
|
2021-03-16 19:43:32 +03:00
|
|
|
for _, player in pairs(get_connected_players()) do
|
2017-11-22 04:59:09 +03:00
|
|
|
player:set_clouds({color="#ADADADE8"})
|
|
|
|
end
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.skycolor.active = true
|
2017-02-20 21:05:26 +03:00
|
|
|
end
|
|
|
|
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.snow.clear = function()
|
|
|
|
mcl_weather.skycolor.remove_layer("weather-pack-snow-sky")
|
|
|
|
mcl_weather.snow.init_done = false
|
2017-02-20 21:05:26 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Simple random texture getter
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.snow.get_texture = function()
|
2020-04-11 05:06:37 +03:00
|
|
|
return "weather_pack_snow_snowflake"..math.random(1,2)..".png"
|
2017-02-20 21:05:26 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
local timer = 0
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2017-11-21 03:35:31 +03:00
|
|
|
if mcl_weather.state ~= "snow" then
|
2017-02-20 21:05:26 +03:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
timer = timer + dtime;
|
|
|
|
if timer >= 0.5 then
|
|
|
|
timer = 0
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-11-21 03:35:31 +03:00
|
|
|
if mcl_weather.snow.init_done == false then
|
|
|
|
mcl_weather.snow.set_sky_box()
|
|
|
|
mcl_weather.snow.init_done = true
|
2017-02-20 21:05:26 +03:00
|
|
|
end
|
|
|
|
|
2021-03-16 19:43:32 +03:00
|
|
|
for _, player in pairs(get_connected_players()) do
|
2019-02-01 08:33:07 +03:00
|
|
|
if (mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos())) then
|
2017-02-20 21:05:26 +03:00
|
|
|
return false
|
|
|
|
end
|
2017-11-21 03:35:31 +03:00
|
|
|
mcl_weather.snow.add_snow_particles(player)
|
2017-02-20 21:05:26 +03:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- register snow weather
|
2017-11-21 03:35:31 +03:00
|
|
|
if mcl_weather.reg_weathers.snow == nil then
|
2021-01-28 01:02:52 +03:00
|
|
|
mcl_weather.reg_weathers.snow = {
|
|
|
|
clear = mcl_weather.snow.clear,
|
|
|
|
light_factor = 0.6,
|
|
|
|
-- 10min - 20min
|
|
|
|
min_duration = 600,
|
|
|
|
max_duration = 1200,
|
|
|
|
transitions = {
|
|
|
|
[65] = "none",
|
|
|
|
[80] = "rain",
|
|
|
|
[100] = "thunder",
|
|
|
|
}
|
|
|
|
}
|
2017-02-20 21:05:26 +03:00
|
|
|
end
|