diff --git a/rain/rain.lua b/rain/rain.lua index d6b8a97..24569cd 100644 --- a/rain/rain.lua +++ b/rain/rain.lua @@ -31,7 +31,7 @@ end rain.add_rain_particles = function(player, dtime) rain.last_rp_count = 0 for i=rain.particles_count, 1,-1 do - local random_pos_x, random_pos_y, random_pos_z = get_random_pos_by_player_look_dir(player) + local random_pos_x, random_pos_y, random_pos_z = weather.get_random_pos_by_player_look_dir(player) if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then rain.last_rp_count = rain.last_rp_count + 1 minetest.add_particle({ @@ -136,7 +136,7 @@ end) rain.make_weather = function() rain.raining = true for _, player in ipairs(minetest.get_connected_players()) do - if (is_underwater(player)) then + if (weather.is_underwater(player)) then return false end rain.add_player(player) diff --git a/snow/snow.lua b/snow/snow.lua index f980a3f..c83ff53 100644 --- a/snow/snow.lua +++ b/snow/snow.lua @@ -6,8 +6,8 @@ snow.particles_count = 25 snow.add_rain_particles = function(player, dtime) rain.last_rp_count = 0 for i=snow.particles_count, 1,-1 do - local random_pos_x, random_pos_y, random_pos_z = get_random_pos_by_player_look_dir(player) - random_pos_y = math.random() + random_pos(player:getpos().y - 1, player:getpos().y + 7) + local random_pos_x, random_pos_y, random_pos_z = weather.get_random_pos_by_player_look_dir(player) + random_pos_y = math.random() + math.random(player:getpos().y - 1, player:getpos().y + 7) if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then rain.last_rp_count = rain.last_rp_count + 1 minetest.add_particle({ @@ -43,7 +43,7 @@ minetest.register_globalstep(function(dtime) end for _, player in ipairs(minetest.get_connected_players()) do - if (is_underwater(player)) then + if (weather.is_underwater(player)) then return false end snow.add_rain_particles(player, dtime) diff --git a/weather_core/weather_core.lua b/weather_core/weather_core.lua index 1ae4208..0e2b265 100644 --- a/weather_core/weather_core.lua +++ b/weather_core/weather_core.lua @@ -47,7 +47,7 @@ end -- checks if player is undewater. This is needed in order to -- turn off weather particles generation. -function is_underwater(player) +weather.is_underwater = function(player) local ppos = player:getpos() local offset = player:get_eye_offset() local player_eye_pos = {x = ppos.x + offset.x, @@ -60,17 +60,9 @@ function is_underwater(player) return false end --- returns random number between a and b. -function random_pos(a, b) - if (a > b) then - return math.random(b, a); - end - return math.random(a, b); -end - -- trying to locate position for particles by player look direction for performance reason. -- it is costly to generate many particles around player so goal is focus mainly on front view. -function get_random_pos_by_player_look_dir(player) +weather.get_random_pos_by_player_look_dir = function(player) local look_dir = player:get_look_dir() local player_pos = player:getpos() @@ -96,7 +88,7 @@ function get_random_pos_by_player_look_dir(player) end end - random_pos_y = math.random() + random_pos(player_pos.y + 1, player_pos.y + 7) + random_pos_y = math.random() + math.random(player_pos.y + 1, player_pos.y + 7) return random_pos_x, random_pos_y, random_pos_z end