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 = {}
mobs.mod = "redo" mobs.mod = "redo"
mobs.version = "20180603" mobs.version = "20180604"
-- Intllib -- Intllib
@ -3254,24 +3254,6 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
-- spawn above node -- spawn above node
pos.y = pos.y + 1 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? -- are we spawning within height limits?
if pos.y > max_height if pos.y > max_height
or pos.y < min_height then or pos.y < min_height then
@ -3288,6 +3270,24 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
return 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
-- 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? -- do we have enough height clearance to spawn mob?
local ent = minetest.registered_entities[name] local ent = minetest.registered_entities[name]
local height = max(0, math.ceil(ent.collisionbox[5] - ent.collisionbox[2]) - 1) local height = max(0, math.ceil(ent.collisionbox[5] - ent.collisionbox[2]) - 1)