if event.type == "program" then -- mem = {} -- mem.events = {} mem.orderSize = 20 mem.outputSize = 22 mem.inputName = "Tacit:tinrefab" mem.itemName = "default:tin_lump" mem.orderName = "tinrefab" mem.interruptInterval = 30 -- mem.power = "off" -- mem.outputCount = 0 -- mem.injectCount = 0 -- mem.state = "checkchest" interrupt(mem.interruptInterval) end if event.type == "interrupt" then if mem.power ~= "off" or mem.outputCount ~= 0 then port.b = not port.b end if mem.state == "checkchest" then digiline_send("chest",{command="get_list"}) end if mem.state == "ordering" then local order = { name=mem.orderName, destination=mem.inputName, item=mem.itemName, stacksize=99, count=mem.orderSize, } digiline_send("drawercontroller", order) mem.state = "waitorder" end if mem.state == "inject" then digiline_send("injector", {name=mem.itemName, count = 99, tags=mem.itemName}) mem.state = "waitoutput" end interrupt(mem.interruptInterval) end if event.type == "digiline" then if event.channel == "chest" then if event.msg.event and event.msg.event == "inject" then mem.injectCount = mem.injectCount + 1 if mem.injectCount == mem.orderSize then mem.injectCount = 0 mem.state = "inject" end end if not event.msg.event then if mem.power == "off" then return end local emptyCount = 0 local stacks = 0 for k,v in pairs(event.msg) do if v == "" then emptyCount = emptyCount + 1 end if v ~= "" then stacks = stacks + 1 end end if stacks == 0 then mem.state = "ordering" else mem.state = "inject" end end end if event.channel == "detector" then mem.outputCount = mem.outputCount + 1 if mem.outputCount == mem.outputSize then mem.outputCount = 0 mem.state = "checkchest" end end end if event.type == "off" then mem.power = "off" mem.interruptInterval = 10 end if event.type == "on" then mem.power = "on" if mem.state == "waitorder" then mem.state = "checkchest" end if mem.state == "waitoutput" then mem.state = "checkchest" mem.outputCount = 0 end mem.interruptInterval = 1 end