]> git.lizzy.rs Git - Crafter.git/blob - mods/redstone/piston.lua
a6067898152b61022b75c72680aef4fba365d575
[Crafter.git] / mods / redstone / piston.lua
1 local minetest,math,ipairs,vector,table = minetest,math,ipairs,vector,table
2 --exclude certain mods and nodes from being pushed and pulled to stop glitches
3 local registered_nodes
4 minetest.register_on_mods_loaded(function()
5         registered_nodes  = minetest.registered_nodes
6 end)
7
8 local excluded_mods = {utility=true,craftingtable=true,buildtest=true,sign=true,bed=true}
9 local excluded_nodes = {
10         ["redstone:piston_on"]=true,
11         ["redstone:sticky_piston_on"]=true,
12         ["redstone:actuator"]=true,
13         ["redstone:sticky_actuator"]=true,
14         ["redstone:inverter_on"]=true,
15         ["redstone:inverter_off"]=true,
16         ["redstone:torch_wall"]=true,
17         ["redstone:torch_floor"]=true,
18         ["redstone:lever_on"]=true,
19         ["redstone:lever_off"]=true,
20         ["redstone:button_on"]=true,
21         ["redstone:button_off"]=true,
22 }
23 for i = 0,8 do
24         excluded_nodes["redstone:dust_"..i] = true
25 end
26 for i = 0,7 do
27         excluded_nodes["redstone:repeater_on_"..i] = true
28         excluded_nodes["redstone:repeater_off_"..i] = true
29 end
30 for i = 0,9 do
31         excluded_nodes["redstone:comparator_"..i] = true
32 end
33 for i = 0,9 do
34         excluded_nodes["redstone:pressure_plate_"..i] = true
35 end
36 for i = 0,1 do
37         excluded_nodes["redstone:ore_"..i] = true
38 end
39
40
41 --[[
42 ███████╗██╗   ██╗███╗   ██╗ ██████╗████████╗██╗ ██████╗ ███╗   ██╗
43 ██╔════╝██║   ██║████╗  ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗  ██║
44 █████╗  ██║   ██║██╔██╗ ██║██║        ██║   ██║██║   ██║██╔██╗ ██║
45 ██╔══╝  ██║   ██║██║╚██╗██║██║        ██║   ██║██║   ██║██║╚██╗██║
46 ██║     ╚██████╔╝██║ ╚████║╚██████╗   ██║   ██║╚██████╔╝██║ ╚████║
47 ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝   ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
48 ]]
49
50 --this is how the piston pushes nodes
51 local move_index
52 local space
53 local index_pos
54 local node
55 local param2
56 local def
57 local push
58 local index
59 local function push_nodes(pos,dir)
60         move_index = {}
61         space = false
62         for i = 1,30 do
63                 index_pos = vector.add(vector.multiply(dir,i),pos)
64                 node = minetest.get_node(index_pos)
65                 param2 = node.param2
66                 def = minetest.registered_nodes[node.name]
67                 name = node.name
68                 push = ((excluded_mods[def.mod_origin] ~= true) and (excluded_nodes[name] ~= true))
69                 if push and name ~= "air" then
70                         index = {}
71                         index.pos = index_pos
72                         index.name = name
73                         index.param2 = param2
74                         table.insert(move_index,index)
75                 elseif name == "air" then
76                         space = true
77                         break
78                 else
79                         space = false
80                         break
81                 end             
82         end
83
84         --check if room to move and objects in log
85         if space == true and next(move_index) then
86                 if table.getn(move_index) == 1 and minetest.get_item_group(move_index[1].name, "falling_node") > 0 then
87                         for i = 1,table.getn(move_index) do
88                                 move_index[i].pos = vector.add(move_index[i].pos,dir)
89                                 minetest.set_node(move_index[i].pos,{name="air"})
90
91                                 local obj = minetest.add_entity(vector.add(move_index[i].pos,dir), "__builtin:falling_node")
92                                 obj:get_luaentity():set_node({name=move_index[i].name})
93                                 obj:set_velocity(vector.multiply(dir,19))
94                         end
95                 else
96                         for i = 1,table.getn(move_index) do
97                                 if move_index[i] then
98                                         if move_index[i].pos then
99                                                 move_index[i].pos = vector.add(move_index[i].pos,dir)
100                                                 minetest.set_node(move_index[i].pos,move_index[i])
101                                                 minetest.check_for_falling(move_index[i].pos)
102                                         end
103                                 end
104                         end
105                 end
106         end
107         return(space)
108 end
109
110 --this is the logic of the piston
111 local facedir
112 local dir
113 local piston_location
114 local worked
115 local function actuator_arm_function(pos)
116         --this is where the piston activates
117         facedir = minetest.get_node(pos).param2
118         dir = minetest.facedir_to_dir(facedir)
119         piston_location = vector.add(pos,dir)
120         worked = push_nodes(pos,dir)
121         local node = minetest.get_node(vector.add(pos,dir)).name
122         
123         if worked == true then
124                 --push player
125                 if node == "air" then
126                         for _,object in ipairs(minetest.get_objects_inside_radius(piston_location, 2)) do
127
128                                 if object:is_player() and object:get_hp() > 0 then
129                                         local pos2 = object:get_pos()
130                                         local compare = vector.subtract(pos2,piston_location)
131                                         local real_y = compare.y
132                                         compare = vector.abs(compare)
133                                         --piston pointing up
134                                         if dir.y == 1 then
135                                                 if compare.y <= 0.5 and compare.x < 0.8 and compare.z < 0.8 then
136                                                         object:move_to(vector.add(dir,pos2))
137                                                         object:add_player_velocity(vector.multiply(dir,20))
138                                                 end
139                                         --piston sideways
140                                         elseif dir.x ~=0 or dir.z ~= 0 then
141                                                 if real_y <= 0.5 and real_y >= -1.6 and compare.x < 0.8 and compare.z < 0.8 then
142                                                         object:move_to(vector.add(dir,pos2))
143                                                         object:add_player_velocity(vector.multiply(dir,19))
144                                                 end
145                                         end
146                                 elseif not object:is_player() and object:get_luaentity().name == "__builtin:falling_node" then
147                                         local pos2 = object:get_pos()
148                                         local compare = vector.subtract(pos2,piston_location)
149                                         local real_y = compare.y
150                                         compare = vector.abs(compare)
151                                         if compare.y <= 1.5 and compare.x <= 1.5 and compare.z <= 1.5 then
152                                                 object:move_to(vector.add(dir,pos2))
153                                                 object:add_velocity(vector.multiply(dir,20))
154                                         end
155                                 elseif not object:is_player() and object:get_luaentity().name == "__builtin:item" then
156                                         local pos2 = object:get_pos()
157                                         local compare = vector.subtract(pos2,piston_location)
158                                         local real_y = compare.y
159                                         compare = vector.abs(compare)
160                                         if compare.y <= 1 and compare.x <= 1 and compare.z <= 1 then
161                                                 object:move_to(vector.add(dir,pos2))
162                                                 object:add_velocity(vector.multiply(dir,20))
163                                                 object:get_luaentity().poll_timer = 0
164                                         end
165                                 end
166                         end
167                 end
168                 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
169                 minetest.set_node(piston_location,{name="redstone:actuator",param2=facedir})
170                 minetest.swap_node(pos,{name="redstone:piston_on",param2=facedir})
171
172                 redstone.inject(pos,{
173                         name = "redstone:piston_on",
174                         activator = true,
175                 })
176                 redstone.update(pos)
177         end
178 end
179
180
181 --[[
182  ██████╗ ███████╗███████╗
183 ██╔═══██╗██╔════╝██╔════╝
184 ██║   ██║█████╗  █████╗  
185 ██║   ██║██╔══╝  ██╔══╝  
186 ╚██████╔╝██║     ██║     
187  ╚═════╝ ╚═╝     ╚═╝     
188 ]]
189
190
191 minetest.register_node("redstone:piston_off", {
192     description = "Piston",
193     tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","wood.png","stone.png"},
194     paramtype2 = "facedir",
195     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
196     sounds = main.stoneSound(),
197     drop = "redstone:piston_off",
198     paramtype = "light",
199         sunlight_propagates = true,
200         --reverse the direction to face the player
201         on_construct = function(pos)
202                 redstone.inject(pos,{
203                         name = "redstone:piston_off",
204                         activator = true,
205                 })
206                 redstone.update(pos)
207         end,
208     after_place_node = function(pos, placer, itemstack, pointed_thing)
209                 local look = placer:get_look_dir()
210                 look = vector.multiply(look,-1)
211                 local dir = minetest.dir_to_facedir(look, true)
212                 minetest.swap_node(pos,{name="redstone:piston_off",param2=dir})
213         end,
214         after_destruct = function(pos, oldnode)
215                 redstone.inject(pos,nil)
216     end,
217 })
218
219
220 redstone.register_activator({
221         name = "redstone:piston_off",
222         activate = function(pos)
223                 minetest.after(0,function()
224                         actuator_arm_function(pos)
225                 end)
226         end
227 })
228
229 minetest.register_lbm({
230         name = "redstone:piston_off",
231         nodenames = {"redstone:piston_off"},
232         run_at_every_load = true,
233         action = function(pos)
234                 redstone.inject(pos,{
235                         name = "redstone:piston_off",
236                         activator = true,
237                 })
238                 --redstone needs to warm up
239                 minetest.after(0,function()
240                         redstone.update(pos)
241                 end)
242         end,
243 })
244
245
246 --[[
247  ██████╗ ███╗   ██╗
248 ██╔═══██╗████╗  ██║
249 ██║   ██║██╔██╗ ██║
250 ██║   ██║██║╚██╗██║
251 ╚██████╔╝██║ ╚████║
252  ╚═════╝ ╚═╝  ╚═══╝
253 ]]
254
255 minetest.register_node("redstone:piston_on", {
256     description = "Piston",
257     tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","stone.png","stone.png"},
258     drawtype = "nodebox",
259     paramtype = "light",
260     paramtype2 = "facedir",
261     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
262     sounds = main.stoneSound(),
263     drop = "redstone:piston_off",
264     node_box = {
265                 type = "fixed",
266                 fixed = {
267                                 --left front bottom right back top
268                                 {-0.5, -0.5,  -0.5, 0.5,  0.5, 3/16},
269                         },
270                 },
271     after_destruct = function(pos, oldnode)
272                 local facedir = oldnode.param2
273                 local dir = minetest.facedir_to_dir(facedir)
274                 local piston_location = vector.add(pos,dir)
275                 minetest.remove_node(piston_location)
276                 redstone.inject(pos,nil)
277     end,
278 })
279
280 minetest.register_lbm({
281         name = "redstone:piston_on",
282         nodenames = {"redstone:piston_on"},
283         run_at_every_load = true,
284         action = function(pos)
285                 redstone.inject(pos,{
286                         name = "redstone:piston_on",
287                         activator = true,
288                 })
289                 --redstone needs to warm up
290                 minetest.after(0,function()
291                         redstone.update(pos)
292                 end)
293         end,
294 })
295
296 redstone.register_activator({
297         name = "redstone:piston_on",
298         deactivate = function(pos)
299                 --this is where the piston deactivates
300                 local facedir = minetest.get_node(pos).param2
301                 local dir = minetest.facedir_to_dir(facedir)
302                 local piston_location = vector.add(pos,dir)
303                 minetest.remove_node(piston_location)
304                 minetest.swap_node(pos,{name="redstone:piston_off",param2=facedir})
305                 piston_location.y = piston_location.y + 1
306                 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
307                 redstone.inject(pos,{
308                         name = "redstone:piston_off",
309                         activator = true,
310                 })
311         end
312 })
313
314
315 --[[
316  █████╗ ██████╗ ███╗   ███╗
317 ██╔══██╗██╔══██╗████╗ ████║
318 ███████║██████╔╝██╔████╔██║
319 ██╔══██║██╔══██╗██║╚██╔╝██║
320 ██║  ██║██║  ██║██║ ╚═╝ ██║
321 ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝
322 ]]
323
324
325
326 minetest.register_node("redstone:actuator", {
327     description = "Piston Actuator",
328     tiles = {"wood.png"},
329     drawtype = "nodebox",
330     paramtype = "light",
331     paramtype2 = "facedir",
332     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
333     sounds = main.stoneSound(),
334     drop = "redstone:piston_off",
335     node_box = {
336                 type = "fixed",
337                 fixed = {
338                                 --left front bottom right back top
339                                 {-0.5, -0.5,  0.2, 0.5,  0.5, 0.5}, --mover
340                                 {-0.15, -0.15,  -0.9, 0.15,  0.15, 0.5}, --actuator
341                         },
342                 },
343         after_destruct = function(pos, oldnode)
344                 local facedir = oldnode.param2
345                 local dir = minetest.facedir_to_dir(facedir)
346                 dir = vector.multiply(dir,-1)
347                 local piston_location = vector.add(pos,dir)
348                 minetest.remove_node(piston_location)
349     end,
350 })
351
352
353
354
355
356 --[[
357 ███████╗████████╗██╗ ██████╗██╗  ██╗██╗   ██╗    ██████╗ ██╗███████╗████████╗ ██████╗ ███╗   ██╗    ██████╗ ███████╗ ██████╗ ██╗███╗   ██╗███████╗
358 ██╔════╝╚══██╔══╝██║██╔════╝██║ ██╔╝╚██╗ ██╔╝    ██╔══██╗██║██╔════╝╚══██╔══╝██╔═══██╗████╗  ██║    ██╔══██╗██╔════╝██╔════╝ ██║████╗  ██║██╔════╝
359 ███████╗   ██║   ██║██║     █████╔╝  ╚████╔╝     ██████╔╝██║███████╗   ██║   ██║   ██║██╔██╗ ██║    ██████╔╝█████╗  ██║  ███╗██║██╔██╗ ██║███████╗
360 ╚════██║   ██║   ██║██║     ██╔═██╗   ╚██╔╝      ██╔═══╝ ██║╚════██║   ██║   ██║   ██║██║╚██╗██║    ██╔══██╗██╔══╝  ██║   ██║██║██║╚██╗██║╚════██║
361 ███████║   ██║   ██║╚██████╗██║  ██╗   ██║       ██║     ██║███████║   ██║   ╚██████╔╝██║ ╚████║    ██████╔╝███████╗╚██████╔╝██║██║ ╚████║███████║
362 ╚══════╝   ╚═╝   ╚═╝ ╚═════╝╚═╝  ╚═╝   ╚═╝       ╚═╝     ╚═╝╚══════╝   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝    ╚═════╝ ╚══════╝ ╚═════╝ ╚═╝╚═╝  ╚═══╝╚══════╝
363 ]]--
364
365
366
367
368
369
370
371 --[[
372 ███████╗██╗   ██╗███╗   ██╗ ██████╗████████╗██╗ ██████╗ ███╗   ██╗
373 ██╔════╝██║   ██║████╗  ██║██╔════╝╚══██╔══╝██║██╔═══██╗████╗  ██║
374 █████╗  ██║   ██║██╔██╗ ██║██║        ██║   ██║██║   ██║██╔██╗ ██║
375 ██╔══╝  ██║   ██║██║╚██╗██║██║        ██║   ██║██║   ██║██║╚██╗██║
376 ██║     ╚██████╔╝██║ ╚████║╚██████╗   ██║   ██║╚██████╔╝██║ ╚████║
377 ╚═╝      ╚═════╝ ╚═╝  ╚═══╝ ╚═════╝   ╚═╝   ╚═╝ ╚═════╝ ╚═╝  ╚═══╝
378 ]]
379
380
381 --this is how the piston pushes nodes
382 local move_index
383 local space
384 local index_pos
385 local node
386 local param2
387 local def
388 local push
389 local index
390 local function sticky_push_nodes(pos,dir)
391         move_index = {}
392         space = false
393         for i = 1,30 do
394                 index_pos = vector.add(vector.multiply(dir,i),pos)
395                 node = minetest.get_node(index_pos)
396                 param2 = node.param2
397                 def = minetest.registered_nodes[node.name]
398                 name = node.name
399                 push = ((excluded_mods[def.mod_origin] ~= true) and (excluded_nodes[name] ~= true))
400                 if push and name ~= "air" then
401                         index = {}
402                         index.pos = index_pos
403                         index.name = name
404                         index.param2 = param2
405                         table.insert(move_index,index)
406                 elseif name == "air" then
407                         space = true
408                         break
409                 else
410                         space = false
411                         break
412                 end             
413         end
414
415         --check if room to move and objects in log
416         if space == true and next(move_index) then
417                 for i = 1,table.getn(move_index) do
418                         move_index[i].pos = vector.add(move_index[i].pos,dir)
419                         minetest.set_node(move_index[i].pos,move_index[i])
420                         minetest.check_for_falling(move_index[i].pos)
421                 end
422         end
423         return(space)
424 end
425
426 --this is the logic of the piston
427 local facedir
428 local dir
429 local piston_location
430 local worked
431 local function sticky_actuator_arm_function(pos)
432         --this is where the piston activates
433         facedir = minetest.get_node(pos).param2
434         dir = minetest.facedir_to_dir(facedir)
435         piston_location = vector.add(pos,dir)
436         worked = sticky_push_nodes(pos,dir)
437         local node = minetest.get_node(vector.add(pos,dir)).name
438         
439         if worked == true then
440                 --push player
441                 if node == "air" then
442                         for _,object in ipairs(minetest.get_objects_inside_radius(piston_location, 2)) do
443
444                                 if object:is_player() and object:get_hp() > 0 then
445                                         local pos2 = object:get_pos()
446                                         local compare = vector.subtract(pos2,piston_location)
447                                         local real_y = compare.y
448                                         compare = vector.abs(compare)
449                                         --piston pointing up
450                                         if dir.y == 1 then
451                                                 if compare.y <= 0.5 and compare.x < 0.8 and compare.z < 0.8 then
452                                                         object:move_to(vector.add(dir,pos2))
453                                                 end
454                                         --piston sideways
455                                         elseif dir.x ~=0 or dir.z ~= 0 then
456                                                 if real_y <= 0.5 and real_y >= -1.6 and compare.x < 0.8 and compare.z < 0.8 then
457                                                         object:move_to(vector.add(dir,pos2))
458                                                 end
459                                         end
460                                 elseif not object:is_player() and object:get_luaentity().name == "__builtin:falling_node" then
461                                         local pos2 = object:get_pos()
462                                         local compare = vector.subtract(pos2,piston_location)
463                                         local real_y = compare.y
464                                         compare = vector.abs(compare)
465                                         if compare.y <= 1.5 and compare.x <= 1.5 and compare.z <= 1.5 then
466                                                 object:move_to(vector.add(dir,pos2))
467                                         end
468                                 elseif not object:is_player() and object:get_luaentity().name == "__builtin:item" then
469                                         local pos2 = object:get_pos()
470                                         local compare = vector.subtract(pos2,piston_location)
471                                         local real_y = compare.y
472                                         compare = vector.abs(compare)
473                                         if compare.y <= 1 and compare.x <= 1 and compare.z <= 1 then
474                                                 object:move_to(vector.add(dir,pos2))
475                                                 object:get_luaentity().poll_timer = 0
476                                         end
477                                 end
478                         end
479                 end
480                 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
481                 minetest.set_node(piston_location,{name="redstone:sticky_actuator",param2=facedir})
482                 minetest.swap_node(pos,{name="redstone:sticky_piston_on",param2=facedir})
483
484                 redstone.inject(pos,{
485                         name = "redstone:sticky_piston_on",
486                         activator = true,
487                 })
488                 
489                 redstone.update(pos)
490         end
491 end
492
493
494 --[[
495  ██████╗ ███████╗███████╗
496 ██╔═══██╗██╔════╝██╔════╝
497 ██║   ██║█████╗  █████╗  
498 ██║   ██║██╔══╝  ██╔══╝  
499 ╚██████╔╝██║     ██║     
500  ╚═════╝ ╚═╝     ╚═╝     
501 ]]
502
503
504 minetest.register_node("redstone:sticky_piston_off", {
505     description = "Sticky Piston",
506     tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","sticky_piston.png","stone.png"},
507     paramtype2 = "facedir",
508     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
509     sounds = main.stoneSound(),
510     drop = "redstone:sticky_piston_off",
511     paramtype = "light",
512         sunlight_propagates = true,
513         on_construct = function(pos)
514                 redstone.inject(pos,{
515                         name = "redstone:sticky_piston_off",
516                         activator = true,
517                 })
518                 redstone.update(pos)
519         end,
520     --reverse the direction to face the player
521     after_place_node = function(pos, placer, itemstack, pointed_thing)
522                 local look = placer:get_look_dir()
523                 look = vector.multiply(look,-1)
524                 local dir = minetest.dir_to_facedir(look, true)
525                 minetest.swap_node(pos,{name="redstone:sticky_piston_off",param2=dir})
526         end,
527         after_destruct = function(pos, oldnode)
528                 redstone.inject(pos,nil)
529     end,
530 })
531
532
533 redstone.register_activator({
534         name = "redstone:sticky_piston_off",
535         activate = function(pos)
536                 minetest.after(0,function()
537                         sticky_actuator_arm_function(pos)
538                 end)
539         end
540 })
541
542 minetest.register_lbm({
543         name = "redstone:sticky_piston_off",
544         nodenames = {"redstone:sticky_piston_off"},
545         run_at_every_load = true,
546         action = function(pos)
547                 redstone.inject(pos,{
548                         name = "redstone:sticky_piston_off",
549                         activator = true,
550                 })
551                 --redstone needs to warm up
552                 minetest.after(0,function()
553                         redstone.update(pos)
554                 end)
555         end,
556 })
557
558
559 --[[
560  ██████╗ ███╗   ██╗
561 ██╔═══██╗████╗  ██║
562 ██║   ██║██╔██╗ ██║
563 ██║   ██║██║╚██╗██║
564 ╚██████╔╝██║ ╚████║
565  ╚═════╝ ╚═╝  ╚═══╝
566 ]]
567
568 local function sticky_piston_pull_nodes(pos,dir)
569         local move_index = {}
570         local index_pos = vector.add(pos,dir)
571         
572         local node = minetest.get_node(index_pos)
573         local param2 = node.param2
574         local def = minetest.registered_nodes[node.name]
575         local name = node.name
576         local pull = ((excluded_mods[def.mod_origin] ~= true) and (excluded_nodes[name] ~= true))
577         --if it can be pulled pull it
578         if pull and name ~= "air" then
579                 minetest.remove_node(index_pos)
580                 minetest.set_node(pos,{name=name,param2=param2})
581         end
582 end
583
584
585
586
587 minetest.register_node("redstone:sticky_piston_on", {
588     description = "Sticky Piston",
589     tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","stone.png","stone.png"},
590     drawtype = "nodebox",
591     paramtype = "light",
592     paramtype2 = "facedir",
593     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
594     sounds = main.stoneSound(),
595     drop = "redstone:sticky_piston_off",
596     node_box = {
597                 type = "fixed",
598                 fixed = {
599                                 --left front bottom right back top
600                                 {-0.5, -0.5,  -0.5, 0.5,  0.5, 3/16},
601                         },
602                 },
603     after_destruct = function(pos, oldnode)
604                 local facedir = oldnode.param2
605                 local dir = minetest.facedir_to_dir(facedir)
606                 local piston_location = vector.add(pos,dir)
607                 minetest.remove_node(piston_location)
608                 redstone.inject(pos,nil)
609     end,
610 })
611
612 minetest.register_lbm({
613         name = "redstone:sticky_piston_on",
614         nodenames = {"redstone:sticky_piston_on"},
615         run_at_every_load = true,
616         action = function(pos)
617                 redstone.inject(pos,{
618                         name = "redstone:sticky_piston_on",
619                         activator = true,
620                 })
621                 --redstone needs to warm up
622                 minetest.after(0,function()
623                         redstone.update(pos)
624                 end)
625         end,
626 })
627
628 redstone.register_activator({
629         name = "redstone:sticky_piston_on",
630         deactivate = function(pos)
631                 --this is where the piston deactivates
632                 local facedir = minetest.get_node(pos).param2
633                 local dir = minetest.facedir_to_dir(facedir)
634                 local piston_location = vector.add(pos,dir)
635                 
636                 minetest.remove_node(piston_location)
637
638                 sticky_piston_pull_nodes(piston_location,dir)
639                 minetest.swap_node(pos,{name="redstone:sticky_piston_off",param2=facedir})
640
641                 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
642                 redstone.inject(pos,{
643                         name = "redstone:sticky_piston_off",
644                         activator = true,
645                 })
646         end
647 })
648
649
650 --[[
651  █████╗ ██████╗ ███╗   ███╗
652 ██╔══██╗██╔══██╗████╗ ████║
653 ███████║██████╔╝██╔████╔██║
654 ██╔══██║██╔══██╗██║╚██╔╝██║
655 ██║  ██║██║  ██║██║ ╚═╝ ██║
656 ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝     ╚═╝
657 ]]
658
659
660
661 minetest.register_node("redstone:sticky_actuator", {
662     description = "Piston Actuator",
663     tiles = {"wood.png","wood.png","wood.png","wood.png","sticky_piston.png","wood.png"},
664     drawtype = "nodebox",
665     paramtype = "light",
666     paramtype2 = "facedir",
667     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
668     sounds = main.stoneSound(),
669     drop = "redstone:piston_off",
670     node_box = {
671                 type = "fixed",
672                 fixed = {
673                                 --left front bottom right back top
674                                 {-0.5, -0.5,  0.2, 0.5,  0.5, 0.5}, --mover
675                                 {-0.15, -0.15,  -0.9, 0.15,  0.15, 0.5}, --actuator
676                         },
677                 },
678         after_destruct = function(pos, oldnode)
679                 local facedir = oldnode.param2
680                 local dir = minetest.facedir_to_dir(facedir)
681                 dir = vector.multiply(dir,-1)
682                 local piston_location = vector.add(pos,dir)
683                 minetest.remove_node(piston_location)
684     end,
685 })
686