Advertisement
LDDestroier

Bread - CC Redirect through BLittle

May 7th, 2016
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. --requires CC 1.76 or higher (MC 1.8 or higher)
  2.  
  3. local endit = function(code)
  4.     local codes = {
  5.         [1] = "Your ComputerCraft version is too low. You need CC1.76 or higher (for Minecraft 1.8)",
  6.         [2] = fs.getName(shell.getRunningProgram()).." <program> ...",
  7.     }
  8.     print(codes[code or 2])
  9.     error()
  10. end
  11.  
  12. if _HOST then
  13.     if tonumber(_HOST:sub(15,18)) < 1.76 then
  14.         endit(1)
  15.     end
  16. else
  17.     endit(1)
  18. end
  19. if tonumber(os.version():sub(9)) < 1.7 then
  20.     endit(1)
  21. end
  22.  
  23. local getFile = function(filename,url)
  24.     if fs.isReadOnly(filename) then
  25.         return false, "access denied"
  26.     end
  27.     local prog = http.get(url)
  28.     if not prog then
  29.         return false, "could not connect"
  30.     end
  31.     prog = prog.readAll()
  32.     local fyle = fs.open(filename,"w")
  33.     fyle.write(prog)
  34.     fyle.close()
  35.     return true, fs.getSize(filename)
  36. end
  37.  
  38. local apidir = fs.combine(shell.dir(),"blittle")
  39. if (not blittle) then
  40.     if fs.exists(apidir) then
  41.         os.loadAPI(apidir)
  42.     else
  43.         print("Downloading blittle...")
  44.         local res = getFile(apidir,"http://pastebin.com/raw/ujchRSnU")
  45.         if not res then
  46.             error("...but couldn't!")
  47.         else
  48.             os.loadAPI(apidir)
  49.         end
  50.     end
  51. end
  52.  
  53. local tArg = {...}
  54. local mon = blittle.createWindow()
  55. local oldTerm = term.redirect(mon)
  56. mon.setVisible(true)
  57. shell.run(unpack(tArg))
  58. mon.setVisible(false)
  59. term.redirect(oldTerm)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement