Advertisement
Guest User

craftAPI

a guest
Jun 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. if recpipes == nil then recipes = {} end
  2. function find(list,item)
  3.     for k,v in pairs(list) do
  4.         if k == item then return true end
  5.         end
  6.     return false
  7. end
  8.  
  9. function add(result)
  10.     recipes[result] = {}
  11.     for i= 1, 11 do
  12.         if i ~= 4 and i ~= 8 then
  13.             local data = turtle.getItemDetail(i)
  14.             if data ~= nil then
  15.                 if recipes[result][data.name] == nil then recipes[result][data.name] = {{},'empty'} end
  16.                 table.insert(recipes[result][data.name][1],i)
  17.             end
  18.         end
  19.     end
  20.     for k,v in pairs(recipes[result]) do
  21.         local count = 0
  22.         for o in pairs(v[1]) do count = count + 1  
  23.         recipes[result][k][2] = count
  24.  
  25.     end
  26. end
  27.  
  28. function search(direction,item)
  29.     inv = peripheral.wrap(direction)
  30.     local list = inv.list()
  31.     for i=1, inv.size() do
  32.         if list[i].name == item then return i,list[i].count end
  33.     end
  34.     return nil,-1
  35. end
  36. end
  37.  
  38. function craft(result,ammount)
  39. for i=1, ammount do
  40.     if not find(recipes,result) then return false
  41.     for item, info in pairs(recipes[item]) do
  42.         slot,count = search('top',item)
  43.         if count < ammount then
  44.             if not craft(item,ammount-count) then return false
  45.             end
  46.         else
  47.         chest.pushItems('down',slot,ammount)
  48.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement