]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/detector.lua
b2c8f27e8c3ef72949e3be02bda49e58af137704
[Crafter.git] / mods / redstone / detector.lua
1 minetest.register_node("redstone:detector_off", {
2     description = "Detector",
3     tiles = {"redstone_piston.png^[invert:rgb^[colorize:yellow:100",
4     "redstone_piston.png^[transformR180^[invert:rgb^[colorize:yellow:100",
5     "redstone_piston.png^[transformR270^[invert:rgb^[colorize:yellow:100",
6     "redstone_piston.png^[transformR90^[invert:rgb^[colorize:yellow:100",
7     "wood.png^[invert:rgb^[colorize:yellow:100",
8     "stone.png^[invert:rgb^[colorize:yellow:100"},
9     paramtype2 = "facedir",
10     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
11     sounds = main.stoneSound(),
12     drop = "redstone:detector_off",
13     paramtype = "light",
14     sunlight_propagates = true,
15     
16     on_timer = function(pos, elapsed)
17         local param2 = minetest.get_node(pos).param2
18         local dir = minetest.facedir_to_dir(param2)
19
20
21         if minetest.get_node(vector.add(pos,dir)).name ~= "air" then
22             minetest.swap_node(pos, {name="redstone:detector_on",param2=param2})
23             
24             redstone.inject(pos,{
25                 name = "redstone:detector_on",
26                 torch = 16,
27             })
28             minetest.after(0,function()
29                 redstone.update(pos)
30             end)
31         end
32
33         local timer = minetest.get_node_timer(pos)
34         if not timer:is_started() then
35             timer:start(1)
36         end
37     end,
38     
39         --reverse the direction to face the player
40         on_construct = function(pos)
41                 redstone.inject(pos,{
42                         name = "redstone:detector_off",
43         })
44         local timer = minetest.get_node_timer(pos)
45                 if not timer:is_started() then
46                         timer:start(1)
47                 end
48         end,
49         on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
50                 local look = clicker:get_look_dir()
51                 look = vector.multiply(look,-1)
52                 local dir = minetest.dir_to_facedir(look, true)
53                 minetest.swap_node(pos,{name="redstone:detector_off",param2=dir})
54         end,
55     after_place_node = function(pos, placer, itemstack, pointed_thing)
56                 local look = placer:get_look_dir()
57                 look = vector.multiply(look,-1)
58                 local dir = minetest.dir_to_facedir(look, true)
59                 minetest.swap_node(pos,{name="redstone:detector_off",param2=dir})
60         end,
61         on_destruct = function(pos, oldnode)
62                 redstone.inject(pos,nil)
63     end,
64 })
65
66
67 minetest.register_lbm({
68         name = "redstone:detector_off",
69         nodenames = {"redstone:detector_off"},
70         run_at_every_load = true,
71         action = function(pos)
72                 redstone.inject(pos,{
73                         name = "redstone:detector_off",
74         })
75
76         local timer = minetest.get_node_timer(pos)
77                 if not timer:is_started() then
78                         timer:start(1)
79                 end
80         end,
81 })
82
83
84 minetest.register_node("redstone:detector_on", {
85     description = "Detector On",
86     tiles = {"redstone_piston.png^[invert:rgb^[colorize:green:100",
87     "redstone_piston.png^[transformR180^[invert:rgb^[colorize:green:100",
88     "redstone_piston.png^[transformR270^[invert:rgb^[colorize:green:100",
89     "redstone_piston.png^[transformR90^[invert:rgb^[colorize:green:100",
90     "wood.png^[invert:rgb^[colorize:green:100",
91     "stone.png^[invert:rgb^[colorize:green:100"},
92     paramtype2 = "facedir",
93     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
94     sounds = main.stoneSound(),
95     drop = "redstone:breaker_off",
96     paramtype = "light",
97     sunlight_propagates = true,
98     on_timer = function(pos, elapsed)
99         local param2 = minetest.get_node(pos).param2
100         local dir = minetest.facedir_to_dir(param2)
101         if minetest.get_node(vector.add(pos,dir)).name == "air" then
102             minetest.swap_node(pos, {name="redstone:detector_off",param2=param2})
103             
104             redstone.inject(pos,{
105                 name = "redstone:detector_off",
106             })
107             minetest.after(0,function()
108                 redstone.update(pos)
109             end)
110         end
111
112         local timer = minetest.get_node_timer(pos)
113         if not timer:is_started() then
114             timer:start(1)
115         end
116     end,
117         --reverse the direction to face the player
118         on_construct = function(pos)
119                 redstone.inject(pos,{
120             name = "redstone:detector_on",
121             torch = 16,
122         })
123         local timer = minetest.get_node_timer(pos)
124                 if not timer:is_started() then
125                         timer:start(1)
126                 end
127                 redstone.update(pos)
128         end,
129         on_destruct = function(pos)
130                 redstone.inject(pos,nil)
131     end,
132 })
133
134
135
136 minetest.register_lbm({
137         name = "redstone:detector_on",
138         nodenames = {"redstone:detector_on"},
139         run_at_every_load = true,
140         action = function(pos)
141                 redstone.inject(pos,{
142                         name = "redstone:detector_on",
143                         torch = 16,
144         })
145         
146         local timer = minetest.get_node_timer(pos)
147                 if not timer:is_started() then
148                         timer:start(1)
149                 end
150
151                 minetest.after(0,function()
152             redstone.update(pos)
153         end)
154         end,
155 })