From a3c71daaf102e615e963284b18f73bd58c5a55fe Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 7 Apr 2024 11:48:34 +0200 Subject: [PATCH] Villager: Fix unstuck behavior for slabs and paths --- mods/rp_mobs_mobs/mobs/villager.lua | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/mods/rp_mobs_mobs/mobs/villager.lua b/mods/rp_mobs_mobs/mobs/villager.lua index f65ffca1..48ad22b3 100644 --- a/mods/rp_mobs_mobs/mobs/villager.lua +++ b/mods/rp_mobs_mobs/mobs/villager.lua @@ -122,6 +122,27 @@ local is_node_blocking_water_ok = function(node) end end +-- Check if node makes villager stuck if inside +local is_node_stucking = function(node) + local def = minetest.registered_nodes[node.name] + if not def then + -- Unknown nodes are blocking + return true + elseif minetest.get_item_group(node.name, "door") ~= 0 + or minetest.get_item_group(node.name, "slab") ~= 0 + or minetest.get_item_group(node.name, "path") ~= 0 then + return false + elseif def.damage_per_second > 0 then + -- No damage allowed + return true + elseif def.walkable then + -- Walkable by definition = blocking + return true + else + return false + end +end + -- Returns true if node is swimmable local is_node_swimmable = function(node) local def = minetest.registered_nodes[node.name] @@ -1031,9 +1052,9 @@ local movement_decider_step = function(task_queue, mob, dtime) local mnode2 = minetest.get_node(rmobpos2) -- Test if mob is stuck; unstuck it if that's the case - if is_node_blocking_water_ok(mnode) or is_node_blocking_water_ok(mnode2) then + if is_node_stucking(mnode) or is_node_stucking(mnode2) then local current_task_entry = task_queue.tasks:getFirst() - if current_task_entry and current_task_entry.data and current_task_entry.data.label == "get unstuck" then + if current_task_entry and current_task_entry.data and current_task_entry.data.label ~= "stand still" then return end rp_mobs.clear_task_queue(task_queue)