summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTenPlus1 <kinsellaja@yahoo.com>2018-01-04 11:13:08 +0000
committerTenPlus1 <kinsellaja@yahoo.com>2018-01-04 11:13:08 +0000
commit0f480942b52f8c96dc7e9f34e442715e2e59d7c2 (patch)
tree64694a69193e504fc5e0699efabb8adadcc9ff59
parent07bb12acac8df1c294714d89f55d46eb55f076d1 (diff)
check height clearance before spawning mob
-rw-r--r--api.lua44
1 files changed, 20 insertions, 24 deletions
diff --git a/api.lua b/api.lua
index ca75f9f..50ff795 100644
--- a/api.lua
+++ b/api.lua
@@ -2862,7 +2862,8 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
action = function(pos, node, active_object_count, active_object_count_wider)
-- is mob actually registered?
- if not mobs.spawning_mobs[name] then
+ if not mobs.spawning_mobs[name]
+ or not minetest.registered_entities[name] then
--print ("--- mob doesn't exist", name)
return
end
@@ -2931,39 +2932,34 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
return
end
- -- are we spawning inside solid nodes?
- if minetest.registered_nodes[node_ok(pos).name].walkable == true then
---print ("--- feet in block", name, node_ok(pos).name)
- return
- 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)
- pos.y = pos.y + 1
+ for n = 0, height do
- if minetest.registered_nodes[node_ok(pos).name].walkable == true then
---print ("--- head in block", name, node_ok(pos).name)
- return
+ local pos2 = {x = pos.x, y = pos.y + n, z = pos.z}
+
+ if minetest.registered_nodes[node_ok(pos2).name].walkable == true then
+--print ("--- inside block", name, node_ok(pos2).name)
+ return
+ end
end
-- spawn mob half block higher than ground
- pos.y = pos.y - 0.5
-
- if minetest.registered_entities[name] then
+ pos.y = pos.y + 0.5
- local mob = minetest.add_entity(pos, name)
+ local mob = minetest.add_entity(pos, name)
--[[
- print ("[mobs] Spawned " .. name .. " at "
- .. minetest.pos_to_string(pos) .. " on "
- .. node.name .. " near " .. neighbors[1])
+ print ("[mobs] Spawned " .. name .. " at "
+ .. minetest.pos_to_string(pos) .. " on "
+ .. node.name .. " near " .. neighbors[1])
]]
- if on_spawn then
+ if on_spawn then
- local ent = mob:get_luaentity()
+ local ent = mob:get_luaentity()
- on_spawn(ent, pos)
- end
- else
- minetest.log("warning", string.format("[mobs] %s failed to spawn at %s",
- name, minetest.pos_to_string(pos)))
+ on_spawn(ent, pos)
end
end
})