2014-04-20 21:44:58 +02:00
|
|
|
-- Dig and place services
|
|
|
|
|
2013-06-05 06:40:53 +02:00
|
|
|
mesecon.on_placenode = function (pos, node)
|
2014-11-22 11:37:47 +01:00
|
|
|
mesecon.update_autoconnect(pos, node)
|
|
|
|
|
2014-03-21 21:31:34 +01:00
|
|
|
-- Receptors: Send on signal when active
|
2014-11-22 15:42:22 +01:00
|
|
|
if mesecon.is_receptor_on(node.name) then
|
|
|
|
mesecon.receptor_on(pos, mesecon.receptor_get_rules(node))
|
2014-03-21 21:31:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Conductors: Send turnon signal when powered or replace by respective offstate conductor
|
|
|
|
-- if placed conductor is an onstate one
|
2014-11-22 15:42:22 +01:00
|
|
|
if mesecon.is_conductor(node.name) then
|
|
|
|
local sources = mesecon.is_powered(pos)
|
2014-11-21 22:04:39 +01:00
|
|
|
if sources then
|
2014-03-21 21:31:34 +01:00
|
|
|
-- also call receptor_on if itself is powered already, so that neighboring
|
|
|
|
-- conductors will be activated (when pushing an on-conductor with a piston)
|
2014-11-21 22:04:39 +01:00
|
|
|
for _, s in ipairs(sources) do
|
|
|
|
local rule = {x = pos.x - s.x, y = pos.y - s.y, z = pos.z - s.z}
|
2014-11-22 15:42:22 +01:00
|
|
|
mesecon.turnon(pos, rule)
|
2014-11-21 22:04:39 +01:00
|
|
|
end
|
2014-11-22 15:42:22 +01:00
|
|
|
--mesecon.receptor_on (pos, mesecon.conductor_get_rules(node))
|
|
|
|
elseif mesecon.is_conductor_on(node) then
|
|
|
|
minetest.swap_node(pos, {name = mesecon.get_conductor_off(node)})
|
2014-03-21 21:31:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Effectors: Send changesignal and activate or deactivate
|
2014-11-22 15:42:22 +01:00
|
|
|
if mesecon.is_effector(node.name) then
|
2014-11-29 15:08:37 +01:00
|
|
|
local powered_rules = {}
|
|
|
|
|
|
|
|
-- for each input rule, check if powered
|
|
|
|
for _, r in ipairs(mesecon.effector_get_rules(node)) do
|
|
|
|
local powered = mesecon.is_powered(pos, r)
|
2015-02-03 20:07:58 +01:00
|
|
|
if powered then table.insert(powered_rules, r) end
|
2014-11-29 15:08:37 +01:00
|
|
|
|
|
|
|
local state = powered and mesecon.state.on or mesecon.state.off
|
|
|
|
mesecon.changesignal(pos, node, r, state, 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
if (#powered_rules > 0) then
|
|
|
|
for _, r in ipairs(powered_rules) do
|
|
|
|
mesecon.activate(pos, node, r, 1)
|
|
|
|
end
|
2012-08-13 11:58:04 +02:00
|
|
|
end
|
|
|
|
end
|
2012-12-15 18:45:51 +01:00
|
|
|
end
|
2012-08-13 11:58:04 +02:00
|
|
|
|
2012-12-15 18:45:51 +01:00
|
|
|
mesecon.on_dignode = function (pos, node)
|
2014-11-22 15:42:22 +01:00
|
|
|
if mesecon.is_conductor_on(node) then
|
|
|
|
mesecon.receptor_off(pos, mesecon.conductor_get_rules(node))
|
|
|
|
elseif mesecon.is_receptor_on(node.name) then
|
|
|
|
mesecon.receptor_off(pos, mesecon.receptor_get_rules(node))
|
2012-08-13 08:50:10 +02:00
|
|
|
end
|
2014-11-22 11:37:47 +01:00
|
|
|
mesecon.queue:add_action(pos, "update_autoconnect", {node})
|
2012-12-15 18:45:51 +01:00
|
|
|
end
|
|
|
|
|
2014-11-22 11:37:47 +01:00
|
|
|
mesecon.queue:add_function("update_autoconnect", mesecon.update_autoconnect)
|
|
|
|
|
2012-12-15 18:45:51 +01:00
|
|
|
minetest.register_on_placenode(mesecon.on_placenode)
|
|
|
|
minetest.register_on_dignode(mesecon.on_dignode)
|
2014-04-20 21:44:58 +02:00
|
|
|
|
|
|
|
-- Overheating service for fast circuits
|
|
|
|
|
|
|
|
-- returns true if heat is too high
|
|
|
|
mesecon.do_overheat = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local heat = meta:get_int("heat") or 0
|
|
|
|
|
|
|
|
heat = heat + 1
|
|
|
|
meta:set_int("heat", heat)
|
|
|
|
|
2014-11-22 22:09:26 +01:00
|
|
|
if heat < mesecon.setting("overheat_max", 20) then
|
2014-04-20 21:44:58 +02:00
|
|
|
mesecon.queue:add_action(pos, "cooldown", {}, 1, nil, 0)
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
mesecon.queue:add_function("cooldown", function (pos)
|
|
|
|
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
|
|
|
|
return -- node has been moved, this one does not use overheating - ignore
|
|
|
|
end
|
|
|
|
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local heat = meta:get_int("heat")
|
|
|
|
|
|
|
|
if (heat > 0) then
|
|
|
|
meta:set_int("heat", heat - 1)
|
|
|
|
end
|
|
|
|
end)
|