Skip to content

Commit

Permalink
fixed theFox6#24 mobs:fence pathfinding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jichi authored and jichi committed Dec 3, 2023
1 parent a70f791 commit 4886613
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion working_villagers/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ function working_villages.villager:handle_obstacles(ignore_fence,ignore_doors)
local front_node = minetest.get_node(front_pos)
above_node = vector.add(above_node,{x=0,y=1,z=0})
above_node = minetest.get_node(above_node)
if minetest.get_item_group(front_node.name, "fence") > 0 and not(ignore_fence) then
if --string.find(front_node.name, "mobs:fence") or -- #42
(minetest.get_item_group(front_node.name, "fence") > 0 and not(ignore_fence)) then
self:change_direction_randomly()
elseif string.find(front_node.name,"doors:door") and not(ignore_doors) then
local door = doors.get(front_pos)
Expand All @@ -562,6 +563,7 @@ function working_villages.villager:handle_obstacles(ignore_fence,ignore_doors)
door:open()
end
end
-- TODO trap doors & ladders
elseif walkable(front_node) --minetest.registered_nodes[front_node.name].walkable
and not(walkable(above_node)) then --not(minetest.registered_nodes[above_node.name].walkable) then
if velocity.y == 0 then
Expand Down
2 changes: 1 addition & 1 deletion working_villagers/jobs/hider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function hider.walk_in_direction(v,dir)
v:set_yaw_by_direction(dir)

--if villager is stoped by obstacle, the villager must jump.
v:handle_obstacles(true)
v:handle_obstacles(true,true)
end

function get_keys(t)
Expand Down
2 changes: 1 addition & 1 deletion working_villagers/jobs/thief.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ working_villages.register_job("working_villages:job_thief", {
--self:handle_job_pos()
self:count_timer("thief:search")
self:count_timer("thief:change_dir")
self:handle_obstacles()
--self:handle_obstacles()
if self:timer_exceeded("thief:search",20) then
thief.step(self)
elseif self:timer_exceeded("thief:change_dir",50) then
Expand Down
7 changes: 6 additions & 1 deletion working_villagers/pathfinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ local function get_distance_to_neighbor(start_pos, end_pos)
end
end
local function walkable(node)
if string.find(node.name,"doors:") then
if string.find(node.name,"doors:")
--or string.find(node.name, "mobs:fence") -- #42
then
return false
else
if minetest.registered_nodes[node.name]~= nil then
Expand Down Expand Up @@ -75,6 +77,9 @@ assert(check_clearance)
local function get_neighbor_ground_level(pos, jump_height, fall_height)
local node = minetest.get_node(pos)
local height = 0
if string.find(node.name, "mobs:fence") then -- #42
return nil
end
if walkable(node) then
repeat
height = height + 1
Expand Down

0 comments on commit 4886613

Please sign in to comment.