From 4c99358b32bf4dedc75c0ecae2e1a0770c64fd4b Mon Sep 17 00:00:00 2001 From: Cristiano Magro <cristiano.magro@vola.it> Date: Tue, 13 Oct 2020 19:43:06 +0200 Subject: [PATCH] try to sign visited node --- technic/tools/xno_tree_tap.lua | 83 ++++++++++++++++++++++++++++++++--------- 1 files changed, 65 insertions(+), 18 deletions(-) diff --git a/technic/tools/xno_tree_tap.lua b/technic/tools/xno_tree_tap.lua index 4dd5341..d030399 100644 --- a/technic/tools/xno_tree_tap.lua +++ b/technic/tools/xno_tree_tap.lua @@ -15,6 +15,8 @@ {"moretrees:rubber_tree_leaves", false}, } +-- Remember node visited recursive and not dig twice +local node_visited = {} local timber_nodenames = {} for _, node in pairs(nodes) do @@ -33,10 +35,14 @@ -- This function checks if the specified node should be sawed local function check_if_node_sawed(pos) - local node_name = minetest.get_node(pos).name + local node = minetest.get_node(pos) + local node_name = node.name + + if timber_nodenames[node_name] or (xnotreetap_leaves and minetest.get_item_group(node_name, "leaves") ~= 0) or minetest.get_item_group(node_name, "tree") ~= 0 then + minetest.log("action", "[Xno Tree Tap] "..node_name.." good node to collect.") --print to log return true end @@ -111,8 +117,47 @@ end end +-- inserisco un valore in tabella +local function add_table(table, toadd) + local i = 1 + while true do + local o = table[i] + if o == toadd then return end + if o == nil then break end + i = i + 1 + end + table[i] = toadd +end +-- bool controllo se un valore � presente in tabella +local function in_table(table, value) + local i = 1 + while true do + local o = table[i] + if o == value then + minetest.log("action", "[Xno Tree Tap] "..value.." visited.") --print to log + return true + end + if o == nil then break end + i = i + 1 + end + return false +end +-- verifico se un nodo � nella tabella visitato +local function check_if_node_visited (pos) + return in_table(node_visited, pos) +end + +local function myString (v) + return v.x.." "..v.y.." "..v.z.." " +end + +local function set_node_visited (pos) + minetest.log("action", "[Xno Tree Tap] "..myString(pos).." set node visited.") --print to log + + add_table(node_visited, pos) +end -- This function does all the hard work. Recursively we dig the node at hand -- if it is in the table and then search the surroundings for more stuff to dig. @@ -120,19 +165,22 @@ if remaining_charge < xnotreetap_charge_per_node then return remaining_charge end - local node = minetest.get_node(pos) + + if check_if_node_visited(pos) then + return remaining_charge + end if not check_if_node_sawed(pos) then return remaining_charge end + local node = minetest.get_node(pos) if node.name == "moretrees:rubber_tree_trunk" then --raccolta gomma node.name = "moretrees:rubber_tree_trunk_empty" minetest.swap_node(pos, node) --- minetest.handle_node_drops(pointed_thing.above, {"technic:raw_latex"}, user) - handle_drops({"technic:raw_latex"}) + handle_drops(minetest.get_node_drops("technic:raw_latex", "")) remaining_charge = remaining_charge - xnotreetap_charge_per_node -- Wood found - cut it @@ -140,16 +188,18 @@ minetest.remove_node(pos) remaining_charge = remaining_charge - xnotreetap_charge_per_node --- if not technic.creative_mode then --- local item_wear = tonumber(itemstack:get_wear()) --- item_wear = item_wear + 819 --- if item_wear > 65535 then --- itemstack:clear() --- return itemstack --- end --- itemstack:set_wear(item_wear) --- end + -- if not technic.creative_mode then + -- local item_wear = tonumber(itemstack:get_wear()) + -- item_wear = item_wear + 819 + -- if item_wear > 65535 then + -- itemstack:clear() + -- return itemstack + -- end + -- itemstack:set_wear(item_wear) + -- end end + + set_node_visited(pos) -- Check surroundings and run recursively if any charge left for npos in iterSawTries(pos) do @@ -230,7 +280,7 @@ inventory_image = "technic_tree_tap.png", stack_max = 1, - + wear_represents = "technic_RE_charge", on_refill = technic.refill_RE_charge, @@ -260,7 +310,7 @@ if node_name ~= "moretrees:rubber_tree_trunk" then return end - + -- Send current charge to digging function so that the -- chainsaw will stop after digging a number of nodes meta.charge = xnotreetap_dig(pointed_thing.under, meta.charge) @@ -294,9 +344,6 @@ -- end -- end --}) - - - -- Gitblit v1.8.0