Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local comp = require("component")
- local s = require("sides")
- local t = comp.transposer
- local gpu = comp.gpu
- local rs = comp.redstone
- local mfsu = comp.ic2_te_mfsu
- gpu.setResolution(80,40)
- local sWidth, sHeight = gpu.getResolution()
- local interfaceSide = s.top
- local inputSlot = 1
- local outputSlot = 2
- local fuelDamage = 10000
- local numOfReactors = 4
- local reactors = {[1]={["side"]=s.west, ["slot"]=14, ["fuel"]=0},
- [2]={["side"]=s.west, ["slot"]=17, ["fuel"]=0},
- [3]={["side"]=s.east, ["slot"]=14, ["fuel"]=0},
- [4]={["side"]=s.east, ["slot"]=17, ["fuel"]=0}}
- local storageEnergy = 0
- local storageDelta = 0
- local storageCapacity = 0
- function CheckReactor(side, slot)
- stack = t.getStackInSlot(side, slot)
- if(stack ~= nil) then
- if(stack.name == "ic2:nuclear") then
- --t.transferItem(s.bottom, s.top, slot, 1)
- return 0
- else
- if(stack.customDamage == nil) then
- return fuelDamage
- end
- return fuelDamage - stack.customDamage
- end
- end
- return 0
- end
- function RefuelReactor(side, slot)
- --Transfer Out
- t.transferItem(side, interfaceSide, 1, slot)
- --Transfer In
- t.transferItem(interfaceSide, side, 1, inputSlot, slot)
- end
- function GetStorage()
- if(storageCapacity == 0) then storageCapacity = mfsu.getCapacity() end
- lastEnergy = storageEnergy
- storageEnergy = mfsu.getEnergy()
- storageDelta = storageEnergy - lastEnergy
- end
- function DisplayClear()
- gpu.setBackground(0x000000, false)
- gpu.fill(1,1, sWidth, sHeight, " ")
- end
- function DisplayBar(y, height, value, text, fgColor1, fgColor2, bgColor1, bgColor2, bgColor3)
- xText = math.floor(((sWidth-2) - #text)/2)+2
- xFill = math.floor((sWidth-2)*value + 0.5)+2
- yText = y + math.floor(height/2)
- gpu.setForeground(fgColor1, false)
- for y=y,y+height-1 do
- if(y == yText) then
- for x=2,xText-1 do
- bgColor = bgColor1
- if(x<xFill) then
- if(x%2==1) then bgColor = bgColor2 end
- else
- bgColor = bgColor3
- end
- gpu.setBackground(bgColor, false)
- gpu.set(x,y, " ")
- end
- x = xText
- for c in text:gmatch(".") do
- bgColor = bgColor1
- if(x<xFill) then
- if(x%2==1) then bgColor = bgColor2 end
- else
- bgColor = bgColor3
- gpu.setForeground(fgColor2, false)
- end
- gpu.setBackground(bgColor, false)
- gpu.set(x,y, c)
- x = x + 1
- end
- for x=xText+#text,sWidth-1 do
- bgColor = bgColor1
- if(x<xFill) then
- if(x%2==1) then bgColor = bgColor2 end
- else
- bgColor = bgColor3
- end
- gpu.setBackground(bgColor, false)
- gpu.set(x,y, " ")
- end
- else
- for x=2,sWidth-1 do
- bgColor = bgColor1
- if(x < xFill) then
- if(x%2==1) then bgColor = bgColor2 end
- else
- bgColor = bgColor3
- end
- gpu.setBackground(bgColor, false)
- gpu.set(x,y, " ")
- end
- end
- end
- end
- function DisplayUpdate()
- --DisplayClear()
- storageText = (math.floor(storageEnergy).. " / " .. math.floor(storageCapacity))
- DisplayBar(2,19, storageEnergy/storageCapacity, storageText, 0x222222, 0xAAAAAA, 0x00B6FF, 0x66B6FF, 0x111111)
- end
- DisplayClear()
- while true do
- rFuelStrings = "Reactors: "
- -- Update Reactors
- for r=1,numOfReactors do
- rSide = reactors[r]["side"]
- rSlot = reactors[r]["slot"]
- rFuel = CheckReactor(rSide, rSlot)
- if(rFuel == 0) then
- RefuelReactor(rSide, rSlot)
- end
- rFuel = CheckReactor(rSide, rSlot)
- --rFuelStrings = rFuelStrings .. "[" .. r .. "]: " .. math.floor(rFuel/fuelDamage * 100) .. ", "
- reactors[r]["fuel"] = rFuel
- end
- --print(rFuelStrings)
- --Update Storage
- GetStorage()
- --print("Storage: " .. math.floor(storageEnergy/storageCapacity * 100))
- if(storageEnergy/storageCapacity < 0.75) then
- rs.setOutput(s.east, 1)
- rs.setOutput(s.west, 1)
- elseif(storageEnergy/storageCapacity > 0.99) then
- rs.setOutput(s.east, 0)
- rs.setOutput(s.west, 0)
- end
- DisplayUpdate()
- os.sleep(1)
- -- break
- end
- --print(CheckReactor(s.top, 1))
- --RefuelReactor(s.top, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement