Advertisement
temposabel

sdefvfrdvgfgcbth

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