Advertisement
guitarplayer616

AutoCook Backup

May 26th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. local tArgs = {...}
  2. local file = fs.open("RecipeList/"..tArgs[1].."/path1","r")
  3. local data = file.readAll()
  4. local item = 0
  5. local amount = {}
  6. local corners = {4,8,12,16,15,14,13}
  7. file.close()
  8. print(data)
  9. path1 = textutils.unserialize(data)
  10.  
  11. local craftingGrid = {1,2,3,5,6,7,9,10,11}
  12.  
  13. function clearInv(n)
  14.   for i=1,n do
  15.     turtle.select(i)
  16.     turtle.drop()
  17.   end
  18. end
  19.  
  20. function sucknsort()
  21.   for k=1,16 do
  22.     turtle.select(k)
  23.     if turtle.suck() then
  24.       item = turtle.getItemDetail()
  25.       for i,v in pairs(path1) do
  26.         if v == item.name then
  27.           turtle.dropUp()
  28.           table.insert(amount,i,v)
  29.         end
  30.       end
  31.       turtle.dropDown()
  32.     else
  33.       return "empty"
  34.     end
  35.   end
  36. end
  37.  
  38. function switchTo(x)
  39.   if not turtle.transferTo(x) then
  40.      local s = turtle.getSelectedSlot()
  41.      turtle.select(x)
  42.      turtle.transferTo(16)
  43.      turtle.select(s)
  44.      turtle.transferTo(x)
  45.      turtle.select(16)
  46.      turtle.transferTo(s)
  47.      turtle.select(s)
  48.   end
  49. end
  50.  
  51. function buffer()
  52.   for i=1,16 do
  53.     turtle.select(16)
  54.     if turtle.suckUp() then
  55.       item = turtle.getItemDetail()
  56.       for i,v in pairs(path1) do
  57.         if v == item.name then
  58.           turtle.transferTo(i)
  59.         end
  60.       end
  61.       if turtle.getItemCount() > 0 then
  62.         turtle.drop()
  63.       end
  64.     end
  65.   end
  66. end
  67.  
  68. function sort()
  69.   for n,s in ipairs(craftingGrid) do
  70.     turtle.select(s)
  71.     item = turtle.getItemDetail()
  72.     if item and item.count > 1 then
  73.       turtle.drop(item.count-1)
  74.     end
  75.     for k,v in pairs(path1) do
  76.       if item and item.name==v and turtle.getSelectedSlot() ~= k then
  77.         turtle.drop()
  78.       end
  79.     end
  80.   end
  81.     --if there are items that are not in the 3x3 grid then drop them up
  82.   for i,v in ipairs(corners) do
  83.     turtle.select(v)
  84.     if turtle.getItemSpace()~=64 then
  85.       turtle.drop()
  86.     end
  87.   end
  88. end  
  89.  
  90.  
  91. function run()
  92.   amount = {}
  93.   turtle.turnRight()
  94.   while sucknsort()~="empty" do end
  95.   buffer()
  96.   sort()
  97.   turtle.select(16)
  98.   if not turtle.craft() then
  99.     textutils.slowPrint("Error: Insufficient Ingredients")
  100.     clearInv(16)
  101.     shell.run("go lt")
  102.     error()
  103.   else
  104.     clearInv(15)
  105.     turtle.turnLeft()
  106.     turtle.turnLeft()
  107.     turtle.select(16)
  108.     turtle.drop()
  109.     turtle.turnRight()
  110.   end
  111. end
  112.  
  113. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement