Guest User

Untitled

a guest
Nov 13th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1.  
  2. local args = {...}
  3.  
  4. -- Config to determine what the turtle should mine
  5. local config = {
  6. ["diamond"] = true,
  7. ["iron ore"] = true,
  8. ["misc"] = false,
  9. }
  10.  
  11. local minFuelLevel = 200
  12. local torchSlot = 1
  13. local fuelSlot = 2
  14. local chestSlot = 3
  15.  
  16. local function initialize()
  17. print("Starting turtle...")
  18. print("Torches set to slot "..torchSlot)
  19. print("Fuel set to slot "..fuelSlot)
  20. end
  21.  
  22. local function digUp()
  23. while turtle.detectUp() do
  24. turtle.digUp()
  25. end
  26. end
  27.  
  28. local function digDown()
  29. while turtle.detectDown() do
  30. turtle.digDown()
  31. end
  32. end
  33.  
  34. local function dig()
  35. while turtle.detect() do
  36. turtle.dig()
  37. end
  38. end
  39.  
  40. local function forward()
  41. while not turtle.forward() do
  42. dig()
  43. end
  44. end
  45.  
  46. local function up()
  47. while not turtle.up() do
  48. digUp()
  49. end
  50. end
  51.  
  52. local function down()
  53. while not turtle.down() do
  54. digDown()
  55. end
  56. end
  57.  
  58. local function aboutFace()
  59. turtle.turnLeft()
  60. turtle.turnLeft()
  61. end
  62.  
  63. local function checkFuelLevel()
  64.  
  65. local fuelLevel = turtle.getFuelLevel()
  66.  
  67. if fuelLevel < minFuelLevel then
  68. turtle.select(fuelSlot)
  69. turtle.refuel(1)
  70. print("Refuelling... fuel level is now "..turtle.getFuelLevel())
  71. end
  72. end
  73.  
  74. local function placeChest()
  75. -- Place a chest behind the turtle
  76. turtle.select(chestSlot)
  77. dig()
  78. turtle.place()
  79.  
  80. for i = 4, 16 do
  81. turtle.select(i)
  82. turtle.drop()
  83. end
  84. end
  85.  
  86. local function mineAboutMine()
  87. dig()
  88. turtle.turnLeft()
  89. turtle.turnLeft()
  90. dig()
  91. end
  92.  
  93. local function doStripMine()
  94.  
  95. local stripLength = 4
  96.  
  97. checkFuelLevel()
  98.  
  99. ------------------------------------
  100. -- STARTING FROM MIDDLE, GO UP THEN MINE DOWN
  101. ------------------------------------
  102. up()
  103.  
  104. for i=1, stripLength / 2 do
  105.  
  106. checkFuelLevel()
  107.  
  108. -- Mine top layer, finish looking right
  109. turtle.turnLeft()
  110. dig()
  111. aboutFace()
  112. dig()
  113.  
  114. if (i % 7) == 0 then
  115. turtle.select(torchSlot)
  116. turtle.place()
  117. end
  118.  
  119. -- Mine middle layer, finish looking left
  120. down()
  121. dig()
  122. aboutFace()
  123. dig()
  124.  
  125. -- Mine bottom layer, finish looking right
  126. down()
  127. dig()
  128. aboutFace()
  129. dig()
  130.  
  131. -- Go forwards to start mining the next layer
  132. turtle.turnLeft()
  133. forward()
  134.  
  135. ------------------------------------
  136. -- STARTING FROM BOTTOM, MINE UP TO THE TOP
  137. ------------------------------------
  138.  
  139. -- Mine bottom layer, finish looking right
  140. turtle.turnLeft()
  141. dig()
  142. aboutFace()
  143. dig()
  144.  
  145. -- Mine middle layer, finish looking left
  146. up()
  147. dig()
  148. aboutFace()
  149. dig()
  150.  
  151. -- Mine top layer, finish looking forward
  152. up()
  153. dig()
  154. aboutFace()
  155. dig()
  156. turtle.turnLeft()
  157. end
  158.  
  159. turtle.down()
  160. turtle.turnLeft()
  161. turtle.turnLeft()
  162.  
  163. for i=1, stripLength do
  164. turtle.forward()
  165. end
  166.  
  167. placeChest()
  168. end
  169.  
  170. for i=1, 10 do
  171. doStripMine()
  172.  
  173. turtle.turnLeft()
  174.  
  175. for j=1, 5 do
  176. forward()
  177. digUp()
  178. digDown()
  179. end
  180.  
  181. turtle.turnLeft()
  182. end
Advertisement
Add Comment
Please, Sign In to add comment