1 --create torch versions of the nodes
2 for name,def in pairs(minetest.registered_nodes) do
3 if def.drawtype == "normal" and string.match(name, "main:") then
4 local def2 = table.copy(def)
5 def2.groups.redstone_torch = 1
6 def2.groups.redstone_power=9
8 def2.mod_origin = "redstone"
9 --def2.textures = "dirt.png"
10 def2.after_destruct = function(pos, oldnode)
11 redstone.collect_info(pos)
13 local newname = "redstone:node_activated_"..string.gsub(name, "main:", "")
15 def2.description = "Redstone "..def.description
16 minetest.register_node(newname,def2)
21 --this removes power from node that the lever is powering
22 local function on_lever_destroy(pos)
23 local param2 = minetest.get_node(pos).param2
24 local self = minetest.get_node(pos)
25 local dir = minetest.wallmounted_to_dir(self.param2)
27 local pos = vector.add(dir,pos)
28 local node = minetest.get_node(pos)
29 local name = node.name
31 local def = minetest.registered_nodes[name]
32 if def.drawtype == "normal" and string.match(name, "redstone:node_activated_")then
33 name = "main:"..string.gsub(name, "redstone:node_activated_", "")
34 minetest.swap_node(pos, {name=name})
35 redstone.collect_info(pos)
40 minetest.register_node("redstone:lever_off", {
41 description = "Lever",
42 tiles = {"stone.png"},
43 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1},
44 sounds = main.stoneSound(),
46 paramtype2 = "wallmounted",
47 sunlight_propagates = true,
50 drop="redstone:lever_off",
54 --left front bottom right back top
55 {-0.3, -0.5, -0.4, 0.3, -0.4, 0.4},
56 {-0.1, -0.5, -0.3, 0.1, 0, -0.1},
59 on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
60 minetest.set_node(pos, {name="redstone:lever_on",param2=node.param2})
61 local dir = minetest.wallmounted_to_dir(node.param2)
62 local pos = vector.add(dir,pos)
63 local name = minetest.get_node(pos).name
64 local def = minetest.registered_nodes[name]
66 if def.drawtype == "normal" and string.match(name, "main:") then
67 minetest.sound_play("lever", {pos=pos})
68 name = "redstone:node_activated_"..string.gsub(name, "main:", "")
69 minetest.swap_node(pos,{name=name})
70 redstone.collect_info(pos)
72 minetest.sound_play("lever", {pos=pos,pitch=0.6})
75 on_destruct = on_lever_destroy,
77 minetest.register_node("redstone:lever_on", {
78 description = "Lever On",
79 tiles = {"stone.png"},
80 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1},
81 sounds = main.stoneSound(),
83 paramtype2 = "wallmounted",
84 sunlight_propagates = true,
87 drop="redstone:lever_off",
91 --left front bottom right back top
92 {-0.3, -0.5, -0.4, 0.3, -0.4, 0.4},
93 {-0.1, -0.5, 0.3, 0.1, 0, 0.1},
96 on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
97 minetest.sound_play("lever", {pos=pos,pitch=0.8})
98 minetest.set_node(pos, {name="redstone:lever_off",param2=node.param2})
101 on_destruct = on_lever_destroy,