1
0
Fork 0

pathfinding: find doors close to target as well

mobs_head_rotation
cora 2022-05-19 14:45:12 +02:00
parent 9ccbf91706
commit 67939f7b7a
2 changed files with 23 additions and 6 deletions

View File

@ -2920,11 +2920,30 @@ local do_states = function(self, dtime)
end end
end end
local plane_adjacents = {
vector.new(1,0,0),
vector.new(-1,0,0),
vector.new(0,0,1),
vector.new(0,0,-1),
}
function mobs:gopath(self,target,callback_arrived) function mobs:gopath(self,target,callback_arrived)
local p = self.object:get_pos() local p = self.object:get_pos()
local t = vector.offset(target,0,1,0) local t = vector.offset(target,0,1,0)
if not target or not p then return end
local wp = minetest.find_path(p,t,150,1,4) local wp = minetest.find_path(p,t,150,1,4)
if not wp then
local d = minetest.find_node_near(target,16,{"group:door"})
if d then
for _,v in pairs(plane_adjacents) do
local pos = vector.add(d,v)
local n = minetest.get_node(pos)
if n.name == "air" then
wp = minetest.find_path(p,pos,150,1,4)
if wp then break end
end
end
end
end
if wp and #wp > 0 then if wp and #wp > 0 then
self._target = t self._target = t
self.callback_arrived = callback_arrived self.callback_arrived = callback_arrived

View File

@ -617,12 +617,10 @@ local function look_for_job(self)
local m=minetest.get_meta(n) local m=minetest.get_meta(n)
if m:get_string("villager") == "" then if m:get_string("villager") == "" then
--minetest.log("goingt to jobsite "..minetest.pos_to_string(n) ) --minetest.log("goingt to jobsite "..minetest.pos_to_string(n) )
minetest.after(0,function() local gp = mobs:gopath(self,n,function()
mobs:gopath(self,n,function() --minetest.log("arrived jobsite "..minetest.pos_to_string(n) )
--minetest.log("arrived jobsite "..minetest.pos_to_string(n) )
end)
end) end)
return if gp then return end
end end
end end
end end