EnderReaper64

Ender OS (Computer Craft)

Oct 9th, 2021 (edited)
855
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Just know that this is still a work in progress.
  2. -- I'll make it so you can download it as an official os later. ok cool.
  3. -- after all this is a hobby project. although, I will show a list of shit im gonna add in later
  4. function getTime()
  5.     local osTime = os.time()
  6.     local minutes = math.floor(osTime%13)
  7.     local seconds = osTime - math.floor(osTime)
  8.     seconds = seconds * 100
  9.     seconds = seconds / (100/60)
  10.     seconds = math.floor(seconds)
  11.     if seconds < 10 then
  12.         seconds = 0 .. seconds
  13.     end
  14.     local timeBracket = " AM"
  15.     if osTime / 13 >= 1 then
  16.         timeBracket = " PM"
  17.     end
  18.     return minutes .. ":" .. seconds .. timeBracket
  19. end
  20.  
  21. function newLine(lines)
  22.     for a = 1, lines do
  23.         print("")
  24.     end
  25. end
  26.  
  27. function printCenter(message, force)
  28.     local x,y = term.getSize()
  29.     local x2,y2 = term.getCursorPos()
  30.     term.setCursorPos(math.floor((x / 2) - (message:len() / 2))+0.5, y2+0.5)
  31.     if not force then
  32.         print(message)
  33.     else
  34.         write(message)
  35.     end
  36. end
  37.  
  38. function colorChange(menuBarColor)
  39.     if menuBarColor == colors.red then
  40.         menuBarColor = colors.orange
  41.     elseif menuBarColor == colors.orange then
  42.         menuBarColor = colors.yellow
  43.     elseif menuBarColor == colors.yellow then
  44.         menuBarColor = colors.green
  45.     elseif menuBarColor == colors.green then
  46.         menuBarColor = colors.blue
  47.     elseif menuBarColor == colors.blue then
  48.         menuBarColor = colors.purple
  49.     elseif menuBarColor == colors.purple then
  50.         menuBarColor = colors.black
  51.     elseif menuBarColor == colors.black then
  52.         menuBarColor = colors.red
  53.     end
  54.     return menuBarColor
  55. end
  56.  
  57. local selection = 0
  58. local screen = 0
  59. local maxSelection = 1
  60. local menuBarColor = colors.red
  61. local backgroundColor = colors.black
  62.  
  63. function keyMain()
  64.     while true do
  65.         local event, key, isHeld = os.pullEvent("key")
  66.         if key == keys.up then
  67.             selection = selection - 1
  68.         elseif key == keys.down then
  69.             selection = selection + 1
  70.         end
  71.         if key == keys.enter and screen == 0 and selection == 0 then
  72.             term.clear()
  73.             error("Goodnight.")
  74.         elseif key == keys.enter and screen == 0 and selection == 2 then
  75.             screen = 1
  76.             selection = 0
  77.         elseif key == keys.enter and screen == 0 and selection == 1 then
  78.             screen = 2
  79.             selection = 0
  80.         elseif key == keys.enter and screen == 1 and selection == 0 then
  81.             screen = 0
  82.             selection = 1
  83.         elseif key == keys.enter and screen == 1 and selection == 1 then
  84.             menuBarColor = colorChange(menuBarColor)
  85.         elseif key == keys.enter and screen == 1 and selection == 2 then
  86.             backgroundColor = colorChange(backgroundColor)
  87.         elseif key == keys.enter and screen == 2 and selection == 0 then
  88.             screen = 0
  89.             selection = 0
  90.         elseif key == keys.enter and screen == 2 and selection == 1 then
  91.             screen = 3
  92.             selection = 0
  93.         elseif key == keys.enter and screen == 3 then
  94.             screen = 2
  95.             selection = 1
  96.         end
  97.     end
  98. end
  99.  
  100. local win = window.create(term.current(),1,1,term.getSize())
  101. term.redirect(win)
  102. function main()
  103. while true do
  104.     win.setVisible(false)
  105.     term.clear()
  106.     term.setCursorPos(1,1)
  107.     local termX, termY = term.getSize()
  108.     if selection > maxSelection then
  109.         selection = 0
  110.     elseif selection < 0 then
  111.         selection = maxSelection
  112.     end
  113.     local bg = term.getBackgroundColor()
  114.     term.setBackgroundColor(backgroundColor)
  115.     for b = 1, termY do
  116.         for a = 1, termX do
  117.             write(" ")
  118.         end
  119.     end
  120.     term.setCursorPos(1, 1)
  121.     term.setBackgroundColor(menuBarColor)
  122.     for a = 1, termX do
  123.         write(" ")
  124.     end
  125.     term.setCursorPos(1, 1)
  126.     write("Ender OS")
  127.     printCenter(getTime(), true)
  128.     term.setBackgroundColor(backgroundColor)
  129.     newLine(1)
  130.     if screen == 0 then
  131.         maxSelection = 2
  132.         newLine(3)
  133.         if selection == 0 then
  134.             printCenter("<Exit>")
  135.         else
  136.             printCenter("Exit")
  137.         end
  138.         if selection == 1 then
  139.             printCenter("<Utilities>")
  140.         else
  141.             printCenter("Utilities")
  142.         end
  143.         if selection == 2 then
  144.             printCenter("<Settings>")
  145.         else
  146.             printCenter("Settings")
  147.         end
  148.     elseif screen == 1 then
  149.         maxSelection = 2
  150.         newLine(2)
  151.         printCenter("[Settings]")
  152.         if selection == 0 then
  153.             printCenter("<Back>")
  154.         else
  155.             printCenter("Back")
  156.         end
  157.         if selection == 1 then
  158.             printCenter("<Menu Bar Color>")
  159.         else
  160.             printCenter("Menu Bar Color")
  161.         end
  162.         if selection == 2 then
  163.             printCenter("<Background Color>")
  164.         else
  165.             printCenter("Background Color")
  166.         end
  167.     elseif screen == 2 then
  168.         maxSelection = 1
  169.         newLine(2)
  170.         printCenter("[Utilities]")
  171.         if selection == 0 then
  172.             printCenter("<Back>")
  173.         else
  174.             printCenter("Back")
  175.         end
  176.         if selection == 1 then
  177.             printCenter("<Autocraft>")
  178.         else
  179.             printCenter("Autocraft")
  180.         end
  181.     elseif screen == 3 then
  182.         newLine(1)
  183.         printCenter("[Autocrafter]")
  184.         print("This will automatically craft with anything in the current inventory. Does NOT work for computers, for turtles only. Only crafts in a 3x3 area. It will deposit anything it crafts below it into a chest. Enjoy!")
  185.         newLine(2)
  186.         printCenter("[Enter] to stop autocrafting")
  187.         local totalcount = 0
  188.         local itemCount = 0
  189.         local maxSelection = 0
  190.         local firstEmpty = 0
  191.         for a = 1, 16 do
  192.             local itemData = turtle.getItemDetail(a)
  193.             if itemData ~= nil then
  194.                 itemCount = itemCount + 1
  195.                 if itemData.count >= 2 then
  196.                     maxSelection = maxSelection + 1
  197.                 end
  198.             else
  199.                 if firstEmpty == 0 then
  200.                     firstEmpty = a
  201.                 end
  202.             end
  203.         end
  204.         if firstEmpty ~= 0 then
  205.             if maxSelection == itemCount then
  206.                 turtle.craft(1)
  207.                 turtle.select(firstEmpty)
  208.                 turtle.dropDown()
  209.             end
  210.         end
  211.     end
  212.     win.setVisible(true)
  213.     os.sleep(0.1)
  214. end
  215. end
  216.  
  217. parallel.waitForAny(main, keyMain)
RAW Paste Data Copied