Flaghacker

BioController 2

Feb 27th, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. --Credit Flaghacker
  2.  
  3. --[[Settings]]--
  4. --Items
  5. --  the minimal amount of diffrent itemStacks
  6. local minStacks = 8
  7. --  the minimal amount of items per itemStack
  8. local minItems = 16
  9.  
  10. --Bioreactor
  11. --  the peripheral itype for a bioreactor
  12. local bioReactorType = "bioreactor"
  13. --  (optionally) the side of the bioreactor
  14. local bioReactorSide
  15. --Chest
  16. --  the peripheral type for a chest
  17. local chestType = "chest"
  18. --  (optionally) the side of the chest
  19. local chestSide
  20.  
  21. --[[Variables]]--
  22. --bioreactor peripheral
  23. local bioreactor
  24. local chest
  25.  
  26. --[[Util]]--
  27. local function findPeripheralSide(peripheralType)
  28.     for _, side in rs.getSides() do
  29.         if peripheral.getType(side) == peripheralType then
  30.             return side
  31.         end
  32.     end
  33. end
  34.  
  35. --[[Functions]]--
  36. local function findPeripherals()
  37.     if bioReactorSide == nil then
  38.         bioReactorSide = findPeripheralSide(bioReactorType)
  39.         if bioreactor == nil then
  40.             error("No bioreactor could be found", 0)
  41.         end
  42.     else
  43.         if not peripheral.getType(bioReactorSide) == bioReactorType then
  44.             error(string.format("Peripheral on side %s is not a bioreactor.", bioReactorSide))
  45.         end
  46.     end
  47.     bioreactor = peripheral.wrap(bioReactorSide)
  48.    
  49.     if chestSide == nil then
  50.         chestSide = findPeripheralSide(chestType)
  51.         if chestSide == nil then
  52.             error("No chest could be found", 0)
  53.         end
  54.     else
  55.         if not peripheral.getType(chestSide) == chestType then
  56.             error(string.format("Peripheral on side %s is not a chest.", chestSide))
  57.         end
  58.     end
  59.     chest = peripheral.wrap(chestSide)
  60. end
  61.  
  62. --returns isFilled, slotArray
  63. local function checkChest()
  64.     local slotArray = {}
  65.    
  66.     for slot, 1, chest.getInventorySize() do
  67.         stack = chest.getStackInSlot(slot)
  68.         if not stack == nil then
  69.             if stack.qty > minItems then
  70.                 slotArray.add(slot)
  71.             end
  72.         end
  73.     end
  74.    
  75.     if table.getn(slotArray) >= minStacks then
  76.         return true, slotArray
  77.     end
  78.    
  79.     return false, {}
  80. end
  81.  
  82. --[[Main program]]--
  83. findPeripherals()
  84.  
  85. --test
  86. while true do
  87.     local bool, slots = checkChest;
  88.     print(bool)
  89.     print(textutils.serialize(slots)
  90.     sleep(1)
  91. end
Advertisement
Add Comment
Please, Sign In to add comment