diff options
| author | Kyle <kyle.kylina@gmail.com> | 2012-09-01 01:23:15 -0700 | 
|---|---|---|
| committer | Kyle <kyle.kylina@gmail.com> | 2012-09-01 01:23:15 -0700 | 
| commit | 6147c385cca2c5b1dbaf93cab4508fb0459b6fdb (patch) | |
| tree | 8109e88c3d1663b00665d6ab692d6403655df06b | |
| parent | 5cc18d8fbd4b09e8c6075ead262e98fd8a663b35 (diff) | |
initial gates commit, logic behind gates works, more work to do.
| -rw-r--r-- | mesecons_gates/depends.txt | 2 | ||||
| -rw-r--r-- | mesecons_gates/init.lua | 124 | ||||
| -rw-r--r-- | mesecons_textures/textures/jeija_gate_and.png | bin | 0 -> 233 bytes | |||
| -rw-r--r-- | mesecons_textures/textures/jeija_gate_diode.png | bin | 0 -> 231 bytes | |||
| -rw-r--r-- | mesecons_textures/textures/jeija_gate_nand.png | bin | 0 -> 251 bytes | |||
| -rw-r--r-- | mesecons_textures/textures/jeija_gate_not.png | bin | 0 -> 241 bytes | |||
| -rw-r--r-- | mesecons_textures/textures/jeija_gate_off.png | bin | 0 -> 195 bytes | |||
| -rw-r--r-- | mesecons_textures/textures/jeija_gate_on.png | bin | 0 -> 195 bytes | |||
| -rw-r--r-- | mesecons_textures/textures/jeija_gate_xor.png | bin | 0 -> 245 bytes | 
9 files changed, 126 insertions, 0 deletions
| 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.pngBinary files differ new file mode 100644 index 0000000..0ddc043 --- /dev/null +++ b/mesecons_textures/textures/jeija_gate_and.png diff --git a/mesecons_textures/textures/jeija_gate_diode.png b/mesecons_textures/textures/jeija_gate_diode.pngBinary files differ new file mode 100644 index 0000000..ffa403f --- /dev/null +++ b/mesecons_textures/textures/jeija_gate_diode.png diff --git a/mesecons_textures/textures/jeija_gate_nand.png b/mesecons_textures/textures/jeija_gate_nand.pngBinary files differ new file mode 100644 index 0000000..0e4294e --- /dev/null +++ b/mesecons_textures/textures/jeija_gate_nand.png diff --git a/mesecons_textures/textures/jeija_gate_not.png b/mesecons_textures/textures/jeija_gate_not.pngBinary files differ new file mode 100644 index 0000000..939fb76 --- /dev/null +++ b/mesecons_textures/textures/jeija_gate_not.png diff --git a/mesecons_textures/textures/jeija_gate_off.png b/mesecons_textures/textures/jeija_gate_off.pngBinary files differ new file mode 100644 index 0000000..44017b0 --- /dev/null +++ b/mesecons_textures/textures/jeija_gate_off.png diff --git a/mesecons_textures/textures/jeija_gate_on.png b/mesecons_textures/textures/jeija_gate_on.pngBinary files differ new file mode 100644 index 0000000..47028a8 --- /dev/null +++ b/mesecons_textures/textures/jeija_gate_on.png diff --git a/mesecons_textures/textures/jeija_gate_xor.png b/mesecons_textures/textures/jeija_gate_xor.pngBinary files differ new file mode 100644 index 0000000..afbd6ab --- /dev/null +++ b/mesecons_textures/textures/jeija_gate_xor.png | 
