Advertisement
temposabel

ghbdrfgdrfgdr

Apr 4th, 2025
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. BLOCKS_PER_CHUNK = 16
  2. MAX_LOADED_CHUNKS_PER_DIRECTION = 20
  3.  
  4. DIRECTIONS = {"north", "east", "south", "west"}
  5. NORTH, EAST, SOUTH, WEST, UP, DOWN = 1, 2, 3, 4, 5, 6
  6. DELTA = {vector.new(0, 0, -1), vector.new(1, 0, 0), vector.new(0, 0, 1), vector.new(-1, 0, 0), vector.new(0, 1, 0), vector.new(0, -1, 0)}
  7.  
  8. BLOCKS_TO_MINE = {
  9. ["minecraft:diamond_ore"]=true,
  10. ["minecraft:deepslate_diamond_ore"]=true,
  11. ["minecraft:emerald_ore"]=true,
  12. ["minecraft:deepslate_emerald_ore"]=true,
  13. ["minecraft:gold_ore"]=true,
  14. ["minecraft:deepslate_gold_ore"]=true,
  15. ["minecraft:iron_ore"]=true,
  16. ["minecraft:deepslate_iron_ore"]=true,
  17. ["minecraft:redstone_ore"]=true,
  18. ["minecraft:deepslate_redstone_ore"]=true,
  19. ["minecraft:coal_ore"]=true,
  20. ["minecraft:deepslate_coal_ore"]=true,
  21. }
  22.  
  23. FUEL_PER_COAL = 80
  24. FUEL_SAFETY_MARGIN = 1 * FUEL_PER_COAL
  25.  
  26. local start_pos = vector.new() -- FILL IN BEFORE START
  27. local current_direction = NORTH -- FILL IN BEFORE START
  28. local current_pos = start_pos
  29. local TARGET_MINING_LEVEL = 27
  30.  
  31.  
  32. function info()
  33. print("-------------------------")
  34. print("XYZ:", current_pos.x, "/", current_pos.y, "/", current_pos.z)
  35. print("Facing: "..DIRECTIONS[current_direction])
  36. print("Fuel Level: "..turtle.getFuelLevel())
  37. print("-------------------------")
  38. end
  39.  
  40. function calculate_rotation(dir, amount)
  41. local d = dir - 1
  42. d = (d + amount) % 4
  43. return d + 1
  44. end
  45.  
  46. function rotate_right(amount)
  47. local amount = amount or 1
  48.  
  49. for i=1, amount do
  50. turtle.turnRight()
  51. end
  52.  
  53. current_direction = calculate_rotation(current_direction, amount)
  54. end
  55.  
  56. function rotate_left(amount)
  57. local amount = amount or 1
  58.  
  59. for i=1, amount do
  60. turtle.turnLeft()
  61. end
  62.  
  63. current_direction = calculate_rotation(current_direction, -amount)
  64. end
  65.  
  66. function face(direction)
  67. if current_direction == direction then
  68. return
  69. elseif calculate_rotation(current_direction, 1) == direction then
  70. rotate_right()
  71. elseif calculate_rotation(current_direction, -1) == direction then
  72. rotate_left()
  73. else
  74. rotate_right(2)
  75. end
  76. end
  77.  
  78. function move_forward(amount, dig)
  79. local amount = amount or 1
  80. local dig = dig or false
  81.  
  82. for i=1, amount do
  83. while turtle.detect() do
  84. if dig then
  85. turtle.dig()
  86. else
  87. print("Stepbro I'm Stuck! (in front)")
  88. end
  89. end
  90.  
  91. turtle.forward()
  92. current_pos = current_pos + DELTA[current_direction]
  93. info()
  94. end
  95. end
  96.  
  97. function move_backward(amount, dig)
  98. rotate_right(2)
  99. move_forward(amount, dig)
  100. rotate_left(2)
  101. end
  102.  
  103. function move_right(amount, dig)
  104. rotate_right()
  105. move_forward(amount, dig)
  106. rotate_left()
  107. end
  108.  
  109. function move_left(amount, dig)
  110. rotate_left()
  111. move_forward(amount, dig)
  112. rotate_right()
  113. end
  114.  
  115. function move_up(amount, dig)
  116. local amount = amount or 1
  117. local dig = dig or false
  118.  
  119. for i=1, amount do
  120. while turtle.detectUp() do
  121. if dig then
  122. turtle.digUp()
  123. else
  124. print("Stepbro I'm Stuck! (above)")
  125. end
  126. end
  127.  
  128. turtle.up()
  129. current_pos = current_pos + DELTA[UP]
  130. info()
  131. end
  132. end
  133.  
  134. function move_down(amount, dig)
  135. local amount = amount or 1
  136. local dig = dig or 1
  137.  
  138. for i=1, amount do
  139. while turtle.detectDown() do
  140. if dig then
  141. turtle.digDown()
  142. else
  143. print("Stepbro I'm Stuck! (below)")
  144. end
  145. end
  146.  
  147. turtle.down()
  148. current_pos = current_pos + DELTA[DOWN]
  149. info()
  150. end
  151. end
  152.  
  153. function manhattan_distance(pos1, pos2)
  154. return math.abs(pos1.x - pos2.x) + math.abs(pos1.y - pos2.y) + math.abs(pos1.z - pos2.z)
  155. end
  156.  
  157. function get_available_fuel()
  158. local available_fuel = turtle.getFuelLevel()
  159.  
  160. for i=1, 16 do
  161. local item = turtle.getItemDetail(i)
  162.  
  163. if item and item.name == "minecraft:coal" then
  164. available_fuel = available_fuel + item.count * FUEL_PER_COAL
  165. end
  166. end
  167.  
  168. return available_fuel
  169. end
  170.  
  171. function has_ore_in_vicinity()
  172. blocks = {}
  173.  
  174. table.insert(blocks, select(2, turtle.inspectDown()).name)
  175. table.insert(blocks, select(2, turtle.inspectUp()).name)
  176.  
  177. table.insert(blocks, select(2, turtle.inspect()).name)
  178. rotate_left()
  179. table.insert(blocks, select(2, turtle.inspect()).name)
  180. rotate_right(2)
  181. table.insert(blocks, select(2, turtle.inspect()).name)
  182. rotate_left()
  183.  
  184. for _, block in ipairs(blocks) do
  185. if BLOCKS_TO_MINE[block] ~= nil then
  186. return true
  187. end
  188. end
  189.  
  190. return false
  191. end
  192.  
  193. function mine_vein(depth, visited)
  194. local visited = visited or {}
  195. if depth == 0 then return end
  196.  
  197. local local_start_dir = current_direction
  198.  
  199. -- Forward/Backward/Left/Right
  200. for i=0, 3 do
  201. local new_dir = calculate_rotation(local_start_dir, i)
  202. local block = (current_pos + DELTA[new_dir]):tostring()
  203.  
  204. if visited[block] == nil then
  205. visited[block] = true
  206.  
  207. face(new_dir)
  208.  
  209. local not_air, block_data = turtle.inspect()
  210. if not_air and BLOCKS_TO_MINE[block_data.name] ~= nil then
  211. move_forward(1, true)
  212. mine_vein(depth - 1, visited)
  213. face(calculate_rotation(new_dir, 2))
  214. move_forward(1, true)
  215. end
  216. end
  217. end
  218.  
  219. -- Up/Down
  220. local block = (current_pos + DELTA[UP]):tostring()
  221. if visited[block] == nil then
  222. visited[block] = true
  223.  
  224. local not_air, block_data = turtle.inspectUp()
  225. if not_air and BLOCKS_TO_MINE[block_data.name] ~= nil then
  226. move_up(1, true)
  227. mine_vein(depth - 1, visited)
  228. move_down(1, true)
  229. end
  230. end
  231.  
  232. local block = (current_pos + DELTA[DOWN]):tostring()
  233. if visited[block] == nil then
  234. visited[block] = true
  235.  
  236. local not_air, block_data = turtle.inspectDown()
  237. if not_air and BLOCKS_TO_MINE[block_data.name] ~= nil then
  238. move_down(1, true)
  239. mine_vein(depth - 1, visited)
  240. move_up(1, true)
  241. end
  242. end
  243.  
  244. face(local_start_dir)
  245. end
  246.  
  247. function go_down(level)
  248. while current_pos.y ~= level do
  249. move_down(1, true)
  250. end
  251. end
  252.  
  253. function go_up()
  254. while current_pos.y ~= start_pos.y do
  255. move_up(1, true)
  256. end
  257. end
  258.  
  259. function go_back_to_mine_start()
  260. rotate_right(2)
  261.  
  262. while current_pos.x ~= start_pos.x and current_pos.z ~= start_pos.z do
  263. move_forward(1, true)
  264. end
  265. end
  266.  
  267. function should_return_home()
  268. local distance = manhattan_distance(current_pos, start_pos)
  269. local available_fuel = get_available_fuel()
  270.  
  271. if available_fuel - FUEL_SAFETY_MARGIN <= distance then
  272. return true
  273. end
  274.  
  275. return false
  276. end
  277.  
  278. function strip_mine(distance)
  279. distance = distance or BLOCKS_PER_CHUNK * MAX_LOADED_CHUNKS_PER_DIRECTION
  280. local distance_mined = 0
  281.  
  282. while distance_mined < distance and not should_return_home() do
  283. if has_ore_in_vicinity() then
  284. mine_vein(99)
  285. end
  286.  
  287. move_forward(1, true)
  288. distance_mined = distance_mined + 1
  289. end
  290. end
  291.  
  292. function main()
  293. go_down()
  294. strip_mine()
  295. go_back_to_mine_start()
  296. go_up()
  297. end
  298.  
  299. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement