Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - local tArgs = { ... }
 - reactor = {
 - controlFace = 'bottom',
 - senseFace = 'front',
 - turnedOn = false,
 - on = function()
 - rs.setOutput(reactor.controlFace, true)
 - turnedOn = true
 - end,
 - off = function()
 - rs.setOutput(reactor.controlFace, false)
 - turnedOn = false
 - end,
 - -- Detects whether the reactor has been disabled
 - -- False unless both we and the thermal monitor allow it to run
 - isRunning = function()
 - return not rs.getInput(reactor.senseFace)
 - end,
 - -- Run the reactor until the thermal monitor stops it
 - heat = function()
 - reactor.on()
 - sleep(0.1)
 - while reactor.isRunning() do
 - sleep(1)
 - end
 - reactor.off()
 - end,
 - -- Run the reactor for a fixed duration
 - run = function(duration)
 - reactor.on()
 - sleep(duration)
 - reactor.off()
 - end
 - }
 - breeder = {
 - iceInventorySlot = 3,
 - cellInventorySlot = 4,
 - -- Run the reactor, chilling if necessary to start
 - run = function(duration)
 - reactor.on()
 - sleep(0.1)
 - if not reactor.isRunning() then
 - reactor.off()
 - breeder.chill()
 - reactor.on()
 - sleep(0.1)
 - end
 - reactor.run(duration)
 - end,
 - replaceCoolant = function()
 - breeder.getCoolant()
 - breeder.putCoolant()
 - end,
 - -- Get a pair of coolant cells
 - getCoolant = function()
 - turtle.turnLeft()
 - for slot = 1,2 do
 - turtle.select(slot)
 - while not turtle.suck() do
 - print("No coolant left")
 - io.read("*l")
 - end
 - end
 - turtle.turnRight()
 - end,
 - -- Put in the reactor, running until we can
 - putCoolant = function()
 - for slot = 1,2 do
 - turtle.select(slot)
 - local success = turtle.drop()
 - while not success do
 - breeder.run(5.0)
 - turtle.select(slot)
 - success = turtle.drop()
 - end
 - end
 - end,
 - -- Use a single piece of ice to chill the reactor
 - -- Brings below the thermal monitor's cutoff, letting the reactor run
 - chill = function()
 - if not reactor.isRunning() then
 - breeder.getIce()
 - breeder.swapInIce()
 - end
 - end,
 - getIce = function()
 - turtle.turnRight()
 - print("Getting ice")
 - turtle.select(breeder.iceInventorySlot)
 - turtle.suck()
 - -- Put back all but one
 - if turtle.getItemCount(breeder.iceInventorySlot) > 1 then
 - turtle.drop(turtle.getItemCount(breeder.iceInventorySlot) - 1)
 - end
 - turtle.turnLeft()
 - end,
 - -- Melt ice in reactor
 - swapInIce = function()
 - -- Pull out top left cell
 - turtle.select(breeder.cellInventorySlot)
 - turtle.suck()
 - -- Put ice in reactor
 - turtle.select(breeder.iceInventorySlot)
 - local success = turtle.drop()
 - if success then
 - print("Chilled")
 - end
 - -- Wait for it to melt
 - sleep(2.0)
 - -- Put cell back in
 - turtle.select(breeder.cellInventorySlot)
 - turtle.drop()
 - end,
 - -- Run a series of breeder cycles
 - doCycles = function(nCycles)
 - local i
 - for i = 1,nCycles do
 - print("Cycle " .. i .. "/" .. nCycles)
 - reactor.heat()
 - breeder.replaceCoolant()
 - breeder.writeRemainingFile(nCycles - i)
 - breeder.run(65.0)
 - end
 - end,
 - -- Writes a script to "remaining" which will finish the current run if executed
 - writeRemainingFile = function(cycles)
 - local h = io.open('remaining', 'w')
 - h:write("shell.run('breeder', ")
 - h:write(cycles)
 - h:write(")")
 - h:close()
 - end,
 - orientToFaceReactor = function()
 - reactor.off()
 - sleep(0.2)
 - while not rs.getInput('front') do
 - turtle.turnRight()
 - end
 - end
 - }
 - local nCycles = tArgs[1] or "6"
 - breeder.orientToFaceReactor()
 - print("Initial heat")
 - reactor.heat()
 - breeder.doCycles(nCycles)
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment