]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/redstone/piston.lua
Extreme redstone optimizations
[Crafter.git] / mods / redstone / piston.lua
index 1acea75106b24a5fdc7344f5cdd5e74e8ac3d480..294479814fc6f86a3de8322bdf9d954810d490fe 100644 (file)
@@ -85,7 +85,6 @@ local function push_nodes(pos,dir)
        if space == true and next(move_index) then
                if table.getn(move_index) == 1 and minetest.get_item_group(move_index[1].name, "falling_node") > 0 then
                        for i = 1,table.getn(move_index) do
-                               print("trying")
                                move_index[i].pos = vector.add(move_index[i].pos,dir)
                                minetest.set_node(move_index[i].pos,{name="air"})
 
@@ -95,9 +94,13 @@ local function push_nodes(pos,dir)
                        end
                else
                        for i = 1,table.getn(move_index) do
-                               move_index[i].pos = vector.add(move_index[i].pos,dir)
-                               minetest.set_node(move_index[i].pos,move_index[i])
-                               minetest.check_for_falling(move_index[i].pos)
+                               if move_index[i] then
+                                       if move_index[i].pos then
+                                       move_index[i].pos = vector.add(move_index[i].pos,dir)
+                                       minetest.set_node(move_index[i].pos,move_index[i])
+                                       minetest.check_for_falling(move_index[i].pos)
+                                       end
+                               end
                        end
                end
        end
@@ -497,7 +500,7 @@ end
 
 minetest.register_node("redstone:sticky_piston_off", {
     description = "Sticky Piston",
-    tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","wood.png","stone.png"},
+    tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","sticky_piston.png","stone.png"},
     paramtype2 = "facedir",
     groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1,redstone_activation=1},
     sounds = main.stoneSound(),
@@ -554,6 +557,25 @@ minetest.register_lbm({
  ╚═════╝ ╚═╝  ╚═══╝
 ]]
 
+local function sticky_piston_pull_nodes(pos,dir)
+       local move_index = {}
+       local index_pos = vector.add(pos,dir)
+       
+       local node = minetest.get_node(index_pos)
+       local param2 = node.param2
+       local def = minetest.registered_nodes[node.name]
+       local name = node.name
+       local pull = ((excluded_mods[def.mod_origin] ~= true) and (excluded_nodes[name] ~= true))
+       --if it can be pulled pull it
+       if pull and name ~= "air" then
+               minetest.remove_node(index_pos)
+               minetest.set_node(pos,{name=name,param2=param2})
+       end
+end
+
+
+
+
 minetest.register_node("redstone:sticky_piston_on", {
     description = "Sticky Piston",
     tiles = {"redstone_piston.png","redstone_piston.png^[transformR180","redstone_piston.png^[transformR270","redstone_piston.png^[transformR90","stone.png","stone.png"},
@@ -595,15 +617,18 @@ minetest.register_lbm({
 })
 
 redstone.register_activator({
-       name = "redstone:piston_on",
+       name = "redstone:sticky_piston_on",
        deactivate = function(pos)
                --this is where the piston deactivates
                local facedir = minetest.get_node(pos).param2
                local dir = minetest.facedir_to_dir(facedir)
                local piston_location = vector.add(pos,dir)
+               
                minetest.remove_node(piston_location)
+
+               sticky_piston_pull_nodes(piston_location,dir)
                minetest.swap_node(pos,{name="redstone:sticky_piston_off",param2=facedir})
-               piston_location.y = piston_location.y + 1
+
                minetest.sound_play("piston", {pos=pos,pitch=math.random(85,100)/100})
                redstone.inject(pos,{
                        name = "redstone:sticky_piston_off",
@@ -626,7 +651,7 @@ redstone.register_activator({
 
 minetest.register_node("redstone:sticky_actuator", {
     description = "Piston Actuator",
-    tiles = {"wood.png"},
+    tiles = {"wood.png","wood.png","wood.png","wood.png","sticky_piston.png","wood.png"},
     drawtype = "nodebox",
     paramtype = "light",
     paramtype2 = "facedir",