Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- debugger = true --TURN DEBUG CONSOLE ON(true)/OFF(false)
- refreshrate = 1 --RATE THE VALUES REFRESH (IN SECONDS)
- --[[
- Code name:
- Reactor Glass
- Mod requirements:
- Open Peripherals
- Big Reactors
- Coded by Cameron Lund
- Bukkit: ShadowDisruptor
- BukkitDev: ShadowDisrupter
- Minecraft: footballfan12
- Pastebin: footballfan12
- License
- Fair-use
- --]]
- --General setup
- term.clear()
- print("Booting ReactorGlass")
- local bridge = peripheral.wrap("top")
- bridge.clear()
- casingTemp = 0
- fuelTemp = 0
- --Function to draw logo
- --Please DO NOT take this away! This is my credit for the code.
- function drawLogo(x,y)
- reactorsFound = bridge.addText(x,y+20,("starting"),0xe0e0e0)
- reactorsFound.setScale(0.5)
- logo = bridge.addIcon(x,y,0764,16384)
- text1 = bridge.addText(x+17,y+3,"FootCo Tech.",0xe0e0e0)
- text2 = bridge.addText(x+17,y+12,"Simplicity for all",0xe0e0e0)
- text2.setScale(0.5)
- end
- drawLogo(10,10)
- reactorsFound.setText("Setting variables")
- local bigReactors = {}
- local passiveReactors = {}
- local activeReactors = {}
- local allowedCommanders = {}
- local bridges = { }
- local messages={}
- local textBoxs={}
- local white=0xFAFFFF
- local black=0xE6F5EB
- local yellow=0xFFFFA3
- local red=0xFF0000
- local hasPassives = false
- local hasActives = false
- sleep(0.2)
- reactorsFound.setText("Compiling functions")
- --Following functions are used to get data from reactors.
- -- Internal energy(Buffer)
- function getEnergy()
- local energy = 0
- local maxEnergy = 0
- for i=1,#passiveReactors do
- local tempReactor = peripheral.wrap(passiveReactors[i])
- energy = energy + tempReactor.getEnergyStored()
- maxEnergy = maxEnergy + 10000000
- end
- local step1 = energy * 100
- local step2 = step1/maxEnergy
- local step3 = math.floor(step2 + 0.5)
- return step3
- end
- -- Internal fuel
- function getInternalFuel()
- local fuel = 0
- local maxFuel = 0
- for i=1,#passiveReactors do
- tempReactor = peripheral.wrap(passiveReactors[i])
- fuel = fuel + tempReactor.getFuelAmount()
- maxFuel = maxFuel + tempReactor.getFuelAmountMax()
- end
- local step1 = fuel * 100
- local step2 = step1/maxFuel
- local step3 = math.floor(step2 + 0.5)
- return step3
- end
- -- Fuel temperature active
- function getFuelTemperature2()
- local temp = 0
- local maxTemp = 0
- for i=1,#activeReactors do
- tempReactor = peripheral.wrap(activeReactors[i])
- temp = temp + tempReactor.getFuelTemperature()
- maxTemp = maxTemp + 3500
- fuelTemp = temp
- end
- local step1 = temp*100
- local step2 = step1/maxTemp
- local step3 = math.floor(step2 + 0.5)
- return step3
- end
- -- Fuel temperature passive
- function getFuelTemperature()
- local temp = 0
- local maxTemp = 0
- for i=1,#passiveReactors do
- tempReactor = peripheral.wrap(passiveReactors[i])
- temp = temp + tempReactor.getFuelTemperature()
- maxTemp = maxTemp + 3500
- fuelTemp = temp
- end
- for i=1,#activeReactors do
- tempReactor = peripheral.wrap(activeReactors[i])
- temp = temp + tempReactor.getFuelTemperature()
- maxTemp = maxTemp + 3500
- maxFuelTemp2 = temp
- end
- local step1 = temp*100
- local step2 = step1/maxTemp
- local step3 = math.floor(step2 + 0.5)
- return step3
- end
- -- Casing temperature
- function getCasingTemperature()
- local temp = 0
- local maxTemp = 0
- for i=1,#passiveReactors do
- tempReactor = peripheral.wrap(passiveReactors[i])
- temp = temp + tempReactor.getCasingTemperature()
- maxTemp = maxTemp + 3500
- casingTemp = temp
- end
- local step1 = temp*100
- local step2 = step1/maxTemp
- local step3 = math.floor(step2 + 0.5)
- return step3
- end
- -- Coolant amount (Internal)
- function getCoolantAmount()
- return 50
- end
- -- Hot fluid amount (Internal)
- function getHotFluidAmount()
- return 50
- end
- --
- --Function to post to debugger
- function chat(message, color , mes )
- if debugger == true then
- xPos1 = 211
- if mes == true then
- message="<CONSOLE> " ..message
- elseif not mes then
- message="<ERROR> " ..message
- end
- if string.len(message)<70 then
- table.insert(textBoxs, bridge.addText(xPos1, 5, message, color))
- textBoxs[#textBoxs].setScale(.5)
- textBoxs[#textBoxs].setY(7+(#textBoxs*6))
- again=false
- else
- table.insert(textBoxs, bridge.addText( xPos1, 5, string.sub(message, 1, 70), color))
- textBoxs[#textBoxs].setScale(.5)
- textBoxs[#textBoxs].setY(7+(#textBoxs*6))
- again=true
- end
- if #textBoxs>8 then
- for i=1,#textBoxs do
- num=#textBoxs-i+1
- if textBoxs[num-1]~= nil then
- textBoxs[num].setY(textBoxs[num-1].getY())
- else
- textBoxs[num].delete()
- table.remove(textBoxs, num)
- end
- end
- end
- if again then
- newMessage(string.sub(message, 70, string.len(message)), color, true)
- end
- sleep(0.5)
- end
- end
- --Function to check which peripherals are reactors
- local function isReactor(input)
- local tempReactor = peripheral.wrap(input)
- local checkReactor = tempReactor.getConnected()
- return checkReactor
- end
- --Function to determine active/passive reactors
- local function whatIs(input)
- local reactor = peripheral.wrap(input)
- local whatIsIt = reactor.isActivelyCooled()
- if whatIsIt then
- table.insert(activeReactors, input)
- else
- table.insert(passiveReactors, input)
- end
- end
- --Function to draw passive group
- function drawPassive(xPos, yPos)
- passiveSubTitle = bridge.addText(xPos-1,yPos-2,("Passive reactor(s) averages"),0xe0e0e0)
- passiveSubTitle.setScale(0.5)
- text1 = bridge.addText((xPos-1),(yPos+3)," Label",0xe0e0e0)
- text1.setScale(0.5)
- text1_1 = bridge.addText((xPos-1),(yPos+7)," Label",0xe0e0e0)
- text1_1.setScale(0.5)
- outline1 = bridge.addBox((xPos-1),(yPos+11),52,7,0xe0e0e0)
- barGreen1= bridge.addBox((xPos),(yPos+12),0,5,0x4dff4d,0.7)
- barYellow1 = bridge.addBox((xPos+17),(yPos+12),0,5,0xffff4d,0.7)
- barRed1 = bridge.addBox((xPos+33),(yPos+12),0,5,0xff3333,0.7)
- ourBar1 = {barGreen1,barYellow1,barRed1,outline1,text1,text1_1}
- text2 = bridge.addText((xPos+54),(yPos+3)," Label",0xe0e0e0)
- text2.setScale(0.5)
- text2_1 = bridge.addText((xPos+54),(yPos+7)," Label",0xe0e0e0)
- text2_1.setScale(0.5)
- outline2 = bridge.addBox((xPos+54),(yPos+11),52,7,0xe0e0e0)
- barGreen2= bridge.addBox((xPos+55),(yPos+12),0,5,0x4dff4d,0.7)
- barYellow2 = bridge.addBox((xPos+71),(yPos+12),0,5,0xffff4d,0.7)
- barRed2 = bridge.addBox((xPos+87),(yPos+12),0,5,0xff3333,0.7)
- ourBar2 = {barGreen2,barYellow2,barRed2,outline2,text2,text2_1}
- text3 = bridge.addText((xPos-1),(yPos+19)," Label",0xe0e0e0)
- text3.setScale(0.5)
- text3_1 = bridge.addText((xPos-1),(yPos+23)," Label",0xe0e0e0)
- text3_1.setScale(0.5)
- outline3 = bridge.addBox((xPos-1),(yPos+27),52,7,0xe0e0e0)
- barGreen3= bridge.addBox((xPos),(yPos+28),0,5,0x4dff4d,0.7)
- barYellow3 = bridge.addBox((xPos+17),(yPos+28),0,5,0xffff4d,0.7)
- barRed3 = bridge.addBox((xPos+33),(yPos+28),0,5,0xff3333,0.7)
- ourBar3 = {barGreen3,barYellow3,barRed3,outline3,text3,text3_1}
- text4 = bridge.addText((xPos+54),(yPos+19)," Label",0xe0e0e0)
- text4.setScale(0.5)
- text4_1 = bridge.addText((xPos+54),(yPos+23)," Label",0xe0e0e0)
- text4_1.setScale(0.5)
- outline4 = bridge.addBox((xPos+54),(yPos+27),52,7,0xe0e0e0)
- barGreen4= bridge.addBox((xPos+55),(yPos+28),0,5,0x4dff4d,0.7)
- barYellow4 = bridge.addBox((xPos+71),(yPos+28),0,5,0xffff4d,0.7)
- barRed4 = bridge.addBox((xPos+87),(yPos+28),0,5,0xff3333,0.7)
- ourBar4 = {barGreen4,barYellow4,barRed4,outline4,text4,text4_1}
- ourBar4 = {barGreen4,barYellow4,barRed4,outline4,text4,text4_1}
- text_rf_tick = bridge.addText((xPos-1),(yPos+32),"KiRF/t: ",0xe0e0e0)
- text_fuel_burnup = bridge.addText((xPos-1),(yPos+36),"Fuel burnup rate:",0xe0e0e0)
- text_rf_tick.setScale(0.5)
- text_fuel_burnup.setScale(0.5)
- end
- --Function to draw active group
- function drawActive(xPos, yPos)
- activeSubTitle = bridge.addText(xPos-1,yPos-2,("Active reactor(s) totals"),0xe0e0e0)
- activeSubTitle.setScale(0.5)
- text5 = bridge.addText((xPos-1),(yPos+3)," Label",0xe0e0e0)
- text5.setScale(0.5)
- outline5 = bridge.addBox((xPos-1),(yPos+7),53,7,0xe0e0e0)
- barGreen5= bridge.addBox((xPos),(yPos+8),0,5,0x4dff4d,0.7)
- barYellow5 = bridge.addBox((xPos+17),(yPos+8),0,5,0xffff4d,0.7)
- barRed5 = bridge.addBox((xPos+33),(yPos+8),0,5,0xff3333,0.7)
- ourBar5 = {barGreen1,barYellow1,barRed1,outline1,text1}
- text6 = bridge.addText((xPos+54),(yPos+3)," Label",0xe0e0e0)
- text6.setScale(0.5)
- outline6 = bridge.addBox((xPos+54),(yPos+7),53,7,0xe0e0e0)
- barGreen6= bridge.addBox((xPos+55),(yPos+8),0,5,0x4dff4d,0.7)
- barYellow6 = bridge.addBox((xPos+71),(yPos+8),0,5,0xffff4d,0.7)
- barRed6 = bridge.addBox((xPos+87),(yPos+8),0,5,0xff3333,0.7)
- ourBar6 = {barGreen2,barYellow2,barRed2,outline2,text2}
- text7 = bridge.addText((xPos-1),(yPos+17)," Label",0xe0e0e0)
- text7.setScale(0.5)
- outline7 = bridge.addBox((xPos-1),(yPos+21),53,7,0xe0e0e0)
- barGreen7= bridge.addBox((xPos),(yPos+22),0,5,0x4dff4d,0.7)
- barYellow7 = bridge.addBox((xPos+17),(yPos+22),0,5,0xffff4d,0.7)
- barRed7 = bridge.addBox((xPos+33),(yPos+22),0,5,0xff3333,0.7)
- ourBar7 = {barGreen3,barYellow3,barRed3,outline3,text3}
- text8 = bridge.addText((xPos+54),(yPos+17)," Label",0xe0e0e0)
- text8.setScale(0.5)
- outline8 = bridge.addBox((xPos+54),(yPos+21),53,7,0xe0e0e0)
- barGreen8= bridge.addBox((xPos+55),(yPos+22),0,5,0x4dff4d,0.7)
- barYellow8 = bridge.addBox((xPos+71),(yPos+22),0,5,0xffff4d,0.7)
- barRed8 = bridge.addBox((xPos+87),(yPos+22),0,5,0xff3333,0.7)
- ourBar8 = {barGreen4,barYellow4,barRed4,outline4,text4}
- end
- --Function to update our bars
- function updateBar(tableName, number)
- while true do
- if number <= 16 then
- tableName[1].setWidth(number)
- tableName[2].setWidth(0)
- tableName[3].setWidth(0)
- break
- elseif ((number >= 17) and (number <= 32)) then
- tableName[2].setWidth(number-16)
- tableName[1].setWidth(16)
- tableName[3].setWidth(0)
- break
- elseif ((number >= 33) and (number <= 50)) then
- tableName[3].setWidth(number-32)
- tableName[1].setWidth(16)
- tableName[2].setWidth(16)
- break
- end
- end
- end
- --Function to update bar labels
- function updateLabel(labelName , labelText, suffix, number)
- labelName[5].setText(labelText..": ")
- local message = math.floor(number)..suffix
- labelName[6].setText(message)
- end
- --END OF FUNCTIONS
- reactorsFound.setText("Managing peripherals..")
- print("Looking for peripherals...")
- foundPeripherals = peripheral.getNames()
- if not (#foundPeripherals == 0) then
- chat(#foundPeripherals.." peripherals found!",yellow,true)
- chat("Checking if any peripherals are reactors...",yellow,true)
- for i=1,#foundPeripherals do
- local ok, err = pcall(isReactor, foundPeripherals[i])
- if ok then
- table.insert(bigReactors, foundPeripherals[i])
- else
- chat(foundPeripherals[i].." is not a reactor!",red,false)
- end
- end
- foundPeripherals = nil
- if #bigReactors > 0 then
- chat("Checking the "..#bigReactors.." big reactors items for passive/active",yellow,true)
- for i=1,#bigReactors do
- local ok, err = pcall(whatIs,bigReactors[i])
- end
- chat("Active reactors found: "..#activeReactors,yellow,true)
- chat("Passive reactors found: "..#passiveReactors,yellow,true)
- else
- reactorsFound.setText("No reactors found!")
- chat("No reactors found!",red,false)
- end
- else
- print("No peripherals found!")
- end
- --##############
- --#END OF SETUP#
- --##############
- --Checking what we're working with...
- if #passiveReactors > 0 then
- hasPassives = true
- end
- if #activeReactors > 0 then
- hasActives = true
- end
- --Drawing the GUI accordingly...
- if ((hasPassives == true) and (hasActives == true)) then--We have both active and passive
- drawPassive(10,40)
- drawActive(10,80)
- elseif ((hasPassives == false) and (hasActives == true)) then--We just have active
- drawActive(10,40)
- elseif ((hasPassives == true) and (hasActives == false)) then--We just have passive
- drawPassive(10,40)
- else
- chat("Neither actives or passives being found!",red,false)
- end
- --FIX THIS
- reactorsFound.setText("Found reactors: "..#passiveReactors.." passive, "..#activeReactors.." active.")
- function updateBoard()
- if hasPassives then
- updateBar(ourBar1, (getEnergy()/2))
- updateBar(ourBar2, (getInternalFuel()/2))
- updateBar(ourBar3, (getFuelTemperature()/2))
- updateBar(ourBar4, (getCasingTemperature()/2))
- updateLabel(ourBar1, "Buffer","%",getEnergy())
- updateLabel(ourBar2, "Internal fuel","%",getInternalFuel())
- updateLabel(ourBar3, "Fuel temperature"," C",math.floor(fuelTemp/#passiveReactors))
- updateLabel(ourBar4, "Casing temperature"," C",math.floor(casingTemp/#passiveReactors))
- end
- if hasActives then
- updateBar(ourBar5, (getEnergy()/2))
- updateBar(ourBar6, (getInternalFuel()/2))
- updateBar(ourBar7, (getFuelTemperature()/2))
- updateBar(ourBar8, (getCasingTemperature()/2))
- updateLabel(ourBar5, "Internal fuel","%",getInternalFuel2())
- updateLabel(ourBar6, "Fuel temperature","C",maxFuelTemp2)
- updateLabel(ourBar7, "Fuel temperature"," C",maxFuelTemp)
- updateLabel(ourBar8, "Casing temperature"," C",maxCasingTemp)
- end
- end
- while true do
- updateBoard()
- sleep(refreshrate)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement