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