Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------Initialization--------
- local digTime = 9 --seconds
- local iterations = 0
- local cell = peripheral.wrap("back")
- local glass = peripheral.wrap("right")
- local numCapacitors = 197
- local glassTextColor = 0x000000
- local oldPowerNum = cell.getEnergyStored() * numCapacitors
- local powerNum = cell.getEnergyStored() * numCapacitors
- local power = "" --this is a string
- local in_outNum = (powerNum - oldPowerNum) / 2
- local in_out = "" --this is a string
- local isNegative = " " -- is ' ' if in-out is negative and "+" if positive
- local maxPowerNum = cell.getMaxEnergyStored() * numCapacitors
- local maxPower = "" --this is a string
- local percentage = (powerNum / maxPowerNum) * 100
- local in_outPercentage = (in_outNum / maxPowerNum) * 100
- local aeCutOff = colors.test (redstone.getBundledInput("top"), colors.white)
- local isIn_OutPercentage = false --whether to display percent gain/loss or RF gain/loss
- local commandString = "null"
- local commandNum = 0
- local digProgress = 0
- local commaResult = "" --output of addComma() function
- local dontPrintData = false
- local isError = false
- local error = " "
- local errorTime = 5 --# of seconds error will be shown on glass
- local tempErrorTime = errorTime
- local isChatCommand = false
- local blueInput = colors.test(rs.getBundledInput("top"),colors.blue)
- -------------Functions-------------
- local function addComma(num)
- local numA = 0
- local numB = 0
- local numC = 0
- local numD = 0
- local divA = 1
- local divB = 1
- local divC = 1
- local divD = 1
- local stringB = ""
- local stringC = ""
- local stringD = ""
- if num >= 1000000000 then
- divA = 1000000000
- divB = 1000000
- divC = 1000
- divD = 1
- elseif num >= 1000000 then
- divA = 1000000
- divB = 1000
- divC = 1
- elseif num >= 1000 then
- divA = 1000
- divB = 1
- else
- divA = 1
- end
- numA = num / divA
- numA = math.floor(numA)
- if num >= 1000 then
- numB = (num - numA * divA) / divB
- numB = math.floor(numB)
- if numB < 1 then
- stringB = "000"
- elseif numB < 10 then
- stringB = "00"..numB
- elseif numB < 100 then
- stringB = "0"..numB
- elseif numB < 1000 then
- stringB = numB
- end
- else
- commaResult = stringA
- end
- if num >= 1000000 then
- numC = (num - numA * divA - numB * divB) / divC
- numC = math.floor(numC)
- if numC < 1 then
- stringC = "000"
- elseif numC < 10 then
- stringC = "00"..numC
- elseif numC < 100 then
- stringC = "0"..numC
- elseif numC < 1000 then
- stringC = numC
- end
- else
- commaResult = stringA..","..stringB
- end
- if num >= 1000000000 then
- numD = (num - numA * divA - numB * divB - numC * divC) / divD
- math.floor(numD)
- if numD < 1 then
- stringD = "000"
- elseif numD < 10 then
- stringD = "00"..numD
- elseif numD < 100 then
- stringD = "0"..numD
- elseif numD < 1000 then
- stringD = numD
- end
- commaResult = stringA..","..stringB..","..stringC..","..stringD
- else
- commaResult = stringA..","..stringB..","..stringC
- end
- end
- local function listenForCommand()
- while true do
- event, command = os.pullEvent("chat_command")
- print(event.." "..command)
- isChatCommand = true
- end
- end
- local function checkCommand()
- local tempCount = 0
- for i in string.gmatch(command, "%S+") do
- tempCount = tempCount + 1
- print(i)
- if tempCount == 1 then
- commandString = i
- elseif tempCount == 2 then
- commandNum = i
- end
- if commandString == "mine" then
- commandNum = tonumber(commandNum)
- end
- end
- print("commandNum:"..commandNum)
- end
- local function getData()
- term.setTextColor(colors.white)
- powerNum = cell.getEnergyStored() * numCapacitors
- addComma(powerNum)
- power = commaResult
- in_outNum = (powerNum - oldPowerNum) / 2
- addComma(in_outNum)
- in_out = commaResult
- oldPowerNum = powerNum
- maxPowerNum = cell.getMaxEnergyStored() * numCapacitors
- addComma(maxPowerNum)
- maxPower = commaResult
- if dontPrintData == false then
- print(power .. "RF out of " .. maxPower .. "RF")
- end
- in_outPercentage = (in_outNum / maxPowerNum) * 100
- aeCutOff = (colors.test (redstone.getBundledInput("top"), colors.white))
- percentage = (powerNum / maxPowerNum) * 100
- if dontPrintData == false then
- print("aka " .. percentage .. "%")
- if aeCutOff == true then
- print("AE Cut Off is true")
- else
- print("AE Cut Off is false")
- end
- end
- end
- local function updateGlass()
- glass.clear()
- glass.addBox(1,1,167,75,0x000000,0.2)
- glass.addText(6,6,"Current Power",0xCC4C4C)
- glass.addText(6,20,power .. "RF / " .. maxPower .. "RF")
- glass.addText(17,34,percentage .. " %",0xF2B233)
- if isError == true and tempErrorTime > 0 then
- glass.addBox(162,1,221,20,0xEDEDED,0.9)
- errorText = glass.addText(167,7,error,0xCC4C4C)
- tempErrorTime = tempErrorTime - 1
- else
- isError = false
- tempErrorTime = errorTime
- error = " "
- end
- if colors.test(rs.getBundledInput("top"),colors.green) == true then
- glass.addText(73,46,"GENERATORS ON",0xCC4444)
- end
- if in_outNum >= 0 then
- glassTextColor = 0x00FF00
- isNegative = "+"
- else
- glassTextColor = 0xCC4C4C
- isNegative = ""
- end
- if isIn_OutPercentage == true then
- glass.addText(90,34,isNegative..in_outPercentage.."%",glassTextColor)
- else
- glass.addText(90,34,isNegative..in_out.."RF",glassTextColor)
- end
- if aeCutOff == true then
- glass.addText(6,58,"Emergency AE Cut Off is Active",0xCC0000)
- end
- if iterations > 0 or iterations == -1 then
- if digProgress == 0 then
- if colors.test(rs.getBundledInput("top"),colors.blue) == false then
- miningTextColor = 0x00FF00
- else
- miningTextColor = 0xCC4444
- end
- end
- if digProgress == 0 then
- glass.addText(4,46,"Mining "..iterations,miningTextColor)
- elseif digProgress == 1 then
- glass.addText(4,46,"Mining "..iterations..".",miningTextColor)
- elseif digProgress == 2 then
- glass.addText(4,46,"Mining "..iterations.."..",miningTextColor)
- elseif digProgress == 3 then
- glass.addText(4,46,"Mining "..iterations.."...",miningTextColor)
- end
- if colors.test(rs.getBundledInput("top"),colors.blue) == true then
- end
- end
- end
- local function moveFrame()
- local blueInput = colors.test(rs.getBundledInput("top"),colors.blue)
- if blueInput == false then
- rs.setBundledOutput("top",colors.red) --> wireless transmitter
- print("set red")
- sleep(1)
- rs.setBundledOutput("top",0)
- print("set all off moveFrame")
- end
- end
- local function dig()
- local blueInput = colors.test(rs.getBundledInput("top"),colors.blue)
- local splitDigTime = digTime / 8
- if blueInput == false then
- digProgress = 0 --used to display iteration's progress on glass
- print("set black")-------------
- rs.setBundledOutput("top",colors.black) -->allows tesseract to transmit power
- term.setTextColor(colors.green)
- term.write("Iteration "..iterations)
- dontPrintData = true
- sleep(splitDigTime)
- getData()
- updateGlass()
- sleep(splitDigTime)
- for i=1,2 do
- term.write(".")
- digProgress = digProgress + 1
- getData()
- updateGlass()
- term.setTextColor(colors.green)
- sleep(splitDigTime)
- getData()
- updateGlass()
- sleep(splitDigTime)
- end
- print(".")
- digProgress = 3
- dontPrintData = false
- for i=1,2 do
- getData()
- updateGlass()
- sleep(splitDigTime)
- end
- rs.setBundledOutput("top",0)
- print("set all off dig")--------------------
- elseif blueInput == true then
- term.setTextColor(colors.red)
- digProgress = 0
- term.write("Skipped Iteration "..iterations)
- sleep(splitDigTime)
- dontPrintData = true
- for i=1,2 do
- term.write(".")
- digProgress = digProgress + 1
- getData()
- updateGlass()
- term.setTextColor(colors.red)
- sleep(splitDigTime)
- getData()
- updateGlass()
- sleep(splitDigTime)
- end
- print(",")
- digProgress = 3
- dontPrintData = false
- for i=1,2 do
- getData()
- updateGlass()
- sleep(splitDigTime)
- end
- digProgress = 0
- end
- end
- local function executeCommandInMine()
- if commandString == "stop" then
- iterations = 0
- elseif commandString == "help" then
- isError = true
- error = "commands: 'mine <#>','help','stop','toggle <>'"
- elseif commandString == "mine" then
- isError = true
- error = "Please enter 'stop' before mining again"
- elseif commandString == "toggle" then
- if commandNum == "in-out" then
- if isIn_OutPercentage == true then
- isIn_OutPercentage = false
- else
- isIn_OutPercentage = true
- end
- elseif commandNum == "ae" then
- rs.setBundledOutput("top",colors.yellow)
- sleep(.5)
- rs.setBundledOutput("top",0)
- else
- isError = true
- error = "Usage: 'toggle <in-out/ae>'"
- end
- else
- isError = true
- error = "that is not a valid command, enter 'help'"
- end
- term.setTextColor(colors.red)
- print(error)
- term.setTextColor(colors.white)
- commandString = "null"
- commandNum = 0
- end
- local function mine()
- local isIterations = true
- print("Mining Process Started with "..iterations.." iterations...")
- if iterations == 0 then
- term.setTextColor(colors.red)
- error = "Error: 0 Iterations?"
- print(error)
- isError = true
- term.setTextColor(colors.white)
- isIterations = false
- elseif iterations <= -1 then
- iterations = -1
- else
- isIterations = true
- end
- while isIterations == true do
- getData()
- updateGlass()
- moveFrame()
- dig()
- if iterations > 0 then
- iterations = iterations - 1
- end
- if iterations == 0 then
- isIterations = false
- end
- if isChatCommand == true then
- isChatCommand = false
- checkCommand()
- executeCommandInMine()
- end
- end
- end
- local function executeCommand()
- if commandString == "mine" then
- iterations = commandNum
- mine()
- elseif commandString == "stop" then
- iterations = 0
- elseif commandString == "help" then
- isError = true
- error = "commands: 'help','mine <#>','stop','toggle <>'"
- elseif commandString == "toggle" then
- if commandNum == "in-out" then
- if isIn_OutPercentage == true then
- isIn_OutPercentage = false
- else
- isIn_OutPercentage = true
- end
- elseif commandNum == "ae" then
- rs.setBundledOutput("top",colors.yellow)
- sleep(.5)
- rs.setBundledOutput("top",0)
- else
- isError = true
- error = "Usage: 'toggle <in-out/ae>'"
- end
- else
- isError = true
- error = "that is not a valid command, enter 'help'"
- end
- commandString = "null"
- commandNum = 0
- end
- ------------Main Function---------
- local function main()
- while true do
- getData()
- updateGlass()
- if isChatCommand == true then
- isChatCommand = false
- checkCommand()
- executeCommand()
- end
- sleep(1)
- end
- end
- ------------Program-------
- parallel.waitForAny(main,listenForCommand) --runs main funtion and listens for commands at the same time
Advertisement
Add Comment
Please, Sign In to add comment