Added Chainsaw
authorMaciej Kasatkin <mk@realbadangel.pl>
Mon, 22 Oct 2012 23:32:29 +0000 (01:32 +0200)
committerMaciej Kasatkin <mk@realbadangel.pl>
Mon, 22 Oct 2012 23:32:29 +0000 (01:32 +0200)
battery_box.lua
chainsaw.lua [new file with mode: 0644]
init.lua
sounds/chainsaw.ogg [new file with mode: 0644]
textures/technic_chainsaw.png [new file with mode: 0644]

index 93f07ee1743c9a71ce51eb68a5de365056c9230d..ed0b2f8f0f5c5ffcd09ebbf878dcf51b7617ac74 100644 (file)
@@ -10,6 +10,7 @@ registered_power_tools_count=registered_power_tools_count+1
 end
 
 register_power_tool ("technic:mining_drill",60000)
+register_power_tool ("technic:chainsaw",40000)
 register_power_tool ("technic:laser_mk1",40000)
 register_power_tool ("technic:battery",10000)
 register_power_tool ("technic:sonic_screwdriver",15000)
@@ -156,7 +157,7 @@ minetest.register_abm({
        chance = 1,
        action = function(pos, node, active_object_count, active_object_count_wider)
        local meta = minetest.env:get_meta(pos)
-       charge= meta:get_float("battery_charge")
+       charge= meta:get_int("battery_charge")
        max_charge= 60000
        local i=math.ceil((charge/max_charge)*8)
        if i>8 then i=8 end
@@ -191,7 +192,7 @@ minetest.register_abm({
                src_item["wear"]=tostring(load1)
                inv:set_stack("src", 1, src_item)
                end
-               meta:set_float("battery_charge",charge)
+               meta:set_int("battery_charge",charge)
        end     
        end
        
@@ -216,7 +217,7 @@ minetest.register_abm({
                end
                
 
-       meta:set_float("battery_charge",charge)
+       meta:set_int("battery_charge",charge)
        meta:set_string("infotext", "Battery box: "..charge.."/"..max_charge);
 
        local load = math.floor(charge/60000 * 100)
diff --git a/chainsaw.lua b/chainsaw.lua
new file mode 100644 (file)
index 0000000..dc1b409
--- /dev/null
@@ -0,0 +1,60 @@
+chainsaw_max_charge=30000
+
+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 charge=tonumber((item["wear"])) 
+               if charge ==0 then charge =65535 end
+               charge=get_RE_item_load(charge,mining_drill_max_charge)
+               charge_to_take=600;
+               if charge-charge_to_take>0 then
+                charge_to_take=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge_to_take)
+                charge=charge-charge_to_take;  
+               charge=set_RE_item_load(charge,mining_drill_max_charge)
+               item["wear"]=tostring(charge)
+               itemstack:replace(item)
+               end
+               return itemstack
+               end
+       end,
+})
+
+minetest.register_craft({
+       output = 'technic:chainsaw',
+       recipe = {
+               {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'},
+               {'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'},
+               {'','','moreores:copper_ingot'},
+       }
+})
+
+
+
+
+timber_nodenames={"default:jungletree", "default:papyrus", "default:cactus", "default:tree"}
+
+function chainsaw_dig_it (pos, player,charge_to_take)          
+       charge_to_take=0
+       local node=minetest.env:get_node(pos)
+       local i=1
+       while timber_nodenames[i]~=nil do
+               if node.name==timber_nodenames[i] then
+                       charge_to_take=600
+                       np={x=pos.x, y=pos.y, z=pos.z}
+                       while minetest.env:get_node(np).name==timber_nodenames[i] do
+                               minetest.env:remove_node(np)
+                               minetest.env:add_item(np, timber_nodenames[i])
+                               np={x=np.x, y=np.y+1, z=np.z}
+                       end
+                       minetest.sound_play("chainsaw", {pos = pos, gain = 1.0, max_hear_distance = 10,})
+                       return charge_to_take   
+               end
+               i=i+1
+       end
+
+return charge_to_take
+end
\ No newline at end of file
index 19b1843ad2b83f5c6266a0b21c37439c954dafba..85854d9453c70667cfd21aa1f0691095bf879faa 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -46,6 +46,7 @@ dofile(minetest.get_modpath("technic").."/constructor.lua")
 dofile(minetest.get_modpath("technic").."/tree_tap.lua")
 dofile(minetest.get_modpath("technic").."/flashlight.lua")
 dofile(minetest.get_modpath("technic").."/cans.lua")
+dofile(minetest.get_modpath("technic").."/chainsaw.lua")
 
 
 function has_locked_chest_privilege(meta, player)
diff --git a/sounds/chainsaw.ogg b/sounds/chainsaw.ogg
new file mode 100644 (file)
index 0000000..5fe7552
Binary files /dev/null and b/sounds/chainsaw.ogg differ
diff --git a/textures/technic_chainsaw.png b/textures/technic_chainsaw.png
new file mode 100644 (file)
index 0000000..b7ceee6
Binary files /dev/null and b/textures/technic_chainsaw.png differ