]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/lever.lua
Rename switches to levers and fix treecapitator with activated tree node
[Crafter.git] / mods / redstone / lever.lua
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
7                 def2.drop = def.drop
8                 def2.mod_origin = "redstone"
9                 --def2.textures = "dirt.png"
10                 def2.after_destruct = function(pos, oldnode)
11                         redstone.collect_info(pos)
12                 end
13                 local newname = "redstone:node_activated_"..string.gsub(name, "main:", "")
14                 def2.name = newname
15                 def2.description = "Redstone "..def.description
16                 minetest.register_node(newname,def2)
17         end
18 end
19
20
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)
26         
27         local pos = vector.add(dir,pos)
28         local node = minetest.get_node(pos)
29         local name = node.name
30         
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)
36         end
37 end
38
39
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(),
45     paramtype = "light",
46         paramtype2 = "wallmounted",
47         sunlight_propagates = true,
48         walkable = false,
49         drawtype= "nodebox",
50         drop="redstone:lever_off",
51         node_box = {
52                 type = "fixed",
53                 fixed = {
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},
57                         },
58                 },
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]
65                 
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)
71                 else
72                         minetest.sound_play("lever", {pos=pos,pitch=0.6})
73                 end
74         end,
75         on_destruct = on_lever_destroy,
76 })
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(),
82     paramtype = "light",
83         paramtype2 = "wallmounted",
84         sunlight_propagates = true,
85         walkable = false,
86         drawtype= "nodebox",
87         drop="redstone:lever_off",
88         node_box = {
89                 type = "fixed",
90                 fixed = {
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},
94                         },
95                 },
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})
99                 on_lever_destroy(pos)
100         end,
101         on_destruct = on_lever_destroy,
102 })