Advertisement
guitarplayer616

AutoCook Backup 4

May 27th, 2015
359
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 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 buffer(num)
  71.   turtle.select(16)
  72.   ingredient = {}
  73.   while amount~=count and turtle.suck() do
  74.     item = turtle.getItemDetail()
  75.     for i,v in pairs(path[num]) do
  76.       if v == item.name then
  77.         for i2,v2 in pairs(ingredients) do
  78.           if v == v2 then
  79.             turtle.dropDown()
  80.           end
  81.         end
  82.         if turtle.getItemCount() > 0 then
  83.           turtle.transferTo(i,1)
  84.           amount = amount + 1
  85.           table.insert(ingredients,item.name)
  86.         end
  87.       end
  88.     end
  89.     if turtle.getItemCount() > 0 then
  90.       turtle.dropDown()
  91.     end
  92.   end
  93. end
  94.  
  95. function craft()
  96.   if not turtle.craft() then
  97.     textutils.slowPrint("Error: Insufficient Ingredients")
  98.     clearInv(15,-1)
  99.     error()
  100.   else
  101.     if turtle.getSelectedSlot() ~= 16 then
  102.       turtle.select(16)
  103.     end
  104.     turtle.dropUp()
  105.     clearInv(15,-1)
  106.   end
  107. end
  108.  
  109. function run()
  110.   loadTable(1)
  111.   displayTable()
  112.   buffer(1)
  113.   craft()
  114. end
  115.  
  116. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement