Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Specific to reactor configuration and placement
- local reactorSide = "left" -- Used to output redstone signal to run the reactor
- local reactorRelPos = "0,-1,-1" -- Relative position from sensor, check "sensorview"
- local maxCookDuration = 716 -- How long does it take (seconds) in THIS reactor to enrich a cell
- local cellSlots = {2, 10, 12, 20} -- Where are the slots for depleted cells
- local uraniumSlots = {11} -- What slots do you want to monitor for uranium, factors into getCookDuration()
- -- Predefining vars, no need to change these
- local cooking = false
- local cookTimer = 0
- local startedTime = 0
- local cookDuration = 0
- -- Find a monitor
- local monitor = nil
- local monitorWidth, monitorHeight = 0
- for sideId, side in ipairs(redstone.getSides()) do
- if peripheral.getType(side) == "monitor" then
- monitor = peripheral.wrap(side)
- monitor.setTextScale(0.5)
- monitorWidth, monitorHeight = monitor.getSize()
- end
- end
- -- Find inventory sensor
- os.loadAPI("ocs/apis/sensor")
- local invSensor = nil
- for sideId, side in ipairs(redstone.getSides()) do
- if peripheral.getType(side) == "sensor" then
- local tempSensor = sensor.wrap(side)
- if tempSensor.getTargetDetails("0,0,0").Slots[1].RawName == "openccsensors.item.inventorysensor" then
- invSensor = sensor.wrap(side)
- end
- end
- end
- local terminalWidth, terminalHeight = term.getSize()
- term.clear()
- local myLine = "Breeder Reactor Control"
- term.setCursorPos(terminalWidth/2-string.len(myLine)/2, 2)
- term.write(myLine)
- myLine = "Press 'Q' to terminate Breeder Control"
- term.setCursorPos(terminalWidth/2-string.len(myLine)/2, 5)
- term.write(myLine)
- local function displayStatus()
- local statusColor = (cooking and colors.red or colors.lime)
- local statusMessage = (cooking and "Enriching" or "Idle")
- local remainingSeconds = math.floor(startedTime + cookDuration - os.clock())
- if monitor ~= nil then
- monitor.setTextColor(statusColor)
- monitor.setCursorPos(monitorWidth/2-string.len(statusMessage)/2, 3)
- monitor.clearLine()
- monitor.write(statusMessage)
- monitor.setCursorPos(monitorWidth/2-6, 6)
- end
- term.setCursorPos(terminalWidth/2-6, 11)
- if cooking then
- term.write("Remaining: "..remainingSeconds.." ")
- if monitor ~= nil then
- monitor.setCursorPos(monitorWidth/2-6, 6)
- monitor.write("Remaining: "..remainingSeconds.." ")
- end
- else
- term.clearLine()
- if monitor ~= nil then monitor.clearLine() end
- end
- end
- local function getCookDuration()
- local duration = 0
- local cellDamage = 0
- local uraniumDamage = 10000
- if invSensor == nil then return maxCookDuration end -- if we don't have a sensor then just cook for the max time
- local reactor = invSensor.getTargetDetails(reactorRelPos)
- local i
- for i = 1, #cellSlots do
- if reactor.Slots[cellSlots[i]].RawName == "item.reactorisotopecell" then
- if reactor.Slots[cellSlots[i]].DamageValue > cellDamage then
- cellDamage = reactor.Slots[cellSlots[i]].DamageValue
- end
- end
- end
- duration = math.ceil(cellDamage/(10000/maxCookDuration)) + 2 -- 2 seconds added to cover the margins
- for i = 1, #uraniumSlots do
- local name = string.find(reactor.Slots[uraniumSlots[i]].RawName, "item.reactoruranium")
- if name ~= nil and not depleted then
- if reactor.Slots[uraniumSlots[i]].DamageValue < uraniumDamage then
- uraniumDamage = reactor.Slots[uraniumSlots[i]].DamageValue
- end
- end
- end
- local maxDuration = 10000 - uraniumDamage
- if (duration) <= maxDuration then
- return duration
- else
- return maxDuration
- end
- end
- os.queueEvent("stopcooking")
- local displayTimer = 0
- while true do
- local event, p1 = os.pullEvent()
- if event == "key" and p1 == 16 then -- 'q' was pressed
- redstone.setOutput(reactorSide, false)
- term.setCursorPos(1, terminalHeight-3)
- if monitor ~= nil then monitor.clear() end
- return
- elseif event == "key" and p1 == 18 and not cooking then -- 'e' pressed and not cooking already
- os.queueEvent("startcooking")
- elseif event == "redstone" and redstone.getInput("front") and not cooking then -- The button was pushed and we aren't cooking
- os.queueEvent("startcooking")
- elseif event == "startcooking" then
- cooking = true
- cookDuration = getCookDuration()
- redstone.setOutput(reactorSide, true)
- cookTimer = os.startTimer(cookDuration)
- startedTime = os.clock()
- myLine = "Press 'T' to terminate cell enrichment"
- term.setCursorPos(terminalWidth/2-string.len(myLine)/2, 7)
- term.clearLine()
- term.write(myLine)
- displayStatus()
- displayTimer = os.startTimer(1)
- elseif event == "key" and p1 == 20 and cooking then -- 't' pressed and cooking so terminate current cook run
- os.queueEvent("stopcooking")
- elseif event == "timer" and p1 == cookTimer and cooking then -- enrichment complete, shut down breeder
- os.queueEvent("stopcooking")
- elseif event == "stopcooking" then
- cooking = false
- redstone.setOutput(reactorSide, false)
- myLine = "Press 'E' to begin cell enrichment"
- term.setCursorPos(terminalWidth/2-string.len(myLine)/2, 7)
- term.clearLine()
- term.write(myLine)
- displayStatus()
- elseif event == "timer" and p1 == displayTimer then
- displayStatus()
- displayTimer = os.startTimer(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment