]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/redstone/button.lua
Fix repeaters rotating sideways
[Crafter.git] / mods / redstone / button.lua
index 7e40b94825111667898c1cdd97c8cb4a6944657c..9fac557f3c78275c36ac2c92bc87eb7e6bf53f24 100644 (file)
@@ -1,16 +1,15 @@
---this removes power from node that the switch is powering
+local minetest,table,vector = minetest,table,vector
+--this removes power from node that the button is powering
 local function on_button_destroy(pos)
        local param2 = minetest.get_node(pos).param2
-       local self = minetest.get_node(pos)
-       local dir = minetest.facedir_to_dir(self.param2)
-       
+       local dir = minetest.wallmounted_to_dir(param2)
        local pos = vector.add(dir,pos)
        local node = minetest.get_node(pos)
        local name = node.name
-       
        local def = minetest.registered_nodes[name]
-       if def.drawtype == "normal" and string.match(name, "redstone:") then
-               name = "main:"..string.gsub(name, "redstone:", "")
+       
+       if def.drawtype == "normal" and string.match(name, "redstone:node_activated_") then
+               name = "main:"..string.gsub(name, "redstone:node_activated_", "")
                minetest.set_node(pos, {name=name})
                redstone.collect_info(pos)
        end
@@ -18,9 +17,9 @@ end
 
 
 minetest.register_node("redstone:button_off", {
-    description = "Crafting Table",
+    description = "Button",
     tiles = {"stone.png"},
-    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1},
+    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1},
     sounds = main.stoneSound(),
     paramtype = "light",
        paramtype2 = "wallmounted",
@@ -36,28 +35,31 @@ minetest.register_node("redstone:button_off", {
                        },
                },
     on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
-               minetest.sound_play("lever", {pos=pos})
                minetest.set_node(pos, {name="redstone:button_on",param2=node.param2})
-               local dir = minetest.facedir_to_dir(node.param2)
+               local dir = minetest.wallmounted_to_dir(node.param2)
                local c_pos = table.copy(pos)
                local pos = vector.add(dir,pos)
                local name = minetest.get_node(pos).name
                local def = minetest.registered_nodes[name]
                
                if def.drawtype == "normal" and string.match(name, "main:") then
-                       name = "redstone:"..string.gsub(name, "main:", "")
+                       minetest.sound_play("lever", {pos=pos})
+                       name = "redstone:node_activated_"..string.gsub(name, "main:", "")
                        minetest.set_node(pos,{name=name})
                        redstone.collect_info(pos)
-                       local timer = minetest.get_node_timer(c_pos)
-                       timer:start(1)
+               else
+                       minetest.sound_play("lever", {pos=pos,pitch=0.6})
                end
+               
+               local timer = minetest.get_node_timer(c_pos)
+               timer:start(1)
        end,
        on_destruct = on_button_destroy,
 })
 minetest.register_node("redstone:button_on", {
-    description = "Crafting Table",
+    description = "Button",
     tiles = {"stone.png"},
-    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1},
+    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1,dig_immediate=1},
     sounds = main.stoneSound(),
     paramtype = "light",
        paramtype2 = "wallmounted",