Advertisement
fimas

Untitled

Jun 7th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.94 KB | None | 0 0
  1. pass = 0
  2. cols = 1
  3. rows = 1
  4.  
  5. function turnLeft()
  6.     turtle.digDown()
  7.     turtle.turnLeft()
  8.     turtle.forward()
  9.     turtle.turnLeft()
  10. end
  11.  
  12. function turnRight()
  13.     turtle.digDown()
  14.     turtle.turnRight()
  15.     turtle.forward()
  16.     turtle.turnRight()
  17. end
  18.  
  19. function turnLeftDown()
  20.     turtle.turnLeft()
  21.     turtle.turnLeft()
  22.     turtle.digDown()
  23.     turtle.down()
  24.     turtle.digDown()
  25.     turtle.forward()
  26. end
  27.  
  28. function turnRightDown()
  29.     turtle.turnRight()
  30.     turtle.turnRight()
  31.     turtle.digDown()
  32.     turtle.down()
  33.     turtle.digDown()
  34.     turtle.forward()
  35. end
  36.  
  37. function forward()
  38.     turtle.digDown()
  39.     turtle.forward()
  40. end
  41.  
  42. function inventoryCheck()
  43.     local usedSlots = 0
  44.    
  45.     for i = 1, 16 do
  46.         if turtle.getItemCount(i) > 0 then
  47.             usedSlots = usedSlots + 1
  48.         end
  49.     end
  50.    
  51.     if usedSlots == 16 then return false end
  52.    
  53.     return true
  54. end
  55.  
  56. function quary()
  57.     while inventoryCheck() do
  58.         if turtle.getFuelLevel() < 15 then
  59.             turtle.refuel(1)  
  60.         end
  61.        
  62.         if pass % 2 == 0 then
  63.             if cols == 8 and rows % 2 > 0 and rows < 8 then
  64.                 turnRight()
  65.                
  66.                 rows = rows + 1
  67.                 cols = 1
  68.             elseif cols == 8 and rows % 2 == 0 and rows < 8 then
  69.                 turnLeft()
  70.                
  71.                 rows = rows + 1
  72.                 cols = 1
  73.             elseif cols == 8 and rows == 8 then
  74.                 turnRightDown()
  75.                
  76.                 rows = 1
  77.                 cols = 1
  78.                 pass = pass + 1
  79.             else
  80.                 forward()
  81.                
  82.                 cols = cols + 1
  83.             end
  84.         elseif pass % 2 > 0 then
  85.             if cols == 8 and rows % 2 > 0 and rows < 8 then
  86.                 turnLeft()
  87.                
  88.                 rows = rows + 1
  89.                 cols = 1
  90.             elseif cols == 8 and rows % 2 == 0 and rows < 8 then
  91.                 turnRight()
  92.                
  93.                 rows = rows + 1
  94.                 cols = 1
  95.             elseif cols == 8 and rows == 8 then
  96.                 turnLeftDown()
  97.                
  98.                 rows = 1
  99.                 cols = 1
  100.                 pass = pass + 1
  101.             else
  102.                 forward()
  103.                
  104.                 cols = cols + 1
  105.             end
  106.         end
  107.     end
  108. end
  109.  
  110. function unLoad()
  111.     local oldPass = pass
  112.     local oldCols = cols
  113.     local oldRows = rows
  114.    
  115.     if turtle.getFuelLevel() < 15 then
  116.         turtle.refuel(3)  
  117.     end
  118.    
  119.     -- Go to chest
  120.    
  121.     while pass ~= 0 do
  122.         turtle.up()
  123.         pass = pass - 1
  124.     end
  125.    
  126.     turtle.up()
  127.    
  128.     if oldPass % 2 == oldRows % 2 then
  129.         turtle.turnLeft()
  130.     else
  131.         turtle.turnRight()
  132.     end
  133.    
  134.     while rows ~= 1 do
  135.         turtle.forward()
  136.         rows = rows - 1
  137.     end
  138.    
  139.     turtle.turnLeft()
  140.    
  141.     while cols ~= 1 do
  142.         turtle.forward()
  143.         cols = cols - 1
  144.     end
  145.    
  146.     -- End go to chest
  147.     -- Empty invetory into chest
  148.    
  149.     for i = 2, 16 do
  150.         turtle.select(i)
  151.         turtle.drop()
  152.     end
  153.    
  154.     turtle.select(1)
  155.    
  156.     -- End empty invetory into chest
  157.     -- Go back
  158.    
  159.     turtle.turnLeft()
  160.     turtle.turnLeft()
  161.    
  162.     while cols ~= oldCols do
  163.         turtle.forward()
  164.         cols = cols + 1
  165.     end
  166.    
  167.     turtle.turnRight()
  168.    
  169.     while rows ~= oldRows do
  170.         turtle.forward()
  171.         rows = rows + 1
  172.     end
  173.    
  174.     while pass ~= oldPass do
  175.         turtle.down()
  176.         pass = pass + 1
  177.     end
  178.    
  179.     if oldPass % 2 == oldRows % 2 then
  180.         turtle.turnLeft()
  181.     else
  182.         turtle.turnRight()
  183.     end
  184.     -- End go back
  185. end
  186.  
  187. function process()
  188.     while true do
  189.         quary()
  190.         unLoad()
  191.     end
  192. end
  193.  
  194. process()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement