simplify nil checks
This commit is contained in:
parent
3155eb8ba2
commit
3a76c4a403
|
@ -28,51 +28,56 @@ local function check_modname_prefix(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function set_defaults(vt,rt)
|
||||||
|
for i,v in pairs(rt) do
|
||||||
|
if not vt[i] then
|
||||||
|
vt[i] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local default_downfall = {
|
||||||
|
--minimum starting position
|
||||||
|
min_pos = {x=-9, y=10, z=-9},
|
||||||
|
--maximum starting position
|
||||||
|
max_pos = {x=9, y=10, z=9},
|
||||||
|
--y falling speed
|
||||||
|
falling_speed = 10,
|
||||||
|
--number of textures spawned
|
||||||
|
amount = 10,
|
||||||
|
--the texture size
|
||||||
|
size = 25,
|
||||||
|
--whether lightning schould be enabled
|
||||||
|
enable_lightning=false,
|
||||||
|
--whether to damage the player
|
||||||
|
damage_player=false
|
||||||
|
}
|
||||||
|
|
||||||
|
local default_damage = {
|
||||||
|
--how many half hearts
|
||||||
|
amount = 1,
|
||||||
|
--chance to damage: .5 is 50% btw.
|
||||||
|
chance = 1,
|
||||||
|
--after how many steps to damage
|
||||||
|
time = 100
|
||||||
|
}
|
||||||
|
|
||||||
function weather_mod.register_downfall(id,def)
|
function weather_mod.register_downfall(id,def)
|
||||||
local name = check_modname_prefix(id)
|
local name = check_modname_prefix(id)
|
||||||
if name == "none" then error("\"none\" means none, thanks") end
|
if name == "none" then error("\"none\" means none, thanks") end
|
||||||
if weather_mod.registered_downfalls[name]~=nil then error(name.." is already registered") end
|
if weather_mod.registered_downfalls[name]~=nil then error(name.." is already registered") end
|
||||||
local ndef = table.copy(def)
|
local ndef = table.copy(def)
|
||||||
if not ndef.min_pos then --minimum starting position
|
--what the downfall looks like
|
||||||
ndef.min_pos = {x=-9, y=10, z=-9}
|
if not ndef.texture then
|
||||||
end
|
|
||||||
if not ndef.maxp then --maximum starting position
|
|
||||||
ndef.max_pos = {x= 9, y=10, z= 9}
|
|
||||||
end
|
|
||||||
if not ndef.falling_speed then --y falling speed
|
|
||||||
ndef.falling_speed = 10
|
|
||||||
end
|
|
||||||
if not ndef.amount then --number of textures spawned
|
|
||||||
ndef.amount = 10
|
|
||||||
end
|
|
||||||
if not ndef.exptime then --when to delete the particles
|
|
||||||
ndef.exptime = ndef.max_pos.y / (math.sqrt(ndef.falling_acceleration) + ndef.falling_speed)
|
|
||||||
end
|
|
||||||
if not ndef.texture then --what the downfall looks like
|
|
||||||
error("no texture given")
|
error("no texture given")
|
||||||
end
|
end
|
||||||
if not ndef.size then --the texture size
|
set_defaults(ndef,default_downfall)
|
||||||
ndef.size = 25
|
--when to delete the particles
|
||||||
end
|
if not ndef.exptime then
|
||||||
if not ndef.enable_lightning then
|
ndef.exptime = ndef.max_pos.y / (math.sqrt(ndef.falling_acceleration) + ndef.falling_speed)
|
||||||
ndef.enable_lightning=false
|
|
||||||
end
|
|
||||||
if not ndef.damage_player then --whether to damage the player
|
|
||||||
ndef.damage_player=false
|
|
||||||
else
|
|
||||||
if not ndef.damage_player.amount then
|
|
||||||
--how many half hearts
|
|
||||||
ndef.damage_player.amount = 1
|
|
||||||
end
|
|
||||||
if not ndef.damage_player.chance then
|
|
||||||
--0.5 is 50% btw.
|
|
||||||
ndef.damage_player.chance = 1
|
|
||||||
end
|
|
||||||
if not ndef.damage_player.time then
|
|
||||||
--after how many steps to damage
|
|
||||||
ndef.damage_player.time = 100
|
|
||||||
end
|
end
|
||||||
|
if ndef.damage_player then
|
||||||
|
set_defaults(ndef.damage_player,default_damage)
|
||||||
end
|
end
|
||||||
--actually register the downfall
|
--actually register the downfall
|
||||||
weather_mod.registered_downfalls[name]=ndef
|
weather_mod.registered_downfalls[name]=ndef
|
||||||
|
|
Loading…
Reference in New Issue