From 1852e967a93f79c75a883e90e8fb3e672aa070d8 Mon Sep 17 00:00:00 2001 From: Jeija Date: Fri, 21 Mar 2014 21:31:34 +0100 Subject: [PATCH] Send changesignals for placed receptors when not powered, make on_placenode code more readable with comments. Also fixes a bug of lua- / microcontrollers not being updated when pushed by a piston. This could cause some bugs, even though I haven't found any while testing as it is a very core part of mesecons. --- mesecons/init.lua | 1 - mesecons/services.lua | 28 ++++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/mesecons/init.lua b/mesecons/init.lua index b5cf68b..c3794a2 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -39,7 +39,6 @@ -- } --} - -- PUBLIC VARIABLES mesecon={} -- contains all functions and all global variables mesecon.queue={} -- contains the ActionQueue diff --git a/mesecons/services.lua b/mesecons/services.lua index a1ab03a..7421b96 100644 --- a/mesecons/services.lua +++ b/mesecons/services.lua @@ -1,19 +1,31 @@ mesecon.on_placenode = function (pos, node) + -- Receptors: Send on signal when active if mesecon:is_receptor_on(node.name) then mesecon:receptor_on(pos, mesecon:receptor_get_rules(node)) - elseif mesecon:is_powered(pos) then - if mesecon:is_conductor(node.name) then - -- receptor_on if itself is powered already + end + + -- Conductors: Send turnon signal when powered or replace by respective offstate conductor + -- if placed conductor is an onstate one + if mesecon:is_conductor(node.name) then + if mesecon:is_powered(pos) then + -- also call receptor_on if itself is powered already, so that neighboring + -- conductors will be activated (when pushing an on-conductor with a piston) mesecon:turnon (pos) mesecon:receptor_on (pos, mesecon:conductor_get_rules(node)) - else + elseif mesecon:is_conductor_off(node.name) then + minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)}) + end + end + + -- Effectors: Send changesignal and activate or deactivate + if mesecon:is_effector(node.name) then + if mesecon:is_powered(pos) then mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "on", 1) mesecon:activate(pos, node, nil, 1) + else + mesecon:changesignal(pos, node, mesecon:effector_get_rules(node), "off", 1) + mesecon:deactivate(pos, node, nil, 1) end - elseif mesecon:is_conductor_on(node) then - minetest.swap_node(pos, {name = mesecon:get_conductor_off(node)}) - elseif mesecon:is_effector_on (node.name) then - mesecon:deactivate(pos, node, nil, 1) end end