From ad137304bce58faca628b280f98751be294ba0fa Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Thu, 3 Nov 2022 01:00:48 +0000 Subject: [PATCH] Fix bug where if it finds wrong door and can't plot route it hogs the pathing --- mods/ENTITIES/mcl_mobs/api.lua | 3 +++ mods/ENTITIES/mobs_mc/villager.lua | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 4687a6b0b..96381dde6 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -3409,6 +3409,7 @@ local function calculate_path_through_door (p, t, target) if not wp then mcl_log("No direct path. Path through door") + -- This could improve. There could be multiple doors. Check you can path from door to target first. local cur_door_pos = minetest.find_node_near(target,16,{"group:door"}) if cur_door_pos then mcl_log("Found a door near: " .. minetest.pos_to_string(cur_door_pos)) @@ -3479,6 +3480,8 @@ function mcl_mobs:gopath(self,target,callback_arrived) local wp = calculate_path_through_door(p, t, target) if not wp then mcl_log("Could not calculate path") + self._pf_last_failed = os.time() + -- Cover for a flaw in pathfind where it chooses the wrong door and gets stuck. Take a break, allow others. end --output_table(wp) diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 36c44856b..4bf174c35 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -609,9 +609,10 @@ local function find_closest_unclaimed_block (p, requested_block_types) for i,n in pairs(nn) do local m = minetest.get_meta(n) - mcl_log("Block: " .. minetest.pos_to_string(n).. ", owner: ".. m:get_string("villager")) if m:get_string("villager") == "" then + mcl_log("Block: " .. minetest.pos_to_string(n).. ", owner: ".. m:get_string("villager")) + local distance_to_block = vector.distance(p, n) mcl_log("Distance to block ".. i .. ": ".. distance_to_block)