ShadowNinja
2013-12-17 5cf765b2f19ef9bf443178e26787fe16233b3f4c
commit | author | age
ee0765 1 local sonic_screwdriver_max_charge = 15000
be2f30 2
S 3 local S = technic.getter
4
ee0765 5 technic.register_power_tool("technic:sonic_screwdriver", sonic_screwdriver_max_charge)
e23f87 6
R 7 minetest.register_tool("technic:sonic_screwdriver", {
be2f30 8     description = S("Sonic Screwdriver"),
eac484 9     inventory_image = "technic_sonic_screwdriver.png",
S 10     on_use = function(itemstack, user, pointed_thing)
11         -- Must be pointing to facedir applicable node
12         if pointed_thing.type ~= "node" then
13             return
14         end
15         local pos = minetest.get_pointed_thing_position(pointed_thing, above)
16         local node = minetest.get_node(pos)
17         local node_name = node.name
18         if minetest.registered_nodes[node_name].paramtype2 ~= "facedir" and
19            minetest.registered_nodes[node_name].paramtype2 ~= "wallmounted" then
20             return itemstack
21         end
22         if node.param2 == nil then
23             return
24         end
5cf765 25         local meta1 = minetest.deserialize(itemstack:get_metadata())
eac484 26         if not meta1 or not meta1.charge then
S 27             return
28         end
29         if meta1.charge - 100 > 0 then
30             minetest.sound_play("technic_sonic_screwdriver",
31                     {pos = pos, gain = 0.3, max_hear_distance = 10})
32             local p = node.param2
33             if minetest.registered_nodes[node_name].paramtype2 == "facedir" then
34                 p = p + 1
35                 if p == 4 then
36                     p = 0
37                 end
38             else
39                 p = p + 1
40                 if p == 6 then
41                     p = 0
42                 end
43             end
818a0e 44             if minetest.is_protected(pos, user:get_player_name()) then
S 45                 minetest.record_protection_violation(pos, user:get_player_name())
46             else
47                 node.param2 = p
f3d8b4 48                 minetest.swap_node(pos, node)
e23f87 49
818a0e 50                 meta1.charge = meta1.charge - 100
5cf765 51                 itemstack:set_metadata(minetest.serialize(meta1))
818a0e 52                 technic.set_RE_wear(itemstack, meta1.charge, sonic_screwdriver_max_charge)
S 53             end
eac484 54         end
S 55         return itemstack
56     end, 
57 })
e23f87 58  
R 59 minetest.register_craft({
60     output = "technic:sonic_screwdriver",
61     recipe = {
cdb368 62         {"default:diamond"},
e23f87 63         {"technic:battery"},
R 64         {"technic:stainless_steel_ingot"}
f3d8b4 65     }
e23f87 66 })
f3d8b4 67