Muire

Minecraft Ancient Debris Mining Turtle

Mar 4th, 2025 (edited)
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.04 KB | Gaming | 0 0
  1. local pos = 0
  2. local fuel = "minecraft:coal"
  3. local keep = {
  4.     [fuel] = true,
  5.     ["minecraft:ancient_debris"] = true,
  6.     ["tconstruct:cobalt_ore"] = true,
  7.     ["minecraft:netherrack"] = true
  8. }
  9. local badFluid = "minecraft:lava"
  10. local tunnelLength = 30 -- How long the tunnel should be
  11.  
  12. -- Refuel from chest behind at start
  13. local function refuel()
  14.     if pos > 0 then
  15.         turtle.turnLeft()
  16.         turtle.turnLeft() -- Face back toward start
  17.         for i = 1, pos do
  18.             while turtle.detect() do turtle.dig() end
  19.             turtle.forward()
  20.         end
  21.     end
  22.     -- At start, chest is behind
  23.     for i = 1, 16 do
  24.         local item = turtle.getItemDetail(i, false)
  25.         if item and item.name == fuel then
  26.             turtle.select(i)
  27.             break
  28.         end
  29.     end
  30.     while turtle.getFuelLevel() < 160 do
  31.         turtle.suck() -- Pull fuel from chest behind
  32.         turtle.refuel(1)
  33.     end
  34.     -- Return to mining position
  35.     if pos > 0 then
  36.         turtle.turnLeft()
  37.         turtle.turnLeft() -- Face forward again
  38.         for i = 1, pos do
  39.             while turtle.detect() do turtle.dig() end
  40.             turtle.forward()
  41.         end
  42.     end
  43. end
  44.  
  45. -- Check if inventory is full (excluding kept items)
  46. local function isInventoryFull()
  47.     for i = 1, 16 do
  48.         if turtle.getItemCount(i) == 0 then
  49.             return false -- Found an empty slot
  50.         end
  51.     end
  52.     return true -- No empty slots
  53. end
  54.  
  55. -- Deposit unwanted items into chest behind at start
  56. local function depositJunk()
  57.     if pos > 0 then
  58.         turtle.turnLeft()
  59.         turtle.turnLeft() -- Face back toward start
  60.         for i = 1, pos do
  61.             while turtle.detect() do turtle.dig() end
  62.             turtle.forward()
  63.         end
  64.     end
  65.     -- At start, deposit into chest behind
  66.     for i = 1, 16 do
  67.         local item = turtle.getItemDetail(i, false)
  68.         if item and not keep[item.name] then
  69.             turtle.select(i)
  70.             turtle.drop() -- Drop into chest behind
  71.         end
  72.     end
  73.     -- Return to mining position
  74.     if pos > 0 then
  75.         turtle.turnLeft()
  76.         turtle.turnLeft() -- Face forward again
  77.         for i = 1, pos do
  78.             while turtle.detect() do turtle.dig() end
  79.             turtle.forward()
  80.         end
  81.     end
  82. end
  83.  
  84. -- Select netherrack to place for lava
  85. local function selectPlaceable()
  86.     for i = 1, 16 do
  87.         local item = turtle.getItemDetail(i, false)
  88.         if item and item.name == "minecraft:netherrack" then
  89.             turtle.select(i)
  90.             return true
  91.         end
  92.     end
  93.     return false
  94. end
  95.  
  96. -- Handle lava in the 3x3 area
  97. local function handleLava()
  98.     local directions = {
  99.         {check = turtle.inspect, place = turtle.place},
  100.         {check = turtle.inspectUp, place = turtle.placeUp},
  101.         {check = turtle.inspectDown, place = turtle.placeDown}
  102.     }
  103.     for _, dir in ipairs(directions) do
  104.         local success, block = dir.check()
  105.         if success and block.name == "minecraft:lava" and selectPlaceable() then
  106.             dir.place()
  107.         end
  108.     end
  109. end
  110.  
  111. -- Mine a 3x3 section
  112. local function mineSection()
  113.     -- Mine forward (middle row)
  114.     while turtle.detect() do turtle.dig() end
  115.     -- Mine up (top row)
  116.     while turtle.detectUp() do turtle.digUp() end
  117.     -- Mine down (bottom row)
  118.     while turtle.detectDown() do turtle.digDown() end
  119.    
  120.     -- Move up to clear top layer
  121.     turtle.up()
  122.     while turtle.detect() do turtle.dig() end
  123.     turtle.down()
  124.    
  125.     -- Move down to clear bottom layer
  126.     turtle.down()
  127.     while turtle.detect() do turtle.dig() end
  128.     turtle.up()
  129.    
  130.     handleLava()
  131.     turtle.forward()
  132. end
  133.  
  134. -- Main loop
  135. while true do
  136.     if turtle.getFuelLevel() < 100 then
  137.         refuel()
  138.     end
  139.    
  140.     if isInventoryFull() then
  141.         depositJunk()
  142.     end
  143.    
  144.     if pos < tunnelLength then
  145.         mineSection()
  146.         pos = pos + 1
  147.     else
  148.         depositJunk() -- End of tunnel, reset
  149.         pos = 0 -- Reset position to start a new tunnel
  150.     end
  151. end
Add Comment
Please, Sign In to add comment