Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Biowatch Program
- -- Watches 2 Bioreactors and turns them on/off depending on how many items are in the reactor
- -- The first reactor will only try to keep one stack of each type of item in its buffer, it will push all
- -- duplicate stacks into the second reactor.
- -- The first reactor will only turn on when a certain number of items are being processed (default 8)
- -- The Second reactor will only turn on if there are 8 (defatult) or more items being processed, or if there are
- -- 6 or more item stacks in the inventory buffer
- -- In the way it is configured now, the first reactor is behind the computer,
- -- The second reactor is directly to the north of the first reactor, and is connected to
- -- the computer via a modem cable. The modem is on the bottom face of the computer
- -- Connected to the top of the computer is a rednet cable which connects to the two reactors
- -- The first reactor's connection is colored orange, the second is magenta
- -- Note: in order to connect a modem to the second reactor, a Peripheral Proxy is required
- local bio = peripheral.wrap("back") -- Location of first reactor
- local modem = peripheral.wrap("bottom") -- Location of modem for second reactor
- local machine = "tile_mfr_machine_bioreactor_name_0" -- Network name of second reactor (this is the default)
- local CableSide = "top" -- location of rednet cable
- local pushDirection = "north" -- Location of the second reactor relative to the first
- local firstReactorColor = colors.orange -- rednet cable color for first reactor
- local secondReactorColor = colors.magenta -- rednet cable color for first reactor
- local FirstReactorVariety = 8 -- number of items required in first reactor to turn on
- local SecondReactorVariety = 8 -- number of items required in second reactor to turn on
- function getSecondStack(stack)
- return modem.callRemote(machine,"getStackInSlot",stack)
- end
- function isIn(var,tab)
- for i,v in ipairs(tab) do
- if ( v == var ) then return true end
- end
- return false
- end
- function PushItem(slot)
- bio.pushItem(pushDirection,slot)
- end
- -- Checks if it should turn on the second reactor
- function checkSecond()
- local count = 0
- for i = 1,9 do
- if ( getSecondStack(i) ~= nil ) then count = count + 1 end
- end
- if ( count >= 6 ) then return false end
- count = 0
- for i=10,18 do
- if ( getSecondStack(i) ~= nil ) then count = count + 1 end
- end
- if ( count >= 8 ) then return false end
- return true
- end
- -- Main Loop
- while true do
- local idList = {}
- local numOfTypes = 0
- -- Check the inventory of the first reactor, push duplicate stacks to the second reactor.
- for i=1,9 do
- local item = bio.getStackInSlot(i)
- if ( item ~= nil ) then
- local code = item.id .. "." .. item.dmg
- if ( isIn(code,idList) ) then
- -- print("Pushing " .. i .. " " .. item.id)
- PushItem(i)
- else
- -- print("Adding " .. i .. " ".. item.id)
- table.insert(idList,code)
- end
- end
- end
- -- Count number of types being processed
- for i=10,18 do
- local item = bio.getStackInSlot(i)
- if ( item ~= nil ) then numOfTypes = numOfTypes + 1 end
- end
- -- Now determine if reactor should be on or off
- local first = true
- local second = checkSecond()
- if ( numOfTypes >= FirstReactorVariety ) then
- first = false
- else
- first = true
- end
- -- set the color outputs for the rednet cable
- local color = 0
- if ( first ) then color = color + firstReactorColor end
- if ( second ) then color = color + secondReactorColor end
- rs.setBundledOutput(CableSide,color)
- os.sleep(10)
- end
Add Comment
Please, Sign In to add comment