guitarplayer616

AutoCook Backup 5

Apr 12th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. local tArgs = {...}
  2. local path = {}
  3. local count = nil
  4. local item = nil
  5. local amount = 0
  6. local craftingGrid = {1,2,3,5,6,7,9,10,11}
  7. local ingredients = {}
  8. local sortTable = {}
  9. local orderedTable = {}
  10.  
  11. function loadTable(num)
  12.   local file = fs.open("RecipeList/"..tArgs[1].."/path"..num,"r")
  13.   local data = file.readAll()
  14.   file.close()
  15.   path[num] = textutils.unserialize(data)
  16.   count = 0
  17.   for i,v in pairs(path[1]) do
  18.     count = count + 1
  19.   end
  20. end
  21.  
  22. function displayTable()
  23.   for i,v in pairs(path) do
  24.     print(i.."\)")
  25.     for k in pairs(path[i]) do
  26.       table.insert(sortTable,k)
  27.     end
  28.     table.sort(sortTable)
  29.     for i2,v2 in ipairs(sortTable) do
  30.       for i3,v3 in pairs(v) do
  31.         if v2==i3 then
  32.           table.insert(orderedTable,i2,v3)
  33.         end
  34.       end
  35.     end
  36.     for i2,v2 in ipairs(orderedTable) do
  37.       for i3,v3 in pairs(v) do
  38.         if v2==v3 then
  39.           if i3 >= 4 then
  40.             i3 = i3 - 1
  41.           end
  42.           if i3 >= 8 then
  43.             i3 = i3 - 1
  44.           end
  45.           print("  "..i3.." - "..v2)
  46.         end
  47.       end
  48.     end
  49.   end
  50.   sortTable = {}
  51.   orderedTable = {}
  52. end
  53.  
  54.    
  55.    
  56. function clearInv(n,p)
  57.   local s = 1
  58.   if p == nil then
  59.     p = 1
  60.   elseif math.abs(p)~=p then
  61.     s = n
  62.     n = 1
  63.   end
  64.   for i=s,n,p do
  65.     turtle.select(i)
  66.     turtle.dropDown()
  67.   end
  68. end
  69.  
  70. function sort(num,dumpDir)
  71.   item = turtle.getItemDetail()
  72.   for i,v in pairs(path[num]) do
  73.     if v == item.name then
  74.       for i2,v2 in pairs(ingredients) do
  75.         if v == v2 then
  76.           if dumpDir == "down" then
  77.             turtle.dropDown()
  78.           elseif dumpDir == "forward" then
  79.             turtle.drop()
  80.           end
  81.         end
  82.       end
  83.       if turtle.getItemCount() > 0 then
  84.         turtle.transferTo(i,1)
  85.         amount = amount + 1
  86.         table.insert(ingredients,item.name)
  87.       end
  88.     end
  89.   end
  90.   if turtle.getItemCount() > 0 then
  91.     if dumpDir == "down" then
  92.       turtle.dropDown()
  93.     elseif dumpDir == "forward" then
  94.       turtle.drop()
  95.     end
  96.   end
  97. end
  98.  
  99. function buffer(num)
  100.   turtle.select(16)
  101.   ingredient = {}
  102.   while amount~=count and turtle.suck() do
  103.     sort(num,"down")
  104.   end
  105.   while amount~=count and turtle.suckDown() do
  106.     sort(num,"forward")
  107.   end
  108. end
  109.  
  110. function craft()
  111.   if not turtle.craft() then
  112.     textutils.slowPrint("Error: Insufficient Ingredients")
  113.     clearInv(15,-1)
  114.     error()
  115.   else
  116.     if turtle.getSelectedSlot() ~= 16 then
  117.       turtle.select(16)
  118.     end
  119.     turtle.dropUp()
  120.     clearInv(15,-1)
  121.   end
  122. end
  123.  
  124. function run()
  125.   loadTable(1)
  126.   displayTable()
  127.   buffer(1)
  128.   craft()
  129. end
  130.  
  131. run()
Add Comment
Please, Sign In to add comment