]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/repeater.lua
Inject torch data
[Crafter.git] / mods / redstone / repeater.lua
1 local minetest,vector = minetest,vector
2
3 local max_timer = 7
4
5 for level = 0,max_timer do
6 minetest.register_node("redstone:repeater_off_"..level, {
7     description = "Redstone Repeater",
8     tiles = {"repeater_off.png"},
9     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,repeater_off=1,repeater=1,redstone_activation_directional=1,repeater_level=level},
10     sounds = main.stoneSound(),
11     paramtype = "light",
12         paramtype2 = "facedir",
13         sunlight_propagates = true,
14         walkable = false,
15         drawtype= "nodebox",
16         drop="redstone:repeater_off_0",
17         node_box = {
18                 type = "fixed",
19                 fixed = {
20                                 --left  front  bottom right back top
21                                 {-0.5, -0.5,  -0.5, 0.5,  -0.3, 0.5}, --base
22                                 {-0.1, -0.5,  0.2, 0.1,  0.1, 0.4}, --output post
23                                 {-0.1, -0.5,  -0.05-(level*0.05), 0.1,  0.1, 0.15-(level*0.05)}, --input post
24                         },
25                 },      
26         redstone_activation = function(pos)
27                 local timer = minetest.get_node_timer(pos)
28                 if not timer:is_started() then
29                         timer:start(level/max_timer)
30                 end
31         end,
32
33         on_timer = function(pos, elapsed)
34                 local param2 = minetest.get_node(pos).param2
35                 minetest.swap_node(pos, {name="redstone:repeater_on_"..level,param2=param2})
36                 redstone.collect_info(pos)
37         end,
38
39         on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
40                 local newlevel = level + 1
41                 if newlevel > max_timer then
42                         newlevel = 0
43                 end
44                 minetest.swap_node(pos,{name="redstone:repeater_off_"..newlevel,param2=node.param2})
45                 minetest.sound_play("lever", {pos=pos})
46         end,
47
48         after_destruct = function(pos, oldnode)
49                 redstone.collect_info(pos)
50         end,
51
52         after_place_node = function(pos)
53                 redstone.collect_info(pos)
54         end
55 })
56
57 minetest.register_node("redstone:repeater_on_"..level, {
58     description = "Redstone Repeater",
59     tiles = {"repeater_on.png"},
60     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,redstone_activation_directional=1,repeater_on=1,repeater=1,torch_directional=1,redstone_power=9,repeater_level=level},
61     sounds = main.stoneSound(),
62     paramtype = "light",
63         paramtype2 = "facedir",
64         sunlight_propagates = true,
65         walkable = false,
66         drawtype= "nodebox",
67         drop="redstone:repeater_off_0",
68         node_box = {
69                 type = "fixed",
70                 fixed = {
71                                 --left  front  bottom right back top
72                                 {-0.5, -0.5,  -0.5, 0.5,  -0.3, 0.5}, --base
73                                 {-0.1, -0.5,  0.2, 0.1,  0.1, 0.4}, --output post
74                                 {-0.1, -0.5,  -0.05-(level*0.05), 0.1,  0.1, 0.15-(level*0.05)}, --input post
75                         },
76                 },
77         on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
78                 local newlevel = level + 1
79                 if newlevel > max_timer then
80                         newlevel = 0
81                 end
82                 minetest.swap_node(pos,{name="redstone:repeater_on_"..newlevel,param2=node.param2})
83                 minetest.sound_play("lever", {pos=pos})
84         end,
85         redstone_deactivation = function(pos)
86                 local timer = minetest.get_node_timer(pos)
87                 if not timer:is_started() then
88                         timer:start(level/max_timer)
89                 end
90         end,
91         on_timer = function(pos, elapsed)
92                 local param2 = minetest.get_node(pos).param2
93                 minetest.swap_node(pos, {name="redstone:repeater_off_"..level,param2=param2})
94                 redstone.collect_info(pos)
95         end,
96         after_destruct = function(pos, oldnode)
97                 redstone.collect_info(pos)
98         end,
99
100         after_place_node = function(pos)
101                 redstone.collect_info(pos)
102         end
103 })
104 end