Advertisement
z1haze

minetest

Feb 11th, 2025 (edited)
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.07 KB | None | 0 0
  1. -- directions pretends turtle looks north when placed down,
  2. -- that means the z axis is forward and back, and the x axis is left and right
  3.  
  4. local blocksToMine = {
  5.   ["minecraft:diamond_ore"] = true,
  6.   ["minecraft:iron_ore"] = true,
  7.   ["minecraft:coal_ore"] = true,
  8.   ["minecraft:gold_ore"] = true,
  9.   ["minecraft:redstone_ore"] = true,
  10.   ["minecraft:lapis_ore"] = true,
  11.   ["minecraft:emerald_ore"] = true,
  12.   ["minecraft:copper_ore"] = true,
  13.   -- Add deepslate variants
  14.   ["minecraft:deepslate_diamond_ore"] = true,
  15.   ["minecraft:deepslate_iron_ore"] = true,
  16.   ["minecraft:deepslate_coal_ore"] = true,
  17.   ["minecraft:deepslate_gold_ore"] = true,
  18.   ["minecraft:deepslate_redstone_ore"] = true,
  19.   ["minecraft:deepslate_lapis_ore"] = true,
  20.   ["minecraft:deepslate_emerald_ore"] = true,
  21.   ["minecraft:deepslate_copper_ore"] = true
  22. }
  23.  
  24. local currentPosition = {
  25.   x = 0,
  26.   y = 0,
  27.   z = 0
  28. }
  29.  
  30. local startingY = 124
  31.  
  32. local minY = -52
  33. local maxY = 16
  34.  
  35. local currentBranch = 0
  36.  
  37. local function descend()
  38.   local blocksToDescend = startingY - minY
  39.  
  40.   for _ = 1, blocksToDescend do
  41.     turtle.digDown()
  42.     turtle.down()
  43.     currentPosition.y = currentPosition.y - 1
  44.   end
  45. end
  46.  
  47. local function shouldMine(blockName)
  48.   return blocksToMine[blockName] or false
  49. end
  50.  
  51. local function checkAndMineAround()
  52.   -- Check up
  53.   local success, data = turtle.inspectUp()
  54.   if success and shouldMine(data.name) then
  55.     turtle.digUp()
  56.   end
  57.  
  58.   -- Check down
  59.   success, data = turtle.inspectDown()
  60.   if success and shouldMine(data.name) then
  61.     turtle.digDown()
  62.   end
  63.  
  64.   -- Check left (need to turn)
  65.   turtle.turnLeft()
  66.   success, data = turtle.inspect()
  67.   if success and shouldMine(data.name) then
  68.     turtle.dig()
  69.   end
  70.   turtle.turnRight()
  71.  
  72.   -- Check right
  73.   turtle.turnRight()
  74.   success, data = turtle.inspect()
  75.   if success and shouldMine(data.name) then
  76.     turtle.dig()
  77.   end
  78.   turtle.turnLeft()
  79. end
  80.  
  81. local function mineBranch()
  82.   for i = 1, 16 do
  83.     checkAndMineAround()
  84.  
  85.     if i < 16 then
  86.       turtle.dig()
  87.       turtle.forward()
  88.  
  89.       if currentBranch % 2 == 1 then
  90.         currentPosition.x = currentPosition.x + 1 -- facing right (east) is positive x
  91.       else
  92.         currentPosition.x = currentPosition.x - 1 -- facing left (west) is negative x
  93.       end
  94.     end
  95.   end
  96. end
  97.  
  98. local function moveToNextBranch()
  99.   if currentBranch % 2 == 1 then
  100.     -- Odd branch, turn left
  101.     turtle.turnLeft()
  102.     for _ = 1, 2 + 1 do
  103.       checkAndMineAround()
  104.       turtle.dig()
  105.       turtle.forward()
  106.       currentPosition.z = currentPosition.z - 1 -- negative z is north
  107.     end
  108.     turtle.turnLeft()
  109.   else
  110.     -- Even branch, turn right
  111.     turtle.turnRight()
  112.     for _ = 1, 2 + 1 do
  113.       checkAndMineAround()
  114.       turtle.dig()
  115.       turtle.forward()
  116.       currentPosition.z = currentPosition.z - 1 -- negative z is north
  117.     end
  118.     turtle.turnRight()
  119.   end
  120. end
  121.  
  122. local function main()
  123.   descend()
  124.  
  125.   turtle.turnRight()
  126.  
  127.   while currentPosition.y < maxY do
  128.     -- do all branches on a level
  129.     for branch = 1, 6 do
  130.       currentBranch = branch
  131.       mineBranch()
  132.  
  133.       if branch < 6 then
  134.         moveToNextBranch()
  135.       end
  136.     end
  137.  
  138.     -- if we end on an odd branch, turn around and come back
  139.     if 6 % 2 == 1 then
  140.       turtle.turnLeft()
  141.       turtle.turnLeft()
  142.  
  143.       for _ = 1, (16 - 1) do
  144.         turtle.forward()
  145.         currentPosition.x = currentPosition.x - 1 -- moving west toward starting point
  146.       end
  147.     end
  148.  
  149.     -- face south
  150.     turtle.turnLeft()
  151.  
  152.     -- move to the starting point
  153.     while currentPosition.z < 0 do
  154.       turtle.forward()
  155.       currentPosition.z = currentPosition.z + 1 -- moving south to starting point
  156.     end
  157.  
  158.     -- turn back forward
  159.     turtle.turnLeft()
  160.     turtle.turnLeft()
  161.  
  162.     -- go up to the next y level
  163.     for _ = 1, 3 do
  164.       if currentPosition.y < maxY then
  165.         turtle.up()
  166.         currentPosition.y = currentPosition.y + 1
  167.       end
  168.     end
  169.   end
  170.  
  171.   -- move back to the starting point
  172.   while currentPosition.y < 0 do
  173.     turtle.up()
  174.   end
  175. end
  176.  
  177. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement