0
0
Fork 0

[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 end
end end
}) })
-- Wetten the soil -- Wetten the soil
minetest.register_abm({ minetest.register_abm({
@ -264,7 +264,7 @@ if mcl_weather.allow_abm then
end end
end end
end end
}) })
end end
if mcl_weather.reg_weathers.rain == nil then if mcl_weather.reg_weathers.rain == nil then

View File

@ -11,7 +11,7 @@ mcl_weather.skycolor = {
-- Update interval. -- Update interval.
update_interval = 15, update_interval = 15,
-- Main sky colors: starts from midnight to midnight. -- Main sky colors: starts from midnight to midnight.
-- Please do not set directly. Use add_layer instead. -- Please do not set directly. Use add_layer instead.
colors = {}, colors = {},
@ -205,8 +205,8 @@ mcl_weather.skycolor = {
-- Returns first player sky color. I assume that all players are in same color layout. -- Returns first player sky color. I assume that all players are in same color layout.
get_current_bg_color = function() get_current_bg_color = function()
local players = mcl_weather.skycolor.utils.get_players(nil) local players = mcl_weather.skycolor.utils.get_players(nil)
for _, player in ipairs(players) do if players[1] then
return player:get_sky() return players[1]:get_sky()
end end
return nil return nil
end end

View File

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

View File

@ -4,60 +4,58 @@ local get_connected_players = minetest.get_connected_players
lightning.auto = false lightning.auto = false
mcl_weather.thunder = { mcl_weather.thunder = {
next_strike = 0, next_strike = 0,
min_delay = 3, min_delay = 3,
max_delay = 12, max_delay = 12,
init_done = false, init_done = false,
} }
minetest.register_globalstep(function(dtime) minetest.register_globalstep(function(dtime)
if mcl_weather.get_weather() ~= "thunder" then if mcl_weather.get_weather() ~= "thunder" then
return false return false
end end
mcl_weather.rain.set_particles_mode("thunder")
mcl_weather.rain.make_weather()
if mcl_weather.thunder.init_done == false then mcl_weather.rain.set_particles_mode("thunder")
mcl_weather.skycolor.add_layer( mcl_weather.rain.make_weather()
"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
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) end)
mcl_weather.thunder.clear = function() function mcl_weather.thunder.clear()
mcl_weather.rain.clear() mcl_weather.rain.clear()
mcl_weather.skycolor.remove_layer("weather-pack-thunder-sky") mcl_weather.skycolor.remove_layer("weather-pack-thunder-sky")
mcl_weather.skycolor.remove_layer("lightning") mcl_weather.skycolor.remove_layer("lightning")
mcl_weather.thunder.init_done = false mcl_weather.thunder.init_done = false
end end
-- register thunderstorm weather -- register thunderstorm weather
if mcl_weather.reg_weathers.thunder == nil then if mcl_weather.reg_weathers.thunder == nil then
mcl_weather.reg_weathers.thunder = { mcl_weather.reg_weathers.thunder = {
clear = mcl_weather.thunder.clear, clear = mcl_weather.thunder.clear,
light_factor = 0.33333, light_factor = 0.33333,
-- 10min - 20min -- 10min - 20min
min_duration = 600, min_duration = 600,
max_duration = 1200, max_duration = 1200,
transitions = { transitions = {
[100] = "rain", [100] = "rain",
} },
} }
end end

View File

@ -1,27 +1,29 @@
local S = minetest.get_translator("mcl_weather") local S = minetest.get_translator("mcl_weather")
local math = math
-- weather states, 'none' is default, other states depends from active mods -- weather states, 'none' is default, other states depends from active mods
mcl_weather.state = "none" mcl_weather.state = "none"
-- player list for saving player meta info -- player list for saving player meta info
mcl_weather.players = {} mcl_weather.players = {}
-- default weather check interval for global step -- default weather check interval for global step
mcl_weather.check_interval = 5 mcl_weather.check_interval = 5
-- weather min duration -- weather min duration
mcl_weather.min_duration = 600 mcl_weather.min_duration = 600
-- weather max duration -- weather max duration
mcl_weather.max_duration = 9000 mcl_weather.max_duration = 9000
-- weather calculated end time -- weather calculated end time
mcl_weather.end_time = nil mcl_weather.end_time = nil
-- registered weathers -- registered weathers
mcl_weather.reg_weathers = {} mcl_weather.reg_weathers = {}
-- global flag to disable/enable ABM logic. -- global flag to disable/enable ABM logic.
mcl_weather.allow_abm = true mcl_weather.allow_abm = true
mcl_weather.reg_weathers["none"] = { mcl_weather.reg_weathers["none"] = {
@ -51,7 +53,7 @@ mcl_weather.get_rand_end_time = function(min_duration, max_duration)
r = math.random(min_duration, max_duration) r = math.random(min_duration, max_duration)
else else
r = math.random(mcl_weather.min_duration, mcl_weather.max_duration) r = math.random(mcl_weather.min_duration, mcl_weather.max_duration)
end end
return minetest.get_gametime() + r return minetest.get_gametime() + r
end end
@ -80,8 +82,8 @@ end
mcl_weather.is_underwater = function(player) mcl_weather.is_underwater = function(player)
local ppos = player:get_pos() local ppos = player:get_pos()
local offset = player:get_eye_offset() local offset = player:get_eye_offset()
local player_eye_pos = {x = ppos.x + offset.x, local player_eye_pos = {x = ppos.x + offset.x,
y = ppos.y + offset.y + 1.5, y = ppos.y + offset.y + 1.5,
z = ppos.z + offset.z} z = ppos.z + offset.z}
local node_level = minetest.get_node_level(player_eye_pos) local node_level = minetest.get_node_level(player_eye_pos)
if node_level == 8 or node_level == 7 then if node_level == 8 or node_level == 7 then
@ -91,14 +93,12 @@ mcl_weather.is_underwater = function(player)
end end
-- trying to locate position for particles by player look direction for performance reason. -- 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. -- it is costly to generate many particles around player so goal is focus mainly on front view.
mcl_weather.get_random_pos_by_player_look_dir = function(player) mcl_weather.get_random_pos_by_player_look_dir = function(player)
local look_dir = player:get_look_dir() local look_dir = player:get_look_dir()
local player_pos = player:get_pos() local player_pos = player:get_pos()
local random_pos_x = 0 local random_pos_x, random_pos_y, random_pos_z
local random_pos_y = 0
local random_pos_z = 0
if look_dir.x > 0 then if look_dir.x > 0 then
if look_dir.z > 0 then if look_dir.z > 0 then
@ -208,7 +208,7 @@ minetest.register_privilege("weather_manager", {
give_to_singleplayer = false give_to_singleplayer = false
}) })
-- Weather command definition. Set -- Weather command definition. Set
minetest.register_chatcommand("weather", { minetest.register_chatcommand("weather", {
params = "(clear | rain | snow | thunder) [<duration>]", params = "(clear | rain | snow | thunder) [<duration>]",
description = S("Changes the weather to the specified parameter."), description = S("Changes the weather to the specified parameter."),
@ -270,7 +270,7 @@ minetest.register_chatcommand("toggledownfall", {
local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm") local weather_allow_abm = minetest.settings:get_bool("weather_allow_abm")
if weather_allow_abm ~= nil and weather_allow_abm == false then if weather_allow_abm ~= nil and weather_allow_abm == false then
mcl_weather.allow_abm = false mcl_weather.allow_abm = false
end end
local load_weather = function() local load_weather = function()