2020-03-21 10:20:40 -04:00
|
|
|
--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
|
2020-03-23 23:46:35 -04:00
|
|
|
def2.groups.redstone_power=9
|
2020-03-26 15:56:39 -04:00
|
|
|
def2.drop = def.drop
|
2020-03-21 10:20:40 -04:00
|
|
|
def2.mod_origin = "redstone"
|
2020-03-21 23:20:35 -04:00
|
|
|
--def2.textures = "dirt.png"
|
2020-03-23 23:46:35 -04:00
|
|
|
def2.after_destruct = function(pos, oldnode)
|
|
|
|
redstone.collect_info(pos)
|
|
|
|
end
|
2020-04-02 21:42:10 -04:00
|
|
|
local newname = "redstone:node_activated_"..string.gsub(name, "main:", "")
|
2020-03-21 10:20:40 -04:00
|
|
|
def2.name = newname
|
2020-03-26 15:56:39 -04:00
|
|
|
def2.description = "Redstone "..def.description
|
2020-03-21 10:20:40 -04:00
|
|
|
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)
|
2020-03-21 12:39:25 -04:00
|
|
|
local dir = minetest.wallmounted_to_dir(self.param2)
|
2020-03-21 10:20:40 -04:00
|
|
|
|
|
|
|
local pos = vector.add(dir,pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local name = node.name
|
|
|
|
|
|
|
|
local def = minetest.registered_nodes[name]
|
2020-04-02 21:42:10 -04:00
|
|
|
if def.drawtype == "normal" and string.match(name, "redstone:node_activated_")then
|
|
|
|
name = "main:"..string.gsub(name, "redstone:node_activated_", "")
|
2020-03-21 10:20:40 -04:00
|
|
|
minetest.set_node(pos, {name=name})
|
2020-03-21 10:34:47 -04:00
|
|
|
redstone.collect_info(pos)
|
2020-03-21 10:20:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_node("redstone:switch_off", {
|
2020-03-22 00:08:59 -04:00
|
|
|
description = "Switch",
|
2020-03-21 10:20:40 -04:00
|
|
|
tiles = {"stone.png"},
|
2020-03-21 10:42:09 -04:00
|
|
|
groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1},
|
2020-03-21 10:20:40 -04:00
|
|
|
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.set_node(pos, {name="redstone:switch_on",param2=node.param2})
|
2020-03-21 12:39:25 -04:00
|
|
|
local dir = minetest.wallmounted_to_dir(node.param2)
|
2020-03-21 10:20:40 -04:00
|
|
|
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
|
2020-04-02 21:42:10 -04:00
|
|
|
minetest.sound_play("lever", {pos=pos})
|
|
|
|
name = "redstone:node_activated_"..string.gsub(name, "main:", "")
|
2020-03-21 10:20:40 -04:00
|
|
|
minetest.set_node(pos,{name=name})
|
|
|
|
redstone.collect_info(pos)
|
2020-04-02 21:42:10 -04:00
|
|
|
else
|
|
|
|
minetest.sound_play("lever", {pos=pos,pitch=0.6})
|
2020-03-21 10:20:40 -04:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_destruct = on_lever_destroy,
|
|
|
|
})
|
|
|
|
minetest.register_node("redstone:switch_on", {
|
|
|
|
description = "Crafting Table",
|
|
|
|
tiles = {"stone.png"},
|
2020-03-21 10:42:09 -04:00
|
|
|
groups = {stone = 1, hard = 1, pickaxe = 1, hand = 4,attached_node = 1},
|
2020-03-21 10:20:40 -04:00
|
|
|
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)
|
|
|
|
end,
|
|
|
|
on_destruct = on_lever_destroy,
|
|
|
|
})
|