Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local serumSlot = 2
- function dumpSerum()
- while turtle.getItemCount(1) > 0 do
- turtle.select(1)
- while not turtle.drop() do
- print("failed to drop serum")
- sleep(1)
- end
- end
- end
- function synthesizerDone()
- local mach = peripheral.wrap("bottom")
- local itemInfo = mach.getStackInSlot(serumSlot)
- return itemInfo ~= nil and itemInfo["dmg"] == 0
- end
- function purifierDone()
- local mach = peripheral.wrap("bottom")
- local itemInfo = mach.getStackInSlot(serumSlot)
- -- shouldn't happen
- if itemInfo == nil then
- return false
- end
- -- Since there's nothing better to go by, we're
- -- going to guess if it's done based on how
- -- how it's energy storage changes over the course
- -- of a few seconds.
- -- If we're low on BNA, assume we're waiting for more
- local bnaTank = mach.getTanks("unknown")[1]
- if (bnaTank.amount == nil or bnaTank.amount < 1000) then
- return false
- end
- local maxPow = 0 + mach.getMaxEnergyStored()
- local startPow = 0 + mach.getEnergyStored()
- sleep(2)
- local endPow = 0 + mach.getEnergyStored()
- -- if the machine is almost full, assume we're done
- if (maxPow - endPow) < 10 then
- return true
- end
- -- I'm afraid of odd ball behavior when we're almost
- -- out of power, let's play it safe
- if endPow < 1000 then
- return false
- end
- -- if we had a gain in energy, we're done
- if endPow - startPow > 20 then
- return true
- end
- -- Either there is an energy shortage, or we're still
- -- working
- return false
- end
- local machineDone = nil
- if args[1] == "purifier" then
- machineDone = purifierDone
- elseif args[1] == "synthesizer" then
- machineDone = synthesizerDone
- else
- print("bad machine name, or arg")
- print("expected one of: purifier, synthesizer")
- error()
- end
- function machineEmpty()
- local mach = peripheral.wrap("bottom")
- local itemInfo = mach.getStackInSlot(serumSlot)
- return itemInfo == nil
- end
- function transferSerum()
- turtle.select(1)
- turtle.suckDown()
- end
- function main()
- dumpSerum()
- while true do
- if machineEmpty() then
- sleep(15)
- else
- if machineDone() then
- transferSerum()
- dumpSerum()
- else
- sleep(1)
- end
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment