From 888b0ebfec8c2eff9015163549a7e47443cb8665 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Fri, 1 Apr 2016 21:00:20 -0400 Subject: "explode" all modpacks into their individual components (you can't have a modpack buried inside a modpack) --- digilines/internal.lua | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 digilines/internal.lua (limited to 'digilines/internal.lua') diff --git a/digilines/internal.lua b/digilines/internal.lua new file mode 100644 index 0000000..f29cc8d --- /dev/null +++ b/digilines/internal.lua @@ -0,0 +1,92 @@ +function digiline:getspec(node) + if not minetest.registered_nodes[node.name] then return false end + return minetest.registered_nodes[node.name].digiline +end + +function digiline:importrules(spec, node) + if type(spec) == 'function' then + return spec(node) + elseif spec then + return spec + else + return digiline.rules.default + end +end + +function digiline:getAnyInputRules(pos) + local node = minetest.get_node(pos) + local spec = digiline:getspec(node) + if not spec then return end + + if spec.wire then + return digiline:importrules(spec.wire.rules, node) + end + if spec.effector then + return digiline:importrules(spec.effector.rules, node) + end + + return rules +end + +function digiline:getAnyOutputRules(pos) + local node = minetest.get_node(pos) + local spec = digiline:getspec(node) + if not spec then return end + + if spec.wire then + return digiline:importrules(spec.wire.rules, node) + end + if spec.receptor then + return digiline:importrules(spec.receptor.rules, node) + end +end + +function digiline:rules_link(output, input) + local outputrules = digiline:getAnyOutputRules(output) + local inputrules = digiline:getAnyInputRules (input) + + if not outputrules or not inputrules then return false end + + + for _, orule in ipairs(outputrules) do + if digiline:cmpPos(digiline:addPosRule(output, orule), input) then + for _, irule in ipairs(inputrules) do + if digiline:cmpPos(digiline:addPosRule(input, irule), output) then + return true + end + end + end + end + return false +end + +function digiline:rules_link_anydir(output, input) + return digiline:rules_link(output, input) + or digiline:rules_link(input, output) +end + +function digiline:transmit(pos, channel, msg, checked) + local checkedid = tostring(pos.x).."_"..tostring(pos.y).."_"..tostring(pos.z) + if checked[checkedid] then return end + checked[checkedid] = true + + local node = minetest.get_node(pos) + local spec = digiline:getspec(node) + if not spec then return end + + + -- Effector actions --> Receive + if spec.effector then + spec.effector.action(pos, node, channel, msg) + end + + -- Cable actions --> Transmit + if spec.wire then + local rules = digiline:importrules(spec.wire.rules, node) + for _,rule in ipairs(rules) do + if digiline:rules_link(pos, digiline:addPosRule(pos, rule)) then + digiline:transmit(digiline:addPosRule(pos, rule), channel, msg, checked) + end + end + end +end -- cgit v1.2.3