Guest User

matron

a guest
May 23rd, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. -- configuration ---------
  2. local princessSlot = 26
  3. local droneSlot = 27
  4. local otherSlot = 1
  5. local chestDir = "up"
  6. local redstoneSide = "top"
  7. local wait = 5
  8. --------------------------
  9.  
  10. local apiaries = {}
  11. local stats = {["Generations"] = 0}
  12.  
  13. function printStats()
  14.   term.clear()
  15.   term.setCursorPos(1, 1)
  16.   print(string.format("Watching %d apiaries", #apiaries))
  17.   print()
  18.   for stat, value in pairs(stats) do
  19.     print(string.format("%s : %d", stat, value))
  20.   end
  21. end
  22.  
  23. -- find apiaries
  24. local sides = peripheral.getNames()
  25. for _, side in ipairs(sides) do
  26.   if peripheral.getType(side):sub(1,10) == "apiculture" then
  27.     table.insert(apiaries, peripheral.wrap(side))
  28.   end
  29. end
  30. if #apiaries == 0 then
  31.   error("No apiaries")
  32. else
  33.   printStats()
  34. end
  35.  
  36. while true do
  37.   local statChange = false
  38.   rs.setOutput(redstoneSide, true)
  39.   for i, apiary in ipairs(apiaries) do
  40.     -- look for outputs
  41.     local inv = apiary.getAllStacks()
  42.     local foundDrone = false
  43.     local foundPrincess = false
  44.     for slot, bee in pairs(inv) do
  45.       if slot >= 3 and slot <= 9 then
  46.         if bee["raw_name"] == "item.for.beeprincessge" then
  47.           apiary.pushItemIntoSlot(chestDir, slot, 1, princessSlot)
  48.           foundPrincess = true
  49.         elseif foundDrone == false and bee["raw_name"] == "item.for.beedronege" then
  50.           apiary.pushItemIntoSlot(chestDir, slot, 1, droneSlot)
  51.           apiary.pushItemIntoSlot(chestDir, slot, 64)
  52.           foundDrone = true
  53.         else
  54.           apiary.pushItemIntoSlot(chestDir, slot, 64)
  55.           if bee["raw_name"] ~= "item.for.beedronege" then
  56.             statChange = true
  57.             if stats[bee["name"]] ~= nil then
  58.               stats[bee["name"]] = stats[bee["name"]] + bee["qty"]
  59.             else
  60.               stats[bee] = bee["qty"]
  61.             end
  62.           end
  63.         end
  64.       end
  65.     end
  66.     -- breed princess and 1 drone
  67.     if apiary.getStackInSlot(1) == nil then
  68.       if apiary.pullItem(chestDir, princessSlot, 1, 1) > 0 then
  69.         stats["Generations"] = stats["Generations"] + 1
  70.       end
  71.       apiary.pullItem(chestDir, droneSlot, 1, 2)
  72.     end
  73.   end
  74.   rs.setOutput(redstoneSide, false)
  75.   if statChange then
  76.     printStats()
  77.   end
  78.   sleep(wait)
  79. end
Advertisement
Add Comment
Please, Sign In to add comment