Here's the code! (note: this is an addon to temperest's code)
Screenshot of the AND and NAND gates that can be used.
How to install
Alright first you need to download mesecons from here
You will need to add this image to mesecons_textures > textures as "jeija_duali"
Now open up mesecons_temperest > init.lua
Then copy the code below, and paste all of it at the bottom of the init.lua file.
Save it and now you have your "and" gate!
I'm sorry that I suck with github, otherwise I could just add all of this to mesecon.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_node("mesecons_temperest:duali", {
drawtype = "raillike",
tile_images = {"jeija_duali.png"},
inventory_image = "jeija_duali.png",
description = "Duali",
walkable = false,
is_ground_content = true,
selection_box = {
type = "fixed",
},
})
local check_dual = function(pos)
local i = 0
local anode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z})
local bnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z})
local cnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1})
local dnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1})
local enode = minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z})
local fnode = minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z})
if anode.name=="mesecons:mesecon_on" then
i = i + 1
end
if bnode.name=="mesecons:mesecon_on" then
i = i + 1
end
if cnode.name=="mesecons:mesecon_on" then
i = i + 1
end
if dnode.name=="mesecons:mesecon_on" then
i = i + 1
end
if enode.name=="mesecons:mesecon_on" then
i = i + 1
end
if fnode.name=="mesecons:mesecon_on" then
i = i + 1
end
if i >=2 and i < 6 then
return true
end
if i < 2 or i == 6 then
return false
end
end
local duali_on = function(pos, node)
if node.name=="mesecons_temperest:duali" then
if check_dual(pos) 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
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
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
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
local duali_off = function(pos, node)
if node.name=="mesecons_temperest:duali" then
if not check_dual(pos) then
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
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
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
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
mesecon:register_on_signal_on(duali_on)
mesecon:register_on_signal_off(duali_off)
There is still a few issues, so don't go using it just yet.
Current problems
Bold = major problem
- The Duali node can be connected to one single powersource, which branched off mesecon to connect to two spots on the Duali
- power not turning off after one power source is turned off.
Updates:
Reworked check code. "if" checks still do not run.
0.1 released. Everything "works" from my tests. If you found any problems please post them here.
0.11: Minor node changes.