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