Guest User

beeTest3

a guest
Aug 13th, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. mg = peripheral.wrap("left")
  2. rednet.open("right")
  3.  
  4. function myPrint(...)
  5.    f = fs.open("inoc.log", "a")
  6.    f.writeLine(...)
  7.    print(...)
  8.    f.close()
  9. end
  10.  
  11. function checkDone()
  12.    state = mg.get()
  13.    printState(state)
  14.    return ((state["Is Not Working"] and state["Energy Stored"]) and state["Cannot Work"])
  15. end
  16.  
  17. function printState(state)
  18.    for k,v in pairs(state) do
  19.       if (v) then myPrint(k) end
  20.    end
  21. end
  22.  
  23. function removeSerum()
  24.    serumSlot = findSerumSlot()
  25.    redstone.setOutput("top", true)
  26.    repeat
  27.       sleep(1)
  28.    until (turtle.getItemCount(serumSlot) > 0)
  29.    redstone.setOutput("top", false)
  30.    turtle.turnRight()
  31.    turtle.select(serumSlot)
  32.    turtle.drop()
  33.    turtle.turnLeft()
  34. end
  35.  
  36. function findSerumSlot()
  37.    local slot
  38.    local _serumSlot = 0
  39.    for slot=1,16 do
  40.       if turtle.getItemCount(slot) == 0 then
  41.          if _serumSlot == 0 then _serumSlot = slot end
  42.       end
  43.    end
  44.    
  45.    myPrint ("Serums should land in slot "..tostring(_serumSlot))
  46.  
  47.    return _serumSlot
  48. end
  49.  
  50. function removeBees(slot)
  51.   for ii = 0,5 do
  52.      if (slot + ii < 16) then
  53.     turtle.select(slot+ii)
  54.     res = turtle.suck()
  55.     --myPrint("To slot "..tostring(slot+ii)..": "..tostring(res))
  56.      end
  57.   end
  58. end
  59.  
  60. function refillSerums()
  61.    myPrint ("Waiting for a refill...")
  62.    rednet.broadcast("Refill")
  63.    repeat
  64.       id,msg,dist = rednet.receive()
  65.    until (msg == "Done") and (dist == 2)
  66. end
  67.  
  68. function doBee(slot)
  69.    local state
  70.    local serumSlot
  71.  
  72.    while true do
  73.       myPrint ("Getting serum...")
  74.       turtle.select(16)
  75.       turtle.turnLeft()
  76.       gotOne = turtle.suck()
  77.       turtle.turnRight()
  78.       if (gotOne == false) then
  79.          myPrint ("No more serums!")
  80.          break
  81.       end
  82.  
  83.       myPrint ("Inserting bees from slots #"..tostring(slot).." - "..tostring(slot+5))
  84.       for ii = 0,5 do
  85.          if (slot + ii < 16) then
  86.             turtle.select(slot+ii)
  87.             res = turtle.drop()
  88.         -- myPrint ("From slot "..tostring(slot+ii).." "..tostring(res))
  89.          end
  90.       end
  91.      
  92.       myPrint ("Inserting serum...")
  93.       turtle.select(16)
  94.       turtle.drop()
  95.  
  96.       myPrint ("Waiting for the machine to finish...")
  97.       repeat
  98.          sleep(100)
  99.       until (checkDone())
  100.  
  101.       myPrint ("Removing the bees...")
  102.       removeBees(slot)
  103.  
  104.       myPrint ("Serum done")
  105.       removeSerum()
  106. --      turtle.drop()
  107.    end
  108.    
  109.    refillSerums()
  110. end
  111.  
  112. -- rs.setBundledOutput("back", colors.red)
  113. serumSlot = findSerumSlot()
  114.  
  115. local hasItems = false
  116.  
  117. for i=1,15,5 do
  118.    hasItems = false
  119.    for ii = 0,5 do
  120.       if (i+ii < 16) then
  121.          if (turtle.getItemCount(i+ii) > 0) then
  122.             hasItems = true
  123.          end
  124.       end
  125.    end
  126.    
  127.    if (hasItems == true) then
  128.       doBee(i)
  129.    end
  130. end
  131. -- rs.setBundledOutput("back", colors.green)
Advertisement
Add Comment
Please, Sign In to add comment