Pinkishu

Untitled

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