akihex

flowersAndBees

Apr 21st, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. -- turtle facing north
  2. local beeDir = {{"front","south"}, {"right","west"}, {"back","north"}, {"left","east"}}
  3. local bee = {}
  4. local princess = "top"
  5. local drone = "bottom"
  6. local generation = {0,0,0,0}
  7.  
  8. for i=1,4 do
  9.   bee[i] = {peripheral.wrap(beeDir[i][1]),beeDir[i][2]}
  10. end
  11.  
  12. -- (limited) turtle inventory clean up
  13. local function checkAndMoveBak(i)
  14.   local result = true
  15.   local destination = 16
  16.   if turtle.getItemCount(i) > 0 then
  17.     print("Attempting clean up in slot " .. i)
  18.     result = false
  19.     turtle.select(i)
  20.     while not turtle.transferTo(destination) do
  21.       destination = destination - 1
  22.       -- print(destination)
  23.       if destination <= 2 then break end
  24.     end
  25.     if destination <= 2 then result = false else result = true end
  26.   end
  27.   return result
  28. end
  29.  
  30. -- (limited) turtle inventory clean up / push stuff into apiaries
  31. --local function checkAndMove(i,apiary)
  32. --  local result = true
  33. --  if turtle.getItemCount(i) > 0 then
  34. --    print("Attempting clean up in slot " .. i)
  35. --    result = false
  36. --    apiary[1].pullItemIntoSlot(apiary[2], 1, 1, 1)
  37. --end
  38.  
  39. local function checkInv(i)
  40.   local result = true
  41.   if turtle.getItemCount(i) > 0 then
  42.     print("Bee found in slot " .. i)
  43.     result = false
  44.   end
  45.   return result
  46. end
  47.  
  48. local function pulse(direction)
  49.   redstone.setOutput(direction,true)
  50.   sleep(0.1)
  51.   redstone.setOutput(direction,false)
  52. end
  53.  
  54. -- request one princess and one drone from fuzzy export buses
  55. local function getBees()
  56.   --local result = checkAndMove(1) and checkAndMove(2)
  57.   --if not result then return result end
  58.   if checkInv(1) then pulse(princess) end
  59.   while turtle.getItemCount(1) ~= 1 do
  60.     print("princess: "..turtle.getItemCount(1))
  61.     sleep(5)
  62.     pulse(princess)
  63.   end
  64.   if checkInv(2) then pulse(drone) end
  65.   while turtle.getItemCount(2) < 1 do
  66.     print("drone: "..turtle.getItemCount(2))
  67.     sleep(5)
  68.     pulse(drone)
  69.   end
  70.   if turtle.getItemCount(1) * turtle.getItemCount(2) < 1 then return false end
  71.   return true
  72. end
  73.  
  74. -- pull princess and drone from turtle
  75. local function fillApiary(apiary,gen,direction)
  76.   local result = 0
  77.   if not getBees() then return false end
  78.   print("Fill ("..direction..") apiary with generation: "..gen)
  79.   -- princess in slot 1 in apiary and turtle inventory
  80.   result = apiary[1].pullItemIntoSlot(apiary[2], 1, 1, 1)
  81.   -- drone in slot 2
  82.   result = result * apiary[1].pullItemIntoSlot(apiary[2], 2, 1, 2)
  83.   if result==1 then return true
  84.   else return false end
  85. end
  86.  
  87. --local function checkQueen(apiary)
  88. --  local queen = apiary.getQueen()
  89. --  return queen
  90. --end
  91.  
  92. --local function getApiaryProducts(apiary)
  93. --  local result = 0
  94. --  for i=3,9 do
  95. --    result = result + apiary.pushItem(interfaceDir,i,64)
  96. --  end
  97. --  return result
  98. --end
  99.  
  100. -- main :)
  101. local fill = true
  102. while true do
  103.   for i=1,4 do
  104.     --check apiaries
  105.     if not bee[i][1].getQueen() then
  106. --      print(getApiaryProducts(bee[i]))
  107.       fill = fillApiary(bee[i],generation[i],beeDir[i][1])
  108.       generation[i] = generation[i] + 1
  109.       if not fill then break end
  110.     end
  111.   end
  112.   if not fill then break end
  113.   sleep(5)
  114. end
Advertisement
Add Comment
Please, Sign In to add comment