Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reactorDir = "left"
- local switchDir = "front"
- local interfaceDir = "north"
- local turtleDir = "east"
- local coolant = "back"
- local coolantID = 30099
- local maxTemp = 9000
- local maxDmg = 9000
- local tempMin = 6000
- local tempMax = 7500
- local reactor = peripheral.wrap(reactorDir)
- local items = nil
- local powered = false
- local on = true
- local off = false
- local critical = false
- local function switch(onOff)
- rs.setOutput(switchDir,onOff)
- powered = onOff --reactor.isActive() --onOff
- if onOff and powered then print("Reactor switched on: "..reactor.getHeat())
- else print("Reactor switched off: "..reactor.getHeat()) end
- end
- local function request(direction)
- rs.setOutput(direction,true)
- sleep(0.1)
- rs.setOutput(direction,false)
- end
- local function checkInv(i)
- local result = true
- if turtle.getItemCount(i) > 0 then
- print("Item found in slot " .. i)
- result = false
- end
- return result
- end
- local nMove = 0
- local item = nil
- local function exchangeParts()
- items = reactor.getAllStacks()
- for i,k in pairs(items) do
- if k.id == coolantID then
- if k.dmg >= maxDmg then
- --if powered then switch(off) end
- switch(off)
- --print("Reactor switched off for maintenance")
- nMove = 0
- while nMove ~= 1 do
- print("Attempting to remove cooling cell in slot " .. i)
- nMove = reactor.pushItem(interfaceDir,i,1)
- if nMove ~= 1 then sleep(1) end
- end
- print("Spent coolant cell removed")
- if not checkInv(1) then
- -- print("wtf")
- -- critical = false
- -- break
- reactor.pullItemIntoSlot(turtleDir, 1, 1, i)
- item = reactor.getStackInSlot(i)
- if item and item.id == coolantID then print("Coolant exchanged in slot "..i)
- else
- print("Coolant exchange failed in slot "..i)
- critical = true
- break
- end
- else
- print("Requesting coolant cell for slot "..i)
- item = reactor.getStackInSlot(i)
- while not item do
- if checkInv(1) then request(coolant) end
- reactor.pullItemIntoSlot(turtleDir, 1, 1, i)
- item = reactor.getStackInSlot(i)
- end
- if item and item.id == coolantID then print("Coolant exchanged in slot "..i)
- else
- print("Coolant exchange failed in slot "..i)
- critical = true
- break
- end
- end
- item = reactor.getStackInSlot(i)
- if not item or item.id ~= coolantID then
- print("no coolant in slot "..i)
- critical = true
- break
- end
- end
- end
- end
- end
- local function checkTemp()
- local T = reactor.getHeat()
- if T < tempMin then
- temperature = 1
- elseif T < tempMax then
- temperature = 0
- elseif T < maxTemp then
- print("Cooldown phase activated: "..T)
- temperature = -1
- else
- switch(off)
- print("Temperature above limit: "..T)
- critical = true
- on = false
- end
- end
- local function changeTemp()
- end
- while true do
- if powered and reactor.getHeat() >= maxTemp then switch(off) end
- if not powered and reactor.getHeat() < maxTemp then switch(on) end
- checkTemp()
- exchangeParts()
- if not critical and not powered then
- sleep(0.1)
- switch(on)
- elseif critical then
- switch(off)
- on = false
- print("Critical Error: All systems switched off")
- break
- end
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment