1 --exclude certain mods and nodes from being pushed and pulled to stop glitches
2 local excluded_mods = {utility=true,craftingtable=true,buildtest=true,sign=true,bed=true}
3 local excluded_nodes = {["redstone:piston_on"]=true,["redstone:sticky_piston_on"]=true,["redstone:actuator"]=true,["redstone:sticky_actuator"]=true}
5 --this is how the piston pushes nodes
6 local function piston_push_nodes(pos,dir)
10 local index_pos = vector.multiply(dir,i)
11 local index_pos = vector.add(index_pos,pos)
12 local node = minetest.get_node(index_pos)
13 local param2 = node.param2
14 local def = minetest.registered_nodes[node.name]
15 local name = node.name
16 local push = ((excluded_mods[def.mod_origin] ~= true) and (excluded_nodes[name] ~= true))
17 if push and name ~= "air" then
22 table.insert(move_index,index)
23 elseif name == "air" then
31 --check if room to move and objects in log
32 if space == true and next(move_index) then
33 for i = 1,table.getn(move_index) do
34 move_index[i].pos = vector.add(move_index[i].pos,dir)
35 minetest.set_node(move_index[i].pos,{name=move_index[i].name,param2=move_index[i].param2})
41 --this is the logic of the piston
42 local function piston_push(pos)
43 --this is where the piston activates
44 local facedir = minetest.get_node(pos).param2
45 local dir = minetest.facedir_to_dir(facedir)
46 local piston_location = vector.add(pos,dir)
47 local worked = piston_push_nodes(pos,dir)
48 local node = minetest.get_node(vector.add(pos,dir)).name
49 if worked == true then
52 for _,object in ipairs(minetest.get_objects_inside_radius(piston_location, 2)) do
53 if object:is_player() and object:get_hp() > 0 then
54 local pos2 = object:get_pos()
55 local compare = vector.subtract(pos2,piston_location)
56 local real_y = compare.y
57 compare = vector.abs(compare)
60 if compare.y <= 0.5 and compare.x < 0.8 and compare.z < 0.8 then
61 object:move_to(vector.add(dir,pos2))
62 object:add_player_velocity(vector.multiply(dir,20))
65 elseif dir.x ~=0 or dir.z ~= 0 then
66 if real_y <= 0.5 and real_y >= -1.6 and compare.x < 0.8 and compare.z < 0.8 then
67 object:move_to(vector.add(dir,pos2))
68 object:add_player_velocity(vector.multiply(dir,20))
75 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
76 minetest.set_node(piston_location,{name="redstone:actuator",param2=facedir})
77 minetest.set_node(pos,{name="redstone:piston_on",param2=facedir})
82 minetest.register_node("redstone:piston_off", {
83 description = "Piston",
84 tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","wood.png","stone.png"},
85 paramtype2 = "facedir",
86 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
87 sounds = main.stoneSound(),
88 drop = "redstone:piston_off",
90 sunlight_propagates = true,
91 redstone_activation = function(pos)
92 if minetest.get_node(pos).name == "redstone:piston_off" then
96 --reverse the direction to face the player
97 after_place_node = function(pos, placer, itemstack, pointed_thing)
98 local look = placer:get_look_dir()
99 look = vector.multiply(look,-1)
100 dir = minetest.dir_to_facedir(look, true)
101 minetest.set_node(pos,{name="redstone:piston_off",param2=dir})
102 redstone.collect_info(pos)
105 minetest.register_node("redstone:piston_on", {
106 description = "Piston",
107 tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","stone.png","stone.png"},
108 drawtype = "nodebox",
110 paramtype2 = "facedir",
111 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
112 sounds = main.stoneSound(),
113 drop = "redstone:piston_off",
117 --left front bottom right back top
118 {-0.5, -0.5, -0.5, 0.5, 0.5, 3/16},
121 redstone_deactivation = function(pos)
122 --this is where the piston deactivates
123 local facedir = minetest.get_node(pos).param2
124 local dir = minetest.facedir_to_dir(facedir)
125 local piston_location = vector.add(pos,dir)
126 minetest.remove_node(piston_location)
127 minetest.set_node(pos,{name="redstone:piston_off",param2=facedir})
128 piston_location.y = piston_location.y + 1
129 minetest.punch_node(piston_location)
130 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
132 after_dig_node = function(pos, oldnode, oldmetadata, digger)
133 local facedir = oldnode.param2
134 local dir = minetest.facedir_to_dir(facedir)
135 local piston_location = vector.add(pos,dir)
136 minetest.remove_node(piston_location)
140 minetest.register_node("redstone:actuator", {
141 description = "Piston Actuator",
142 tiles = {"wood.png"},
143 drawtype = "nodebox",
145 paramtype2 = "facedir",
146 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
147 sounds = main.stoneSound(),
148 drop = "redstone:piston_off",
152 --left front bottom right back top
153 {-0.5, -0.5, 0.2, 0.5, 0.5, 0.5}, --mover
154 {-0.15, -0.15, -0.9, 0.15, 0.15, 0.5}, --actuator
157 after_dig_node = function(pos, oldnode, oldmetadata, digger)
158 local facedir = oldnode.param2
159 local dir = minetest.facedir_to_dir(facedir)
160 dir = vector.multiply(dir,-1)
161 local piston_location = vector.add(pos,dir)
162 minetest.remove_node(piston_location)
166 -------------------------------------------------------------------------------------------------------------------------------------------------------
167 --this is how the piston pushes nodes
168 local function sticky_piston_push_nodes(pos,dir)
169 local move_index = {}
172 local index_pos = vector.multiply(dir,i)
173 local index_pos = vector.add(index_pos,pos)
174 local node = minetest.get_node(index_pos)
175 local param2 = node.param2
176 local def = minetest.registered_nodes[node.name]
177 local name = node.name
178 local push = ((excluded_mods[def.mod_origin] ~= true) and (excluded_nodes[name] ~= true))
179 if push and name ~= "air" then
181 index.pos = index_pos
183 index.param2 = param2
184 table.insert(move_index,index)
185 elseif name == "air" then
193 --check if room to move and objects in log
194 if space == true and next(move_index) then
195 for i = 1,table.getn(move_index) do
196 move_index[i].pos = vector.add(move_index[i].pos,dir)
197 minetest.set_node(move_index[i].pos,{name=move_index[i].name,param2=move_index[i].param2})
203 --this is the logic of the piston
204 local function sticky_piston_push(pos)
205 --this is where the piston activates
206 local facedir = minetest.get_node(pos).param2
207 local dir = minetest.facedir_to_dir(facedir)
208 local piston_location = vector.add(pos,dir)
209 local worked = sticky_piston_push_nodes(pos,dir)
210 local node = minetest.get_node(vector.add(pos,dir)).name
211 if worked == true then
213 if node == "air" then
214 for _,object in ipairs(minetest.get_objects_inside_radius(piston_location, 2)) do
215 if object:is_player() and object:get_hp() > 0 then
216 local pos2 = object:get_pos()
217 local compare = vector.subtract(pos2,piston_location)
218 local real_y = compare.y
219 compare = vector.abs(compare)
222 if compare.y <= 0.5 and compare.x < 0.8 and compare.z < 0.8 then
223 object:move_to(vector.add(dir,pos2))
224 --object:add_player_velocity(vector.multiply(dir,20))
227 elseif dir.x ~=0 or dir.z ~= 0 then
228 if real_y <= 0.5 and real_y >= -1.6 and compare.x < 0.8 and compare.z < 0.8 then
229 object:move_to(vector.add(dir,pos2))
230 --object:add_player_velocity(vector.multiply(dir,20))
237 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
238 minetest.set_node(piston_location,{name="redstone:sticky_actuator",param2=facedir})
239 minetest.set_node(pos,{name="redstone:sticky_piston_on",param2=facedir})
245 --this is how sticky pistons pull nodes
246 local function sticky_piston_pull_nodes(pos,dir)
248 local move_index = {}
249 local index_pos = vector.add(pos,dir)
251 local node = minetest.get_node(index_pos)
252 local param2 = node.param2
253 local def = minetest.registered_nodes[node.name]
254 local name = node.name
255 local pull = ((excluded_mods[def.mod_origin] ~= true) and (excluded_nodes[name] ~= true))
256 --if it can be pulled pull it
257 if pull and name ~= "air" then
258 minetest.remove_node(index_pos)
259 minetest.set_node(pos,{name=name,param2=param2})
263 ------------------------------[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
265 --this is the logic of the sticky piston on return
266 local function sticky_piston_pull(pos,dir)
267 --this is where the piston activates
268 --local facedir = minetest.get_node(pos).param2
269 --local dir = minetest.facedir_to_dir(facedir)
270 --local piston_location = vector.add(pos,dir)
272 local in_front_pos = vector.add(pos,dir)
274 local node = minetest.get_node(in_front_pos).name
276 sticky_piston_pull_nodes(pos,dir)
279 if node == "air" then
280 for _,object in ipairs(minetest.get_objects_inside_radius(in_front_pos, 2)) do
281 if object:is_player() and object:get_hp() > 0 then
282 local pos2 = object:get_pos()
283 local compare = vector.subtract(pos2,in_front_pos)
284 local real_y = compare.y
285 compare = vector.abs(compare)
288 if compare.y <= 0.5 and compare.x < 0.8 and compare.z < 0.8 then
289 dir = vector.multiply(dir,-1)
290 object:move_to(vector.add(dir,pos2))
291 --object:add_player_velocity(vector.multiply(dir,20))
294 elseif dir.x ~=0 or dir.z ~= 0 then
295 if real_y <= 0.5 and real_y >= -1.6 and compare.x < 0.8 and compare.z < 0.8 then
296 dir = vector.multiply(dir,-1)
297 object:move_to(vector.add(dir,pos2))
298 --object:add_player_velocity(vector.multiply(dir,20))
305 minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
306 --minetest.set_node(piston_location,{name="redstone:sticky_actuator",param2=facedir})
307 --minetest.set_node(pos,{name="redstone:sticky_piston_on",param2=facedir})
310 ------------------------------[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
312 minetest.register_node("redstone:sticky_piston_off", {
313 description = "Sticky Piston",
314 tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","sticky_piston.png","stone.png"},
315 paramtype2 = "facedir",
316 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
317 sounds = main.stoneSound(),
318 drop = "redstone:sticky_piston_off",
320 sunlight_propagates = true,
321 redstone_activation = function(pos)
322 if minetest.get_node(pos).name == "redstone:sticky_piston_off" then
323 sticky_piston_push(pos)
326 --reverse the direction to face the player
327 after_place_node = function(pos, placer, itemstack, pointed_thing)
328 local look = placer:get_look_dir()
329 look = vector.multiply(look,-1)
330 dir = minetest.dir_to_facedir(look, true)
331 minetest.set_node(pos,{name="redstone:sticky_piston_off",param2=dir})
332 redstone.collect_info(pos)
337 --------------------------
340 minetest.register_node("redstone:sticky_piston_on", {
341 description = "Sticky Piston",
342 tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","stone.png","stone.png"},
343 drawtype = "nodebox",
345 paramtype2 = "facedir",
346 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
347 sounds = main.stoneSound(),
348 drop = "redstone:sticky_piston_off",
352 --left front bottom right back top
353 {-0.5, -0.5, -0.5, 0.5, 0.5, 3/16},
356 redstone_deactivation = function(pos)
357 --this is where the piston deactivates
358 local facedir = minetest.get_node(pos).param2
359 local dir = minetest.facedir_to_dir(facedir)
360 local piston_location = vector.add(pos,dir)
361 minetest.remove_node(piston_location)
362 minetest.set_node(pos,{name="redstone:sticky_piston_off",param2=facedir})
364 sticky_piston_pull(piston_location,dir)
366 piston_location.y = piston_location.y + 1
367 minetest.punch_node(piston_location)
368 --minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
370 after_dig_node = function(pos, oldnode, oldmetadata, digger)
371 local facedir = oldnode.param2
372 local dir = minetest.facedir_to_dir(facedir)
373 local piston_location = vector.add(pos,dir)
374 minetest.remove_node(piston_location)
378 minetest.register_node("redstone:sticky_actuator", {
379 description = "Redstone Piston",
380 tiles = {"wood.png","wood.png","wood.png","wood.png","sticky_piston.png","wood.png"},
381 drawtype = "nodebox",
383 paramtype2 = "facedir",
384 groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
385 sounds = main.stoneSound(),
386 drop = "redstone:sticky_piston_off",
390 --left front bottom right back top
391 {-0.5, -0.5, 0.2, 0.5, 0.5, 0.5}, --mover
392 {-0.15, -0.15, -0.9, 0.15, 0.15, 0.5}, --actuator
395 after_dig_node = function(pos, oldnode, oldmetadata, digger)
396 local facedir = oldnode.param2
397 local dir = minetest.facedir_to_dir(facedir)
398 dir = vector.multiply(dir,-1)
399 local piston_location = vector.add(pos,dir)
400 minetest.remove_node(piston_location)