Second_Cup

Untitled

Jul 29th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. -- Function to get user input safely
  2. local function getNumber(prompt)
  3. print(prompt)
  4. local n = tonumber(read())
  5. while not n or n < 1 do
  6. print("Please enter a positive number.")
  7. n = tonumber(read())
  8. end
  9. return math.floor(n)
  10. end
  11.  
  12. -- Prompt for dimensions and options
  13. local length = getNumber("Enter length:")
  14. local width = getNumber("Enter width:")
  15. local height = getNumber("Enter height:")
  16. print("Start at TOP or BOTTOM? (type 'top' or 'bottom')")
  17. local startPos = read():lower()
  18. while startPos ~= "top" and startPos ~= "bottom" do
  19. print("Please type 'top' or 'bottom'")
  20. startPos = read():lower()
  21. end
  22.  
  23. -- Direction tracking (0=+X, 1=+Z, 2=-X, 3=-Z)
  24. local dir = 0
  25.  
  26. local function turnLeft()
  27. turtle.turnLeft()
  28. dir = (dir - 1) % 4
  29. end
  30.  
  31. local function turnRight()
  32. turtle.turnRight()
  33. dir = (dir + 1) % 4
  34. end
  35.  
  36. local function face(targetDir)
  37. while dir ~= targetDir do
  38. turnRight()
  39. end
  40. end
  41.  
  42. -- Movement functions with digging
  43. local function tryDig() while turtle.detect() do turtle.dig(); sleep(0.2) end end
  44. local function tryDigDown() while turtle.detectDown() do turtle.digDown(); sleep(0.2) end end
  45. local function tryDigUp() while turtle.detectUp() do turtle.digUp(); sleep(0.2) end end
  46.  
  47. local function forward()
  48. tryDig()
  49. while not turtle.forward() do sleep(0.2) end
  50. end
  51.  
  52. local function up()
  53. tryDigUp()
  54. while not turtle.up() do sleep(0.2) end
  55. end
  56.  
  57. local function down()
  58. tryDigDown()
  59. while not turtle.down() do sleep(0.2) end
  60. end
  61.  
  62. -- Fuel check
  63. local estimatedFuel = length * width * height * 1.5 + (length + width + height) * 2
  64. if turtle.getFuelLevel() < estimatedFuel then
  65. print("Warning: Low fuel! Required: "..estimatedFuel.." Current: "..turtle.getFuelLevel())
  66. print("Continue anyway? (y/n)")
  67. if read():lower() ~= "y" then return end
  68. end
  69.  
  70. -- Dig one horizontal layer
  71. local function digLayer()
  72. for w = 1, width do
  73. -- Dig the row
  74. for l = 1, length-1 do
  75. forward()
  76. end
  77.  
  78. -- Turn and move to next row (except on last row)
  79. if w < width then
  80. if w % 2 == 1 then
  81. turnRight()
  82. forward()
  83. turnRight()
  84. else
  85. turnLeft()
  86. forward()
  87. turnLeft()
  88. end
  89. end
  90. end
  91.  
  92. -- Return to starting position of layer
  93. if width % 2 == 0 then
  94. -- Even width means we ended facing opposite direction
  95. turnLeft()
  96. for w = 1, width-1 do forward() end
  97. turnLeft()
  98. else
  99. -- Odd width means we need to turn around
  100. turnLeft()
  101. turnLeft()
  102. for l = 1, length-1 do forward() end
  103. turnRight()
  104. turnRight()
  105. end
  106. end
  107.  
  108. -- Move to starting position
  109. if startPos == "top" then
  110. for h = 1, height-1 do
  111. down()
  112. end
  113. end
  114.  
  115. -- Main digging loop
  116. for h = 1, height do
  117. print("Digging layer "..h.." of "..height)
  118. digLayer()
  119.  
  120. if h < height then
  121. if startPos == "bottom" then
  122. up()
  123. else
  124. down()
  125. end
  126. end
  127. end
  128.  
  129. -- Return to starting height
  130. if startPos == "bottom" then
  131. for h = 1, height-1 do down() end
  132. else
  133. for h = 1, height-1 do up() end
  134. end
  135.  
  136. print("Quarry complete!")
Advertisement
Add Comment
Please, Sign In to add comment