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
technic.register_LV_power_tool ("technic:chainsaw",chainsaw_max_charge)
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({
@@ -50,6 +53,16 @@
        timber_nodenames["default:leaves"] = true
end
-- technic_worldgen defines rubber trees if moretrees isn't installed
if minetest.get_modpath("technic_worldgen") or
   minetest.get_modpath("moretrees") then
   timber_nodenames["moretrees:rubber_tree_trunk_empty"] = true
   timber_nodenames["moretrees:rubber_tree_trunk"]       = true
   if chainsaw_leaves then
                timber_nodenames["moretrees:rubber_tree_leaves"] = true
   end
end
-- Support moretrees if it is there
if( minetest.get_modpath("moretrees") ~= nil ) then
        timber_nodenames["moretrees:apple_tree_trunk"]                 = true
@@ -66,9 +79,7 @@
        timber_nodenames["moretrees:palm_trunk_sideways"]              = true
        timber_nodenames["moretrees:pine_trunk"]                       = true
        timber_nodenames["moretrees:pine_trunk_sideways"]              = true
        timber_nodenames["moretrees:rubber_tree_trunk"]                = true
        timber_nodenames["moretrees:rubber_tree_trunk_sideways"]       = true
        timber_nodenames["moretrees:rubber_tree_trunk_empty"]          = true
        timber_nodenames["moretrees:rubber_tree_trunk_sideways_empty"] = true
        timber_nodenames["moretrees:sequoia_trunk"]                    = true
        timber_nodenames["moretrees:sequoia_trunk_sideways"]           = true
@@ -79,7 +90,7 @@
        timber_nodenames["moretrees:jungletree_trunk"]                 = true
        timber_nodenames["moretrees:jungletree_trunk_sideways"]        = true
        if chainsaw_leaves == true then
        if chainsaw_leaves then
                timber_nodenames["moretrees:apple_tree_leaves"]        = true
                timber_nodenames["moretrees:oak_leaves"]               = true
                timber_nodenames["moretrees:sequoia_leaves"]           = true
@@ -90,7 +101,6 @@
                timber_nodenames["moretrees:spruce_leaves"]            = true
                timber_nodenames["moretrees:pine_leaves"]              = true
                timber_nodenames["moretrees:willow_leaves"]            = true
                timber_nodenames["moretrees:rubber_tree_leaves"]       = true
                timber_nodenames["moretrees:jungletree_leaves_green"]  = true
                timber_nodenames["moretrees:jungletree_leaves_yellow"] = true
                timber_nodenames["moretrees:jungletree_leaves_red"]    = true