Advertisement
guitarplayer616

Harvestcraft Turtle "Cook"

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