Advertisement
Ubidibity

stripmine.lua

Jun 18th, 2025 (edited)
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.70 KB | Gaming | 0 0
  1. -- Robust movement to dig through obstacles
  2. function safeMoveForward()
  3.     while not turtle.forward() do
  4.         turtle.dig() -- Dig block in front (stone, gravel, etc.)
  5.         os.sleep(0.1) -- Pause for gravel/sand to fall
  6.     end
  7. end
  8.  
  9. -- Dig 3x1 (forward, up, down)
  10. function digStep()
  11.     turtle.dig()       -- Dig forward
  12.     turtle.digUp()     -- Dig above
  13.     turtle.digDown()   -- Dig below
  14.     safeMoveForward()  -- Move forward, digging if needed
  15. end
  16.  
  17. -- Mine a tunnel of given length
  18. function mineTunnel(length)
  19.     for i = 1, length do
  20.         digStep()
  21.         -- Check fuel and inventory every 10 blocks
  22.         if i % 10 == 0 then
  23.             if turtle.getFuelLevel() < 20 then
  24.                 print("Low fuel! Stopping.")
  25.                 return false
  26.             end
  27.             if turtle.getItemCount(16) > 0 then
  28.                 print("Inventory full! Stopping.")
  29.                 return false
  30.             end
  31.         end
  32.     end
  33.     return true
  34. end
  35.  
  36. -- Unload inventory into chest in front
  37. function unload()
  38.     for i = 1, 16 do
  39.         turtle.select(i)
  40.         turtle.drop() -- Drop into chest
  41.     end
  42.     turtle.select(1)
  43. end
  44.  
  45. -- Main program for multi-turtle setup
  46. function main()
  47.     print("Starting mining run...")
  48.     -- Mine 32 blocks out (2 chunks)
  49.     if mineTunnel(32) then
  50.         turtle.turnLeft()
  51.         safeMoveForward() -- Shift 1 block left
  52.         turtle.turnLeft() -- Face negative X
  53.         -- Mine 32 blocks back
  54.         if mineTunnel(32) then
  55.             print("Mining complete!")
  56.             -- Face chest at Z=502 (adjust Z if needed)
  57.             -- Turtle is at Z=502/504/506; adjust to Z=502
  58.             local turtleZ = 502 -- Change to your chest's Z
  59.             local steps = turtleZ == 502 and 0 or (turtleZ == 504 and 2) or -2 -- Move to Z=502
  60.             if steps ~= 0 then
  61.                 if steps > 0 then
  62.                     turtle.turnLeft() -- Face positive Z
  63.                 else
  64.                     turtle.turnRight() -- Face negative Z
  65.                 end
  66.                 for i = 1, math.abs(steps) do
  67.                     safeMoveForward()
  68.                 end
  69.                 if steps > 0 then
  70.                     turtle.turnRight() -- Face negative X
  71.                 else
  72.                     turtle.turnLeft() -- Face negative X
  73.                 end
  74.             end
  75.             -- Move 1 block to chest (X=505 to X=500)
  76.             safeMoveForward()
  77.         else
  78.             print("Return trip failed. Check fuel/inventory.")
  79.         end
  80.     else
  81.         print("Outbound trip failed. Check fuel/inventory.")
  82.     end
  83.     -- Unload into chest
  84.     unload()
  85.     print("Inventory unloaded.")
  86. end
  87.  
  88. -- Run the program
  89. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement