Advertisement
guitarplayer616

"Cook" Backup

May 26th, 2015
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. local tArgs = { ... }
  2. local events = {}
  3. local exist = true
  4. local record = false
  5. if #tArgs < 1 then
  6.   print("Usage: cook <recipe>")
  7.   return
  8. end
  9. function cookwrite(string,x,y,txtcol,bakcol)
  10.   if txtcol then
  11.     term.setTextColor(txtcol)
  12.   end
  13.   if bakcol then
  14.     term.setBackgroundColor(bakcol)
  15.   end
  16.   if x and y then
  17.     term.setCursorPos(x, y)
  18.   end
  19.   write(string)
  20.   term.setTextColor(colors.white)
  21.   term.setBackgroundColor(colors.black)
  22. end
  23. local w,h = term.getSize()
  24. term.setBackgroundColor(colors.black)
  25. term.clear()
  26. term.setCursorPos(1,1)
  27.  
  28. function drawCentered(str,height)
  29.   term.setCursorPos((w/2-(#str/2)),height)
  30.   print(str)
  31. end
  32.  
  33. fs.makeDir("RecipeList/"..tArgs[1])
  34.  
  35. --[[if fs.isDir("RecipeList/"..tArgs[1]) then
  36.   term.setTextColor(colors.red)
  37.   textutils.slowPrint("Recipe Already Exists")
  38.   term.setTextColor(colors.white)
  39.   error()
  40. else]]--
  41. fs.makeDir("RecipeList/"..tArgs[1])
  42. --end
  43.  
  44.  
  45.  
  46.  
  47. --[[local input = read()
  48. if string.lower(input) == "craft" then
  49.   print("Please put crafting recipe in turtle inventory")
  50.   textutils.slowPrint("Press any key to continue...")
  51.   read()
  52. else
  53.   print("fail")
  54.   return
  55. end]]--
  56.  
  57. local craftingGrid = {1,2,3,5,6,7,9,10,11}
  58.  
  59. function run()
  60.   while true do
  61.     drawCentered("Recipe: "..tArgs[1],1)
  62.     print(string.rep("-",w))
  63.     print("  Step 1 - Craft or Smelt?")
  64.     if not record and exist then
  65.       cookwrite("+",2,4)
  66.     elseif record and exist then
  67.       cookwrite(" ",2,4)
  68.       cookwrite("+",2,5)
  69.     else
  70.       cookwrite(" ",2,4)
  71.       cookwrite(" ",2,5)
  72.     end
  73.     events = {os.pullEvent()}
  74.     if events[1] == "mouse_click" and events[3] > 11 and events[3] < 17 and events[4] == 3 then
  75.       cookwrite(" Record \n",4,4,colors.white,colors.red)
  76.       record = true
  77.     end
  78.     if record and events[1] == "mouse_click" and events[2] == 1 and events[3] > 3 and events[3] < 10 and events[4] == 4 then
  79.       cookwrite(" Record \n",4,4,colors.white,colors.green)
  80.       for i,v in ipairs(craftingGrid) do
  81.         turtle.select(v)
  82.         local data = turtle.getItemDetail()
  83.         local tab = {}
  84.         if data then
  85.           tab[i] = {data.name,data.damage}
  86.         end
  87.         local fa1 = fs.open("RecipeList/"..tArgs[1].."/path1","a")
  88.         fa1.write(textutils.serialize(tab))
  89.         fa1.close()
  90.       end
  91.       cookwrite(" Record \n",4,4,colors.white,colors.red)
  92.     end
  93.     if record and events[1] == "mouse_click" and events[2] == 2 and events[3] > 3 and events[3] < 10 and events[4] == 4 then
  94.       cookwrite(" Record \n",4,4,colors.white,colors.red)
  95.     end
  96.     if record and events[1] == "mouse_click" and events[2] == 1 and events[3] == 2 and (events[4] == 5 or events[4] == 4) then
  97.       cookwrite("Step 2 - Craft or Smelt?",3,6)
  98.       exist = false
  99.     end  
  100.     if events[1] == "mouse_click" and events[3] > 11 and events[3] < 17 and events[4] == 6 then
  101.       cookwrite(" Record \n",4,7,colors.white,colors.red)
  102.       record2 = true
  103.     end
  104.     if record2 and events[1] == "mouse_click" and events[2] == 1 and events[3] > 3 and events[3] < 10 and events[4] == 7 then
  105.       cookwrite(" Record \n",4,7,colors.white,colors.green)
  106.       for i,v in ipairs(craftingGrid) do
  107.         turtle.select(v)
  108.         local data = turtle.getItemDetail()
  109.         local tab = {}
  110.         if data then
  111.           tab[i] = {data.name,data.damage}
  112.         end
  113.         local fa1 = fs.open("RecipeList/"..tArgs[1].."/path2","a")
  114.         fa1.write(textutils.serialize(tab))
  115.         fa1.close()
  116.       end
  117.       cookwrite(" Record \n",4,7,colors.white,colors.red)
  118.     end
  119.     if record and events[1] == "mouse_click" and events[2] == 2 and events[3] > 3 and events[3] < 10 and events[4] == 7 then
  120.       cookwrite(" Record \n",4,7,colors.white,colors.red)
  121.     end
  122.     local cdx,cdy = term.getCursorPos()
  123.     term.setCursorPos(1,h-#events)
  124.     for i=1,#events do
  125.       print(events[i].."        ")
  126.     end
  127.     term.setCursorPos(cdx,cdy)
  128.   end
  129. end
  130. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement