Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- turtle facing north
- local beeDir = {{"front","south"}, {"right","west"}, {"back","north"}, {"left","east"}}
- local bee = {}
- local nApiaries = #beeDir
- local chestDir = "bottom"
- local pushDir = "up"
- local chest = nil
- local generation = {0,0,0,0}
- local princess = 13341
- local drone = 13340
- for i=1,nApiaries do
- bee[i] = {peripheral.wrap(beeDir[i][1]),beeDir[i][2]}
- end
- chest = peripheral.wrap(chestDir)
- local chestSize = chest.getInventorySize()
- -- (limited) turtle inventory clean up
- local function checkAndMoveBak(i)
- local result = true
- local destination = 16
- if turtle.getItemCount(i) > 0 then
- print("Attempting clean up in slot " .. i)
- result = false
- turtle.select(i)
- while not turtle.transferTo(destination) do
- destination = destination - 1
- -- print(destination)
- if destination <= 2 then break end
- end
- if destination <= 2 then result = false else result = true end
- end
- return result
- end
- -- (limited) turtle inventory clean up / push stuff into apiaries
- --local function checkAndMove(i,apiary)
- -- local result = true
- -- if turtle.getItemCount(i) > 0 then
- -- print("Attempting clean up in slot " .. i)
- -- result = false
- -- apiary[1].pullItemIntoSlot(apiary[2], 1, 1, 1)
- --end
- local function checkInv(i)
- local result = true
- if turtle.getItemCount(i) > 0 then
- print("Bee found in slot " .. i)
- result = false
- end
- return result
- end
- local function pulse(direction)
- redstone.setOutput(direction,true)
- sleep(0.1)
- redstone.setOutput(direction,false)
- end
- local function getBBak(beeID,slot)
- local found = false
- local item = nil
- for i=1,chestSize do
- item = chest.getStackInSlot(i)
- if item and item.id == beeID then
- if chest.pushItemIntoSlot(pushDir,i,1,slot) == 1 then found = true
- else found = false end
- break
- end
- end
- return found
- end
- local function getB(beeID,slot)
- local found = false
- local items = nil
- items = chest.getAllStacks()
- if not items then return false end
- for i,k in pairs(items) do
- if k.id == beeID then
- if chest.pushItemIntoSlot(pushDir,i,1,slot) == 1 then found = true
- else found = false end
- break
- end
- end
- return found
- end
- -- pull out one princess and one drone from chest
- local function getBees()
- if checkInv(1) then getB(princess,1) end
- while turtle.getItemCount(1) ~= 1 do
- print("princess: "..turtle.getItemCount(1))
- sleep(5)
- getB(princess,1)
- end
- if checkInv(2) then getB(drone,2) end
- while turtle.getItemCount(2) < 1 do
- print("drone: "..turtle.getItemCount(2))
- sleep(5)
- getB(drone,2)
- end
- if turtle.getItemCount(1) * turtle.getItemCount(2) < 1 then return false end
- return true
- end
- -- pull princess and drone from turtle
- local function fillApiary(apiary,gen,direction)
- local result = 0
- if not getBees() then return false end
- print("Fill ("..direction..") apiary with generation: "..gen)
- -- princess in slot 1 in apiary and turtle inventory
- result = apiary[1].pullItemIntoSlot(apiary[2], 1, 1, 1)
- -- drone in slot 2
- result = result * apiary[1].pullItemIntoSlot(apiary[2], 2, 1, 2)
- if result==1 then return true
- else return false end
- end
- --local function checkQueen(apiary)
- -- local queen = apiary.getQueen()
- -- return queen
- --end
- --local function getApiaryProducts(apiary)
- -- local result = 0
- -- for i=3,9 do
- -- result = result + apiary.pushItem(interfaceDir,i,64)
- -- end
- -- return result
- --end
- -- main :)
- local fill = true
- while true do
- for i=1,4 do
- --check apiaries
- if not bee[i][1].getQueen() then
- -- print(getApiaryProducts(bee[i]))
- fill = fillApiary(bee[i],generation[i],beeDir[i][1])
- generation[i] = generation[i] + 1
- if not fill then break end
- end
- end
- if not fill then break end
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement