Advertisement
Pirsqed

Router Bot Beta

Apr 2nd, 2013
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --routerbot!
  2. function suck()
  3.   print "Starting suck cycle!"
  4.   while not turtle.suck() do
  5.     print "Nothing in the Ender chest. Waiting a while..."
  6.     sleep(20)
  7.   end
  8.   local sucked = 1
  9.   print "Sucking!!"
  10.   while turtle.suck() do
  11.     sucked = sucked + 1
  12.   end
  13.   print "Sucked this many items"
  14.   print sucked
  15. end
  16.  
  17. function spin()
  18.   turtle.turnRight()
  19.   turtle.turnRight()
  20. end
  21.  
  22. function unclog()
  23.   print "Possible Clog?"
  24.   sleep(1)
  25.   local counter = 0
  26.   for i = 1, 10 do
  27.     sleep(1)
  28.     print "Trying to drop!"
  29.     if turtle.drop() then
  30.       break
  31.     end
  32.     counter = counter + 1
  33.     if counter == 10 then
  34.       local full = 1
  35.       for i = 1, 16 do
  36.         print "Checking slot " --.. i
  37.         if turtle.getItemCount(i) == 0 then
  38.           print "Room found for clogged item in slot " --.. i
  39.           turtle.suck()
  40.           turtle.select(i)
  41.           print "Putting it into the chest above me."
  42.           if turtle.dropUp() == true then
  43.             full = 0
  44.           end
  45.           break
  46.         end
  47.       end  
  48.       if full == 1 then
  49.         print "SHIT BE FULL, YO."
  50.         return false
  51.       else
  52.         return true
  53.       end
  54.     end
  55.   end
  56.   return true
  57. end
  58.  
  59. function drop()
  60.   for i=1,16 do
  61.     turtle.select(i)
  62.     if getItemCount(i) == 0 then
  63.       break
  64.     end
  65.     if turtle.drop() == false then
  66.       if unclog() == false then
  67.         return false
  68.       end
  69.       turtle.select(i)
  70.       turtle.drop()
  71.     end
  72.   end
  73.   print "Slight rest."
  74.   sleep(3)
  75.   print "Checking router for clogged item before next cycle."
  76.   if turtle.suck() then
  77.     if turtle.dropUp() == false then
  78.       print "There was an item in the router, but the chest is full. "
  79.       return false
  80.     end
  81.   end
  82.   return true
  83. end
  84. function router()
  85.   local doStuff = true
  86.   while doStuff do
  87.     suck()
  88.     spin()
  89.     doStuff = drop()
  90.     spin()
  91.   end
  92. end
  93.  
  94. router()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement