Advertisement
CaptainSpaceCat

Flywheel Fuel Facilitator

May 14th, 2022
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. furn = peripheral.wrap("bottom")
  2. chest = peripheral.wrap("top")
  3. args = {...}
  4.  
  5. function formatTime(s)
  6.     totalTime = s
  7.     hours = math.floor(totalTime/3600)
  8.     totalTime = totalTime % 3600
  9.     minutes = math.floor(totalTime/60)
  10.     seconds = totalTime % 60
  11.  
  12.     output = ""
  13.     if hours > 0 then
  14.         output = output .. tostring(hours) .. " h "
  15.     end
  16.     if minutes > 0 then
  17.         output = output .. tostring(minutes) .. " m "
  18.     end
  19.     output = output .. tostring(seconds) .. " s"
  20.     return output
  21. end
  22.  
  23. function showTime(s)
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26.     print("Powering Flywheel...")
  27.     if s then
  28.         print("Time remaining: " .. formatTime(s))
  29.     else
  30.         print("Time remaining: 'till we run out of fuel or the server crashes!")
  31.     end
  32. end
  33.  
  34. function loop()
  35.     furn.pullItems("top", 1, 1)
  36.     sleep(0.5)
  37.     chest.pullItems("bottom", 1, 1)
  38.     sleep(0.5)
  39. end
  40.  
  41. function parse(targs)
  42.     if #targs == 0 then
  43.         return -1
  44.     elseif #targs == 1 then
  45.         return tonumber(targs[1])
  46.     else
  47.         if targs[2] == 'h' then
  48.             return tonumber(targs[1]) * 3600
  49.         elseif targs[2] == 'm' then
  50.             return tonumber(targs[1]) * 60
  51.         elseif targs[2] == 's' then
  52.             return tonumber(targs[1])
  53.         end
  54.     end
  55. end                    
  56.  
  57. loops = parse(args)
  58. if loops >= 0 then
  59.     for i = 1, loops do
  60.         showTime(loops - i + 1)
  61.         loop()
  62.     end
  63. else
  64.     while true do
  65.         showTime()
  66.         loop()
  67.     end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement