Zefram
2014-04-30 00d7c9bdead4d77f0ca88036eda44b8cce6cca34
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",
99fd5d 10     wear_represents = "technic_RE_charge",
00d7c9 11     on_refill = technic.refill_RE_charge,
eac484 12     on_use = function(itemstack, user, pointed_thing)
S 13         -- Must be pointing to facedir applicable node
14         if pointed_thing.type ~= "node" then
15             return
16         end
bab851 17         local pos = pointed_thing.under
S 18         if minetest.is_protected(pos, user:get_player_name()) then
19             minetest.record_protection_violation(pos, user:get_player_name())
20             return
21         end
eac484 22         local node = minetest.get_node(pos)
S 23         local node_name = node.name
24         if minetest.registered_nodes[node_name].paramtype2 ~= "facedir" and
25            minetest.registered_nodes[node_name].paramtype2 ~= "wallmounted" then
bab851 26             return
eac484 27         end
S 28         if node.param2 == nil then
29             return
30         end
5cf765 31         local meta1 = minetest.deserialize(itemstack:get_metadata())
eac484 32         if not meta1 or not meta1.charge then
S 33             return
34         end
5c59d9 35         if meta1.charge >= 100 then
eac484 36             minetest.sound_play("technic_sonic_screwdriver",
S 37                     {pos = pos, gain = 0.3, max_hear_distance = 10})
38             local p = node.param2
39             if minetest.registered_nodes[node_name].paramtype2 == "facedir" then
40                 p = p + 1
41                 if p == 4 then
42                     p = 0
43                 end
44             else
45                 p = p + 1
46                 if p == 6 then
47                     p = 0
48                 end
49             end
818a0e 50             if minetest.is_protected(pos, user:get_player_name()) then
S 51                 minetest.record_protection_violation(pos, user:get_player_name())
52             else
53                 node.param2 = p
f3d8b4 54                 minetest.swap_node(pos, node)
e23f87 55
818a0e 56                 meta1.charge = meta1.charge - 100
5cf765 57                 itemstack:set_metadata(minetest.serialize(meta1))
818a0e 58                 technic.set_RE_wear(itemstack, meta1.charge, sonic_screwdriver_max_charge)
S 59             end
eac484 60         end
S 61         return itemstack
62     end, 
63 })
e23f87 64  
R 65 minetest.register_craft({
66     output = "technic:sonic_screwdriver",
67     recipe = {
cdb368 68         {"default:diamond"},
e23f87 69         {"technic:battery"},
R 70         {"technic:stainless_steel_ingot"}
f3d8b4 71     }
e23f87 72 })
f3d8b4 73