From 67939f7b7a57d0cf2eca92c31b48ed187d16a933 Mon Sep 17 00:00:00 2001 From: cora Date: Thu, 19 May 2022 14:45:12 +0200 Subject: [PATCH] pathfinding: find doors close to target as well --- mods/ENTITIES/mcl_mobs/api.lua | 21 ++++++++++++++++++++- mods/ENTITIES/mobs_mc/villager.lua | 8 +++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index e5e3063a2..3fb2bcc9e 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2920,11 +2920,30 @@ local do_states = function(self, dtime) 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) local p = self.object:get_pos() 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) + 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 self._target = t self.callback_arrived = callback_arrived diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 07126db97..0e3236a84 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -617,12 +617,10 @@ local function look_for_job(self) local m=minetest.get_meta(n) if m:get_string("villager") == "" then --minetest.log("goingt to jobsite "..minetest.pos_to_string(n) ) - minetest.after(0,function() - mobs:gopath(self,n,function() - --minetest.log("arrived jobsite "..minetest.pos_to_string(n) ) - end) + local gp = mobs:gopath(self,n,function() + --minetest.log("arrived jobsite "..minetest.pos_to_string(n) ) end) - return + if gp then return end end end end