Advertisement
MrkikouLIF

Bee machine

Oct 17th, 2021 (edited)
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local chests_stock = {}
  2. local chest_bees
  3. local chest_bees_label = "ironchest:diamond_chest_48"
  4. local centrifuges = {}
  5. local apiary_sto = {}
  6. local periphs_labels = {}
  7. local blacklist_comb = {"rock_honeycomb","rgbee_honeycomb","woody_honeycomb","nether_honeycomb"}
  8.  
  9. modem = peripheral.wrap("bottom")
  10. periphs_labels = modem.getNamesRemote()
  11. chest_bees = peripheral.wrap(chest_bees_label)
  12.  
  13. for i,periph in pairs(periphs_labels) do
  14.     if string.find(periph,"chest") and periph ~= chest_bees_label then
  15.         table.insert(chests_stock,peripheral.wrap(periph))
  16.     elseif string.find(periph,"centrifuge") then
  17.         table.insert(centrifuges,peripheral.wrap(periph))
  18.     elseif string.find(periph,"apiary_storage") then
  19.         table.insert(apiary_sto,peripheral.wrap(periph))
  20.     end
  21. end
  22.  
  23. function has_value(tableau, valeur)
  24.     for i, item in pairs(tableau) do
  25.         if string.find(valeur, item) then
  26.             return true
  27.         end
  28.     end
  29.     return false
  30. end
  31.  
  32.  
  33. function apiaryToProcess()  
  34.     while true do
  35.         for j=2,7 do
  36.             if not centrifuges[1].getItemDetail(j) then
  37.                 for i,item in pairs(apiary_sto[1].list()) do
  38.                     if not has_value(blacklist_comb, item.name) and string.find(item.name, "honeycomb") then
  39.                         centrifuges[1].pullItems(peripheral.getName(apiary_sto[1]), i, 1)
  40.                         break
  41.                     end
  42.                 end
  43.             end
  44.         end
  45.     end
  46. end
  47.  
  48. function chestToProcess()
  49.     while true do
  50.     for j=2,7 do
  51.         broke = false
  52.         if not centrifuges[1].getItemDetail(j) then
  53.             for c,chest in pairs(chests_stock) do
  54.                 for i,item in pairs(chest.list()) do
  55.                     if not has_value(blacklist_comb, item.name) and string.find(item.name, "honeycomb") then
  56.                         centrifuges[1].pullItems(peripheral.getName(chest), i, 1)
  57.                         broke = true
  58.                     end
  59.                     if broke then break end
  60.                 end
  61.                 if broke then break end
  62.             end
  63.         end
  64.     end
  65.     end
  66. end
  67.  
  68. function outProcess()
  69.     while true do
  70.     stockFull = false
  71.     for j,item in pairs(centrifuges[1].list()) do
  72.         --itemOut = centrifuges[1].getItemDetail(j)
  73.         if j>7 then
  74.             for c,chest in pairs(chests_stock) do
  75.                 item.count = item.count - centrifuges[1].pushItems(peripheral.getName(chest),j)
  76.                 if item.count <= 0 then
  77.                     break    
  78.                 end
  79.             end
  80.         end
  81.     end
  82.     end
  83. end
  84.  
  85. while true do
  86.     parallel.waitForAny(chestToProcess,outProcess,apiaryToProcess)
  87. end
  88.  
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement