ShadowNinja
2013-10-30 be2f30a1a2f5b6c2aae7fd4cf8231aec2da0844d
technic/tools/chainsaw.lua
@@ -3,30 +3,33 @@
local chainsaw_charge_per_node = 12    -- 12    - Gives 2500 nodes on a single charge (about 50 complete normal trees)
local chainsaw_leaves          = true  -- true  - Cut down entire trees, leaves and all
local S = technic.getter
technic.register_power_tool("technic:chainsaw", chainsaw_max_charge)
minetest.register_tool("technic:chainsaw", {
        description = "Chainsaw",
        inventory_image = "technic_chainsaw.png",
        stack_max = 1,
        on_use = function(itemstack, user, pointed_thing)
                if pointed_thing.type=="node" then
                        item=itemstack:to_table()
                        local meta=get_item_meta(item["metadata"])
                        if meta==nil then return end --tool not charged
                        if meta["charge"]==nil then return end
                        -- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes.
                        local charge=meta["charge"]
                        if charge < chainsaw_charge_per_node then return end -- only cut if charged
   description = S("Chainsaw"),
   inventory_image = "technic_chainsaw.png",
   stack_max = 1,
   on_use = function(itemstack, user, pointed_thing)
      if pointed_thing.type == "node" then
         return itemstack
      end
      local meta = get_item_meta(itemstack:get_metadata())
      if not meta or not meta.charge then
         return
      end
      -- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes.
      if meta.charge < chainsaw_charge_per_node then
         return
      end
                        charge=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge)
                        technic.set_RE_wear(item,charge,chainsaw_max_charge)
                        meta["charge"]=charge
                        item["metadata"]=set_item_meta(meta)
                        itemstack:replace(item)
                        return itemstack
                end
        end,
      local pos = minetest.get_pointed_thing_position(pointed_thing, above)
      meta.charge = chainsaw_dig_it(pos, user, meta.charge)
      technic.set_RE_wear(itemstack, meta.charge, chainsaw_max_charge)
      itemstack:set_metadata(set_item_meta(meta))
      return itemstack
   end,
})
minetest.register_craft({