Advertisement
guitarplayer616

OpenComputer Brewer

Nov 26th, 2019
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. --openComputers autoBrew program
  2. --brew [transposerAddress]
  3.  
  4. component = require("component")
  5. args = {...}
  6.  
  7. if #args < 5 then
  8.     print("brew [address] [chestSide] [bottlerSide] [waterSide] [ingredientsSide]")
  9.     return
  10. end
  11.  
  12. tranposer = component.proxy(component.get(args[1]))
  13. chestSide = sides[args[2]]
  14. waterSide = sides[args[4]]
  15. bottlerSide = sides[args[3]]
  16. ingredientsSide = sides[args[5]]
  17. fuel = 0
  18.  
  19. function listItems(side)
  20.   for i in transposer.getAllStacks(side) do
  21.     for k,v in pairs(i) do
  22.       if k == "label" then
  23.         print(string.lower(v))
  24.       end
  25.     end
  26.   end
  27. end
  28.  
  29. function findItems(side,itemName)
  30.     itemName = string.lower(itemName)
  31.     local invSize = transposer.getInventorySize(side)
  32.     local tab = transposer.getAllStacks(side)
  33.     --going through all the slots in the chest
  34.     for slot = 1,invSize do
  35.         print(tab[slot]["label"])
  36.         if string.lower(tab[slot]["label"]) == itemName then
  37.             -- if the slot has the item we're looking for
  38.             return slot, tab[slot]["size"]
  39.         end
  40.     end
  41.     return false
  42. end
  43.  
  44. function bottleWater()
  45.     local count = count or 3
  46.     local slot, cnt = findItems(chestSide,"glass bottle")
  47.     if cnt < count then
  48.         return "not enough bottles"
  49.     end
  50.     transposer.transferItem(chestSide,bottlerSide,count,slot)
  51.     for i = 1,3 do
  52.         os.sleep(3)
  53.         transposer.transferItem(bottlerSide,waterSide)
  54.     end
  55. end
  56.  
  57. function brewPotion(...)
  58.     --get some water bottles or fill up some water bottles
  59.     local queue = {...}
  60.     bottleWater()
  61.     if fuel <= 0 then
  62.         local slot = findItems(chestSide,"blaze powder")
  63.         if transposer.transferItem(chestSide,waterSide,1,slot) then
  64.             fuel = 20
  65.         end
  66.     end
  67.     while #queue > 0 do
  68.         local ingredient = table.remove(queue,1)
  69.         local slot = findItems(chestSide,ingredient)
  70.         transposer.transferItem(chestSide,ingredientsSide,1,slot)
  71.         os.sleep(21)
  72.         fuel = fuel - 1
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement