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