Advertisement
CleaTorris

turtle mining fast

May 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs ~= 3 then
  4. print("Usage: mining <main tunnel length> <side tunnel length> <side tunnel every [] blocks>")
  5. return
  6. end
  7.  
  8. mTLength = tonumber(tArgs[1])
  9. sTLength = tonumber(tArgs[2])
  10. sTSpacing = tonumber(tArgs[3])
  11.  
  12. x = 0
  13. z = 0
  14. dir = 0
  15. mined = 0
  16.  
  17. function goto(tx, tz, tdir)
  18. dx = x - tx
  19. dz = z - tz
  20.  
  21. if dz > 0 and dx > 0 then
  22.  
  23. while dir ~= 1 do
  24. turnLeft()
  25. end
  26.  
  27. while z > tz do
  28. forward()
  29. end
  30.  
  31. while dir ~= 2 do
  32. turnLeft()
  33. end
  34.  
  35. while x > tx do
  36. forward()
  37. end
  38.  
  39. elseif dz < 0 and dx < 0 then
  40.  
  41. while dir ~= 0 do
  42. turnLeft()
  43. end
  44.  
  45. while x < tx do
  46. forward()
  47. end
  48.  
  49. while dir ~= 3 do
  50. turnLeft()
  51. end
  52.  
  53. while z < tz do
  54. forward()
  55. end
  56. end
  57.  
  58. while dir ~= tdir do
  59. turnLeft()
  60. end
  61. end
  62.  
  63. function returnHome()
  64. goto(0, 0, 2)
  65. end
  66.  
  67. function isFull()
  68. return mined >= 16*64
  69. end
  70.  
  71. function turnRight()
  72. turtle.turnRight()
  73. dir = (dir - 1) % 4
  74. end
  75.  
  76. function turnLeft()
  77. turtle.turnLeft()
  78. dir = (dir + 1) % 4
  79. end
  80.  
  81. function forward()
  82. if dir == 0 then x = x + 1
  83. elseif dir == 1 then z = z - 1
  84. elseif dir == 2 then x = x - 1
  85. elseif dir == 3 then z = z + 1
  86. end
  87. return turtle.forward()
  88. end
  89.  
  90. function forceForward()
  91. if turtle.detect then
  92. turtle.dig()
  93. mined = mined + 1
  94. if isFull() then emptyInv() end
  95. end
  96. forward()
  97. turtle.digUp()
  98. mined = mined + 1
  99. if isFull() then emptyInv() end
  100. turtle.digDown()
  101. mined = mined + 1
  102. if isFull() then emptyInv() end
  103. end
  104.  
  105. function emptyInv()
  106. memX = x
  107. memY = y
  108. memDir = dir
  109. returnHome()
  110.  
  111. for i = 1,16 do
  112. if turtle.refuel(0) and turtle.getFuelLevel() < turtle.getFuelLimit()/10 then
  113. turtle.refuel()
  114. else
  115. turtle.drop()
  116. end
  117. end
  118. goto(memX, memY, memDir)
  119. end
  120.  
  121. for i = 1,mTLength do
  122.  
  123. forceForward()
  124. turnRight()
  125. forceForward()
  126.  
  127. if i%sTSpacing == 0 then
  128. memZ = z
  129. for j = 1,sTLength do
  130. forceForward()
  131. end
  132. turnLeft()
  133. turnLeft()
  134. for j = 1,sTLength do
  135. forward()
  136. end
  137. else
  138. turnLeft()
  139. turnLeft()
  140. end
  141. forward()
  142. turnRight()
  143. end
  144.  
  145. returnHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement