added support for the lightning mod
This commit is contained in:
parent
593eeb71da
commit
08d7f5d54c
|
@ -55,39 +55,49 @@ function weather_mod.register_downfall(id,def)
|
||||||
if not ndef.size then
|
if not ndef.size then
|
||||||
ndef.size = 25
|
ndef.size = 25
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function()
|
minetest.register_globalstep(function()
|
||||||
if weather.type=="none" then
|
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
|
if math.random(1, 50000) == 1 then
|
||||||
weather.wind = {}
|
weather.wind = {}
|
||||||
weather.wind.x = math.random(0,10)
|
weather.wind.x = math.random(0,10)
|
||||||
weather.wind.y = 0
|
weather.wind.y = 0
|
||||||
weather.wind.z = math.random(0,10)
|
weather.wind.z = math.random(0,10)
|
||||||
weather.type = id
|
weather.type = id
|
||||||
|
weather_mod.handle_lightning()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if math.random(1, 10000) == 1 then
|
if math.random(1, 10000) == 1 then
|
||||||
weather.type = "none"
|
weather.type = "none"
|
||||||
|
lightning.auto = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local current_downfall
|
local current_downfall = weather_mod.registered_downfalls[weather.type]
|
||||||
for id,el in pairs(weather_mod.registered_downfalls) do
|
|
||||||
if weather.type == id then
|
|
||||||
current_downfall = el
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if current_downfall==nil then return end
|
if current_downfall==nil then return end
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local ppos = player:getpos()
|
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 wind_pos = vector.multiply(weather.wind,-1)
|
||||||
|
|
||||||
local minp = vector.add(vector.add(ppos, current_downfall.min_pos),wind_pos)
|
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,
|
minacc=acc, maxacc=acc,
|
||||||
minexptime=exp, maxexptime=exp,
|
minexptime=exp, maxexptime=exp,
|
||||||
minsize=current_downfall.size, maxsize=current_downfall.size,
|
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()})
|
texture=current_downfall.texture, player=player:get_player_name()})
|
||||||
end
|
end
|
||||||
end)
|
end)
|
|
@ -18,6 +18,7 @@ minetest.register_chatcommand("setweather", {
|
||||||
minetest.chat_send_player(name, "avalible weather types: "..types)
|
minetest.chat_send_player(name, "avalible weather types: "..types)
|
||||||
else
|
else
|
||||||
weather.type = param
|
weather.type = param
|
||||||
|
weather_mod.handle_lightning()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
lightning?
|
|
@ -34,3 +34,5 @@ dofile(weather_mod.modpath.."/api.lua")
|
||||||
dofile(weather_mod.modpath.."/rain.lua")
|
dofile(weather_mod.modpath.."/rain.lua")
|
||||||
dofile(weather_mod.modpath.."/snow.lua")
|
dofile(weather_mod.modpath.."/snow.lua")
|
||||||
dofile(weather_mod.modpath.."/command.lua")
|
dofile(weather_mod.modpath.."/command.lua")
|
||||||
|
|
||||||
|
weather_mod.handle_lightning()
|
||||||
|
|
|
@ -7,4 +7,5 @@ weather_mod.register_downfall("weather:rain",{
|
||||||
exptime=0.8,
|
exptime=0.8,
|
||||||
size=25,
|
size=25,
|
||||||
texture="weather_rain.png",
|
texture="weather_rain.png",
|
||||||
|
enable_lightning=true,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue