Advertisement
TheDieselPunk

Untitled

Jul 29th, 2024 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. -- Tunnel Mining Program for ComputerCraft Turtle
  2.  
  3. -- Define the width and height of the tunnel
  4. local width = 3
  5. local height = 3
  6.  
  7. -- Function to refuel the turtle if it has fuel items
  8. local function refuel()
  9. for i = 1, 16 do
  10. turtle.select(i)
  11. if turtle.refuel(1) then
  12. print("Refueled.")
  13. return true
  14. end
  15. end
  16. return false
  17. end
  18.  
  19. -- Function to check fuel and halt if out of fuel
  20. local function checkFuel()
  21. if turtle.getFuelLevel() == 0 then
  22. print("Out of fuel. Attempting to refuel...")
  23. if not refuel() then
  24. print("Still out of fuel. Please add fuel items.")
  25. return false
  26. end
  27. end
  28. return true
  29. end
  30.  
  31. -- Function to dig a 3x3 tunnel
  32. local function digTunnel()
  33. while true do
  34. for h = 1, height do
  35. for w = 1, width do
  36. if not checkFuel() then return end
  37. turtle.dig()
  38. turtle.forward()
  39. if h < height then
  40. turtle.digUp()
  41. turtle.up()
  42. end
  43. end
  44.  
  45. for w = 1, width do
  46. if not checkFuel() then return end
  47. if w < width then
  48. turtle.back()
  49. end
  50. if h < height then
  51. turtle.down()
  52. end
  53. end
  54. end
  55.  
  56. turtle.turnRight()
  57. if not checkFuel() then return end
  58. turtle.dig()
  59. turtle.forward()
  60. turtle.turnLeft()
  61. end
  62. end
  63.  
  64. -- Start digging the tunnel
  65. print("Starting to dig 3x3 tunnel...")
  66. digTunnel()
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement