Advertisement
joebodo

inoculator.lua

Apr 29th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. os.loadAPI('apis.lua')
  2.  
  3. local p
  4. local BEE_INO_SLOT = 3
  5. local BEE_RES_START_SLOT = 4
  6. local BEE_RES_END_SLOT = 9
  7. local BEE_FIN_SLOT = 10
  8. local SERUM_SLOT = 16
  9.  
  10. local args = {...}
  11.  
  12. returnOffset = tonumber(args[1])
  13.  
  14. function refillSerum(slot)
  15.   TL2.pathtofreely(0, 1+returnOffset, -1)
  16.   turtle.select(slot)
  17.   turtle.dropDown()
  18.   TL2.pathtofreely(0, 0, -1)
  19.   p = peripheral.wrap("bottom")
  20. end
  21.  
  22. function ejectSerum(serum, slot)
  23.   print("ejecting to slot " .. slot)
  24.   p.pushItemIntoSlot("up", SERUM_SLOT, 1, slot)
  25.   refillSerum(slot)
  26. end
  27.  
  28. function getFinishedBees()
  29.   local tslot = 0
  30.   for i = 10, 15, 1 do
  31.     bees = p.getStackInSlot(i)
  32.     if bees then
  33.       p.pushItemIntoSlot("up", i, bees.qty, tslot)
  34.       tslot = tslot+1
  35.     end
  36.   end
  37. end
  38.  
  39. function inoculate()
  40.  
  41.   TL2.pathto(0, 0, -1)
  42.   p = peripheral.wrap("bottom")
  43.  
  44.   -- insert bees
  45.   local slot = BEE_INO_SLOT
  46.   for i = 1, 16, 1 do
  47.     local qty = turtle.getItemCount(i)
  48.     if qty > 0 then
  49.       for k = BEE_RES_START_SLOT, BEE_RES_END_SLOT, 1 do
  50.         if not p.getStackInSlot(k) then
  51.           slot = k
  52.           break
  53.         end
  54.       end
  55.       print("pulling " .. i .. " to " .. slot)
  56.       p.pullItemIntoSlot("up", i, qty, slot)
  57.     end
  58.   end
  59.  
  60.   -- process serums
  61.   for i = 1, 16, 1 do
  62.     if turtle.getItemCount(i) > 0 then
  63.       -- insert serum
  64.       print("inserting serum from slot " .. i)
  65.       TL2.setHeading(0)
  66.       p.pullItemIntoSlot("up", i, 1, SERUM_SLOT)
  67.  
  68.       -- Move bees back if already
  69.       -- processed
  70.       if not p.getStackInSlot(BEE_INO_SLOT) then
  71.         for j = 15, 10, -1 do
  72.           if p.getStackInSlot(j) then
  73.             p.swapStacks(j, j-6)
  74.           end
  75.         end
  76.       end
  77.  
  78.       while true do
  79.         serum = p.getStackInSlot(SERUM_SLOT)
  80.         if not p.getStackInSlot(BEE_INO_SLOT) then
  81.  
  82.           -- eject serum
  83.           if serum then
  84.             ejectSerum(serum, i)
  85.             break
  86.           end
  87.  
  88.         elseif serum and serum.dmg == 16 then
  89.           --ender.broadcastMsg("beechat", "Reload " .. serum.name .. " when refilled")
  90.           print('serum empty ' .. serum.name)
  91.           ejectSerum(serum, i)
  92.         end        
  93.         os.sleep(10)
  94.       end
  95.     end
  96.   end
  97.  
  98.   --ender.broadcastMsg("beechat", "Finished inoculation")
  99.   --getFinishedBees()
  100.   TL2.pathto(0, 0, 0, 0)
  101.   TL2.emptySlots(turtle.dropUp)
  102. end
  103.  
  104. while true do
  105.   os.sleep(5)
  106.   if turtle.getItemCount(1) > 0 then
  107.     os.sleep(5)
  108.     inoculate()
  109.     os.shutdown()
  110.   end
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement