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