Advertisement
Pirsqed

Router bot RC1

Apr 3rd, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 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. GONNA THROW UP NOW"
  50.         turtle.turnLeft()
  51.         if turtle.drop() then
  52.           print "*BARF*"
  53.         end
  54.         turtle.turnRight()
  55.         return false
  56.       else
  57.         return true
  58.       end
  59.     end
  60.   end
  61.   return true
  62. end
  63.  
  64. function drop()
  65.   for i=1,16 do
  66.     turtle.select(i)
  67.     if turtle.getItemCount(i) > 0 then
  68.       if turtle.drop() == false then
  69.         if unclog() == false then
  70.           return false
  71.         end
  72.         turtle.select(i)
  73.         turtle.drop()
  74.       end
  75.     end
  76.   end
  77.   print "Slight rest."
  78.   sleep(3)
  79.   print "Checking router for clogged item before next cycle."
  80.   if turtle.suck() then
  81.     if turtle.dropUp() == false then
  82.       print "There was an item in the router, but the chest is full. Disposing of item."
  83.       turtle.turnLeft()
  84.       if turtle.drop then
  85.         print "Gently placing the item onto the ground."
  86.       end
  87.       turtle.turnRight()
  88.       return false
  89.     end
  90.   end
  91.   return true
  92. end
  93. function router()
  94.   local doStuff = true
  95.   while doStuff do
  96.     suck()
  97.     spin()
  98.     doStuff = drop()
  99.     spin()
  100.   end
  101. end
  102.  
  103. router()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement