[mcl_weather] fix warnings

This commit is contained in:
AFCMS 2021-05-23 14:44:50 +02:00
parent 21b7647731
commit 5f8d79b37a
5 changed files with 122 additions and 124 deletions

View File

@ -249,7 +249,7 @@ if mcl_weather.allow_abm then
end
end
end
})
})
-- Wetten the soil
minetest.register_abm({
@ -264,7 +264,7 @@ if mcl_weather.allow_abm then
end
end
end
})
})
end
if mcl_weather.reg_weathers.rain == nil then

View File

@ -205,8 +205,8 @@ mcl_weather.skycolor = {
-- Returns first player sky color. I assume that all players are in same color layout.
get_current_bg_color = function()
local players = mcl_weather.skycolor.utils.get_players(nil)
for _, player in ipairs(players) do
return player:get_sky()
if players[1] then
return players[1]:get_sky()
end
return nil
end

View File

@ -7,78 +7,78 @@ mcl_weather.snow.init_done = false
-- calculates coordinates and draw particles for snow weather
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)
random_pos_y = math.random() + math.random(player:get_pos().y - 1, player:get_pos().y + 7)
if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then
mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1
minetest.add_particle({
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
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,
collisiondetection = true,
collision_removal = true,
object_collision = false,
vertical = false,
texture = mcl_weather.snow.get_texture(),
playername = player:get_player_name()
})
end
end
mcl_weather.rain.last_rp_count = 0
for i=mcl_weather.snow.particles_count, 1,-1 do
local random_pos_x, _, random_pos_z = mcl_weather.get_random_pos_by_player_look_dir(player)
local random_pos_y = math.random() + math.random(player:get_pos().y - 1, player:get_pos().y + 7)
if minetest.get_node_light({x=random_pos_x, y=random_pos_y, z=random_pos_z}, 0.5) == 15 then
mcl_weather.rain.last_rp_count = mcl_weather.rain.last_rp_count + 1
minetest.add_particle({
pos = {x=random_pos_x, y=random_pos_y, z=random_pos_z},
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,
collisiondetection = true,
collision_removal = true,
object_collision = false,
vertical = false,
texture = mcl_weather.snow.get_texture(),
playername = player:get_player_name()
})
end
end
end
mcl_weather.snow.set_sky_box = function()
mcl_weather.skycolor.add_layer(
"weather-pack-snow-sky",
{{r=0, g=0, b=0},
{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
for _, player in pairs(get_connected_players()) do
player:set_clouds({color="#ADADADE8"})
end
mcl_weather.skycolor.active = true
mcl_weather.skycolor.add_layer(
"weather-pack-snow-sky",
{{r=0, g=0, b=0},
{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
for _, player in pairs(get_connected_players()) do
player:set_clouds({color="#ADADADE8"})
end
mcl_weather.skycolor.active = true
end
mcl_weather.snow.clear = function()
mcl_weather.skycolor.remove_layer("weather-pack-snow-sky")
mcl_weather.snow.init_done = false
function mcl_weather.snow.clear()
mcl_weather.skycolor.remove_layer("weather-pack-snow-sky")
mcl_weather.snow.init_done = false
end
-- Simple random texture getter
mcl_weather.snow.get_texture = function()
return "weather_pack_snow_snowflake"..math.random(1,2)..".png"
function mcl_weather.snow.get_texture()
return "weather_pack_snow_snowflake"..math.random(1,2)..".png"
end
local timer = 0
minetest.register_globalstep(function(dtime)
if mcl_weather.state ~= "snow" then
return false
end
if mcl_weather.state ~= "snow" then
return false
end
timer = timer + dtime;
if timer >= 0.5 then
timer = 0
else
return
end
timer = timer + dtime;
if timer >= 0.5 then
timer = 0
else
return
end
if mcl_weather.snow.init_done == false then
mcl_weather.snow.set_sky_box()
mcl_weather.snow.init_done = true
end
if mcl_weather.snow.init_done == false then
mcl_weather.snow.set_sky_box()
mcl_weather.snow.init_done = true
end
for _, player in pairs(get_connected_players()) do
if (mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos())) then
return false
end
mcl_weather.snow.add_snow_particles(player)
end
for _, player in pairs(get_connected_players()) do
if (mcl_weather.is_underwater(player) or not mcl_worlds.has_weather(player:get_pos())) then
return false
end
mcl_weather.snow.add_snow_particles(player)
end
end)
-- register snow weather

View File

@ -4,60 +4,58 @@ local get_connected_players = minetest.get_connected_players
lightning.auto = false
mcl_weather.thunder = {
next_strike = 0,
min_delay = 3,
max_delay = 12,
init_done = false,
next_strike = 0,
min_delay = 3,
max_delay = 12,
init_done = false,
}
minetest.register_globalstep(function(dtime)
if mcl_weather.get_weather() ~= "thunder" then
return false
end
if mcl_weather.get_weather() ~= "thunder" then
return false
end
mcl_weather.rain.set_particles_mode("thunder")
mcl_weather.rain.make_weather()
if mcl_weather.thunder.init_done == false then
mcl_weather.skycolor.add_layer(
"weather-pack-thunder-sky",
{{r=0, g=0, b=0},
{r=40, g=40, b=40},
{r=85, g=86, b=86},
{r=40, g=40, b=40},
{r=0, g=0, b=0}})
mcl_weather.skycolor.active = true
for _, player in pairs(get_connected_players()) do
player:set_clouds({color="#3D3D3FE8"})
end
mcl_weather.thunder.init_done = true
end
if (mcl_weather.thunder.next_strike <= minetest.get_gametime()) then
lightning.strike()
local delay = math.random(mcl_weather.thunder.min_delay, mcl_weather.thunder.max_delay)
mcl_weather.thunder.next_strike = minetest.get_gametime() + delay
end
mcl_weather.rain.set_particles_mode("thunder")
mcl_weather.rain.make_weather()
if mcl_weather.thunder.init_done == false then
mcl_weather.skycolor.add_layer("weather-pack-thunder-sky", {
{r=0, g=0, b=0},
{r=40, g=40, b=40},
{r=85, g=86, b=86},
{r=40, g=40, b=40},
{r=0, g=0, b=0},
})
mcl_weather.skycolor.active = true
for _, player in pairs(get_connected_players()) do
player:set_clouds({color="#3D3D3FE8"})
end
mcl_weather.thunder.init_done = true
end
if (mcl_weather.thunder.next_strike <= minetest.get_gametime()) then
lightning.strike()
local delay = math.random(mcl_weather.thunder.min_delay, mcl_weather.thunder.max_delay)
mcl_weather.thunder.next_strike = minetest.get_gametime() + delay
end
end)
mcl_weather.thunder.clear = function()
mcl_weather.rain.clear()
mcl_weather.skycolor.remove_layer("weather-pack-thunder-sky")
mcl_weather.skycolor.remove_layer("lightning")
mcl_weather.thunder.init_done = false
function mcl_weather.thunder.clear()
mcl_weather.rain.clear()
mcl_weather.skycolor.remove_layer("weather-pack-thunder-sky")
mcl_weather.skycolor.remove_layer("lightning")
mcl_weather.thunder.init_done = false
end
-- register thunderstorm weather
if mcl_weather.reg_weathers.thunder == nil then
mcl_weather.reg_weathers.thunder = {
clear = mcl_weather.thunder.clear,
light_factor = 0.33333,
-- 10min - 20min
min_duration = 600,
max_duration = 1200,
transitions = {
[100] = "rain",
}
}
mcl_weather.reg_weathers.thunder = {
clear = mcl_weather.thunder.clear,
light_factor = 0.33333,
-- 10min - 20min
min_duration = 600,
max_duration = 1200,
transitions = {
[100] = "rain",
},
}
end

View File

@ -1,5 +1,7 @@
local S = minetest.get_translator("mcl_weather")
local math = math
-- weather states, 'none' is default, other states depends from active mods
mcl_weather.state = "none"
@ -96,9 +98,7 @@ mcl_weather.get_random_pos_by_player_look_dir = function(player)
local look_dir = player:get_look_dir()
local player_pos = player:get_pos()
local random_pos_x = 0
local random_pos_y = 0
local random_pos_z = 0
local random_pos_x, random_pos_y, random_pos_z
if look_dir.x > 0 then
if look_dir.z > 0 then