From 9b1ceebf0d3db46d8f3f40f478e9af121cf2decd Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Wed, 7 Dec 2022 23:38:44 +0000 Subject: [PATCH] Villagers will now pathfind to town bell that isn't on the ground --- mods/ENTITIES/mcl_mobs/pathfinding.lua | 7 ++++--- mods/ENTITIES/mobs_mc/villager.lua | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/pathfinding.lua b/mods/ENTITIES/mcl_mobs/pathfinding.lua index 6cb37434f..04138bed0 100644 --- a/mods/ENTITIES/mcl_mobs/pathfinding.lua +++ b/mods/ENTITIES/mcl_mobs/pathfinding.lua @@ -35,19 +35,20 @@ function append_paths (wp1, wp2) end local function output_enriched (wp_out) - mcl_log("Output enriched path") + --mcl_log("Output enriched path") local i = 0 for _,outy in pairs (wp_out) do i = i + 1 - mcl_log("Pos ".. i ..":" .. minetest.pos_to_string(outy["pos"])) + --mcl_log("Pos ".. i ..":" .. minetest.pos_to_string(outy["pos"])) local action = outy["action"] if action then + mcl_log("Pos ".. i ..":" .. minetest.pos_to_string(outy["pos"])) mcl_log("type: " .. action["type"]) mcl_log("action: " .. action["action"]) mcl_log("target: " .. minetest.pos_to_string(action["target"])) end - mcl_log("failed attempts: " .. outy["failed_attempts"]) + --mcl_log("failed attempts: " .. outy["failed_attempts"]) end end diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 9215416b8..b1f73247c 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -1190,6 +1190,19 @@ local function do_work (self) end end +local below_vec = vector.new(0, -1, 0) + +local function get_ground_below_floating_object (float_pos) + local pos = float_pos + repeat + mcl_log("Current pos: " .. minetest.pos_to_string(pos)) + pos = vector.add(pos, below_vec) + local node = minetest.get_node(pos) + mcl_log("First non air materials: ".. tostring(node.name)) + until node.name ~= "air" + return pos +end + local function go_to_town_bell(self) if self.order == GATHERING then mcl_log("Already gathering") @@ -1208,8 +1221,9 @@ local function go_to_town_bell(self) --Ideally should check for closest available. It'll make pathing easier. for _,n in pairs(nn) do mcl_log("Found bell") - - local gp = self:gopath(n,function(self) + local target_point = get_ground_below_floating_object(n) + + local gp = self:gopath(target_point,function(self) if self then self.order = GATHERING mcl_log("Callback has a self")