]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/button.lua
Add piston sound
[Crafter.git] / mods / redstone / button.lua
1 --this removes power from node that the switch is powering
2 local function on_button_destroy(pos)
3         local param2 = minetest.get_node(pos).param2
4         local self = minetest.get_node(pos)
5         local dir = minetest.wallmounted_to_dir(self.param2)
6         
7         local pos = vector.add(dir,pos)
8         local node = minetest.get_node(pos)
9         local name = node.name
10         
11         local def = minetest.registered_nodes[name]
12         if def.drawtype == "normal" and string.match(name, "redstone:") then
13                 name = "main:"..string.gsub(name, "redstone:", "")
14                 minetest.set_node(pos, {name=name})
15                 redstone.collect_info(pos)
16         end
17 end
18
19
20 minetest.register_node("redstone:button_off", {
21     description = "Crafting Table",
22     tiles = {"stone.png"},
23     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1},
24     sounds = main.stoneSound(),
25     paramtype = "light",
26         paramtype2 = "wallmounted",
27         sunlight_propagates = true,
28         walkable = false,
29         drawtype= "nodebox",
30         drop="redstone:button_off",
31         node_box = {
32                 type = "fixed",
33                 fixed = {
34                                 --left front bottom right back top
35                                 {-0.25, -0.5,  -0.15, 0.25,  -0.3, 0.15},
36                         },
37                 },
38     on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
39                 minetest.sound_play("lever", {pos=pos})
40                 minetest.set_node(pos, {name="redstone:button_on",param2=node.param2})
41                 local dir = minetest.wallmounted_to_dir(node.param2)
42                 local c_pos = table.copy(pos)
43                 local pos = vector.add(dir,pos)
44                 local name = minetest.get_node(pos).name
45                 local def = minetest.registered_nodes[name]
46                 
47                 if def.drawtype == "normal" and string.match(name, "main:") then
48                         name = "redstone:"..string.gsub(name, "main:", "")
49                         minetest.set_node(pos,{name=name})
50                         redstone.collect_info(pos)
51                         local timer = minetest.get_node_timer(c_pos)
52                         timer:start(1)
53                 end
54         end,
55         on_destruct = on_button_destroy,
56 })
57 minetest.register_node("redstone:button_on", {
58     description = "Crafting Table",
59     tiles = {"stone.png"},
60     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1},
61     sounds = main.stoneSound(),
62     paramtype = "light",
63         paramtype2 = "wallmounted",
64         sunlight_propagates = true,
65         walkable = false,
66         drawtype= "nodebox",
67         drop="redstone:button_off",
68         node_box = {
69                 type = "fixed",
70                 fixed = {
71                                 --left front bottom right back top
72                                 {-0.25, -0.5,  -0.15, 0.25,  -0.45, 0.15},
73                         },
74                 },
75     on_timer = function(pos, elapsed)
76                 minetest.sound_play("lever", {pos=pos,pitch=0.8})
77                 local node = minetest.get_node(pos)
78                 minetest.set_node(pos, {name="redstone:button_off",param2=node.param2})
79                 on_button_destroy(pos)
80         end,
81         on_destruct = on_button_destroy,
82 })