Advertisement
akihex

flowersNBees

Apr 23rd, 2014
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- turtle facing north
  2. local beeDir = {{"front","south"}, {"right","west"}, {"back","north"}, {"left","east"}}
  3. local bee = {}
  4. local nApiaries = #beeDir
  5. local chestDir = "bottom"
  6. local pushDir = "up"
  7. local chest = nil
  8. local generation = {0,0,0,0}
  9. local princess = 13341
  10. local drone = 13340
  11.  
  12. for i=1,nApiaries do
  13.   bee[i] = {peripheral.wrap(beeDir[i][1]),beeDir[i][2]}
  14. end
  15.  
  16. chest = peripheral.wrap(chestDir)
  17. local chestSize = chest.getInventorySize()
  18.  
  19. -- (limited) turtle inventory clean up
  20. local function checkAndMoveBak(i)
  21.   local result = true
  22.   local destination = 16
  23.   if turtle.getItemCount(i) > 0 then
  24.     print("Attempting clean up in slot " .. i)
  25.     result = false
  26.     turtle.select(i)
  27.     while not turtle.transferTo(destination) do
  28.       destination = destination - 1
  29.       -- print(destination)
  30.       if destination <= 2 then break end
  31.     end
  32.     if destination <= 2 then result = false else result = true end
  33.   end
  34.   return result
  35. end
  36.  
  37. -- (limited) turtle inventory clean up / push stuff into apiaries
  38. --local function checkAndMove(i,apiary)
  39. --  local result = true
  40. --  if turtle.getItemCount(i) > 0 then
  41. --    print("Attempting clean up in slot " .. i)
  42. --    result = false
  43. --    apiary[1].pullItemIntoSlot(apiary[2], 1, 1, 1)
  44. --end
  45.  
  46. local function checkInv(i)
  47.   local result = true
  48.   if turtle.getItemCount(i) > 0 then
  49.     print("Bee found in slot " .. i)
  50.     result = false
  51.   end
  52.   return result
  53. end
  54.  
  55. local function pulse(direction)
  56.   redstone.setOutput(direction,true)
  57.   sleep(0.1)
  58.   redstone.setOutput(direction,false)
  59. end
  60.  
  61. local function getBBak(beeID,slot)
  62.   local found = false
  63.   local item = nil
  64.   for i=1,chestSize do
  65.     item = chest.getStackInSlot(i)
  66.     if item and item.id == beeID then
  67.       if chest.pushItemIntoSlot(pushDir,i,1,slot) == 1 then found = true
  68.       else found = false end
  69.       break
  70.     end
  71.   end
  72.   return found
  73. end
  74.  
  75. local function getB(beeID,slot)
  76.   local found = false
  77.   local items = nil
  78.   items = chest.getAllStacks()
  79.   if not items then return false end
  80.   for i,k in pairs(items) do
  81.     if k.id == beeID then
  82.       if chest.pushItemIntoSlot(pushDir,i,1,slot) == 1 then found = true
  83.       else found = false end
  84.       break
  85.     end
  86.   end
  87.   return found
  88. end
  89.  
  90.  
  91. -- pull out one princess and one drone from chest
  92. local function getBees()
  93.   if checkInv(1) then getB(princess,1) end
  94.   while turtle.getItemCount(1) ~= 1 do
  95.     print("princess: "..turtle.getItemCount(1))
  96.     sleep(5)
  97.     getB(princess,1)
  98.   end
  99.   if checkInv(2) then getB(drone,2) end
  100.   while turtle.getItemCount(2) < 1 do
  101.     print("drone: "..turtle.getItemCount(2))
  102.     sleep(5)
  103.     getB(drone,2)
  104.   end
  105.   if turtle.getItemCount(1) * turtle.getItemCount(2) < 1 then return false end
  106.   return true
  107. end
  108.  
  109. -- pull princess and drone from turtle
  110. local function fillApiary(apiary,gen,direction)
  111.   local result = 0
  112.   if not getBees() then return false end
  113.   print("Fill ("..direction..") apiary with generation: "..gen)
  114.   -- princess in slot 1 in apiary and turtle inventory
  115.   result = apiary[1].pullItemIntoSlot(apiary[2], 1, 1, 1)
  116.   -- drone in slot 2
  117.   result = result * apiary[1].pullItemIntoSlot(apiary[2], 2, 1, 2)
  118.   if result==1 then return true
  119.   else return false end
  120. end
  121.  
  122. --local function checkQueen(apiary)
  123. --  local queen = apiary.getQueen()
  124. --  return queen
  125. --end
  126.  
  127. --local function getApiaryProducts(apiary)
  128. --  local result = 0
  129. --  for i=3,9 do
  130. --    result = result + apiary.pushItem(interfaceDir,i,64)
  131. --  end
  132. --  return result
  133. --end
  134.  
  135. -- main :)
  136. local fill = true
  137. while true do
  138.   for i=1,4 do
  139.     --check apiaries
  140.     if not bee[i][1].getQueen() then
  141. --      print(getApiaryProducts(bee[i]))
  142.       fill = fillApiary(bee[i],generation[i],beeDir[i][1])
  143.       generation[i] = generation[i] + 1
  144.       if not fill then break end
  145.     end
  146.   end
  147.   if not fill then break end
  148.   sleep(5)
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement