Advertisement
guitarplayer616

AutoCook Backup 3

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