Advertisement
Pirsqed

Router Bot v1 Alpha

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