Pinkishu

Untitled

May 5th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. print("ok")
  2. local origin = {0,0,0}
  3. local max = {72,2,144}
  4. local dir = 1;
  5. local modX = {0,1,0,-1}
  6. local modZ = {-1,0,1,0}
  7. local location = {0,0,0}
  8.  
  9. function turnAround()
  10. right()
  11. right()
  12. end
  13.  
  14. function right()
  15.   dir = (dir + 1) % 5
  16.   turtle.turnRight()
  17. end
  18.  
  19.  
  20.  
  21. function left()
  22.   dir = dir - 1
  23.   if dir < 1 then
  24.     dir = 1
  25.   end
  26.   turtle.turnLeft()
  27. end
  28.  
  29. function down(dig)
  30.   while true do
  31.     if turtle.down() then
  32.       break
  33.     end
  34.     if turtle.detectDown() then
  35.       if dig then
  36.         turtle.digDown()
  37.       end
  38.     end
  39.     sleep(0)
  40.   end
  41.   location[1]=location[1]-1
  42. end
  43.  
  44. function up(dig)
  45.   while true do
  46.     if turtle.up() then
  47.       break
  48.     end
  49.     if dig then
  50.       if turtle.detectUp() then
  51.         turtle.digUp()
  52.       end
  53.     end
  54.   sleep(0)
  55.   end
  56.   location[2] = location[2] + 1
  57. end
  58. function forward(dig)
  59.   while true do
  60.     if turtle.forward() then
  61.       break
  62.     end
  63.     if turtle.detect() then
  64.       if dig then
  65.         turtle.dig()
  66.       end
  67.     end
  68.     sleep(0)
  69.   end
  70.   print(dir);
  71.   location[1] = location[1] + modX[dir];
  72.   location[3] = location[3] + modZ[dir];
  73. end
  74.  
  75. function back(dig)
  76.   while true do
  77.     if turtle.back() then
  78.       break
  79.     end
  80.     if dig then
  81.       turnAround()
  82.       if turtle.detect() then
  83.         turtle.dig()
  84.       end
  85.       turnAround()
  86.     end
  87.     sleep(0)
  88.   end
  89.   location[1] = location[1]+modX[dir];
  90.   location[3] = location[3]+modZ[dir];
  91. end
  92.  
  93. function getLocCopy()
  94.   local copy = {}
  95.   for i,n in ipairs(location) do
  96.     copy[i]=n
  97.   end
  98.   return copy;
  99. end
  100.  
  101. function checkInventory()
  102.   if turtle.getItemCount(9) > 0 then
  103.     return true
  104.    end
  105.    return false
  106. end
  107.  
  108. function dropOff(x,y,z)
  109.   local org = getLocCopy()
  110.   if z%2 == 1 then
  111.     left()
  112.     forward(false)
  113.     right()
  114.   end
  115.   while dir~=2 do
  116.     left()
  117.     sleep(0)
  118.   end
  119.   while location[3] ~= origin[3] do
  120.     forward(false)
  121.     sleep(0)
  122.   end
  123.   if location[1] ~= origin[1] then
  124.     local left = false
  125.     if location[1] <0 then
  126.       left()
  127.       left = true
  128.     elseif location[1]>0 then
  129.       right()
  130.     end
  131.     while location[1] ~= origin[1] do
  132.       forward(false)
  133.       sleep(0)
  134.     end
  135.  
  136.     if left then
  137.      right()
  138.     else
  139.       left()
  140.     end
  141.  
  142.   end
  143.   forward(false)
  144.   forward(false)
  145.   dropAll()
  146.   turnAround()
  147.   forward(false)
  148.   forward(false)
  149.  
  150.   if left then
  151.     left()
  152.   else
  153.     right()
  154.   end
  155.   while location[1] ~= org[1] do
  156.       forward(false)
  157.       sleep(0)
  158.   end
  159.    
  160.   if left then
  161.     right()
  162.   else
  163.     left()
  164.   end
  165.   if org[3] % 2 == 1 then
  166.     right()
  167.     forward(false)
  168.     left()
  169.   end
  170.   while location[3]~=org[3] do
  171.     forward(false)
  172.     sleep(0)
  173.   end
  174.   if org[3]%2==1 then
  175.     left()
  176.     forward(true)
  177.     right()
  178.    
  179.   end
  180.  
  181. end
  182.  
  183. function dropAll()
  184.   for i=1,9,1 do
  185.     turtle.select(i)
  186.     if turtle.getItemCount(i) >0 then
  187.       turtle.drop(turtle.getItemCount(i));
  188.     end
  189.   end
  190.  
  191. end
  192.  
  193. local input = ""
  194. while input ~= "start" do
  195.   input = io.read()
  196.   sleep(0)
  197. end
  198.  
  199. local location = {0,0,0}
  200.  
  201.   for x=0,max[1],1 do
  202.     for z=0,max[3],1 do
  203.       for y=1,max[2]-1,1 do
  204.        
  205.         while turtle.detectUp() do
  206.           turtle.digUp()
  207.           sleep(0)
  208.         end
  209.         checkInventory()
  210.        
  211.         print(tostring(x).."/"..tostring(y).."/"..tostring(z))
  212.       end
  213.       forward(true);
  214.       if checkInventory() then
  215.         dropOff(x,y,z)
  216.       end
  217.     end
  218.     left()
  219.     forward(true)
  220.     left()
  221.     back(true)
  222.   end
Advertisement
Add Comment
Please, Sign In to add comment