From c189a33eec2e9a22c0101c07e4177619c6b6240c Mon Sep 17 00:00:00 2001 From: Cristiano Magro <cristiano.magro@vola.it> Date: Mon, 19 Oct 2020 22:28:10 +0200 Subject: [PATCH] Super Xno Pick --- technic/textures/xno_superpick.png | 0 technic/tools/init.lua | 1 technic/tools/xno_pick.lua | 367 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 368 insertions(+), 0 deletions(-) diff --git a/technic/textures/xno_superpick.png b/technic/textures/xno_superpick.png new file mode 100644 index 0000000..a32aa1f --- /dev/null +++ b/technic/textures/xno_superpick.png Binary files differ diff --git a/technic/tools/init.lua b/technic/tools/init.lua index c4a8c36..8023a37 100644 --- a/technic/tools/init.lua +++ b/technic/tools/init.lua @@ -13,6 +13,7 @@ dofile(path.."/chainsaw.lua") dofile(path.."/tree_tap.lua") dofile(path.."/xno_tree_tap.lua") +dofile(path.."/xno_pick.lua") dofile(path.."/sonic_screwdriver.lua") dofile(path.."/prospector.lua") dofile(path.."/vacuum.lua") diff --git a/technic/tools/xno_pick.lua b/technic/tools/xno_pick.lua new file mode 100644 index 0000000..f5bbba3 --- /dev/null +++ b/technic/tools/xno_pick.lua @@ -0,0 +1,367 @@ +-- Configuration + +local xnopick_max_charge = 30000 -- Maximum charge of the saw +-- Gives 2500 nodes on a single charge +local xnopick_charge_per_node = 12 +-- Dig node cost + + +local S = technic.getter + +technic.register_power_tool("technic:xnopick", xnopick_max_charge) + +local mesecons_materials = minetest.get_modpath("mesecons_materials") + +-- This function checks if the specified node should be dig +local function check_if_node_picked(pos) + local node = minetest.get_node(pos) + local node_name = node.name + + if node_name:match("default:.*_with_.*") or + node_name:match("default:coalblock") or + node_name:match("technic:mineral_.*") or + node_name:match("xtraores:.*_ore") or + node_name:match("underch:.*_ore") or + node_name:match("underch:coal_dust") or + node_name:match("underch:coal_diamond") or + node_name:match("moreores:mineral_.*") or + node_name:match(".*coal_dense_ore") + then + minetest.log("action", "[Xno Pick Magic] "..node_name.." good node to collect.") --print to log + return true + end + + return false +end + +local function collect_node(user, pos, current_charge) + if current_charge < xnopick_charge_per_node then + return current_charge + end + + local node_name = minetest.get_node(pos).name + local droped = minetest.get_node_drops(node_name) + for _, nameDroped in pairs(droped) do + --add node back into placer's inv + user:get_inventory():add_item("main", nameDroped .. ' 1') + end + + minetest.remove_node(pos) + local remain_charge = current_charge - xnopick_charge_per_node + + return remain_charge +end + +local function collect_block_node(user, pos, current_charge) + local radius = 4 + local dropPos = {} + local remain_charge = current_charge + for z = -radius, radius do + dropPos.z = pos.z + z + for y = -radius, radius do + dropPos.y = pos.y + y + for x = -radius, radius do + dropPos.x = pos.x + x + + if check_if_node_picked(dropPos) then + remain_charge = collect_node(user, dropPos, remain_charge) + end + end + end + end + + return remain_charge +end + + + +minetest.register_tool("technic:xnopick", { + description = S("Xno Pick Magic"), + inventory_image = "xno_superpick.png", + + stack_max = 1, + + wear_represents = "technic_RE_charge", + on_refill = technic.refill_RE_charge, + + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "node" then + return itemstack + end + + --check tool charge + local meta = minetest.deserialize(itemstack:get_metadata()) + if not meta or not meta.charge or + meta.charge < xnopick_charge_per_node then + return + end + + --check node protection + local pos = pointed_thing.under + if minetest.is_protected(pos, user:get_player_name()) then + minetest.record_protection_violation(pos, user:get_player_name()) + return + end + + --reinizializze visited struct + nodeVisited = Pointset.create() + + --can collect only digging node + if not check_if_node_picked(pos) then + return itemstack + end + + + -- Send current charge to digging function so that the + -- chainsaw will stop after digging a number of nodes + meta.charge = collect_block_node(user, pos, meta.charge) + if not technic.creative_mode then + technic.set_RE_wear(itemstack, meta.charge, xnopick_max_charge) + itemstack:set_metadata(minetest.serialize(meta)) + end + return itemstack + + end, +}) + +minetest.register_craft({ + output = "technic:xnopick", + recipe = { + {"group:wood", "group:wood", "group:wood",}, + {"technic:battery", "default:stick", "pipeworks:tube_1"}, + {"technic:battery", "default:stick", "pipeworks:tube_1"}, + }, +}) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- Gitblit v1.8.0