Advertisement
Pirsqed

Untitled

Apr 2nd, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. --routerbot!
  2. function suck()
  3.   print "Starting suck cycle!"
  4.   turtle.select(1)
  5.   while not turtle.suck() do
  6.     print "Nothing in the Ender chest. Waiting a while..."
  7.     sleep(20)
  8.   end
  9.   local sucked = 1
  10.   print "Sucking!!"
  11.   while turtle.suck() do
  12.     sucked = sucked + 1
  13.   end
  14.   print ("Finished sucking. Got ".. sucked .. " items.")
  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.select(i)
  40.           turtle.suck()
  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 turtle.getItemCount(i) > 0 then
  63.       if turtle.drop() == false then
  64.         if unclog() == false then
  65.           return false
  66.         end
  67.         turtle.select(i)
  68.         turtle.drop()
  69.       end
  70.     end
  71.   end
  72.   print "Slight rest."
  73.   sleep(3)
  74.   print "Checking router for clogged item before next cycle."
  75.   if turtle.suck() then
  76.     if turtle.dropUp() == false then
  77.       print "There was an item in the router, but the chest is full. "
  78.       return false
  79.     end
  80.   end
  81.   return true
  82. end
  83. function router()
  84.   local doStuff = true
  85.   while doStuff do
  86.     suck()
  87.     spin()
  88.     doStuff = drop()
  89.     spin()
  90.   end
  91. end
  92.  
  93. router()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement