forked from mtcontrib/mobs_redo
added auto range checking for mob counting
This commit is contained in:
parent
0a6fdbc3f1
commit
29b0f9d351
26
api.lua
26
api.lua
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
-- Mobs Api (2nd December 2016)
|
-- Mobs Api (6th December 2016)
|
||||||
|
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
|
@ -41,6 +41,11 @@ local spawn_protected = tonumber(minetest.setting_get("mobs_spawn_protected")) o
|
||||||
local remove_far = minetest.setting_getbool("remove_far_mobs")
|
local remove_far = minetest.setting_getbool("remove_far_mobs")
|
||||||
local difficulty = tonumber(minetest.setting_get("mob_difficulty")) or 1.0
|
local difficulty = tonumber(minetest.setting_get("mob_difficulty")) or 1.0
|
||||||
|
|
||||||
|
-- calculate aoc range for mob counts
|
||||||
|
local aosrb = tonumber(minetest.setting_get("active_object_send_range_blocks"))
|
||||||
|
local abr = tonumber(minetest.setting_get("active_block_range"))
|
||||||
|
local aoc_range = math.max(aosrb, abr) * 16
|
||||||
|
|
||||||
-- pathfinding settings
|
-- pathfinding settings
|
||||||
local enable_pathfinding = true
|
local enable_pathfinding = true
|
||||||
local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching
|
local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching
|
||||||
|
@ -2461,7 +2466,7 @@ end -- END mobs:register_mob function
|
||||||
local count_mobs = function(pos, type)
|
local count_mobs = function(pos, type)
|
||||||
|
|
||||||
local num = 0
|
local num = 0
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 32)
|
local objs = minetest.get_objects_inside_radius(pos, aoc_range)
|
||||||
|
|
||||||
for n = 1, #objs do
|
for n = 1, #objs do
|
||||||
|
|
||||||
|
@ -2469,7 +2474,8 @@ local count_mobs = function(pos, type)
|
||||||
|
|
||||||
local obj = objs[n]:get_luaentity()
|
local obj = objs[n]:get_luaentity()
|
||||||
|
|
||||||
if obj and obj.name and obj.name == type then
|
if obj and obj.name and obj.name == type then -- mob type count
|
||||||
|
--if obj and obj.name and obj.health ~= nil then -- all mob count
|
||||||
num = num + 1
|
num = num + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2566,6 +2572,13 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- are we spawning within height limits?
|
||||||
|
if pos.y > max_height
|
||||||
|
or pos.y < min_height then
|
||||||
|
--print ("--- height limits not met", name, pos.y)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- are light levels ok?
|
-- are light levels ok?
|
||||||
local light = minetest.get_node_light(pos)
|
local light = minetest.get_node_light(pos)
|
||||||
if not light
|
if not light
|
||||||
|
@ -2575,13 +2588,6 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- are we spawning within height limits?
|
|
||||||
if pos.y > max_height
|
|
||||||
or pos.y < min_height then
|
|
||||||
--print ("--- height limits not met", name, pos.y)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- are we spawning inside solid nodes?
|
-- are we spawning inside solid nodes?
|
||||||
if minetest.registered_nodes[node_ok(pos).name].walkable == true then
|
if minetest.registered_nodes[node_ok(pos).name].walkable == true then
|
||||||
--print ("--- feet in block", name, node_ok(pos).name)
|
--print ("--- feet in block", name, node_ok(pos).name)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user