MudkipTheEpic

Ancient Debris Tunnel (AI Slop)

Jan 8th, 2026 (edited)
91
0
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.21 KB | None | 0 0
  1. local args = { ... }
  2. local length      = tonumber(args[1])
  3. local num_tunnels = tonumber(args[2]) or 1
  4. local spacing     = tonumber(args[3]) or 3
  5.  
  6. if not length or length < 1 or num_tunnels < 1 then
  7.   print("Usage: tunnel_ancient <length> [num_tunnels=1] [spacing=3]")
  8.   return
  9. end
  10.  
  11. local ANCIENT = "minecraft:ancient_debris"
  12. local LAVA    = "minecraft:lava"
  13. local NETH    = "minecraft:netherrack"
  14.  
  15. local MIN_FUEL = 200
  16.  
  17. local nethSlot = nil
  18. local fuelSlots = {}
  19.  
  20. -- -------- inventory / fuel --------
  21.  
  22. local function fuelLevel()
  23.   local f = turtle.getFuelLevel()
  24.   return type(f) == "string" and math.huge or f
  25. end
  26.  
  27. local function isFuel()
  28.   return turtle.refuel(0)
  29. end
  30.  
  31. local function rescanInventory()
  32.   fuelSlots = {}
  33.   nethSlot = nil
  34.  
  35.   for i = 1, 16 do
  36.     local d = turtle.getItemDetail(i)
  37.     if d then
  38.       if d.name == ANCIENT then
  39.         -- keep
  40.       elseif d.name == NETH then
  41.         if not nethSlot then
  42.           nethSlot = i
  43.         else
  44.           turtle.select(i)
  45.           turtle.drop()
  46.         end
  47.       else
  48.         turtle.select(i)
  49.         if isFuel() then
  50.           fuelSlots[#fuelSlots + 1] = i
  51.         else
  52.           turtle.drop()
  53.         end
  54.       end
  55.     end
  56.   end
  57.   turtle.select(1)
  58. end
  59.  
  60. local function refuelFast()
  61.   if fuelLevel() >= MIN_FUEL then return end
  62.   for _, s in ipairs(fuelSlots) do
  63.     if turtle.getItemCount(s) > 0 then
  64.       turtle.select(s)
  65.       turtle.refuel()
  66.       if fuelLevel() >= MIN_FUEL then break end
  67.     end
  68.   end
  69.   turtle.select(1)
  70. end
  71.  
  72. local function selectNeth()
  73.   if nethSlot and turtle.getItemCount(nethSlot) > 0 then
  74.     turtle.select(nethSlot)
  75.     return true
  76.   end
  77.   for i = 1, 16 do
  78.     local d = turtle.getItemDetail(i)
  79.     if d and d.name == NETH and turtle.getItemCount(i) > 0 then
  80.       nethSlot = i
  81.       turtle.select(i)
  82.       return true
  83.     end
  84.   end
  85.   return false
  86. end
  87.  
  88. -- -------- two core ops --------
  89.  
  90. -- navigate: dig solids (gravel-safe) then move. ignores liquids.
  91. local function navigate(detectFn, digFn, moveFn, attackFn)
  92.   while detectFn() do
  93.     digFn()
  94.   end
  95.   while not moveFn() do
  96.     if attackFn then attackFn() end
  97.   end
  98. end
  99.  
  100. -- check: if air -> place neth; if lava -> place neth; if ancient -> dig then place neth
  101. local function check(inspectFn, digFn, placeFn)
  102.   local ok, b = inspectFn()
  103.  
  104.   -- No block (air): fill it to make walkable/sealed
  105.   if not ok then
  106.     if selectNeth() then
  107.       placeFn()
  108.       turtle.select(1)
  109.     end
  110.     return
  111.   end
  112.  
  113.   if not b then return end
  114.  
  115.   if b.name == ANCIENT then
  116.     digFn()
  117.     if selectNeth() then
  118.       placeFn()
  119.       turtle.select(1)
  120.     end
  121.   elseif b.name == LAVA then
  122.     if selectNeth() then
  123.       placeFn()
  124.       turtle.select(1)
  125.     end
  126.   end
  127. end
  128.  
  129. -- -------- directional wrappers --------
  130.  
  131. local function navigateForward() navigate(turtle.detect, turtle.dig, turtle.forward, turtle.attack) end
  132. local function navigateUp()      navigate(turtle.detectUp, turtle.digUp, turtle.up, turtle.attackUp) end
  133. local function navigateDown()    navigate(turtle.detectDown, turtle.digDown, turtle.down, turtle.attackDown) end
  134.  
  135. local function checkForward() check(turtle.inspect, turtle.dig, turtle.place) end
  136. local function checkUp()      check(turtle.inspectUp, turtle.digUp, turtle.placeUp) end
  137. local function checkDown()    check(turtle.inspectDown, turtle.digDown, turtle.placeDown) end
  138.  
  139. -- -------- tunnel dig --------
  140.  
  141. local function digTunnel(len)
  142.   local upper = false
  143.  
  144.   for i = 1, len do
  145.     refuelFast()
  146.  
  147.     -- move
  148.     navigateForward()
  149.  
  150.     -- walls at current height
  151.     turtle.turnLeft();  checkForward()
  152.     turtle.turnRight(); turtle.turnRight(); checkForward()
  153.     turtle.turnLeft()
  154.  
  155.     -- seal relevant walk surface at current height
  156.     if upper then
  157.       checkUp()     -- ceiling
  158.     else
  159.       checkDown()   -- floor
  160.     end
  161.  
  162.     -- transition + walls + surface at new height
  163.     if upper then
  164.       navigateDown()
  165.       upper = false
  166.  
  167.       turtle.turnLeft();  checkForward()
  168.       turtle.turnRight(); turtle.turnRight(); checkForward()
  169.       turtle.turnLeft()
  170.  
  171.       checkDown()
  172.     else
  173.       navigateUp()
  174.       upper = true
  175.  
  176.       turtle.turnLeft();  checkForward()
  177.       turtle.turnRight(); turtle.turnRight(); checkForward()
  178.       turtle.turnLeft()
  179.  
  180.       checkUp()
  181.     end
  182.  
  183.     if (i % 10) == 0 then rescanInventory() end
  184.   end
  185.  
  186.   -- normalize to lower
  187.   if upper then
  188.     navigateDown()
  189.   end
  190. end
  191.  
  192. -- -------- main --------
  193.  
  194. rescanInventory()
  195.  
  196. for t = 1, num_tunnels do
  197.   digTunnel(length)
  198.  
  199.   if t < num_tunnels then
  200.     -- return to tunnel origin
  201.     turtle.turnRight(); turtle.turnRight()
  202.     for _ = 1, length do turtle.forward() end
  203.     turtle.turnRight(); turtle.turnRight()
  204.  
  205.     -- shift right to next tunnel start
  206.     turtle.turnRight()
  207.     for _ = 1, spacing do navigateForward() end
  208.     turtle.turnLeft()
  209.   end
  210. end
  211.  
  212. -- return to absolute start
  213. turtle.turnRight(); turtle.turnRight()
  214. for _ = 1, length do turtle.forward() end
  215. turtle.turnRight(); turtle.turnRight()
  216.  
  217. if num_tunnels > 1 then
  218.   turtle.turnLeft()
  219.   for _ = 1, spacing * (num_tunnels - 1) do navigateForward() end
  220.   turtle.turnRight()
  221. end
  222.  
  223. print("Done. Returned to start.")
  224.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment