Increase weather duration
[MineClone/MineClone2.git] / mods / ENVIRONMENT / weather_pack / snow.lua
blob0749b233dcb4df9568a46e4fcfb132fb60b19fdd
1 snow = {}
3 snow.particles_count = 15
4 snow.init_done = false
6 -- calculates coordinates and draw particles for snow weather
7 snow.add_rain_particles = function(player)
8 rain.last_rp_count = 0
9 for i=snow.particles_count, 1,-1 do
10 local random_pos_x, random_pos_y, random_pos_z = weather.get_random_pos_by_player_look_dir(player)
11 random_pos_y = math.random() + math.random(player:getpos().y - 1, player:getpos().y + 7)
12 if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then
13 rain.last_rp_count = rain.last_rp_count + 1
14 minetest.add_particle({
15 pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
16 velocity = {x = math.random(-1,-0.5), y = math.random(-2,-1), z = math.random(-1,-0.5)},
17 acceleration = {x = math.random(-1,-0.5), y=-0.5, z = math.random(-1,-0.5)},
18 expirationtime = 2.0,
19 size = math.random(0.5, 2),
20 collisiondetection = true,
21 collision_removal = true,
22 vertical = true,
23 texture = snow.get_texture(),
24 playername = player:get_player_name()
26 end
27 end
28 end
30 snow.set_sky_box = function()
31 skycolor.add_layer(
32 "weather-pack-snow-sky",
33 {{r=0, g=0, b=0},
34 {r=241, g=244, b=249},
35 {r=0, g=0, b=0}}
37 skycolor.active = true
38 end
40 snow.clear = function()
41 skycolor.remove_layer("weather-pack-snow-sky")
42 snow.init_done = false
43 end
45 -- Simple random texture getter
46 snow.get_texture = function()
47 local texture_name
48 local random_number = math.random()
49 if random_number > 0.5 then
50 texture_name = "weather_pack_snow_snowflake1.png"
51 else
52 texture_name = "weather_pack_snow_snowflake2.png"
53 end
54 return texture_name;
55 end
57 local timer = 0
58 minetest.register_globalstep(function(dtime)
59 if weather.state ~= "snow" then
60 return false
61 end
63 timer = timer + dtime;
64 if timer >= 0.5 then
65 timer = 0
66 else
67 return
68 end
70 if snow.init_done == false then
71 snow.set_sky_box()
72 snow.init_done = true
73 end
75 for _, player in ipairs(minetest.get_connected_players()) do
76 if (weather.is_underwater(player) or not mcl_util.has_weather(player:getpos())) then
77 return false
78 end
79 snow.add_rain_particles(player)
80 end
81 end)
83 -- register snow weather
84 if weather.reg_weathers.snow == nil then
85 weather.reg_weathers.snow = {
86 chance = 10,
87 clear = snow.clear,
88 -- 10min - 20min
89 min_duration = 600,
90 max_duration = 1200,
92 end