2012-09-12 02:22:18 +02:00
|
|
|
sonic_screwdriver_max_charge=15000
|
2012-09-13 09:14:29 +02:00
|
|
|
|
|
|
|
minetest.register_tool("technic:sonic_screwdriver", {
|
2012-09-12 02:22:18 +02:00
|
|
|
description = "Sonic Screwdriver",
|
|
|
|
inventory_image = "technic_sonic_screwdriver.png",
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
-- Must be pointing to facedir applicable node
|
|
|
|
if pointed_thing.type~="node" then return end
|
2012-09-13 09:14:29 +02:00
|
|
|
local pos=minetest.get_pointed_thing_position(pointed_thing,above)
|
|
|
|
local node=minetest.env:get_node(pos)
|
|
|
|
local node_name=node.name
|
|
|
|
if minetest.registered_nodes[node_name].paramtype2 == "facedir" or minetest.registered_nodes[node_name].paramtype2 == "wallmounted" then
|
|
|
|
if node.param2==nil then return end
|
2012-09-12 02:22:18 +02:00
|
|
|
item=itemstack:to_table()
|
2012-09-13 09:14:29 +02:00
|
|
|
local charge=tonumber((item["wear"]))
|
|
|
|
if charge ==0 then charge =65535 end
|
|
|
|
charge=get_RE_item_load(charge,sonic_screwdriver_max_charge)
|
|
|
|
if charge-100>0 then
|
2012-10-10 21:13:20 +02:00
|
|
|
minetest.sound_play("technic_sonic_screwdriver", {pos = pos, gain = 0.3, max_hear_distance = 10,})
|
2012-09-13 09:14:29 +02:00
|
|
|
local n = node.param2
|
|
|
|
if minetest.registered_nodes[node_name].paramtype2 == "facedir" then
|
|
|
|
n = n+1
|
|
|
|
if n == 4 then n = 0 end
|
|
|
|
else
|
|
|
|
n = n+1
|
|
|
|
if n == 6 then n = 0 end
|
|
|
|
end
|
|
|
|
-- hacky_swap_node, unforunatly.
|
|
|
|
local meta = minetest.env:get_meta(pos)
|
|
|
|
local meta0 = meta:to_table()
|
|
|
|
node.param2 = n
|
|
|
|
minetest.env:set_node(pos,node)
|
|
|
|
meta = minetest.env:get_meta(pos)
|
|
|
|
meta:from_table(meta0)
|
|
|
|
|
|
|
|
charge =charge-100;
|
|
|
|
charge=set_RE_item_load(charge,sonic_screwdriver_max_charge)
|
|
|
|
item["wear"]=tostring(charge)
|
|
|
|
itemstack:replace(item)
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
else
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2012-09-12 02:22:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "technic:sonic_screwdriver",
|
|
|
|
recipe = {
|
2012-09-12 09:15:04 +02:00
|
|
|
{"technic:diamond"},
|
|
|
|
{"technic:battery"},
|
2012-09-12 02:37:46 +02:00
|
|
|
{"technic:stainless_steel_ingot"}
|
2012-09-12 02:22:18 +02:00
|
|
|
}
|
|
|
|
})
|