commit | author | age
|
a30f1d
|
1 |
minetest.register_tool("technic:screwdriver", { |
R |
2 |
description = "Screwdriver", |
|
3 |
inventory_image = "technic_screwdriver.png", |
|
4 |
on_use = function(itemstack, user, pointed_thing) |
|
5 |
-- Must be pointing to facedir applicable node |
|
6 |
if pointed_thing.type~="node" then return end |
|
7 |
local pos=minetest.get_pointed_thing_position(pointed_thing,above) |
|
8 |
local node=minetest.env:get_node(pos) |
|
9 |
local node_name=node.name |
|
10 |
if minetest.registered_nodes[node_name].paramtype2 == "facedir" or minetest.registered_nodes[node_name].paramtype2 == "wallmounted" then |
|
11 |
if node.param2==nil then return end |
|
12 |
-- Get ready to set the param2 |
|
13 |
local n = node.param2 |
|
14 |
if minetest.registered_nodes[node_name].paramtype2 == "facedir" then |
|
15 |
n = n+1 |
|
16 |
if n == 4 then n = 0 end |
|
17 |
else |
|
18 |
n = n+1 |
|
19 |
if n == 6 then n = 0 end |
|
20 |
end |
|
21 |
-- hacky_swap_node, unforunatly. |
|
22 |
local meta = minetest.env:get_meta(pos) |
|
23 |
local meta0 = meta:to_table() |
|
24 |
node.param2 = n |
|
25 |
minetest.env:set_node(pos,node) |
|
26 |
meta = minetest.env:get_meta(pos) |
|
27 |
meta:from_table(meta0) |
|
28 |
local item=itemstack:to_table() |
|
29 |
local item_wear=tonumber((item["wear"])) |
|
30 |
item_wear=item_wear+819 |
|
31 |
if item_wear>65535 then itemstack:clear() return itemstack end |
|
32 |
item["wear"]=tostring(item_wear) |
|
33 |
itemstack:replace(item) |
|
34 |
return itemstack |
|
35 |
else |
|
36 |
return itemstack |
|
37 |
end |
|
38 |
end, |
|
39 |
}) |
|
40 |
|
|
41 |
minetest.register_craft({ |
|
42 |
output = "technic:screwdriver", |
|
43 |
recipe = { |
|
44 |
{"technic:stainless_steel_ingot"}, |
|
45 |
{"default:stick"} |
|
46 |
} |
|
47 |
}) |