diff --git a/abms.lua b/abms.lua index b800d89..1956fd8 100644 --- a/abms.lua +++ b/abms.lua @@ -15,7 +15,6 @@ local fortress_mob_count = 5 local players_in_orbit = {} local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"} -local hunger_mod = minetest.get_modpath("hunger") -- fungal tree nodes @@ -64,10 +63,18 @@ local fortress_group = {'group:fortress'} local firework_active = false local function firework() local t = minetest.get_timeofday() + if not (t and type(t) == 'number') then + return + end + if not firework_active and (t < 0.25 or t > 0.75) then firework_active = true local ps = {} local players = minetest.get_connected_players() + if not (players and type(players) == 'table') then + return + end + for i = 1, #players do local pp = players[i]:getpos() if pp and pp.y > 0 then @@ -89,7 +96,14 @@ local function firework() end minetest.register_globalstep(function(dtime) + if not (dtime and type(dtime) == 'number') then + return + end + local time = minetest.get_gametime() + if not (time and type(time) == 'number') then + return + end -- Execute only after an interval. if last_dps_check and time - last_dps_check < dps_delay then @@ -130,6 +144,10 @@ minetest.register_globalstep(function(dtime) -- Spawn mobs in fortresses -- only when a player is near local minetest_find_nodes_in_area = minetest.find_nodes_in_area local players = minetest.get_connected_players() + if not (players and type(players) == 'table') then + return + end + local do_fortress_spawns = (fun_caves.fortress_spawns and #fun_caves.fortress_spawns > 0) for i = 1, #players do local player = players[i] @@ -153,7 +171,11 @@ minetest.register_globalstep(function(dtime) if mob_count < fortress_mob_count then local f1 = vector.subtract(pos, fortress_floor) local f2 = vector.add(pos, fortress_floor) - local floor_nodes, count = minetest.find_nodes_in_area_under_air(f1, f2, fortress_group) + local floor_nodes = minetest.find_nodes_in_area_under_air(f1, f2, fortress_group) + if not (floor_nodes and type(floor_nodes) == 'table') then + return + end + if #floor_nodes > 0 then local new_mob_pos = floor_nodes[math.random(#floor_nodes)] new_mob_pos.y = new_mob_pos.y + 2 @@ -223,12 +245,20 @@ minetest.register_globalstep(function(dtime) -- ... from standing on or near hot objects. local counts = minetest_find_nodes_in_area(minp, maxp, hot_stuff) + if not (counts and type(counts) == 'table') then + return + end + if #counts > 1 then player:set_hp(player:get_hp() - 1) end -- ... from standing on or near poison. local counts = minetest_find_nodes_in_area(minp, maxp, poison_stuff) + if not (counts and type(counts) == 'table') then + return + end + if #counts > 1 then player:set_hp(player:get_hp() - 1) end @@ -236,6 +266,10 @@ minetest.register_globalstep(function(dtime) -- ... from standing on or near cold objects (less often). if dps_count % cold_delay == 0 then counts = minetest_find_nodes_in_area(minp, maxp, cold_stuff) + if not (counts and type(counts) == 'table') then + return + end + if #counts > 1 then player:set_hp(player:get_hp() - 1) end @@ -254,6 +288,9 @@ minetest.register_globalstep(function(dtime) end last_dps_check = minetest.get_gametime() + if not (last_dps_check and type(last_dps_check) == 'number') then + last_dps_check = 0 + end dps_count = dps_count - 1 end) @@ -269,6 +306,10 @@ minetest.register_abm({ chance = 10, catch_up = false, action = function(pos, node) + if not (pos and node) then + return + end + minetest.set_node(pos, {name = "default:cobble"}) minetest.sound_play("default_cool_lava", {pos = pos, max_hear_distance = 16, gain = 0.25}) @@ -282,6 +323,10 @@ minetest.register_abm({ chance = 150, catch_up = false, action = function(pos, node) + if not (pos and node) then + return + end + fun_caves.soft_boom(pos) end }) @@ -294,6 +339,10 @@ minetest.register_abm({ chance = 50, catch_up = false, action = function(pos, node) + if not (pos and node) then + return + end + fun_caves.soft_boom(pos) end }) @@ -306,6 +355,10 @@ minetest.register_abm({ interval = fun_caves.time_factor, chance = 25, action = function(pos, node) + if not (pos and node) then + return + end + -- Check for stem under the cap. local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z}) if not node_under or node_under.name ~= "fun_caves:giant_mushroom_stem" then @@ -321,6 +374,10 @@ minetest.register_abm({ interval = 2 * fun_caves.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 minetest.remove_node(pos) return @@ -338,6 +395,10 @@ minetest.register_abm({ chance = 100, catch_up = false, action = function(pos, node) + if not (pos and node) then + return + end + pos.y = pos.y - 1 local node_below = minetest.get_node_or_nil(pos) if node_below and node_below.name == 'air' then @@ -352,6 +413,10 @@ minetest.register_abm({ chance = 40, catch_up = false, action = function(pos, node) + if not (pos and node) then + return + end + minetest.remove_node(pos) end }) @@ -363,29 +428,14 @@ minetest.register_abm({ interval = fun_caves.time_factor, chance = 10, action = function(pos, node) + if not (pos and node) then + return + end + minetest.set_node(pos, ice_node) end }) -if false then -minetest.register_abm({ - nodenames = {"fun_caves:pyramid_1"}, - interval = 1, - chance = 1, - action = function(pos, node) - local p = table.copy(pos) - for i = 1, 20 do - p.y = p.y + 1 - local node = minetest.get_node_or_nil(p) - if not node or node.name ~= 'air' then - return - end - end - minetest.set_node(pos, {name = 'default:sandstone'}) - end -}) -end - 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({ @@ -394,6 +444,10 @@ minetest.register_abm({ chance = 900, catch_up = false, action = function(pos, node) + if not (pos and node) then + return + end + local new_pos = minetest.find_node_near(pos, 1, no_tree_grow) if new_pos then return @@ -425,6 +479,10 @@ minetest.register_abm({ interval = fun_caves.time_factor, chance = 10, action = function(pos, node) + if not (pos and node) then + return + end + if pos.y <= 11168 or pos.y >= 15168 then return end @@ -432,6 +490,10 @@ minetest.register_abm({ local p1 = vector.subtract(pos, 1) local p2 = vector.add(pos, 1) local positions = minetest.find_nodes_in_area(p1, p2, air_list) + if not (positions and type(positions) == 'table') then + return + end + local minetest_get_node_or_nil = minetest.get_node_or_nil local minetest_set_node = minetest.set_node for _, p3 in pairs(positions) do @@ -451,6 +513,10 @@ minetest.register_abm({ chance = 50, catch_up = false, 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 minetest.remove_node(pos) return @@ -492,6 +558,10 @@ minetest.register_abm({ interval = 2 * fun_caves.time_factor, chance = 75, action = function(pos, node) + if not (pos and node) then + return + end + local pos_up = {x=pos.x,y=pos.y+1,z=pos.z} local node_up = minetest.get_node_or_nil(pos_up) if not node_up or node_up.name ~= "air" then @@ -515,6 +585,10 @@ minetest.register_abm({ interval = 2 * fun_caves.time_factor, chance = 75, action = function(pos, node) + if not (pos and node) then + return + end + if pos.y > 0 then return end @@ -539,6 +613,10 @@ minetest.register_abm({ interval = 5 * fun_caves.time_factor, chance = 375, action = function(pos, node) + if not (pos and node) then + return + end + -- Clumsy, but it's the best way to limit them to caves. if pos.y > 0 then return @@ -569,6 +647,10 @@ minetest.register_abm({ interval = 9 * fun_caves.time_factor, chance = 1000, action = function(pos, node) + if not (pos and node) then + return + end + local pos_up = {x=pos.x,y=pos.y+1,z=pos.z} local node_up = minetest.get_node_or_nil(pos_up) if not node_up or node_up.name ~= "air" then @@ -594,6 +676,10 @@ minetest.register_abm({ interval = 3 * fun_caves.time_factor, chance = 300, action = function(pos, node) + if not (pos and node) then + return + end + if not fun_caves.hot_spike then return end @@ -639,8 +725,16 @@ minetest.register_abm({ catch_up = false, chance = 32767, action = function(pos, node) + if not (pos and node) then + return + end + local ps = {} local players = minetest.get_connected_players() + if not (players and type(players) == 'table') then + return + end + for i = 1, #players do local pp = players[i]:getpos() local pd = vector.subtract(pp, pos) @@ -669,6 +763,10 @@ minetest.register_abm({ interval = 3 * fun_caves.time_factor, chance = 330, action = function(pos, node) + if not (pos and node) then + return + end + minetest.set_node(pos, {name="default:dirt"}) end }) @@ -706,6 +804,10 @@ minetest.after(0, function() end) local function add_effects(pos, radius) + if not (pos and radius and type(radius) == 'number') then + return + end + minetest.add_particlespawner({ amount = 128, time = 1, @@ -724,6 +826,10 @@ local function add_effects(pos, radius) end local function destroy(pos, cid) + if not (pos and cid) then + return + end + local def = cid_data[cid] if not def or minetest.is_protected(pos, "") then return @@ -744,6 +850,10 @@ local function destroy(pos, cid) end local function explode(pos, radius) + if not (pos and radius and type(radius) == 'number') then + return + end + local pos = vector.round(pos) local vm = VoxelManip() local p1 = vector.subtract(pos, radius) @@ -778,6 +888,10 @@ local function explode(pos, radius) end local function calc_velocity(pos1, pos2, old_vel, power) + if not (pos1 and pos2 and old_vel and power) then + return + end + local vel = vector.direction(pos1, pos2) vel = vector.normalize(vel) vel = vector.multiply(vel, power) @@ -793,9 +907,17 @@ local function calc_velocity(pos1, pos2, old_vel, power) end local function entity_physics(pos, radius) + if not (pos and radius and type(radius) == 'number') then + return + end + -- Make the damage radius larger than the destruction radius radius = radius * 2 local objs = minetest.get_objects_inside_radius(pos, radius) + if not (objs and type(objs) == 'table') then + return + end + local math_max = math.max local vector_distance = vector.distance for _, obj in pairs(objs) do diff --git a/init.lua b/init.lua index fac24e0..e42f3db 100644 --- a/init.lua +++ b/init.lua @@ -227,11 +227,15 @@ function fun_caves.hunger_change(player, change) end local hp = player:get_hp() + if not (hp and type(hp) == 'number') then + return + end + if change < 0 or hp >= 16 then fun_caves.db.hunger[player_name] = math.min(20, math.max(0, fun_caves.db.hunger[player_name] + change)) player:hud_change(fun_caves.hunger_id[player_name], 'number', fun_caves.db.hunger[player_name]) if fun_caves.db.hunger[player_name] == 0 then - player:set_hp(player:get_hp() - 1) + player:set_hp(hp - 1) end end end