Advertisement
Guest User

Untitled

a guest
Jan 12th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. local x1 = -37;
  2. local y1 = 97;
  3. local z1 = 188;
  4. local x2 = -51;
  5. local y2 = 98;
  6. local z2 = 200;
  7.  
  8. local xDir = math.abs(x2 - x1);
  9. local yDir = math.abs(y2 - y1);
  10. local zDir = math.abs(z2 - z1);
  11.  
  12. local movedX = 0;
  13. local movedY = 0;
  14. local movedZ = 0;
  15.  
  16. local left = true;
  17.  
  18. function log(message)
  19. term.write(message);
  20. local cursorX, cursorY = term.getCursorPos();
  21. term.setCursorPos(cursorX, cursorY + 1);
  22. end
  23.  
  24. function isComplete()
  25. return movedX >= xDir and movedY >= yDir and movedZ >= zDir;
  26. end
  27.  
  28. function shouldMoveZ()
  29. return movedX >= xDir;
  30. end
  31.  
  32. function shouldMoveY()
  33. return movedZ >= zDir;
  34. end
  35.  
  36. function moveX()
  37. if turtle.detect() then
  38. turtle.dig();
  39. end
  40.  
  41. log("Moving in X direction!");
  42. checkFuel();
  43. turtle.forward();
  44.  
  45. movedX = movedX + 1;
  46. if not shouldMoveZ() then
  47. return;
  48. end
  49.  
  50. moveZ();
  51. end
  52.  
  53. function moveZ()
  54. if shouldMoveY() then
  55. moveY();
  56. return;
  57. end
  58.  
  59. if left then
  60. turtle.turnLeft();
  61. else
  62. turtle.turnRight();
  63. end
  64.  
  65. if turtle.detect() then
  66. turtle.dig();
  67. end
  68.  
  69. log("Moving in Z direction!");
  70. checkFuel();
  71. turtle.forward();
  72.  
  73. movedZ = movedZ + 1;
  74.  
  75. if left then
  76. turtle.turnLeft();
  77. else
  78. turtle.turnRight();
  79. end
  80.  
  81. left = not left;
  82. movedX = 1;
  83. end
  84.  
  85. function moveY()
  86. if isComplete() then
  87. log("Completed!");
  88. return;
  89. end
  90.  
  91. if turtle.detectUp() then
  92. log("Digging up!");
  93. turtle.digUp();
  94. end
  95.  
  96. log("Moving up!");
  97. checkFuel();
  98. turtle.moveUp();
  99.  
  100. turtle.turnLeft();
  101. turtle.turnLeft();
  102.  
  103. left = not left;
  104.  
  105. movedZ = 1;
  106. movedX = 1;
  107. movedY = movedY + 1;
  108. end
  109.  
  110. function checkFuel()
  111. if turtle.getFuelLevel() > 0 then
  112. return;
  113. end
  114.  
  115. log("Refuelling!");
  116. turtle.refuel(1);
  117. end
  118.  
  119. while not isComplete() do
  120. moveX();
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement