Fluffy41

Untitled

Jul 26th, 2023 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.77 KB | None | 0 0
  1. -- Function to check if the turtle has enough fuel to move
  2. local function checkFuel()
  3. if turtle.getFuelLevel() < 100 then
  4. for slot = 1, 16 do
  5. turtle.select(slot)
  6. if turtle.refuel(1) then
  7. break
  8. end
  9. end
  10. end
  11. end
  12.  
  13. -- Function to drop all items from inventory into the chest
  14. local function dropItems()
  15. turtle.turnLeft()
  16. turtle.turnLeft()
  17. for slot = 2, 16 do
  18. turtle.select(slot)
  19. turtle.drop()
  20. end
  21. turtle.turnLeft()
  22. turtle.turnLeft()
  23. end
  24.  
  25. -- Setup section
  26. print("Welcome to the Mining Turtle Script Setup!")
  27. print("Please answer the following questions:")
  28. print()
  29.  
  30. -- Get starting height
  31. print("At which height should the turtle start mining? (Enter a number):")
  32. local startHeight = tonumber(read())
  33.  
  34. -- Get tunnel height
  35. print("What should be the height of the tunnel? (Enter a number):")
  36. local tunnelHeight = tonumber(read())
  37.  
  38. -- Choose mining mode
  39. print("Mining Mode:")
  40. print("1. Mine All Blocks")
  41. print("2. Mine Ores Only")
  42. print("Enter 1 or 2:")
  43. local miningMode = tonumber(read())
  44.  
  45. -- Get tunnel dimensions
  46. print("Enter the desired tunnel dimensions:")
  47. print("Length:")
  48. local length = tonumber(read())
  49. print("Width:")
  50. local width = tonumber(read())
  51.  
  52. -- Choose whether to refuel with coal found while mining
  53. print("Should the turtle refuel with coal it finds while mining?")
  54. print("1. Yes")
  55. print("2. No")
  56. print("Enter 1 or 2:")
  57. local refuelOption = tonumber(read())
  58. local shouldRefuel = (refuelOption == 1)
  59.  
  60. -- Main mining function
  61. local function mine()
  62. local currentHeight = 0
  63.  
  64. while currentHeight < tunnelHeight do
  65. -- Check and refill fuel
  66. checkFuel()
  67.  
  68. -- Dig down to the starting height
  69. while currentHeight > startHeight do
  70. turtle.down()
  71. currentHeight = currentHeight - 1
  72. end
  73.  
  74. -- Mine ores in the current layer
  75. for h = 1, tunnelHeight do
  76. for i = 1, width do
  77. for j = 1, length - 1 do
  78. while turtle.detect() do
  79. turtle.dig()
  80. end
  81. turtle.forward()
  82. end
  83.  
  84. -- Check and refill fuel after each row
  85. checkFuel()
  86.  
  87. -- Turn around at the end of each row
  88. if i < width then
  89. if i % 2 == 0 then
  90. turtle.turnRight()
  91. while turtle.detect() do
  92. turtle.dig()
  93. end
  94. turtle.forward()
  95. turtle.turnRight()
  96. else
  97. turtle.turnLeft()
  98. while turtle.detect() do
  99. turtle.dig()
  100. end
  101. turtle.forward()
  102. turtle.turnLeft()
  103. end
  104. end
  105. end
  106.  
  107. -- Go up to the next layer, if not the last layer
  108. if h < tunnelHeight then
  109. for k = 1, h do
  110. turtle.up()
  111. currentHeight = currentHeight + 1
  112. end
  113. end
  114. end
  115.  
  116. -- Return to the surface
  117. while currentHeight > 0 do
  118. turtle.up()
  119. currentHeight = currentHeight - 1
  120. end
  121.  
  122. -- Deposit items into the chest
  123. dropItems()
  124.  
  125. -- Refuel with coal if required and available
  126. if shouldRefuel then
  127. turtle.select(1)
  128. while turtle.detect() do
  129. turtle.dig()
  130. end
  131. turtle.refuel()
  132. end
  133. end
  134. end
  135.  
  136. -- Start the mining process
  137. mine()
  138.  
Advertisement
Add Comment
Please, Sign In to add comment