Fettish

mining dimension turtle

Jan 10th, 2026 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.20 KB | None | 0 0
  1. -- miner.lua
  2. local startY = 75
  3. local targetY = 30
  4. local depth = startY - targetY
  5. local length = 60
  6. local maxStrips = 10
  7. local fuelThreshold = 500
  8. local stripCount = 0
  9. local lateralOffset = 0
  10.  
  11. turtle.refuel(64)
  12.  
  13. local trashList = {
  14.   ["minecraft:stone"] = true,
  15.   ["minecraft:gravel"] = true,
  16.   ["minecraft:dirt"] = true,
  17.   ["minecraft:cobblestone"] = true,
  18.   ["minecraft:sand"] = true,
  19.   ["minecraft:flint"] = true
  20. }
  21.  
  22. function shiftLeft(n)
  23.   print("Shifting left " .. n .. " blocks...")
  24.   turtle.turnLeft()
  25.   for i = 1, n do
  26.     local tries = 0
  27.     while not turtle.forward() do
  28.       turtle.dig()
  29.       turtle.attack()
  30.       sleep(0.2)
  31.       tries = tries + 1
  32.       if tries >= 10 then
  33.         print("Failed to shift left after 10 tries. Skipping.")
  34.         break
  35.       end
  36.     end
  37.   end
  38.   turtle.turnRight()
  39. end
  40.  
  41. function checkFuel()
  42.   print("Checking fuel...")
  43.   local level = turtle.getFuelLevel()
  44.   if level < fuelThreshold then
  45.     print("Fuel too low. Refueling")
  46.     turtle.back()
  47.     sleep(5)
  48.     turtle.refuel()
  49.     turtle.forward()
  50.     turtle.select(1)
  51.   end
  52. end
  53.  
  54. function shouldTrash(name)
  55.   return trashList[name] or false
  56. end
  57.  
  58. function cleanInventory()
  59.   print("Cleaning inventory...")
  60.   for slot = 1, 16 do
  61.     turtle.select(slot)
  62.     local item = turtle.getItemDetail()
  63.     if item and shouldTrash(item.name) then
  64.       print("Dropping:", item.name)
  65.       turtle.dropDown()
  66.     end
  67.   end
  68. end
  69.  
  70. function goToStripStart()
  71.   print("Returning to mine...")
  72.  
  73.   -- Move forward to strip depth
  74.   for i = 1, 7 do
  75.     turtle.forward()
  76.   end
  77.  
  78.   -- Move left to current strip offset
  79.   if lateralOffset > 0 then
  80.     turtle.turnLeft()
  81.     for i = 1, lateralOffset do
  82.       turtle.forward()
  83.     end
  84.     turtle.turnRight()
  85.   end
  86. end
  87.  
  88. function mineDown(d)
  89.   print("Mining down to depth " .. d)
  90.   for i = 1, d do
  91.     turtle.digDown()
  92.     turtle.down()
  93.   end
  94. end
  95.  
  96. function mineForward()
  97.   print("Mining forward...")
  98.   for i = 1, length do
  99.     turtle.dig()
  100.     local tries = 0
  101.     while not turtle.forward() do
  102.       turtle.dig()
  103.       turtle.attack()
  104.       sleep(0.2)
  105.       tries = tries + 1
  106.       if tries >= 10 then break end
  107.     end
  108.  
  109.     turtle.turnLeft()
  110.     turtle.dig()
  111.     turtle.turnRight()
  112.     turtle.turnRight()
  113.     turtle.dig()
  114.     turtle.turnLeft()
  115.   end
  116.  
  117.   turtle.turnLeft()
  118.   turtle.turnLeft()
  119.   for i = 1, length do
  120.     local tries = 0
  121.     while not turtle.forward() do
  122.       turtle.dig()
  123.       turtle.attack()
  124.       sleep(0.2)
  125.       tries = tries + 1
  126.       if tries >= 10 then break end
  127.     end
  128.   end
  129.   turtle.turnLeft()
  130.   turtle.turnLeft()
  131. end
  132.  
  133. function returnToBaseFrom(depth)
  134.   print("Returning to base from depth " .. depth)
  135.   for i = 1, depth do
  136.     turtle.up()
  137.   end
  138.   for i = 1, 7 do
  139.     turtle.back()
  140.   end
  141.   if lateralOffset > 0 then
  142.     turtle.turnRight()
  143.     for i = 1, lateralOffset do
  144.       turtle.forward()
  145.     end
  146.     turtle.turnLeft()
  147.   end
  148. end
  149.  
  150. function dumpInventoryToHopper()
  151.   print("Dumping inventory...")
  152.   for slot = 1, 16 do
  153.     turtle.select(slot)
  154.     turtle.dropDown()
  155.   end
  156.   turtle.select(1)
  157. end
  158.  
  159. -- Main loop
  160. while stripCount < maxStrips do
  161.   -- Layer 1
  162.   goToStripStart()
  163.   mineDown(depth)
  164.   mineForward()
  165.   cleanInventory()
  166.   returnToBaseFrom(depth)
  167.   dumpInventoryToHopper()
  168.   sleep(3)
  169.   checkFuel()
  170.  
  171.   -- Layer 2
  172.   goToStripStart()
  173.   mineDown(depth + 1)
  174.   mineForward()
  175.   cleanInventory()
  176.   returnToBaseFrom(depth + 1)
  177.   dumpInventoryToHopper()
  178.   sleep(3)
  179.   checkFuel()
  180.  
  181.   -- Layer 3
  182.   goToStripStart()
  183.   mineDown(depth + 2)
  184.   mineForward()
  185.   cleanInventory()
  186.   returnToBaseFrom(depth + 2)
  187.   dumpInventoryToHopper()
  188.   sleep(3)
  189.   checkFuel()
  190.  
  191.   -- Layer 4
  192.   goToStripStart()
  193.   mineDown(depth + 3)
  194.   mineForward()
  195.   cleanInventory()
  196.   returnToBaseFrom(depth + 3)
  197.   dumpInventoryToHopper()
  198.   sleep(3)
  199.   checkFuel()
  200.  
  201.   -- Layer 5
  202.   goToStripStart()
  203.   mineDown(depth + 4)
  204.   mineForward()
  205.   cleanInventory()
  206.   returnToBaseFrom(depth + 4)
  207.   dumpInventoryToHopper()
  208.   sleep(3)
  209.   checkFuel()
  210.  
  211.   lateralOffset = lateralOffset + 3
  212.   stripCount = stripCount + 1
  213.   print("Strip #" .. stripCount .. " complete")
  214. end
  215.  
  216. print("Mining operation complete.")
  217.  
Advertisement
Add Comment
Please, Sign In to add comment