]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/lever.lua
Make levers and buttons work
[Crafter.git] / mods / redstone / lever.lua
1
2 local
3 minetest,vector,math,pairs
4 =
5 minetest,vector,math,pairs
6
7
8 minetest.register_node("redstone:lever_on", {
9     description = "Lever On",
10     tiles = {"stone.png"},
11     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1},
12     sounds = main.stoneSound(),
13     paramtype = "light",
14         paramtype2 = "wallmounted",
15         sunlight_propagates = true,
16         walkable = false,
17         drawtype= "nodebox",
18         drop="redstone:lever_off",
19         node_box = {
20                 type = "fixed",
21                 fixed = {
22                                 --left front bottom right back top
23                                 {-0.3, -0.5,  -0.4, 0.3,  -0.4, 0.4},
24                                 {-0.1, -0.5,  0.3, 0.1,  0, 0.1},
25                         },
26                 },
27     on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
28                 minetest.swap_node(pos, {name="redstone:lever_off",param2=node.param2})
29
30                 minetest.sound_play("lever", {pos=pos})
31
32                 local dir = minetest.wallmounted_to_dir(node.param2)
33
34                 redstone.inject(pos,nil)
35                 local pos2 = vector.add(dir,pos)
36                 redstone.inject(pos2,nil)
37
38                 redstone.update(pos)
39                 redstone.update(pos2)
40         end,
41         after_destruct = function(pos, oldnode)
42                 redstone.inject(pos,nil)
43                 local dir = minetest.wallmounted_to_dir(oldnode.param2)
44                 local pos2 = vector.add(dir,pos)
45                 redstone.inject(pos2,nil)
46
47                 redstone.update(pos)
48                 redstone.update(pos2)
49         end,
50 })
51
52
53
54 minetest.register_node("redstone:lever_off", {
55     description = "Lever",
56     tiles = {"stone.png"},
57     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1},
58     sounds = main.stoneSound(),
59     paramtype = "light",
60         paramtype2 = "wallmounted",
61         sunlight_propagates = true,
62         walkable = false,
63         drawtype= "nodebox",
64         drop="redstone:lever_off",
65         node_box = {
66                 type = "fixed",
67                 fixed = {
68                                 --left front bottom right back top
69                                 {-0.3, -0.5,  -0.4, 0.3,  -0.4, 0.4},
70                                 {-0.1, -0.5,  -0.3, 0.1,  0, -0.1},
71                         },
72                 },
73     on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
74                 minetest.swap_node(pos, {name="redstone:lever_on",param2=node.param2})
75                 minetest.sound_play("lever", {pos=pos})
76
77                 local dir = minetest.wallmounted_to_dir(node.param2)
78
79                 redstone.inject(pos,{torch=9})
80                 local pos2 = vector.add(dir,pos)
81                 redstone.inject(pos2,{torch=9})
82
83                 redstone.update(pos)
84                 redstone.update(pos2)
85         end,
86         after_destruct = function(pos, oldnode)
87                 redstone.inject(pos,nil)
88                 local dir = minetest.wallmounted_to_dir(oldnode.param2)
89                 local pos2 = vector.add(dir,pos)
90                 redstone.inject(pos2,nil)
91
92                 redstone.update(pos)
93                 redstone.update(pos2)
94         end,
95 })