Cristiano Magro
2020-10-19 c189a33eec2e9a22c0101c07e4177619c6b6240c
Super Xno Pick
2 files added
1 files modified
368 ■■■■■ changed files
technic/textures/xno_superpick.png patch | view | raw | blame | history
technic/tools/init.lua 1 ●●●● patch | view | raw | blame | history
technic/tools/xno_pick.lua 367 ●●●●● patch | view | raw | blame | history
technic/textures/xno_superpick.png
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")
technic/tools/xno_pick.lua
New file
@@ -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"},
  },
})