Advertisement
Spytox

Mining turtle strip

Jan 16th, 2025 (edited)
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | Gaming | 0 0
  1. -- Strip Mining Turtle Program for ComputerCraft
  2.  
  3. -- Configuration
  4. local MINING_DEPTH = 50  -- Number of blocks to mine in one direction
  5. local STRIP_WIDTH = 3    -- Width of the mining strip
  6. local FUEL_SLOT = 16     -- Slot dedicated for fuel
  7.  
  8. -- Helper functions
  9. local function refuel()
  10.     turtle.select(FUEL_SLOT)
  11.     if turtle.getFuelLevel() < MINING_DEPTH * 2 then
  12.         turtle.refuel()
  13.     end
  14. end
  15.  
  16. local function forward()
  17.     while not turtle.forward() do
  18.         if turtle.detect() then
  19.             turtle.dig()
  20.         elseif turtle.attack() then
  21.             -- Handle mobs if necessary
  22.         else
  23.             sleep(0.5)
  24.         end
  25.     end
  26. end
  27.  
  28. local function digLayer(depth)
  29.     for _ = 1, depth do
  30.         for _ = 1, STRIP_WIDTH - 1 do
  31.             forward()
  32.             turtle.digUp()
  33.             turtle.digDown()
  34.         end
  35.         -- Turn around at the end of the strip
  36.         if depth % 2 == 0 then
  37.             turtle.turnLeft()
  38.             forward()
  39.             turtle.turnLeft()
  40.         else
  41.             turtle.turnRight()
  42.             forward()
  43.             turtle.turnRight()
  44.         end
  45.     end
  46. end
  47.  
  48. local function returnToStart()
  49.     -- Return to starting position
  50.     for _ = 1, MINING_DEPTH do
  51.         if not turtle.back() then
  52.             turtle.turnLeft()
  53.             turtle.turnLeft()
  54.             forward()
  55.             turtle.turnLeft()
  56.             turtle.turnLeft()
  57.         end
  58.     end
  59. end
  60.  
  61. local function emptyInventory()
  62.     for slot = 1, 16 do
  63.         if slot ~= FUEL_SLOT then
  64.             turtle.select(slot)
  65.             turtle.drop()
  66.         end
  67.     end
  68. end
  69.  
  70. -- Main program
  71. local function mineStrip()
  72.     refuel()
  73.  
  74.     for strip = 1, MINING_DEPTH / STRIP_WIDTH do
  75.         digLayer(STRIP_WIDTH)
  76.         -- Return to base after finishing the strip
  77.         returnToStart()
  78.         emptyInventory()
  79.     end
  80. end
  81.  
  82. mineStrip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement