re-organise spawning checks (lightest first)

This commit is contained in:
TenPlus1 2018-06-04 16:51:11 +01:00
parent c23d58f1ec
commit 4a5563854d

38
api.lua
View File

@ -3,7 +3,7 @@
mobs = {}
mobs.mod = "redo"
mobs.version = "20180603"
mobs.version = "20180604"
-- Intllib
@ -3254,24 +3254,6 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
-- spawn above node
pos.y = pos.y + 1
-- only spawn away from player
local objs = minetest.get_objects_inside_radius(pos, 10)
for n = 1, #objs do
if objs[n]:is_player() then
--print ("--- player too close", name)
return
end
end
-- mobs cannot spawn in protected areas when enabled
if not spawn_protected
and minetest.is_protected(pos, "") then
--print ("--- inside protected area", name)
return
end
-- are we spawning within height limits?
if pos.y > max_height
or pos.y < min_height then
@ -3288,6 +3270,24 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
return
end
-- mobs cannot spawn in protected areas when enabled
if not spawn_protected
and minetest.is_protected(pos, "") then
--print ("--- inside protected area", name)
return
end
-- only spawn away from player
local objs = minetest.get_objects_inside_radius(pos, 10)
for n = 1, #objs do
if objs[n]:is_player() then
--print ("--- player too close", name)
return
end
end
-- do we have enough height clearance to spawn mob?
local ent = minetest.registered_entities[name]
local height = max(0, math.ceil(ent.collisionbox[5] - ent.collisionbox[2]) - 1)