From 6147c385cca2c5b1dbaf93cab4508fb0459b6fdb Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 01:23:15 -0700 Subject: initial gates commit, logic behind gates works, more work to do. --- mesecons_gates/depends.txt | 2 + mesecons_gates/init.lua | 124 ++++++++++++++++++++++++ mesecons_textures/textures/jeija_gate_and.png | Bin 0 -> 233 bytes mesecons_textures/textures/jeija_gate_diode.png | Bin 0 -> 231 bytes mesecons_textures/textures/jeija_gate_nand.png | Bin 0 -> 251 bytes mesecons_textures/textures/jeija_gate_not.png | Bin 0 -> 241 bytes mesecons_textures/textures/jeija_gate_off.png | Bin 0 -> 195 bytes mesecons_textures/textures/jeija_gate_on.png | Bin 0 -> 195 bytes mesecons_textures/textures/jeija_gate_xor.png | Bin 0 -> 245 bytes 9 files changed, 126 insertions(+) create mode 100644 mesecons_gates/depends.txt create mode 100644 mesecons_gates/init.lua create mode 100644 mesecons_textures/textures/jeija_gate_and.png create mode 100644 mesecons_textures/textures/jeija_gate_diode.png create mode 100644 mesecons_textures/textures/jeija_gate_nand.png create mode 100644 mesecons_textures/textures/jeija_gate_not.png create mode 100644 mesecons_textures/textures/jeija_gate_off.png create mode 100644 mesecons_textures/textures/jeija_gate_on.png create mode 100644 mesecons_textures/textures/jeija_gate_xor.png diff --git a/mesecons_gates/depends.txt b/mesecons_gates/depends.txt new file mode 100644 index 0000000..52fb260 --- /dev/null +++ b/mesecons_gates/depends.txt @@ -0,0 +1,2 @@ +mesecons +mesecons_microcontroller diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua new file mode 100644 index 0000000..1c84005 --- /dev/null +++ b/mesecons_gates/init.lua @@ -0,0 +1,124 @@ +gates = {"diode", "not", "nand", "and", "xor"} +for g in ipairs(gates) do gate = gates[g] + + inrules = {} + outrules = {} + rules = {} + table.insert(outrules, {x=1, y=0, z=0}) + table.insert(rules, {x=1, y=0, z=0}) + if g < 3 then + table.insert(inrules, {x=-1, y=0, z=0}) + table.insert(rules, {x=-1, y=0, z=0}) + else + table.insert(inrules, {x=0, y=0, z=1}) + table.insert(rules, {x=0, y=0, z=1}) + table.insert(inrules, {x=0, y=0, z=-1}) + table.insert(rules, {x=0, y=0, z=-1}) + end + --table.insert(rules, inrules) + --table.insert(rules, outrules) + + for on=0,1 do + if on == 1 then + onoff = "on" + else + onoff = "off" + end + if on == 1 then + groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} + else + groups = {dig_immediate=2, mesecon = 3} + end + + nodename = "mesecons_gates:"..gate.."_"..onoff + + minetest.register_node(nodename, { + description = gate.." Gate", + drawtype = "normal", + tiles = { + "jeija_gate_"..onoff..".png^".. + "jeija_gate_"..gate..".png", + }, + walkable = true, + on_construct = function(pos) + update_gate(pos) + end, + groups = groups, + + }) + + mesecon:add_rules(gate,outrules) + mesecon:register_effector(nodename, nodename, rules) + --if on then + -- mesecon:add_receptor_node(nodename, outrules) + --end + --mesecon:add_receptor_node("mesecons_gates:and_off", + --mesecon:add_receptor_node("mesecons_gates:and_on", + end +end + +function get_gate(pos) + string = minetest.env:get_node(pos).name + string = string.gsub(string, "mesecons_gates:", "") + --gate + string = string.gsub(string, "_on", "") + string = string.gsub(string, "_off", "") + return string +end + +function gate_state(pos) + name = minetest.env:get_node(pos).name + if string.find(name, "off")~=nil then + return false + else + return true + end +end +--[[ +function gate_on(pos) + if !gate_state(pos) then + minetest.env:add_node("mesecons_gates:"..get_gate(pos).."_on") + end +end + +function gate_off(pos) + if gate_state(pos) then + minetest.env:add_node("mesecons_gates:"..get_gate(pos).."_off") + end +end +--]] +function set_gate(pos, open) + if open then + if not gate_state(pos) then + minetest.env:add_node(pos, {name="mesecons_gates:"..get_gate(pos).."_on"}) + end + else + if gate_state(pos) then + minetest.env:add_node(pos, {name="mesecons_gates:"..get_gate(pos).."_off"}) + end + end +end + +function update_gate(pos) + gate = get_gate(pos) + L = yc_get_real_portstates(pos) + if gate == "diode" then + set_gate(pos, L.a) + elseif gate == "not" then + set_gate(pos, not L.a) + elseif gate == "nand" then + set_gate(pos, not(L.b and L.d)) + elseif gate == "and" then + set_gate(pos, L.b and L.d) + else--if gate == "xor" then + set_gate(pos, (L.b and not L.d) or (not L.b and L.d)) + end +end + +mesecon:register_on_signal_change(function(pos,node) + if string.find(node.name, "mesecons_gates:")~=nil then + update_gate(pos) + end +end) + + diff --git a/mesecons_textures/textures/jeija_gate_and.png b/mesecons_textures/textures/jeija_gate_and.png new file mode 100644 index 0000000..0ddc043 Binary files /dev/null and b/mesecons_textures/textures/jeija_gate_and.png differ diff --git a/mesecons_textures/textures/jeija_gate_diode.png b/mesecons_textures/textures/jeija_gate_diode.png new file mode 100644 index 0000000..ffa403f Binary files /dev/null and b/mesecons_textures/textures/jeija_gate_diode.png differ diff --git a/mesecons_textures/textures/jeija_gate_nand.png b/mesecons_textures/textures/jeija_gate_nand.png new file mode 100644 index 0000000..0e4294e Binary files /dev/null and b/mesecons_textures/textures/jeija_gate_nand.png differ diff --git a/mesecons_textures/textures/jeija_gate_not.png b/mesecons_textures/textures/jeija_gate_not.png new file mode 100644 index 0000000..939fb76 Binary files /dev/null and b/mesecons_textures/textures/jeija_gate_not.png differ diff --git a/mesecons_textures/textures/jeija_gate_off.png b/mesecons_textures/textures/jeija_gate_off.png new file mode 100644 index 0000000..44017b0 Binary files /dev/null and b/mesecons_textures/textures/jeija_gate_off.png differ diff --git a/mesecons_textures/textures/jeija_gate_on.png b/mesecons_textures/textures/jeija_gate_on.png new file mode 100644 index 0000000..47028a8 Binary files /dev/null and b/mesecons_textures/textures/jeija_gate_on.png differ diff --git a/mesecons_textures/textures/jeija_gate_xor.png b/mesecons_textures/textures/jeija_gate_xor.png new file mode 100644 index 0000000..afbd6ab Binary files /dev/null and b/mesecons_textures/textures/jeija_gate_xor.png differ -- cgit v1.2.3 From f93930a4781f113da7b84d4b834f2859d17181ee Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 13:07:18 -0700 Subject: gate output works --- mesecons_gates/init.lua | 69 +++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index 1c84005..b8f4797 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -1,33 +1,30 @@ gates = {"diode", "not", "nand", "and", "xor"} +out = {x=1, y=0, z=0} +inonerules = {{x=-1, y=0, z=0}} +intworules = {{x=0, y=0, z=1},{x=0, y=0, z=-1}} +onerules = inonerules +table.insert(onerules, out) +tworules = intworules +table.insert(tworules, out) +outrules = {} +outrules = table.insert(outrules, out) for g in ipairs(gates) do gate = gates[g] - - inrules = {} - outrules = {} - rules = {} - table.insert(outrules, {x=1, y=0, z=0}) - table.insert(rules, {x=1, y=0, z=0}) if g < 3 then - table.insert(inrules, {x=-1, y=0, z=0}) - table.insert(rules, {x=-1, y=0, z=0}) + inrules = inonerules + rules = onerules else - table.insert(inrules, {x=0, y=0, z=1}) - table.insert(rules, {x=0, y=0, z=1}) - table.insert(inrules, {x=0, y=0, z=-1}) - table.insert(rules, {x=0, y=0, z=-1}) + inrules = intworules + rules = tworules end - --table.insert(rules, inrules) - --table.insert(rules, outrules) - for on=0,1 do if on == 1 then onoff = "on" - else - onoff = "off" - end - if on == 1 then groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} + drop = "mesecons_gates:"..gate.."_off" else + onoff = "off" groups = {dig_immediate=2, mesecon = 3} + drop = nodename end nodename = "mesecons_gates:"..gate.."_"..onoff @@ -44,16 +41,11 @@ for g in ipairs(gates) do gate = gates[g] update_gate(pos) end, groups = groups, + drop = drop, }) - mesecon:add_rules(gate,outrules) - mesecon:register_effector(nodename, nodename, rules) - --if on then - -- mesecon:add_receptor_node(nodename, outrules) - --end - --mesecon:add_receptor_node("mesecons_gates:and_off", - --mesecon:add_receptor_node("mesecons_gates:and_on", + mesecon:register_effector(nodename, nodename, inrules) end end @@ -74,27 +66,19 @@ function gate_state(pos) return true end end ---[[ -function gate_on(pos) - if !gate_state(pos) then - minetest.env:add_node("mesecons_gates:"..get_gate(pos).."_on") - end -end -function gate_off(pos) - if gate_state(pos) then - minetest.env:add_node("mesecons_gates:"..get_gate(pos).."_off") - end -end ---]] -function set_gate(pos, open) - if open then +function set_gate(pos, on) + gate = get_gate(pos) + local rules = {{x=1, y=0, z=0}} + if on then if not gate_state(pos) then - minetest.env:add_node(pos, {name="mesecons_gates:"..get_gate(pos).."_on"}) + minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_on"}) + mesecon:receptor_on(pos, rules) end else if gate_state(pos) then - minetest.env:add_node(pos, {name="mesecons_gates:"..get_gate(pos).."_off"}) + minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_off"}) + mesecon:receptor_off(pos, rules) end end end @@ -121,4 +105,3 @@ mesecon:register_on_signal_change(function(pos,node) end end) - -- cgit v1.2.3 From b44f443fb27ebdf0129bade9b4d1fbfbfdaf66e5 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 13:48:16 -0700 Subject: nodeboxes --- mesecons_gates/init.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index b8f4797..fd680e1 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -29,13 +29,22 @@ for g in ipairs(gates) do gate = gates[g] nodename = "mesecons_gates:"..gate.."_"..onoff + node_box = { + type = "fixed", + fixed = { -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, + } + minetest.register_node(nodename, { description = gate.." Gate", - drawtype = "normal", + paramtype = "light", + drawtype = "nodebox", tiles = { + "jeija_microcontroller_bottom.png^".. "jeija_gate_"..onoff..".png^".. "jeija_gate_"..gate..".png", }, + selection_box = node_box, + node_box = node_box, walkable = true, on_construct = function(pos) update_gate(pos) -- cgit v1.2.3 From efd06143b19ad627a9b5e6b2edd122486f4c3710 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 16:10:23 -0700 Subject: gates overheat --- mesecons_gates/init.lua | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index fd680e1..089d608 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -21,10 +21,12 @@ for g in ipairs(gates) do gate = gates[g] onoff = "on" groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} drop = "mesecons_gates:"..gate.."_off" + description = "You hacker you!" else onoff = "off" groups = {dig_immediate=2, mesecon = 3} drop = nodename + description = gate.." Gate" end nodename = "mesecons_gates:"..gate.."_"..onoff @@ -35,7 +37,7 @@ for g in ipairs(gates) do gate = gates[g] } minetest.register_node(nodename, { - description = gate.." Gate", + description = description, paramtype = "light", drawtype = "nodebox", tiles = { @@ -47,6 +49,8 @@ for g in ipairs(gates) do gate = gates[g] node_box = node_box, walkable = true, on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_int("heat", 0) update_gate(pos) end, groups = groups, @@ -69,25 +73,47 @@ end function gate_state(pos) name = minetest.env:get_node(pos).name - if string.find(name, "off")~=nil then - return false - else - return true - end + return string.find(name, "off") == nil +end + +function pop_gate(pos) + gate = get_gate(pos) + minetest.env:remove_node(pos) + minetest.after(0.2, yc_overheat_off, pos) + minetest.env:add_item(pos, "mesecons_gates:"..gate.."_off") end function set_gate(pos, on) gate = get_gate(pos) + local meta = minetest.env:get_meta(pos) local rules = {{x=1, y=0, z=0}} if on then if not gate_state(pos) then - minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_on"}) - mesecon:receptor_on(pos, rules) + yc_heat(meta) + minetest.after(0.5, yc_cool, meta) + if yc_overheat(meta) then + pop_gate(pos) + else + heat = meta:get_int("heat") + minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_on"}) + local meta2 = minetest.env:get_meta(pos) + meta2:set_int("heat", heat) + mesecon:receptor_on(pos, rules) + end end else if gate_state(pos) then - minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_off"}) - mesecon:receptor_off(pos, rules) + yc_heat(meta) + minetest.after(0.5, yc_cool, meta) + if yc_overheat(meta) then + pop_gate(pos) + else + heat = meta:get_int("heat") + minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_off"}) + local meta2 = minetest.env:get_meta(pos) + meta2:set_int("heat", heat) + mesecon:receptor_off(pos, rules) + end end end end -- cgit v1.2.3 From 9af83593ace4f035e5eee257ee4ff84d80ba8f39 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 17:07:00 -0700 Subject: added recipes --- mesecons_gates/depends.txt | 2 ++ mesecons_gates/init.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/mesecons_gates/depends.txt b/mesecons_gates/depends.txt index 52fb260..4ed39f9 100644 --- a/mesecons_gates/depends.txt +++ b/mesecons_gates/depends.txt @@ -1,2 +1,4 @@ mesecons mesecons_microcontroller +mesecons_torch +mesecons_materials diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index 089d608..b58e0bc 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -140,3 +140,48 @@ mesecon:register_on_signal_change(function(pos,node) end end) +minetest.register_craft({ + output = 'mesecons_gates:diode_off', + recipe = { + {'', '', ''}, + {'mesecons:mesecon', 'mesecons_torch:mesecon_torch_on', 'mesecons_torch:mesecon_torch_on'}, + {'', '', ''}, + }, +}) + +minetest.register_craft({ + output = 'mesecons_gates:not_off', + recipe = { + {'', '', ''}, + {'mesecons:mesecon', 'mesecons_torch:mesecon_torch_on', 'mesecons:mesecon'}, + {'', '', ''}, + }, +}) + +minetest.register_craft({ + output = 'mesecons_gates:and_off', + recipe = { + {'mesecons:mesecon', '', ''}, + {'', 'mesecons_materials:silicon', 'mesecons:mesecon'}, + {'mesecons:mesecon', '', ''}, + }, +}) + +minetest.register_craft({ + output = 'mesecons_gates:nand_off', + recipe = { + {'mesecons:mesecon', '', ''}, + {'', 'mesecons_materials:silicon', 'mesecons_torch:mesecon_torch_on'}, + {'mesecons:mesecon', '', ''}, + }, +}) + +minetest.register_craft({ + output = 'mesecons_gates:xor_off', + recipe = { + {'mesecons:mesecon', '', ''}, + {'', 'mesecons_materials:silicon', 'mesecons_materials:silicon'}, + {'mesecons:mesecon', '', ''}, + }, +}) + -- cgit v1.2.3 From dc3fc4deb5e6b4d68a10799fc623176f996bcc24 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 18:26:15 -0700 Subject: cut set_gate in half --- mesecons_gates/init.lua | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index b58e0bc..27719a4 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -87,31 +87,24 @@ function set_gate(pos, on) gate = get_gate(pos) local meta = minetest.env:get_meta(pos) local rules = {{x=1, y=0, z=0}} - if on then - if not gate_state(pos) then - yc_heat(meta) - minetest.after(0.5, yc_cool, meta) - if yc_overheat(meta) then - pop_gate(pos) + if on ~= gate_state(pos) then + yc_heat(meta) + minetest.after(0.5, yc_cool, meta) + if yc_overheat(meta) then + pop_gate(pos) + else + heat = meta:get_int("heat") + if on then + onoff = "_on" else - heat = meta:get_int("heat") - minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_on"}) - local meta2 = minetest.env:get_meta(pos) - meta2:set_int("heat", heat) - mesecon:receptor_on(pos, rules) + onoff = "_off" end - end - else - if gate_state(pos) then - yc_heat(meta) - minetest.after(0.5, yc_cool, meta) - if yc_overheat(meta) then - pop_gate(pos) + minetest.env:add_node(pos, {name="mesecons_gates:"..gate..onoff}) + local meta2 = minetest.env:get_meta(pos) + meta2:set_int("heat", heat) + if on then + mesecon:receptor_on(pos, rules) else - heat = meta:get_int("heat") - minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_off"}) - local meta2 = minetest.env:get_meta(pos) - meta2:set_int("heat", heat) mesecon:receptor_off(pos, rules) end end -- cgit v1.2.3 From 6f1296198cc7aa0a159893429672e77c524ad8c2 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 18:53:31 -0700 Subject: simplified effector rules --- mesecons_gates/init.lua | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index 27719a4..fdb0dc1 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -1,20 +1,14 @@ gates = {"diode", "not", "nand", "and", "xor"} -out = {x=1, y=0, z=0} -inonerules = {{x=-1, y=0, z=0}} -intworules = {{x=0, y=0, z=1},{x=0, y=0, z=-1}} -onerules = inonerules -table.insert(onerules, out) -tworules = intworules -table.insert(tworules, out) -outrules = {} -outrules = table.insert(outrules, out) for g in ipairs(gates) do gate = gates[g] if g < 3 then - inrules = inonerules - rules = onerules + rules = { + {x=-1, y=0, z=0}, + } else - inrules = intworules - rules = tworules + rules = { + {x=0, y=0, z=1}, + {x=0, y=0, z=-1}, + } end for on=0,1 do if on == 1 then @@ -58,7 +52,7 @@ for g in ipairs(gates) do gate = gates[g] }) - mesecon:register_effector(nodename, nodename, inrules) + mesecon:register_effector(nodename, nodename, rules) end end -- cgit v1.2.3 From 0f7a87538d435a758d364e821c08c1cfa65e998c Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 18:59:10 -0700 Subject: (oops) forgot the "out" connection --- mesecons_gates/init.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index fdb0dc1..ce22f1d 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -3,11 +3,13 @@ for g in ipairs(gates) do gate = gates[g] if g < 3 then rules = { {x=-1, y=0, z=0}, + {x=1, y=0, z=0}, } else rules = { {x=0, y=0, z=1}, {x=0, y=0, z=-1}, + {x=1, y=0, z=0}, } end for on=0,1 do -- cgit v1.2.3 From 845c27512171e3f4aa05ea9bc931bd8920696c2f Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 22:06:25 -0700 Subject: registering the on receptor makes placing a mesecon on the out port of the gate update the circuitry after it --- mesecons_gates/init.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index ce22f1d..af7d87a 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -1,3 +1,6 @@ +outrules = { + {x=1, y=0, z=0}, +} gates = {"diode", "not", "nand", "and", "xor"} for g in ipairs(gates) do gate = gates[g] if g < 3 then @@ -13,20 +16,22 @@ for g in ipairs(gates) do gate = gates[g] } end for on=0,1 do + nodename = "mesecons_gates:"..gate if on == 1 then onoff = "on" + drop = nodename.."_off" groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} - drop = "mesecons_gates:"..gate.."_off" description = "You hacker you!" + nodename = nodename.."_"..onoff + mesecon:add_receptor_node(nodename, outrules) else onoff = "off" groups = {dig_immediate=2, mesecon = 3} - drop = nodename description = gate.." Gate" + nodename = nodename.."_"..onoff + --mesecon:add_receptor_node_off(nodename, rules) end - nodename = "mesecons_gates:"..gate.."_"..onoff - node_box = { type = "fixed", fixed = { -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, -- cgit v1.2.3 From b0142a7429f4b6e0745290982b3781b5b883530c Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 23:27:23 -0700 Subject: flat inventory image for easy gate identification --- mesecons_gates/init.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index af7d87a..ac1e4c9 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -37,15 +37,16 @@ for g in ipairs(gates) do gate = gates[g] fixed = { -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, } + tiles = "jeija_microcontroller_bottom.png^".. + "jeija_gate_"..onoff..".png^".. + "jeija_gate_"..gate..".png" + minetest.register_node(nodename, { description = description, paramtype = "light", drawtype = "nodebox", - tiles = { - "jeija_microcontroller_bottom.png^".. - "jeija_gate_"..onoff..".png^".. - "jeija_gate_"..gate..".png", - }, + tiles = {tiles}, + inventory_image = tiles, selection_box = node_box, node_box = node_box, walkable = true, -- cgit v1.2.3 From e65c5ca9dc43f09934007fddd89ae81b579bec50 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 3 Sep 2012 11:50:43 -0700 Subject: nodeboxes now show which sides connect --- mesecons_gates/init.lua | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index ac1e4c9..92f0d9a 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -8,12 +8,29 @@ for g in ipairs(gates) do gate = gates[g] {x=-1, y=0, z=0}, {x=1, y=0, z=0}, } + node_box = { + type = "fixed", + fixed = { + {-6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, + {6/16, -8/16, -2/16, 8/16, -7/16, 2/16 }, + {-8/16, -8/16, -2/16, -6/16, -7/16, 2/16 }, + }, + } else rules = { {x=0, y=0, z=1}, {x=0, y=0, z=-1}, {x=1, y=0, z=0}, } + node_box = { + type = "fixed", + fixed = { + {-6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, + {6/16, -8/16, -2/16, 8/16, -7/16, 2/16 }, + {-2/16, -8/16, 6/16, 2/16, -7/16, 8/16 }, + {-2/16, -8/16, -8/16, 2/16, -7/16, -6/16 }, + }, + } end for on=0,1 do nodename = "mesecons_gates:"..gate @@ -32,11 +49,6 @@ for g in ipairs(gates) do gate = gates[g] --mesecon:add_receptor_node_off(nodename, rules) end - node_box = { - type = "fixed", - fixed = { -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, - } - tiles = "jeija_microcontroller_bottom.png^".. "jeija_gate_"..onoff..".png^".. "jeija_gate_"..gate..".png" @@ -88,7 +100,6 @@ end function set_gate(pos, on) gate = get_gate(pos) local meta = minetest.env:get_meta(pos) - local rules = {{x=1, y=0, z=0}} if on ~= gate_state(pos) then yc_heat(meta) minetest.after(0.5, yc_cool, meta) @@ -105,9 +116,9 @@ function set_gate(pos, on) local meta2 = minetest.env:get_meta(pos) meta2:set_int("heat", heat) if on then - mesecon:receptor_on(pos, rules) + mesecon:receptor_on(pos, outrules) else - mesecon:receptor_off(pos, rules) + mesecon:receptor_off(pos, outrules) end end end -- cgit v1.2.3 From 17fc6ac1f04e8f75674e6e895f78e477e38b0e5c Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 4 Sep 2012 21:16:32 -0700 Subject: FACEDIR! (among other things) --- mesecons_gates/init.lua | 97 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 70 insertions(+), 27 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index 92f0d9a..b7eae45 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -1,13 +1,38 @@ outrules = { {x=1, y=0, z=0}, } +oneinput = { + {x=-1, y=0, z=0}, + {x=1, y=0, z=0}, +} +twoinputs = { + {x=0, y=0, z=1}, + {x=0, y=0, z=-1}, + {x=1, y=0, z=0}, +} +function get_gate_rules(param2, onlyout, singleinput) + if onlyout then + rules = outrules + else + if singleinput then + rules = oneinput + else + rules = twoinputs + end + end + for rotations=0, param2-1 do + rules = mesecon:rotate_rules_left(rules) + end + return rules +end + +function get_gate_rules_one(param2) return get_gate_rules(param2, false, true) end +function get_gate_rules_two(param2) return get_gate_rules(param2, false, false) end +function get_gate_rules_out(param2) return get_gate_rules(param2, true) end gates = {"diode", "not", "nand", "and", "xor"} for g in ipairs(gates) do gate = gates[g] if g < 3 then - rules = { - {x=-1, y=0, z=0}, - {x=1, y=0, z=0}, - } + get_rules = get_gate_rules_one node_box = { type = "fixed", fixed = { @@ -17,11 +42,7 @@ for g in ipairs(gates) do gate = gates[g] }, } else - rules = { - {x=0, y=0, z=1}, - {x=0, y=0, z=-1}, - {x=1, y=0, z=0}, - } + get_rules = get_gate_rules_two node_box = { type = "fixed", fixed = { @@ -37,16 +58,17 @@ for g in ipairs(gates) do gate = gates[g] if on == 1 then onoff = "on" drop = nodename.."_off" - groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} - description = "You hacker you!" nodename = nodename.."_"..onoff - mesecon:add_receptor_node(nodename, outrules) + description = "You hacker you!" + groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} + mesecon:add_receptor_node(nodename, get_rules, get_gate_rules_out) + --mesecon:add_receptor_node(nodename, mesecon:get_rules("insulated_all")) else onoff = "off" - groups = {dig_immediate=2, mesecon = 3} - description = gate.." Gate" nodename = nodename.."_"..onoff - --mesecon:add_receptor_node_off(nodename, rules) + description = gate.." Gate" + groups = {dig_immediate=2, mesecon = 3} + --mesecon:add_receptor_node_off(nodename, get_gate_rules_out) end tiles = "jeija_microcontroller_bottom.png^".. @@ -56,6 +78,7 @@ for g in ipairs(gates) do gate = gates[g] minetest.register_node(nodename, { description = description, paramtype = "light", + paramtype2 = "facedir", drawtype = "nodebox", tiles = {tiles}, inventory_image = tiles, @@ -72,22 +95,24 @@ for g in ipairs(gates) do gate = gates[g] }) - mesecon:register_effector(nodename, nodename, rules) + mesecon:register_effector(nodename, nodename, mesecon:get_rules("insulated_all"), get_rules) end end function get_gate(pos) - string = minetest.env:get_node(pos).name - string = string.gsub(string, "mesecons_gates:", "") - --gate - string = string.gsub(string, "_on", "") - string = string.gsub(string, "_off", "") - return string + return + string.gsub( + string.gsub( + string.gsub( + minetest.env:get_node(pos).name + , "mesecons_gates:", "") --gate + ,"_on", "") + ,"_off", "") end function gate_state(pos) name = minetest.env:get_node(pos).name - return string.find(name, "off") == nil + return string.find(name, "_on") ~= nil end function pop_gate(pos) @@ -112,21 +137,39 @@ function set_gate(pos, on) else onoff = "_off" end - minetest.env:add_node(pos, {name="mesecons_gates:"..gate..onoff}) + param2 = minetest.env:get_node(pos).param2 + minetest.env:add_node(pos, { + name = "mesecons_gates:"..gate..onoff, + param2 = param2, + }) local meta2 = minetest.env:get_meta(pos) meta2:set_int("heat", heat) if on then - mesecon:receptor_on(pos, outrules) + mesecon:receptor_on(pos, get_gate_rules(param2, true)) else - mesecon:receptor_off(pos, outrules) + mesecon:receptor_off(pos, mesecon:get_rules("insulated_all")) end end end end +function rotate_ports(L, param2) + for rotations=0, param2-1 do + port = L.a + L.a = L.b + L.b = L.c + L.c = L.d + L.d = port + end + return L +end + function update_gate(pos) gate = get_gate(pos) - L = yc_get_real_portstates(pos) + L = rotate_ports( + yc_get_real_portstates(pos), + minetest.env:get_node(pos).param2 + ) if gate == "diode" then set_gate(pos, L.a) elseif gate == "not" then -- cgit v1.2.3 From 9fbc4b4587b1aa6dca926ddf6105f022f01055b1 Mon Sep 17 00:00:00 2001 From: Kyle Date: Tue, 4 Sep 2012 21:22:29 -0700 Subject: went back to large nodeboxes which agree with inventory image --- mesecons_gates/init.lua | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index b7eae45..aa9da75 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -33,25 +33,8 @@ gates = {"diode", "not", "nand", "and", "xor"} for g in ipairs(gates) do gate = gates[g] if g < 3 then get_rules = get_gate_rules_one - node_box = { - type = "fixed", - fixed = { - {-6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, - {6/16, -8/16, -2/16, 8/16, -7/16, 2/16 }, - {-8/16, -8/16, -2/16, -6/16, -7/16, 2/16 }, - }, - } else get_rules = get_gate_rules_two - node_box = { - type = "fixed", - fixed = { - {-6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, - {6/16, -8/16, -2/16, 8/16, -7/16, 2/16 }, - {-2/16, -8/16, 6/16, 2/16, -7/16, 8/16 }, - {-2/16, -8/16, -8/16, 2/16, -7/16, -6/16 }, - }, - } end for on=0,1 do nodename = "mesecons_gates:"..gate @@ -75,6 +58,13 @@ for g in ipairs(gates) do gate = gates[g] "jeija_gate_"..onoff..".png^".. "jeija_gate_"..gate..".png" + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, + }, + } + minetest.register_node(nodename, { description = description, paramtype = "light", -- cgit v1.2.3 From 6aa330e85c3612fc24c9d5b24d3b53b4f9f93348 Mon Sep 17 00:00:00 2001 From: Kyle Date: Wed, 5 Sep 2012 10:09:53 -0700 Subject: depend on mesecons_delayer's all_rules instead of getting both insulated and microcontroller rules --- mesecons_gates/depends.txt | 2 ++ mesecons_gates/init.lua | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mesecons_gates/depends.txt b/mesecons_gates/depends.txt index 4ed39f9..f3e0392 100644 --- a/mesecons_gates/depends.txt +++ b/mesecons_gates/depends.txt @@ -1,4 +1,6 @@ mesecons mesecons_microcontroller +mesecons_delayer + mesecons_torch mesecons_materials diff --git a/mesecons_gates/init.lua b/mesecons_gates/init.lua index aa9da75..8a4629f 100644 --- a/mesecons_gates/init.lua +++ b/mesecons_gates/init.lua @@ -85,7 +85,7 @@ for g in ipairs(gates) do gate = gates[g] }) - mesecon:register_effector(nodename, nodename, mesecon:get_rules("insulated_all"), get_rules) + mesecon:register_effector(nodename, nodename, all_rules, get_rules) end end @@ -137,7 +137,7 @@ function set_gate(pos, on) if on then mesecon:receptor_on(pos, get_gate_rules(param2, true)) else - mesecon:receptor_off(pos, mesecon:get_rules("insulated_all")) + mesecon:receptor_off(pos, all_rules) end end end -- cgit v1.2.3