]> git.lizzy.rs Git - Crafter.git/commitdiff
Add in detector
authoroilboi <47129783+oilboi@users.noreply.github.com>
Wed, 1 Jul 2020 22:01:29 +0000 (18:01 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Wed, 1 Jul 2020 22:01:29 +0000 (18:01 -0400)
mods/redstone/craft.lua
mods/redstone/detector.lua [new file with mode: 0644]
mods/redstone/init.lua

index 26429a9abde2e0e484eca7c759a4c0f2f432b226..b0ce41ab334676787cbfdbef9fe9d68603fe3982 100644 (file)
@@ -69,6 +69,15 @@ minetest.register_craft({
        }
 })
 
+minetest.register_craft({
+       output = "redstone:detector_off",
+       recipe = {
+               {"main:stone","main:stone","main:stone"},
+               {"main:stone","main:ironpick","main:stone"},
+               {"main:stone","main:stone","main:stone"},
+       }
+})
+
 minetest.register_craft({
        output = "redstone:sticky_piston_off",
        type = "shapeless",
diff --git a/mods/redstone/detector.lua b/mods/redstone/detector.lua
new file mode 100644 (file)
index 0000000..b2c8f27
--- /dev/null
@@ -0,0 +1,155 @@
+minetest.register_node("redstone:detector_off", {
+    description = "Detector",
+    tiles = {"redstone_piston.png^[invert:rgb^[colorize:yellow:100",
+    "redstone_piston.png^[transformR180^[invert:rgb^[colorize:yellow:100",
+    "redstone_piston.png^[transformR270^[invert:rgb^[colorize:yellow:100",
+    "redstone_piston.png^[transformR90^[invert:rgb^[colorize:yellow:100",
+    "wood.png^[invert:rgb^[colorize:yellow:100",
+    "stone.png^[invert:rgb^[colorize:yellow:100"},
+    paramtype2 = "facedir",
+    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
+    sounds = main.stoneSound(),
+    drop = "redstone:detector_off",
+    paramtype = "light",
+    sunlight_propagates = true,
+    
+    on_timer = function(pos, elapsed)
+        local param2 = minetest.get_node(pos).param2
+        local dir = minetest.facedir_to_dir(param2)
+
+
+        if minetest.get_node(vector.add(pos,dir)).name ~= "air" then
+            minetest.swap_node(pos, {name="redstone:detector_on",param2=param2})
+            
+            redstone.inject(pos,{
+                name = "redstone:detector_on",
+                torch = 16,
+            })
+            minetest.after(0,function()
+               redstone.update(pos)
+            end)
+        end
+
+        local timer = minetest.get_node_timer(pos)
+        if not timer:is_started() then
+            timer:start(1)
+        end
+    end,
+    
+       --reverse the direction to face the player
+       on_construct = function(pos)
+               redstone.inject(pos,{
+                       name = "redstone:detector_off",
+        })
+        local timer = minetest.get_node_timer(pos)
+               if not timer:is_started() then
+                       timer:start(1)
+               end
+       end,
+       on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+               local look = clicker:get_look_dir()
+               look = vector.multiply(look,-1)
+               local dir = minetest.dir_to_facedir(look, true)
+               minetest.swap_node(pos,{name="redstone:detector_off",param2=dir})
+       end,
+    after_place_node = function(pos, placer, itemstack, pointed_thing)
+               local look = placer:get_look_dir()
+               look = vector.multiply(look,-1)
+               local dir = minetest.dir_to_facedir(look, true)
+               minetest.swap_node(pos,{name="redstone:detector_off",param2=dir})
+       end,
+       on_destruct = function(pos, oldnode)
+               redstone.inject(pos,nil)
+    end,
+})
+
+
+minetest.register_lbm({
+       name = "redstone:detector_off",
+       nodenames = {"redstone:detector_off"},
+       run_at_every_load = true,
+       action = function(pos)
+               redstone.inject(pos,{
+                       name = "redstone:detector_off",
+        })
+
+        local timer = minetest.get_node_timer(pos)
+               if not timer:is_started() then
+                       timer:start(1)
+               end
+       end,
+})
+
+
+minetest.register_node("redstone:detector_on", {
+    description = "Detector On",
+    tiles = {"redstone_piston.png^[invert:rgb^[colorize:green:100",
+    "redstone_piston.png^[transformR180^[invert:rgb^[colorize:green:100",
+    "redstone_piston.png^[transformR270^[invert:rgb^[colorize:green:100",
+    "redstone_piston.png^[transformR90^[invert:rgb^[colorize:green:100",
+    "wood.png^[invert:rgb^[colorize:green:100",
+    "stone.png^[invert:rgb^[colorize:green:100"},
+    paramtype2 = "facedir",
+    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
+    sounds = main.stoneSound(),
+    drop = "redstone:breaker_off",
+    paramtype = "light",
+    sunlight_propagates = true,
+    on_timer = function(pos, elapsed)
+        local param2 = minetest.get_node(pos).param2
+        local dir = minetest.facedir_to_dir(param2)
+        if minetest.get_node(vector.add(pos,dir)).name == "air" then
+            minetest.swap_node(pos, {name="redstone:detector_off",param2=param2})
+            
+            redstone.inject(pos,{
+                name = "redstone:detector_off",
+            })
+            minetest.after(0,function()
+               redstone.update(pos)
+            end)
+        end
+
+        local timer = minetest.get_node_timer(pos)
+        if not timer:is_started() then
+            timer:start(1)
+        end
+    end,
+       --reverse the direction to face the player
+       on_construct = function(pos)
+               redstone.inject(pos,{
+            name = "redstone:detector_on",
+            torch = 16,
+        })
+        local timer = minetest.get_node_timer(pos)
+               if not timer:is_started() then
+                       timer:start(1)
+               end
+               redstone.update(pos)
+       end,
+       on_destruct = function(pos)
+               redstone.inject(pos,nil)
+    end,
+})
+
+
+
+minetest.register_lbm({
+       name = "redstone:detector_on",
+       nodenames = {"redstone:detector_on"},
+       run_at_every_load = true,
+       action = function(pos)
+               redstone.inject(pos,{
+                       name = "redstone:detector_on",
+                       torch = 16,
+        })
+        
+        local timer = minetest.get_node_timer(pos)
+               if not timer:is_started() then
+                       timer:start(1)
+               end
+
+               minetest.after(0,function()
+            redstone.update(pos)
+        end)
+       end,
+})
index 74c4f34f5a593cb1c8703a5a8a9387515999b06a..b93a81a3f6208a04c795aea84f3ff354d117555c 100644 (file)
@@ -82,6 +82,7 @@ dofile(path.."/space_maker.lua")
 --dofile(path.."/pressure_plate.lua")
 dofile(path.."/capacitors.lua")
 dofile(path.."/breaker.lua")
+dofile(path.."/detector.lua")
 
 
 --this is written out manually so that