]> git.lizzy.rs Git - Crafter.git/commitdiff
Make levers use node meta, to place on anything
authoroilboi <47129783+oilboi@users.noreply.github.com>
Fri, 26 Jun 2020 09:20:26 +0000 (05:20 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Fri, 26 Jun 2020 09:20:26 +0000 (05:20 -0400)
mods/redstone/init.lua
mods/redstone/lever.lua
mods/redstone/light.lua

index fa384157e13cdce091aba423a6aea3c2ff9f31aa..2e74c74d49ca774d1c1cf5313f72a404d2bb503a 100644 (file)
@@ -161,13 +161,20 @@ localredstone.injector = function(i)
                if not a_index[i.x][i.y][i.z] then a_index[i.x][i.y][i.z] = {} end
                a_index[i.x][i.y][i.z].redstone_activation = true
        end
+
+       --sneaky way to make levers and buttons work
+       if get_meta(i):get_int("redstone_power") > 0 then
+               if not r_index[i.x] then r_index[i.x] = {} end
+               if not r_index[i.x][i.y] then r_index[i.x][i.y] = {} end
+               r_index[i.x][i.y][i.z] = {torch = true,power=9}
+       end
 end
 
 localredstone.collector = function(pos)
        for x = -1,1 do
        for y = -1,1 do
        for z = -1,1 do
-               if abs(x)+abs(y)+abs(z) == 1 then
+               if abs(x)+abs(z) == 1 then
                        localredstone.injector(add_vec(pos,new_vec(x,y,z)))
                end
        end
@@ -299,7 +306,7 @@ local function redstone_pathfinder(source,source_level,direction)
                for x = -1,1 do
                for y = -1,1 do
                for z = -1,1 do
-                       if not (abs(x)+abs(z) > 1) or (abs(x)+abs(z) == 0) then
+                       if abs(x)+abs(z) == 1 then
                                i = add_vec(source,new_vec(x,y,z))
                                if r_index and r_index[i.x] and r_index[i.x][i.y] and r_index[i.x][i.y][i.z] then
                                        index = r_index[i.x][i.y][i.z]                                  
index 1e7967a4ed3afef89726fc4a8a2a10d5d2ec23b6..82824b311982e91e5705b22bd5bbb5c261b0c904 100644 (file)
@@ -1,42 +1,5 @@
 
 local minetest,vector,math,pairs = minetest,vector,math,pairs
---create torch versions of the nodes
-for name,def in pairs(minetest.registered_nodes) do
-       if def.drawtype == "normal" and string.match(name, "main:") then
-               local def2 = table.copy(def)
-               def2.groups.redstone_torch = 1
-               def2.groups.redstone_power=9
-               def2.drop = def.drop
-               def2.mod_origin = "redstone"
-               --def2.textures = "dirt.png"
-               def2.after_destruct = function(pos, oldnode)
-                       redstone.collect_info(pos)
-               end
-               local newname = "redstone:node_activated_"..string.gsub(name, "main:", "")
-               def2.name = newname
-               def2.description = "Redstone "..def.description
-               minetest.register_node(newname,def2)
-       end
-end
-
-
---this removes power from node that the lever is powering
-local function on_lever_destroy(pos)
-       local param2 = minetest.get_node(pos).param2
-       local self = minetest.get_node(pos)
-       local dir = minetest.wallmounted_to_dir(self.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:node_activated_")then
-               name = "main:"..string.gsub(name, "redstone:node_activated_", "")
-               minetest.swap_node(pos, {name=name})
-               redstone.collect_info(pos)
-       end
-end
 
 
 minetest.register_node("redstone:lever_off", {
@@ -60,21 +23,28 @@ minetest.register_node("redstone:lever_off", {
                },
     on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
                minetest.set_node(pos, {name="redstone:lever_on",param2=node.param2})
+               minetest.sound_play("lever", {pos=pos})
+
                local dir = minetest.wallmounted_to_dir(node.param2)
-               local pos = vector.add(dir,pos)
-               local name = minetest.get_node(pos).name
-               local def = minetest.registered_nodes[name]
+               pos = vector.add(dir,pos)
+       
+               local meta = minetest.get_meta(pos)
+
+               meta:set_int("redstone_power", 9)
+               
                
-               if def.drawtype == "normal" and string.match(name, "main:") then
-                       minetest.sound_play("lever", {pos=pos})
-                       name = "redstone:node_activated_"..string.gsub(name, "main:", "")
-                       minetest.swap_node(pos,{name=name})
-                       redstone.collect_info(pos)
-               else
-                       minetest.sound_play("lever", {pos=pos,pitch=0.6})
-               end
+               redstone.collect_info(pos)
+       end,
+       after_destruct = function(pos, oldnode)
+               local dir = minetest.wallmounted_to_dir(oldnode.param2)
+               pos = vector.add(dir,pos)
+       
+               local meta = minetest.get_meta(pos)
+
+               meta:set_int("redstone_power", 0)
+               
+               redstone.collect_info(pos)
        end,
-       on_destruct = on_lever_destroy,
 })
 minetest.register_node("redstone:lever_on", {
     description = "Lever On",
@@ -96,9 +66,27 @@ minetest.register_node("redstone:lever_on", {
                        },
                },
     on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
-               minetest.sound_play("lever", {pos=pos,pitch=0.8})
                minetest.set_node(pos, {name="redstone:lever_off",param2=node.param2})
-               on_lever_destroy(pos)
+
+               minetest.sound_play("lever", {pos=pos})
+
+               local dir = minetest.wallmounted_to_dir(node.param2)
+               pos = vector.add(dir,pos)
+       
+               local meta = minetest.get_meta(pos)
+
+               meta:set_int("redstone_power", 0)
+               
+               redstone.collect_info(pos)
+       end,
+       after_destruct = function(pos, oldnode)
+               local dir = minetest.wallmounted_to_dir(oldnode.param2)
+               pos = vector.add(dir,pos)
+       
+               local meta = minetest.get_meta(pos)
+
+               meta:set_int("redstone_power", 0)
+               
+               redstone.collect_info(pos)
        end,
-       on_destruct = on_lever_destroy,
 })
index 4a33e614eea880b02645cf16da8460a40274cca8..0ce26b8114322ad865d24ba98e2caa4b4028c3cd 100644 (file)
@@ -13,7 +13,8 @@ minetest.register_node("redstone:light_on", {
     redstone_activation = function(pos)
     end,
     redstone_deactivation = function(pos)
-               minetest.set_node(pos,{name="redstone:light_off"})
+    minetest.set_node(pos,{name="redstone:light_off"})
+    
     end,
 })
 minetest.register_node("redstone:light_off", {