From 6147c385cca2c5b1dbaf93cab4508fb0459b6fdb Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 1 Sep 2012 01:23:15 -0700 Subject: [PATCH] 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 .../textures/jeija_gate_diode.png | Bin 0 -> 231 bytes .../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 0000000000000000000000000000000000000000..0ddc0434112164f957814cba436c92aa01485ce2 GIT binary patch literal 233 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(}u`rZR{xJ$JMiD8gCb z5ecNZg+Z8+Vb&Z8pdfpRr>`sf9Zp6TZatOt{1!kV$r9Iy66gHf+|;}h2Ir#G#FEq$ zh4Rdj3j}~- znkp)s3}(v8%gluKcBt4+-W2V1X@*ux0n_yZ-V^5^uujQqnrwb+Rbsen*R`MgA%5#M VBy8`sf9Zp6TZo`$!na%=*BuiW)N}Tg^b5rw57@Uhz6H8K4 z6v{J8G8EiBeFMT9`NV;W{5@S9Lo7}oon*+zV8FpN@&EssetDspv$puSJaA3EKb%Ga`8%5vqbFQ1<6xcb5_Y~{zB+W*fp3C>ZG UH_6`p4`?)lr>mdKI;Vst0GPT+D*ylh literal 0 HcmV?d00001 diff --git a/mesecons_textures/textures/jeija_gate_nand.png b/mesecons_textures/textures/jeija_gate_nand.png new file mode 100644 index 0000000000000000000000000000000000000000..0e4294eb434c4661fe66deafab1a31a5ec007c8a GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(}u`rZR{xJ$JMiD8gCb z5ecNZg+Z8+Vb&Z8pdfpRr>`sf9Zp6TZj+m5zc~SgBuiW)N}Tg^b5rw57@Uhz6H8K4 z6v{J8G8EiBeFMT9`NV;Wl097_&rL#}Ob+Lo_)Mx7s7-vrC6qsZ(v{fAhI{vTwz2St@4Bj3xa-)Rjd9xF7e32d px;*!YU+L;rE0y09?iBxP*JBW{kl|jd{|0CsgQu&X%Q~loCIGIFQeOZ7 literal 0 HcmV?d00001 diff --git a/mesecons_textures/textures/jeija_gate_not.png b/mesecons_textures/textures/jeija_gate_not.png new file mode 100644 index 0000000000000000000000000000000000000000..939fb761d9a05f0d254bc679efc90e881e1e0c7f GIT binary patch literal 241 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(}u`rZR{xJ$JMiD8gCb z5ecNZg+Z8+Vb&Z8pdfpRr>`sf9Zp6TZZq@4)AN8rk|nMYCC>S|xv6<249-QVi6yBi z3gww484B*6z5(HleBwYwk)AG&Ar_~PPBP>>puoeN+x@@(X6%Y7j8c>M?zD*fl*oBt zRwKVHmTM9V!&|=PFHYYRyYX$M%Wmf>1wleCo$A`1|E^hVTJ`As>Q(My=gb!A+*!AA fZ}Y1q?>{qK6*ZCB;<@iD&=LkuS3j3^P6`sf9Zp6T9+9<=9DIR7k|nMYCC>S|xv6<249-QVi6yBi z3gww484B*6z5(HleBwYw+MX_sAr_~T6C^SYa3uT8)cQAHq}TGMzNDmtgv1Pu(t|4) h7qjv3F|)}rFuZ%nA`yJlSQMy@!PC{xWt~$(69CWIF&zK^ literal 0 HcmV?d00001 diff --git a/mesecons_textures/textures/jeija_gate_on.png b/mesecons_textures/textures/jeija_gate_on.png new file mode 100644 index 0000000000000000000000000000000000000000..47028a89aced921d48a8d61c738f376c42041154 GIT binary patch literal 195 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(}u`rZR{xJ$JMiD8gCb z5ecNZg+Z8+Vb&Z8pdfpRr>`sf9Zp6T9+htEf`>pM$r9Iy66gHf+|;}h2Ir#G#FEq$ zh4Rdj3A@9@ hi`jVinAzkQ7(^LZBvgO%&j4y;@O1TaS?83{1OUSjFaH1l literal 0 HcmV?d00001 diff --git a/mesecons_textures/textures/jeija_gate_xor.png b/mesecons_textures/textures/jeija_gate_xor.png new file mode 100644 index 0000000000000000000000000000000000000000..afbd6abe6973063ff5f5e4695429cb664ccfa814 GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE(}u`rZR{xJ$JMiD8gCb z5ecNZg+Z8+Vb&Z8pdfpRr>`sf9Zp6TZY#Ue+pa(%$r9Iy66gHf+|;}h2Ir#G#FEq$ zh4Rdj3YCM zTFCC%*CfcuFuk5j<#3+EE>B0+A14~U9hP%Vn!9nf&AkOo&#p@qN6p6& i+j5icAAP^PCeB==%0t{R#NZduA_h-aKbLh*2~7ay