| | |
| | | -- if this is disabled. |
| | | local xnotreetap_leaves = true |
| | | |
| | | -- First value is node name; second is whether the node is considered even if chainsaw_leaves is false. |
| | | -- First value is node name; second is whether the node is considered even if xnotreetap_leaves is false. |
| | | local nodes = { |
| | | -- Rubber trees from moretrees or technic_worldgen if moretrees isn't installed |
| | | {"moretrees:rubber_tree_trunk_empty", true}, |
| | |
| | | {"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 |
| | | if chainsaw_leaves or node[2] then |
| | | if xnotreetap_leaves or node[2] then |
| | | timber_nodenames[node[1]] = true |
| | | end |
| | | end |
| | |
| | | |
| | | -- 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 |
| | | |
| | |
| | | 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. |
| | |
| | | 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(minetest.get_node_drops("technic:raw_latex", "")) |
| | | remaining_charge = remaining_charge - xnotreetap_charge_per_node |
| | | |
| | | -- Wood found - cut it |
| | |
| | | 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 |
| | |
| | | inventory_image = "technic_tree_tap.png", |
| | | |
| | | stack_max = 1, |
| | | |
| | | |
| | | wear_represents = "technic_RE_charge", |
| | | on_refill = technic.refill_RE_charge, |
| | | |
| | |
| | | if node_name ~= "moretrees:rubber_tree_trunk" then |
| | | return |
| | | end |
| | | |
| | | --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) |
| | | -- |
| | | -- 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 |
| | | -- return itemstack |
| | | |
| | | -- Send current charge to digging function so that the |
| | | -- chainsaw will stop after digging a number of nodes |
| | |
| | | -- end |
| | | -- end |
| | | --}) |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |