Actions: Fix bug and add support for using access node.

This commit is contained in:
Hector Franqui 2017-09-01 14:13:13 -04:00
parent ba6348663b
commit 40ac2a55a1

View File

@ -504,7 +504,7 @@ end
-- walking from one place to another, operating a furnace, storing or taking
-- items from a chest, are provided here.
local function get_pos_argument(self, pos)
local function get_pos_argument(self, pos, use_access_node)
--minetest.log("Type of pos: "..dump(type(pos)))
-- Check which type of position argument we received
if type(pos) == "table" then
@ -543,15 +543,23 @@ local function get_pos_argument(self, pos)
-- Check all places, return owned if existent, else return the first one
for i = 1, #places_pos do
if places_pos[i].status == "owned" then
if use_access_node then
return places_pos[i].access_node
else
return places_pos[i].pos
end
end
end
end
-- Return the first position only if it couldn't find an owned
-- place, or if it there is only oneg
-- place, or if it there is only one
if use_access_node then
return places_pos[1].access_node
else
return places_pos[1].pos
end
end
end
-- This function allows a NPC to use a furnace using only items from
-- its own inventory. Fuel is not provided. Once the furnace is finished
@ -830,7 +838,7 @@ end
-- path.
function npc.actions.walk_to_pos(self, args)
-- Get arguments for this task
local end_pos = get_pos_argument(self, args.end_pos)
local end_pos = get_pos_argument(self, args.end_pos, args.use_access_node)
if end_pos == nil then
npc.log("WARNING", "Got nil position in 'walk_to_pos' using args.pos: "..dump(args.end_pos))
return