Advertisement
temposabel

minaina

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