Advertisement
bueddl

Untitled

Jun 15th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1.  
  2. --------------------------------------------------------------------------------------------------------------
  3.  
  4. --
  5. --
  6. --
  7. --
  8.  
  9. -- cache
  10. cache = {}
  11. cache[1] = vector.new(0, 0, 0)
  12. cache[2] = vector.new(0, 0, -3)
  13. cache[3] = vector.new(0, 0, -6)
  14.  
  15. -- chest to seek for
  16. Turtle.addWayPoint()
  17.  
  18. Turtle.cache = function()
  19.  
  20.     while true do
  21.  
  22.         turtle.select(1)
  23.         -- wait until we got at least one item
  24.         print('Waiting for new items to arrive')
  25.        
  26.         while not turtle.suckDown() do
  27.             sleep(0.1)
  28.         end
  29.        
  30.         print('Grabbing items...')
  31.  
  32.         -- if there is something in the box, grab it
  33.         while turtle.suckDown() do
  34.         end
  35.  
  36.         print('Caching...')
  37.         -- if we are here, our turtle grabbed ALL items or is at least full of items, however, we are dropping them to a cache chest
  38.        
  39.         for id, coords in pairs(cache) do
  40.             Turtle.goTo(coords)
  41.            
  42.             -- try to drop items
  43.             itemsLeft = false
  44.            
  45.             print('Dropping items to cache chest #' .. id .. '...')
  46.             for slotId = 1, 16 do
  47.                 turtle.select(slotId)
  48.                
  49.                 if not turtle.dropUp() and turtle.getItemCount(slotId) ~= 0 then
  50.                     itemsLeft = true
  51.                 end
  52.             end
  53.            
  54.             -- if we gave up at at east one item, search another chest
  55.             if not itemsLeft then
  56.                 break
  57.             end
  58.            
  59.             print('Items remaining, but cache chest seems to be full...')
  60.         end
  61.        
  62.    
  63.        
  64.        
  65.         print('Returning to seeking chest')
  66.         Turtle.goToLastWP2()
  67.        
  68.     end
  69.  
  70. end
  71.  
  72.  
  73.  
  74. term.clear()
  75. term.setCursorPos(1, 1)
  76.  
  77. Turtle.cache()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement