Extra error checking: global variables
This commit is contained in:
parent
bf26b8bee1
commit
1648bc459f
17 changed files with 362 additions and 323 deletions
75
abms.lua
75
abms.lua
|
@ -16,6 +16,9 @@ local players_in_orbit = {}
|
|||
|
||||
local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"}
|
||||
|
||||
local time_factor = (fun_caves.time_factor or 10)
|
||||
local light_max = (fun_caves.light_max or 10)
|
||||
|
||||
|
||||
-- fungal tree nodes
|
||||
local fungal_tree_leaves = {}
|
||||
|
@ -36,6 +39,9 @@ fungal_nodes[#fungal_nodes+1] = {name = 'fun_caves:fungal_tree_fruit'}
|
|||
|
||||
local fungi_to_explode = {} -- see below
|
||||
local exploding_fungi = fun_caves.exploding_fungi
|
||||
if not exploding_fungi then
|
||||
exploding_fungi = {}
|
||||
end
|
||||
|
||||
|
||||
-- hot spike parameters
|
||||
|
@ -100,6 +106,10 @@ minetest.register_globalstep(function(dtime)
|
|||
return
|
||||
end
|
||||
|
||||
if not (fun_caves.db.status and fun_caves.registered_status) then
|
||||
return
|
||||
end
|
||||
|
||||
local time = minetest.get_gametime()
|
||||
if not (time and type(time) == 'number') then
|
||||
return
|
||||
|
@ -122,6 +132,10 @@ minetest.register_globalstep(function(dtime)
|
|||
|
||||
-- Promote mobs based on spawn position
|
||||
local is_fortress = fun_caves.is_fortress
|
||||
if not is_fortress then
|
||||
return
|
||||
end
|
||||
|
||||
for _, mob in pairs(minetest.luaentities) do
|
||||
if not mob.initial_promotion then
|
||||
local pos = mob.object:getpos()
|
||||
|
@ -276,7 +290,7 @@ minetest.register_globalstep(function(dtime)
|
|||
end
|
||||
|
||||
-- ... from hunger (even less often).
|
||||
if dps_count % hunger_delay == 0 then
|
||||
if dps_count % hunger_delay == 0 and fun_caves.hunger_change then
|
||||
fun_caves.hunger_change(player, -1)
|
||||
end
|
||||
end
|
||||
|
@ -319,7 +333,7 @@ minetest.register_abm({
|
|||
-- Exploding fungal fruit
|
||||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:fungal_tree_fruit"},
|
||||
interval = 2 * fun_caves.time_factor,
|
||||
interval = 2 * time_factor,
|
||||
chance = 150,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
|
@ -335,7 +349,7 @@ minetest.register_abm({
|
|||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:fungal_tree_fruit"},
|
||||
neighbors = {"fire:basic_flame"},
|
||||
interval = fun_caves.time_factor,
|
||||
interval = time_factor,
|
||||
chance = 50,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
|
@ -352,7 +366,7 @@ minetest.register_abm({
|
|||
-- since it only checks below the node.
|
||||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:giant_mushroom_cap", "fun_caves:huge_mushroom_cap"},
|
||||
interval = fun_caves.time_factor,
|
||||
interval = time_factor,
|
||||
chance = 25,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -371,14 +385,14 @@ minetest.register_abm({
|
|||
-- Destroy mushroom caps in the light.
|
||||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:giant_mushroom_cap", "fun_caves:huge_mushroom_cap"},
|
||||
interval = 2 * fun_caves.time_factor,
|
||||
interval = 2 * time_factor,
|
||||
chance = 110,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
return
|
||||
end
|
||||
|
||||
if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then
|
||||
if (minetest.get_node_light(pos, nil) or 99) >= light_max + 2 then
|
||||
minetest.remove_node(pos)
|
||||
return
|
||||
end
|
||||
|
@ -391,7 +405,7 @@ minetest.register_abm({
|
|||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:leaves"},
|
||||
interval = 10 * fun_caves.time_factor,
|
||||
interval = 10 * time_factor,
|
||||
chance = 100,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
|
@ -409,7 +423,7 @@ minetest.register_abm({
|
|||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:apple"},
|
||||
interval = fun_caves.time_factor,
|
||||
interval = time_factor,
|
||||
chance = 40,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
|
@ -425,7 +439,7 @@ minetest.register_abm({
|
|||
local ice_node = {name = 'default:ice'}
|
||||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:freezing_vapor"},
|
||||
interval = fun_caves.time_factor,
|
||||
interval = time_factor,
|
||||
chance = 10,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -440,7 +454,7 @@ local no_tree_grow = {'fun_caves:bark', 'fun_caves:leaves'}
|
|||
local wood_nodes = {{name = 'fun_caves:diamondwood'}, {name = 'fun_caves:ironwood'}, {name = 'fun_caves:sap'}, {name = 'fun_caves:tree'}}
|
||||
minetest.register_abm({
|
||||
neighbors = {'air'},
|
||||
interval = 5 * fun_caves.time_factor,
|
||||
interval = 5 * time_factor,
|
||||
chance = 900,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
|
@ -476,7 +490,7 @@ local air_list = {'air'}
|
|||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:vacuum"},
|
||||
neighbors = {"air"},
|
||||
interval = fun_caves.time_factor,
|
||||
interval = time_factor,
|
||||
chance = 10,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -509,7 +523,7 @@ minetest.register_abm({
|
|||
minetest.register_abm({
|
||||
nodenames = fungal_tree_leaves,
|
||||
neighbors = {"air", "group:liquid"},
|
||||
interval = fun_caves.time_factor,
|
||||
interval = time_factor,
|
||||
chance = 50,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
|
@ -517,7 +531,7 @@ minetest.register_abm({
|
|||
return
|
||||
end
|
||||
|
||||
if (minetest.get_node_light(pos, nil) or 99) >= fun_caves.light_max + 2 then
|
||||
if (minetest.get_node_light(pos, nil) or 99) >= light_max + 2 then
|
||||
minetest.remove_node(pos)
|
||||
return
|
||||
end
|
||||
|
@ -531,7 +545,7 @@ minetest.register_abm({
|
|||
|
||||
grow_pos = {x=math.random(-1,1)+pos.x, y=math.random(-1,1)+pos.y, z=math.random(-1,1)+pos.z}
|
||||
grow_node = minetest.get_node_or_nil(grow_pos)
|
||||
if grow_node and grow_node.name == "air" and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
|
||||
if grow_node and grow_node.name == "air" and (minetest.get_node_light(grow_pos, nil) or 99) <= light_max then
|
||||
minetest.set_node(grow_pos, node)
|
||||
return
|
||||
elseif grow_node and is_fungal_leaf[grow_node.name] and grow_node.name ~= node.name then
|
||||
|
@ -555,7 +569,7 @@ minetest.register_abm({
|
|||
local huge_mushroom_cap_node = {name = 'fun_caves:huge_mushroom_cap'}
|
||||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:giant_mushroom_stem"},
|
||||
interval = 2 * fun_caves.time_factor,
|
||||
interval = 2 * time_factor,
|
||||
chance = 75,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -568,7 +582,7 @@ minetest.register_abm({
|
|||
return
|
||||
end
|
||||
|
||||
if (minetest.get_node_light(pos_up, nil) or 99) <= fun_caves.light_max then
|
||||
if (minetest.get_node_light(pos_up, nil) or 99) <= light_max then
|
||||
minetest.set_node(pos_up, huge_mushroom_cap_node)
|
||||
end
|
||||
end
|
||||
|
@ -582,7 +596,7 @@ end
|
|||
minetest.register_abm({
|
||||
nodenames = {"default:dirt"},
|
||||
neighbors = {"air"},
|
||||
interval = 2 * fun_caves.time_factor,
|
||||
interval = 2 * time_factor,
|
||||
chance = 75,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -596,7 +610,7 @@ minetest.register_abm({
|
|||
local grow_pos = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local grow_node = minetest.get_node_or_nil(grow_pos)
|
||||
if grow_node and grow_node.name == "air"
|
||||
and (minetest.get_node_light(grow_pos, nil) or 99) <= fun_caves.light_max then
|
||||
and (minetest.get_node_light(grow_pos, nil) or 99) <= light_max then
|
||||
if math.random(4) == 1 then
|
||||
minetest.set_node(grow_pos, fungal_nodes[math.random(#fungal_nodes - 1)])
|
||||
else
|
||||
|
@ -610,7 +624,7 @@ minetest.register_abm({
|
|||
local giant_mushroom_stem_node = {name = 'fun_caves:giant_mushroom_stem'}
|
||||
minetest.register_abm({
|
||||
nodenames = mushrooms,
|
||||
interval = 5 * fun_caves.time_factor,
|
||||
interval = 5 * time_factor,
|
||||
chance = 375,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -631,7 +645,7 @@ minetest.register_abm({
|
|||
local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
|
||||
if not node_under
|
||||
or minetest.get_item_group(node_under.name, "soil") == 0
|
||||
or (minetest.get_node_light(pos_up, nil) or 99) > fun_caves.light_max then
|
||||
or (minetest.get_node_light(pos_up, nil) or 99) > light_max then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -644,7 +658,7 @@ minetest.register_abm({
|
|||
local giant_mushroom_cap_node = {name = "fun_caves:giant_mushroom_cap"}
|
||||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:huge_mushroom_cap"},
|
||||
interval = 9 * fun_caves.time_factor,
|
||||
interval = 9 * time_factor,
|
||||
chance = 1000,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -661,7 +675,7 @@ minetest.register_abm({
|
|||
local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 2, z = pos.z})
|
||||
if not node_under
|
||||
or minetest.get_item_group(node_under.name, "soil") == 0
|
||||
or (minetest.get_node_light(pos_up, nil) or 99) > fun_caves.light_max then
|
||||
or (minetest.get_node_light(pos_up, nil) or 99) > light_max then
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -673,16 +687,17 @@ minetest.register_abm({
|
|||
-- Spike spread and death
|
||||
minetest.register_abm({
|
||||
nodenames = fun_caves.hot_spikes,
|
||||
interval = 3 * fun_caves.time_factor,
|
||||
interval = 3 * time_factor,
|
||||
chance = 300,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
return
|
||||
end
|
||||
|
||||
if not fun_caves.hot_spike then
|
||||
if not (fun_caves.hot_spike and fun_caves.hot_spikes) then
|
||||
return
|
||||
end
|
||||
|
||||
local spike_num = fun_caves.hot_spike[node.name]
|
||||
if not spike_num then
|
||||
return
|
||||
|
@ -721,7 +736,7 @@ minetest.register_abm({
|
|||
minetest.register_abm({
|
||||
nodenames = {"default:dirt_with_grass", "default:dirt_with_dry_grass", 'default:dirt_with_snow'},
|
||||
neighbors = {"air", 'default:snow'},
|
||||
interval = 25 * fun_caves.time_factor,
|
||||
interval = 25 * time_factor,
|
||||
catch_up = false,
|
||||
chance = 32767,
|
||||
action = function(pos, node)
|
||||
|
@ -760,7 +775,7 @@ minetest.register_abm({
|
|||
-- Remove old craters.
|
||||
minetest.register_abm({
|
||||
nodenames = {"fun_caves:meteorite_crater"},
|
||||
interval = 3 * fun_caves.time_factor,
|
||||
interval = 3 * time_factor,
|
||||
chance = 330,
|
||||
action = function(pos, node)
|
||||
if not (pos and node) then
|
||||
|
@ -968,10 +983,10 @@ end
|
|||
-- Mushroom spread and death
|
||||
--minetest.register_abm({
|
||||
-- nodenames = mushrooms,
|
||||
-- interval = 1 * fun_caves.time_factor,
|
||||
-- interval = 1 * time_factor,
|
||||
-- chance = 50,
|
||||
-- action = function(pos, node)
|
||||
-- if minetest.get_node_light(pos, nil) >= fun_caves.light_max + 2 then
|
||||
-- if minetest.get_node_light(pos, nil) >= light_max + 2 then
|
||||
-- minetest.remove_node(pos)
|
||||
-- return
|
||||
-- end
|
||||
|
@ -992,8 +1007,8 @@ end
|
|||
--
|
||||
-- if (minetest.get_item_group(node_under.name, "soil") ~= 0 or
|
||||
-- minetest.get_item_group(node_under.name, "tree") ~= 0) and
|
||||
-- minetest.get_node_light(pos, 0.5) <= fun_caves.light_max and
|
||||
-- minetest.get_node_light(random, 0.5) <= fun_caves.light_max then
|
||||
-- minetest.get_node_light(pos, 0.5) <= light_max and
|
||||
-- minetest.get_node_light(random, 0.5) <= light_max then
|
||||
-- minetest.set_node(random, {name = node.name})
|
||||
-- end
|
||||
-- end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue