summaryrefslogtreecommitdiff
path: root/mesecons_delayer/init.lua
blob: 6eb9d7b5a02fbf9a199031a832ec69a37df645de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
minetest.register_node("mesecons_delayer:delayer_off_1", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_off_1.png"},
	inventory_image = "mesecons_delayer_off_1.png",
	wield_image = "mesecons_delayer_off_1.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})

minetest.register_node("mesecons_delayer:delayer_off_2", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_off_2.png"},
	inventory_image = "mesecons_delayer_off_2.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})

minetest.register_node("mesecons_delayer:delayer_off_3", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_off_3.png"},
	inventory_image = "mesecons_delayer_off_3.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})

minetest.register_node("mesecons_delayer:delayer_off_4", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_off_4.png"},
	inventory_image = "mesecons_delayer_off_4.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})





minetest.register_node("mesecons_delayer:delayer_on_1", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_on_1.png"},
	inventory_image = "mesecons_delayer_on_1.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})

minetest.register_node("mesecons_delayer:delayer_on_2", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_on_2.png"},
	inventory_image = "mesecons_delayer_on_2.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})

minetest.register_node("mesecons_delayer:delayer_on_3", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_on_3.png"},
	inventory_image = "mesecons_delayer_on_3.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})

minetest.register_node("mesecons_delayer:delayer_on_4", {
	description = "Delayer",
	drawtype = "raillike",
	tile_images = {"mesecons_delayer_on_4.png"},
	inventory_image = "mesecons_delayer_on_4.png",
	walkable = false,
	selection_box = {type = "fixed",},
	groups = {bendy=2,snappy=1,dig_immediate=2},
	paramtype = "light",
	drop = 'mesecons_delayer:delayer_off_1',
})




minetest.register_on_punchnode(function (pos, node)
	if node.name=="mesecons_delayer:delayer_off_1" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2"})
	end
	if node.name=="mesecons_delayer:delayer_off_2" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3"})
	end
	if node.name=="mesecons_delayer:delayer_off_3" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4"})
	end
	if node.name=="mesecons_delayer:delayer_off_4" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1"})
	end
end)

minetest.register_on_punchnode(function (pos, node)
	if node.name=="mesecons_delayer:delayer_on_1" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2"})
	end
	if node.name=="mesecons_delayer:delayer_on_2" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3"})
	end
	if node.name=="mesecons_delayer:delayer_on_3" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4"})
	end
	if node.name=="mesecons_delayer:delayer_on_4" then
		minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1"})
	end
end)

mesecon.delayer_signal_change = function(pos, node)
	if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
		np={x=pos.x-1, y=pos.y, z=pos.z}
		nn=minetest.env:get_node(np)
		if nn.name=="mesecons:mesecon_on" or mesecon:is_receptor_node(nn.name, np, pos) then
			local time
			if node.name=="mesecons_delayer:delayer_off_1" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1"})
				time=0.1
			end
			if node.name=="mesecons_delayer:delayer_off_2" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2"})
				time=0.3
			end
			if node.name=="mesecons_delayer:delayer_off_3" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3"})
				time=0.5
			end
			if node.name=="mesecons_delayer:delayer_off_4" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4"})
				time=1
			end
			minetest.after(time, mesecon.delayer_turnon, {pos=pos})

		end
	end
	if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then
		np={x=pos.x-1, y=pos.y, z=pos.z}
		nn=minetest.env:get_node(np)
		if nn.name=="mesecons:mesecon_off" or mesecon:is_receptor_node_off(nn.name, np, pos) or nn.name=="air" then
			local time
			if node.name=="mesecons_delayer:delayer_on_1" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1"})
				time=0.1
			end
			if node.name=="mesecons_delayer:delayer_on_2" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2"})
				time=0.3
			end
			if node.name=="mesecons_delayer:delayer_on_3" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3"})
				time=0.5
			end
			if node.name=="mesecons_delayer:delayer_on_4" then
				minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4"})
				time=1
			end
			minetest.after(time, mesecon.delayer_turnoff, {pos=pos})
		end
	end
end

mesecon:register_on_signal_change(mesecon.delayer_signal_change)

mesecon.delayer_turnon=function(params)
	mesecon:receptor_on(params.pos, mesecon:get_rules("delayer"))
end

mesecon.delayer_turnoff=function(params)
	mesecon:receptor_off(params.pos, mesecon:get_rules("delayer"))
end

mesecon:add_rules("delayer", {{x=1, y=0, z=0}})

mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", mesecon:get_rules("delayer"))
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", mesecon:get_rules("delayer"))
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", mesecon:get_rules("delayer"))
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", mesecon:get_rules("delayer"))

mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", mesecon:get_rules("delayer"))
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", mesecon:get_rules("delayer"))
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", mesecon:get_rules("delayer"))
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", mesecon:get_rules("delayer"))