mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-26 02:10:18 +01:00
Refactor plugs and sockets to be smaller and faster, make inverters default to the On state.
This commit is contained in:
parent
e94941931d
commit
1ac2bc910f
@ -17,5 +17,5 @@ minetest.register_alias("jeija:pressure_plate_wood", "jeija:pressure_plate_wood_
|
||||
|
||||
if ENABLE_TEMPEREST==1 then
|
||||
minetest.register_alias("jeija:mesecon_socket", "jeija:mesecon_socket_off")
|
||||
minetest.register_alias("jeija:mesecon_inverter", "jeija:mesecon_inverter_off")
|
||||
minetest.register_alias("jeija:mesecon_inverter", "jeija:mesecon_inverter_on")
|
||||
end
|
@ -15,9 +15,7 @@ minetest.register_node("jeija:mesecon_plug", {
|
||||
description = "Plug",
|
||||
})
|
||||
|
||||
mesecon:register_on_signal_on(function(pos, node)
|
||||
if node.name=="jeija:mesecon_plug" then
|
||||
local set_node_on = function(pos)
|
||||
local set_node_on = function(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if node.name=="jeija:mesecon_socket_off" then
|
||||
minetest.env:add_node(pos, {name="jeija:mesecon_socket_on"})
|
||||
@ -28,8 +26,23 @@ mesecon:register_on_signal_on(function(pos, node)
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local set_node_off = function(pos)
|
||||
node = minetest.env:get_node(pos)
|
||||
if node.name=="jeija:mesecon_socket_on" then
|
||||
minetest.env:add_node(pos, {name="jeija:mesecon_socket_off"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
elseif node.name=="jeija:mesecon_inverter_off" then
|
||||
minetest.env:add_node(pos, {name="jeija:mesecon_inverter_on"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local plug_on = function(pos, node)
|
||||
if node.name=="jeija:mesecon_plug" then
|
||||
local lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_on({x=pos.x-2, y=pos.y, z=pos.z}) end
|
||||
|
||||
@ -42,23 +55,10 @@ mesecon:register_on_signal_on(function(pos, node)
|
||||
local lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_on({x=pos.x, y=pos.y, z=pos.z+2}) end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
mesecon:register_on_signal_off(function(pos, node)
|
||||
local plug_off = function(pos, node)
|
||||
if node.name=="jeija:mesecon_plug" then
|
||||
local set_node_off = function(pos)
|
||||
node = minetest.env:get_node(pos)
|
||||
if node.name=="jeija:mesecon_socket_on" then
|
||||
minetest.env:add_node(pos, {name="jeija:mesecon_socket_off"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
elseif node.name=="jeija:mesecon_inverter_off" then
|
||||
minetest.env:add_node(pos, {name="jeija:mesecon_inverter_on"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
end
|
||||
|
||||
lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_off({x=pos.x-2, y=pos.y, z=pos.z}) end
|
||||
|
||||
@ -71,37 +71,12 @@ mesecon:register_on_signal_off(function(pos, node)
|
||||
lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_off({x=pos.x, y=pos.y, z=pos.z+2}) end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
if oldnode.name == "jeija:mesecon_plug" then
|
||||
local set_node_deactivated = function(pos)
|
||||
node = minetest.env:get_node(pos)
|
||||
if node.name=="jeija:mesecon_socket_on" then
|
||||
minetest.env:add_node(pos, {name="jeija:mesecon_socket_off"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
elseif node.name=="jeija:mesecon_inverter_on" then
|
||||
minetest.env:add_node(pos, {name="jeija:mesecon_inverter_off"})
|
||||
nodeupdate(pos)
|
||||
mesecon:receptor_off(pos)
|
||||
end
|
||||
end
|
||||
|
||||
lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_deactivated({x=pos.x-2, y=pos.y, z=pos.z}) end
|
||||
|
||||
lnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_deactivated({x=pos.x+2, y=pos.y, z=pos.z}) end
|
||||
|
||||
lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_deactivated({x=pos.x, y=pos.y, z=pos.z-2}) end
|
||||
|
||||
lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
|
||||
if lnode.name=="air" then set_node_deactivated({x=pos.x, y=pos.y, z=pos.z+2}) end
|
||||
end
|
||||
end)
|
||||
mesecon:register_on_signal_on(plug_on)
|
||||
mesecon:register_on_signal_off(plug_off)
|
||||
|
||||
minetest.register_on_dignode(plug_off)
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'node "jeija:mesecon_plug" 2',
|
||||
|
Loading…
Reference in New Issue
Block a user