]> git.lizzy.rs Git - Crafter.git/commitdiff
Add in switches
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 21 Mar 2020 14:20:40 +0000 (10:20 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sat, 21 Mar 2020 14:20:40 +0000 (10:20 -0400)
mods/main/nodes.lua
mods/redstone/init.lua
mods/redstone/sounds/lever.ogg [new file with mode: 0644]
mods/redstone/switches.lua [new file with mode: 0644]
todo.txt

index 0b56aa19d42c04360837e938af81215148b9118d..3d0d7712ea7298a5a34c612b7a0d883287afdc08 100644 (file)
@@ -35,14 +35,16 @@ end
 minetest.register_node("main:stone", {
     description = "Stone",
     tiles = {"stone.png"},
-    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1, redstone_activation=1},
+    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,pathable = 1},
     sounds = main.stoneSound(),
+    --[[
     redstone_activation = function(pos)
                --pass
     end,
     redstone_deactivation = function(pos)
                minetest.set_node(pos,{name="main:cobble"})
     end,
+    ]]--
     drop = {
                max_items = 1,
                items= {
@@ -58,14 +60,16 @@ minetest.register_node("main:stone", {
 minetest.register_node("main:cobble", {
     description = "Cobblestone",
     tiles = {"cobble.png"},
-    groups = {stone = 2, hard = 1, pickaxe = 2, hand = 4,pathable = 1, redstone_activation=1},
+    groups = {stone = 2, hard = 1, pickaxe = 2, hand = 4,pathable = 1},
     sounds = main.stoneSound(),
+    --[[
     redstone_activation = function(pos)
                minetest.set_node(pos,{name="main:stone"})
     end,
     redstone_deactivation = function(pos)
                --pass
     end,
+    ]]--
     drop = {
                max_items = 1,
                items= {
index 0066c71e9f1b205102f5e2a19cbb98c8faaad970..6406614945061eb9b9cd71804ae69d02674d1beb 100644 (file)
@@ -11,6 +11,7 @@ might have to calculate this in a local memory table then set the nodes using a
 local path = minetest.get_modpath("redstone")
 dofile(path.."/wire.lua")
 dofile(path.."/torch.lua")
+dofile(path.."/switches.lua")
 
 redstone = {}
 
diff --git a/mods/redstone/sounds/lever.ogg b/mods/redstone/sounds/lever.ogg
new file mode 100644 (file)
index 0000000..80d0dae
Binary files /dev/null and b/mods/redstone/sounds/lever.ogg differ
diff --git a/mods/redstone/switches.lua b/mods/redstone/switches.lua
new file mode 100644 (file)
index 0000000..e338178
--- /dev/null
@@ -0,0 +1,95 @@
+--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.drop = name
+               def2.mod_origin = "redstone"
+               def2.textures = "dirt.png"
+               local newname = "redstone:"..string.gsub(name, "main:", "")
+               def2.name = newname
+               minetest.register_node(newname,def2)
+       end
+end
+
+
+--this removes power from node that the switch is powering
+local function on_lever_destroy(pos)
+       local param2 = minetest.get_node(pos).param2
+       local self = minetest.get_node(pos)
+       local dir = minetest.facedir_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:") then
+               name = "main:"..string.gsub(name, "redstone:", "")
+               minetest.set_node(pos, {name=name})
+       end
+end
+
+
+minetest.register_node("redstone:switch_off", {
+    description = "Crafting Table",
+    tiles = {"stone.png"},
+    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4},
+    sounds = main.stoneSound(),
+    paramtype = "light",
+       paramtype2 = "wallmounted",
+       sunlight_propagates = true,
+       walkable = false,
+       drawtype= "nodebox",
+       drop="redstone:switch_off",
+       node_box = {
+               type = "fixed",
+               fixed = {
+                               --left front bottom right back top
+                               {-0.3, -0.5,  -0.4, 0.3,  -0.4, 0.4},
+                               {-0.1, -0.5,  -0.3, 0.1,  0, -0.1},
+                       },
+               },
+    on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+               minetest.sound_play("lever", {pos=pos})
+               minetest.set_node(pos, {name="redstone:switch_on",param2=node.param2})
+               local dir = minetest.facedir_to_dir(node.param2)
+               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.set_node(pos,{name=name})
+                       redstone.collect_info(pos)
+               end
+       end,
+       on_destruct = on_lever_destroy,
+})
+minetest.register_node("redstone:switch_on", {
+    description = "Crafting Table",
+    tiles = {"stone.png"},
+    groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4},
+    sounds = main.stoneSound(),
+    paramtype = "light",
+       paramtype2 = "wallmounted",
+       sunlight_propagates = true,
+       walkable = false,
+       drawtype= "nodebox",
+       drop="redstone:switch_off",
+       node_box = {
+               type = "fixed",
+               fixed = {
+                               --left front bottom right back top
+                               {-0.3, -0.5,  -0.4, 0.3,  -0.4, 0.4},
+                               {-0.1, -0.5,  0.3, 0.1,  0, 0.1},
+                       },
+               },
+    on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+               minetest.sound_play("lever", {pos=pos,pitch=0.8})
+               minetest.set_node(pos, {name="redstone:switch_off",param2=node.param2})
+               on_lever_destroy(pos)
+               redstone.collect_info(pos)
+       end,
+       on_destruct = on_lever_destroy,
+})
index 4f6f5fbdff9f5d1ccb58b1a128c01324bbbc4794..ab91b308e9be82e9641576a5a9c7d8f30be5ad5d 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -51,9 +51,9 @@ ALPHA STATE CHANGELOG
 --added glass - smelt sand
 --added boat 
 --rightclicking with tool places torch
-chest
-make chest drop all items when you mine them
-
+--add chest
+--make chest drop all items when you mine them
+--add in switches
 
 farming - 
 - add fertilizer (pig drops bone randomly) 
@@ -94,6 +94,7 @@ make entities push against players
 
 
 open bugs:
+--ghost chest bug
 fix torches not deleting particles when mounted node dug <- meta glitch?
 --fixing with abm