diff options
author | Jeija <norrepli@gmail.com> | 2012-12-11 19:49:55 +0100 |
---|---|---|
committer | Jeija <norrepli@gmail.com> | 2012-12-11 19:49:55 +0100 |
commit | de46729b971b5e59394834b8a01d4a7005318114 (patch) | |
tree | 5a2cf1f18b485ddefa8e255ac6d6a600ef2e2e12 /mesecons_microcontroller | |
parent | 31f3c99288355193dc68a6e83dfc63140fd02fa0 (diff) | |
parent | 5540fcbcb31eb32003fa0391113ed3b1dea25e47 (diff) | |
download | mesecons-de46729b971b5e59394834b8a01d4a7005318114.tar mesecons-de46729b971b5e59394834b8a01d4a7005318114.tar.gz mesecons-de46729b971b5e59394834b8a01d4a7005318114.tar.bz2 mesecons-de46729b971b5e59394834b8a01d4a7005318114.tar.xz mesecons-de46729b971b5e59394834b8a01d4a7005318114.zip |
Merge branch 'mesecons_in_nodedef'
Conflicts:
mesecons/internal.lua
Diffstat (limited to 'mesecons_microcontroller')
-rw-r--r-- | mesecons_microcontroller/init.lua | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 121eb25..a359d05 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -23,6 +23,33 @@ if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then else groups = {dig_immediate=2, mesecon = 3} end +local rules={} +if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end +if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end +if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end +if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end + +local input_rules={} +if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0}) end +if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1}) end +if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0}) end +if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1}) end +mesecon:add_rules(nodename, rules) + +local mesecons = {effector = +{ + rules = input_rules, + action_change = function (pos, node) + update_yc(pos) + end +}} +if nodename ~= "mesecons_microcontroller:microcontroller0000" then + mesecons.receptor = { + state = mesecon.state.on, + rules = rules + } +end + minetest.register_node(nodename, { description = "Microcontroller", drawtype = "nodebox", @@ -101,25 +128,12 @@ minetest.register_node(nodename, { yc_reset (pos) update_yc(pos) end, + mesecons = mesecons, + after_dig_node = function (pos, node) + rules = mesecon:get_rules(node.name) + mesecon:receptor_off(pos, rules) + end, }) - -local rules={} -if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end -if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end -if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end -if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end - -local input_rules={} -if (a == 0) then table.insert(input_rules, {x = -1, y = 0, z = 0}) end -if (b == 0) then table.insert(input_rules, {x = 0, y = 0, z = 1}) end -if (c == 0) then table.insert(input_rules, {x = 1, y = 0, z = 0}) end -if (d == 0) then table.insert(input_rules, {x = 0, y = 0, z = -1}) end -mesecon:add_rules(nodename, rules) - -mesecon:register_effector(nodename, nodename, input_rules) -if nodename ~= "mesecons_microcontroller:microcontroller0000" then - mesecon:add_receptor_node(nodename, rules) -end end end end @@ -682,16 +696,3 @@ function yc_overheat_off(pos) rules = mesecon:get_rules("mesecons_microcontroller:microcontroller1111") mesecon:receptor_off(pos, rules) end - -mesecon:register_on_signal_change(function(pos, node) - if string.find(node.name, "mesecons_microcontroller:microcontroller")~=nil then - update_yc(pos) - end -end) - -minetest.register_on_dignode(function(pos, node) - if string.find(node.name, "mesecons_microcontroller:microcontroller") then - rules = mesecon:get_rules(node.name) - mesecon:receptor_off(pos, rules) - end -end) |