diff --git a/weather/api.lua b/weather/api.lua index 6ce4f55..33a5753 100644 --- a/weather/api.lua +++ b/weather/api.lua @@ -55,39 +55,49 @@ function weather_mod.register_downfall(id,def) if not ndef.size then ndef.size = 25 end - weather_mod.registered_downfalls[name]=def + if not ndef.enable_lightning then + ndef.enable_lightning=false + end + weather_mod.registered_downfalls[name]=ndef +end + +if minetest.get_modpath("lightning") then + lightning.auto = false +end + +function weather_mod.handle_lightning() + if not minetest.get_modpath("lightning") then return end + local current_downfall = weather_mod.registered_downfalls[weather.type] + lightning.auto = current_downfall.enable_lightning + if current_downfall.enable_lightning and math.random(1,2) == 1 then + local time = math.floor(math.random(lightning.interval_low/2,lightning.interval_low)) + minetest.after(time, lightning.strike) + end end minetest.register_globalstep(function() if weather.type=="none" then - for id,_ in pairs(weather_mod.registered_downfalls) do + for id,el in pairs(weather_mod.registered_downfalls) do if math.random(1, 50000) == 1 then weather.wind = {} weather.wind.x = math.random(0,10) weather.wind.y = 0 weather.wind.z = math.random(0,10) weather.type = id + weather_mod.handle_lightning() end end else if math.random(1, 10000) == 1 then weather.type = "none" + lightning.auto = false end end - local current_downfall - for id,el in pairs(weather_mod.registered_downfalls) do - if weather.type == id then - current_downfall = el - break - end - end + local current_downfall = weather_mod.registered_downfalls[weather.type] if current_downfall==nil then return end for _, player in ipairs(minetest.get_connected_players()) do local ppos = player:getpos() - -- Make sure player is not in a cave/house... - if minetest.env:get_node_light(ppos, 0.5) ~= 15 then return end - local wind_pos = vector.multiply(weather.wind,-1) local minp = vector.add(vector.add(ppos, current_downfall.min_pos),wind_pos) @@ -104,7 +114,8 @@ minetest.register_globalstep(function() minacc=acc, maxacc=acc, minexptime=exp, maxexptime=exp, minsize=current_downfall.size, maxsize=current_downfall.size, - collisiondetection=false, vertical=true, + collisiondetection=true, collision_removal=true, + vertical=true, texture=current_downfall.texture, player=player:get_player_name()}) end end) \ No newline at end of file diff --git a/weather/command.lua b/weather/command.lua index f1a8734..6900072 100644 --- a/weather/command.lua +++ b/weather/command.lua @@ -18,6 +18,7 @@ minetest.register_chatcommand("setweather", { minetest.chat_send_player(name, "avalible weather types: "..types) else weather.type = param + weather_mod.handle_lightning() end end }) diff --git a/weather/depends.txt b/weather/depends.txt new file mode 100644 index 0000000..b129625 --- /dev/null +++ b/weather/depends.txt @@ -0,0 +1 @@ +lightning? \ No newline at end of file diff --git a/weather/init.lua b/weather/init.lua index 861051b..bfd61aa 100644 --- a/weather/init.lua +++ b/weather/init.lua @@ -34,3 +34,5 @@ dofile(weather_mod.modpath.."/api.lua") dofile(weather_mod.modpath.."/rain.lua") dofile(weather_mod.modpath.."/snow.lua") dofile(weather_mod.modpath.."/command.lua") + +weather_mod.handle_lightning() diff --git a/weather/rain.lua b/weather/rain.lua index abfda27..1a187bf 100644 --- a/weather/rain.lua +++ b/weather/rain.lua @@ -7,4 +7,5 @@ weather_mod.register_downfall("weather:rain",{ exptime=0.8, size=25, texture="weather_rain.png", + enable_lightning=true, })