Don't like ads? PRO users don't see any ads ;-)
Guest

clear

By: a guest on May 5th, 2012  |  syntax: Lua  |  size: 2.86 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. local origin = {0,0,0}
  2. local max = {72,2,144}
  3. local dir = 0;
  4. local modX = {0,1,0,-1}
  5. local modZ = {-1,0,1,0}
  6. local location = {0,0,0}
  7.  
  8. function turnAround()
  9. right()
  10. right()
  11. end
  12.  
  13. function right()
  14.   dir = dir + 1 % 4
  15. end
  16.  
  17.  
  18.  
  19. function left()
  20.   dir = dir - 1
  21.   if dir < 0 then
  22.     dir = 0
  23. end
  24.  
  25. function down(dig=false)
  26.   while true do
  27.     if turtle.down() then
  28.       break
  29.     end
  30.     if turtle.detectDown() then
  31.       if dig then
  32.         turtle.digDown()
  33.       end
  34.     end
  35.     sleep(0)
  36.   end
  37.   location[1]=location[1]-1
  38. end
  39.  
  40. function up(dig=false)
  41.   while true do
  42.     if turtle.up() then
  43.       break
  44.     end
  45.     if dig then
  46.       if turtle.detectUp() then
  47.         turtle.digUp()
  48.       end
  49.     end
  50.   sleep(0)
  51.   end
  52.   location[2] = location[2] + 1
  53. end
  54. function forward(dig=false)
  55.   while true do
  56.     if turtle.forward() then
  57.       break
  58.     end
  59.     if turtle.detect() then
  60.       if dig then
  61.         turtle.dig()
  62.       end
  63.     end
  64.     sleep(0)
  65.   end
  66.   location[1] = location[1] + modX[dir];
  67.   location[3] = location[3] + modZ[dir];
  68. end
  69.  
  70. function back()
  71.   while true do
  72.     if turtle.back() then
  73.       break
  74.     end
  75.     if dig then
  76.       turnAround()
  77.       if turlte.detect() then
  78.         turtle.dig()
  79.       end
  80.       turnAround()
  81.     end
  82.     sleep(0)
  83.   end
  84.   location[1] = location[1]+modX[dir];
  85.   location[3] = location[3]+modZ[dir];
  86. end
  87.  
  88. function getLocCopy()
  89.   local copy = {}
  90.   for i,n in ipairs(location) do
  91.     copy[i]=n
  92.   end
  93.   return copy;
  94. end
  95.  
  96. function checkInventory()
  97.   if turtle.getItemCount(9> > 0 then
  98.     return true
  99.    end
  100.    return false
  101. end
  102.  
  103. function dropOff(x,y,z)
  104.   local org = getLocCopy()
  105.   if z%2 == 1 then
  106.     left()
  107.     forward()
  108.     right()
  109.   end
  110.   while not dir==2 do
  111.     left()
  112.     sleep(0)
  113.   end
  114.   while not location[3] == origin[3]
  115.     forward()
  116.     sleep(0)
  117.   end
  118.   if not location[1] == origin[1] then
  119.     local left = false
  120.     if location[1] <0 then
  121.       left()
  122.       left = ture
  123.     end
  124.     elseif location[1]>0 then
  125.       right()
  126.     end
  127.     while not location[1] == origin[1]
  128.       forward()
  129.       sleep(0)
  130.     end
  131.  
  132.     if left then
  133.      right()
  134.     else
  135.       left()
  136.     end
  137.  
  138.   end
  139.   forward()
  140.   forward()
  141.   dropAll()
  142.   turnAround()
  143.   forward()
  144.   forward()
  145. end
  146.  
  147. function dropAll()
  148.   for i=1,9,1 do
  149.     turtle.select(i)
  150.     if turtle.getItemCount(i) >0 then
  151.       turtle.drop(turtle.getItemCount(i);
  152.     end
  153.   end
  154.  
  155. end
  156.  
  157. local in = ""
  158. while not in == "start" do
  159.   in = io.read()
  160.   sleep(0)
  161. end
  162.  
  163. local location = {0,0,0}
  164.  
  165.   for x=0,max[1],1 do
  166.     for z=0,max[2],1 do
  167.       for y=1,max[3],1 do
  168.        
  169.         up(true);
  170.         checkInventory()
  171.         down(false);
  172.       end
  173.       forward(true);
  174.       checkInventory()
  175.     end
  176.     left()
  177.     forward(true)
  178.     left()
  179.     back(true)
  180.     checkInventory()
  181.   end