Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Credit Flaghacker
- --Settings
- --how many slots the bioreactor has to contain in order to be "filled"
- local minSlots = 4
- -- the peripheral id for a bioreactor
- local bioReactorId = "bioreactor"
- --(optionally) the side of the bioreactor
- local bioReactorSide
- --vars
- local p
- local s = 10
- local e = 18
- --util
- function printBoolean(boolean)
- if term.isColor() then
- if boolean then
- term.setTextColor(colors.lime)
- else
- term.setTextColor(colors.red)
- end
- end
- print(boolean)
- if term.isColor() then
- term.setTextColor(colors.white)
- end
- end
- --functions
- local function wrapPeripheral()
- if bioReactorSide == nil then
- for i, v in ipairs(rs.getSides()) do
- if peripheral.getType(v) == bioReactorId then
- p = peripheral.wrap(v)
- bioReactorSide = v;
- return
- end
- end
- else
- if (peripheral.getType(bioReactorSide)) == bioReactorId then
- p = peripheral.wrap(bioReactorSide)
- else
- error(string.format("The peripheral on side '%s' is not of type '%s', but of type '%s'", tostring(bioReactorSide), tostring(bioReactorId), tostring(peripheral.getType(bioReactorSide))))
- end
- end
- error("No bioreactor could be found")
- end
- local function isSlotFilled(slot)
- return not (p.getStackInSlot(slot) == nil)
- end
- local function isReactorFilled()
- local t = 0;
- for i = s, e do
- if (isSlotFilled(i)) then
- t = t + 1
- end
- end
- return t >= minSlots
- end
- --main code
- wrapPeripheral()
- while true do
- local a = isReactorFilled()
- rs.setOutput(bioReactorSide, not a)
- rs.setOutput("top", not a)
- term.clear()
- write("Bio reactor enabled: ")
- printBoolean(a)
- sleep(.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment