Advertisement
antrobot123

automation wrapper

Jun 24th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. local c = rednet.lookup('link','craft') or 'self'
  2. local m = rednet.lookup('link','machine') or 'self'
  3.  
  4. local dictionary = run(c,craftAPI.getDict())
  5. for k,v in pairs(run(m,machineAPI.getDict())) do dictionary[k] = v end
  6.  
  7. local input = {...}
  8. rednet.host('link','computer')
  9. function run(id,code)
  10.     if id == self then loadstring('return '..code)
  11.     else
  12.         rednet.send(id,code)
  13.         local temp = {rednet.receive()}
  14.         return temp[2]
  15.     end
  16. end
  17.  
  18. function request(count,item,damage)
  19.     if dictionary[item] then
  20.         item = dictionary[item].name
  21.         damage = dictionary[item].damage
  22.     end
  23.     damage = damage or 0
  24.     local tempInfo = 'nil'
  25.     local search = run(c,search(run(craftAPI.getChest()).dir,item,damage))
  26.     if search then
  27.         if search.count == count then return true
  28.         else request(count-search.count,item,damage) end
  29.     end
  30.     if run(c,craftAPI.searchRecipes(item,damage)) then
  31.         tempInfo = run(c,craftAPI.craft(count,item,damage))
  32.         if tempInfo.bool then return true
  33.         else request(tempInfo.count,tempInfo.item,tempInfo.damage) end
  34.     else if run(m,machineAPI.searchRecipes(item,damage)) then
  35.         tempInfo = run(m,machineAPI.craft(count,item,damage))
  36.         if tempInfo.bool then return true
  37.         else request(tempInfo.count,tempInfo.item,tempInfo.damage) end
  38.     else return count,item,damage end
  39.     end
  40. end
  41.  
  42. print(request(input[1],input[2],input[3]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement