[Addon] Mesecon "and" gate

Gatharoth
Member
 
Posts: 196
Joined: Thu Dec 22, 2011 02:54

[Addon] Mesecon "and" gate

by Gatharoth » Fri Mar 16, 2012 05:44

Alright, so after awhile of messing around with Temperest's OGAM. I thought, why can't there be an "and" gate? So I got to work on it.

Here's the code! (note: this is an addon to temperest's code)

Screenshot of the AND and NAND gates that can be used.
Image

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"
Image

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.
Last edited by Gatharoth on Fri Mar 16, 2012 20:04, edited 1 time in total.
 

Gatharoth
Member
 
Posts: 196
Joined: Thu Dec 22, 2011 02:54

by Gatharoth » Fri Mar 16, 2012 07:55

Alright, I'm to my wits end. Why aren't the "if"s running??

Its only the "if"s for a-dnode that aren't running. Both the "if i >=2.." and "if i < 2.." both work fine.

Edit: Okay, so they are running, but are failing. Why?!?! It's not like the nodes changed!
Last edited by Gatharoth on Fri Mar 16, 2012 08:02, edited 1 time in total.
 

Temperest
Member
 
Posts: 651
Joined: Tue Nov 15, 2011 23:13
GitHub: Uberi

by Temperest » Fri Mar 16, 2012 15:22

Gatharoth wrote:Alright, I'm to my wits end. Why aren't the "if"s running??

Its only the "if"s for a-dnode that aren't running. Both the "if i >=2.." and "if i < 2.." both work fine.

Edit: Okay, so they are running, but are failing. Why?!?! It's not like the nodes changed!


Well if you are using a more recent version of Mesecons, the mod name has changed from "jeija" to "mesecons", "mesecons_alias", "mesecons_blinkyplant", and etc. Therefore you need to check for "mesecons:mesecon_on" instead of "jeija:mesecon_on".
WorldEdit 1.0 released

The Mesecons Laboratory - the art of Mesecons circuitry
Latest article: Mesecons Basics.
 

Gatharoth
Member
 
Posts: 196
Joined: Thu Dec 22, 2011 02:54

by Gatharoth » Fri Mar 16, 2012 18:17

Temperest wrote:
Gatharoth wrote:Alright, I'm to my wits end. Why aren't the "if"s running??

Its only the "if"s for a-dnode that aren't running. Both the "if i >=2.." and "if i < 2.." both work fine.

Edit: Okay, so they are running, but are failing. Why?!?! It's not like the nodes changed!


Well if you are using a more recent version of Mesecons, the mod name has changed from "jeija" to "mesecons", "mesecons_alias", "mesecons_blinkyplant", and etc. Therefore you need to check for "mesecons:mesecon_on" instead of "jeija:mesecon_on".


I was using the version prior to those changes. Then got a problem with calling the register_on_signal functions. So I downloaded the latest and try that to see if it would fix it; Which it did not. And of course, I changed the sames.
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 25 guests

cron