Advertisement
SryNotToxic

Untitled

Sep 30th, 2024
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. -- Quarry program with stairs, custom dimensions, and inventory management
  2. -- User input for quarry dimensions
  3. local length, width
  4. local currentX, currentY, currentZ = 0, 0, 0 -- Position of the turtle relative to the starting point
  5. local dir = 0 -- Direction: 0 = forward, 1 = right, 2 = backward, 3 = left
  6.  
  7. -- Input the dimensions
  8. print("Enter quarry length:")
  9. length = tonumber(read())
  10. print("Enter quarry width:")
  11. width = tonumber(read())
  12.  
  13. -- Fuel Management
  14. local function refuelIfNeeded()
  15. if turtle.getFuelLevel() < (length * width * 2) then -- Arbitrary number; adjust as needed for distance
  16. turtle.select(16)
  17. turtle.suckUp()
  18. turtle.refuel()
  19. end
  20. end
  21.  
  22. -- Inventory Management: Return to the start, unload, refuel, then return to digging
  23. local function returnToStartAndUnload()
  24. -- Return to starting position
  25. while dir ~= 2 do -- Ensure turtle faces "backward" (towards starting point)
  26. turtle.turnRight()
  27. dir = (dir + 1) % 4
  28. end
  29. for i = 1, currentX do
  30. turtle.forward()
  31. end
  32. for i = 1, currentZ do
  33. turtle.up()
  34. end
  35.  
  36. -- Unload items in chest above
  37. for i = 1, 15 do -- Leave slot 16 for fuel
  38. turtle.select(i)
  39. turtle.dropUp()
  40. end
  41.  
  42. -- Refuel if needed
  43. refuelIfNeeded()
  44.  
  45. -- Return to digging position
  46. for i = 1, currentZ do
  47. turtle.down()
  48. end
  49. for i = 1, currentX do
  50. turtle.back()
  51. end
  52. turtle.turnLeft() -- Return to facing forward
  53. dir = 0
  54. end
  55.  
  56. -- Check if the inventory is full
  57. local function isInventoryFull()
  58. for i = 1, 15 do
  59. if turtle.getItemCount(i) == 0 then
  60. return false
  61. end
  62. end
  63. return true
  64. end
  65.  
  66. -- Move forward safely (handle block detection)
  67. local function safeForward()
  68. while not turtle.forward() do
  69. turtle.dig()
  70. end
  71. currentX = currentX + 1
  72. end
  73.  
  74. -- Turn right and update direction
  75. local function turnRight()
  76. turtle.turnRight()
  77. dir = (dir + 1) % 4
  78. end
  79.  
  80. -- Turn left and update direction
  81. local function turnLeft()
  82. turtle.turnLeft()
  83. dir = (dir + 3) % 4
  84. end
  85.  
  86. -- Move down and dig stairs
  87. local function digDown()
  88. turtle.digDown()
  89. turtle.down()
  90. currentZ = currentZ + 1
  91. if currentX % 2 == 0 then -- Every second block, dig a stair block
  92. turtle.dig()
  93. safeForward()
  94. end
  95. end
  96.  
  97. -- Main quarry function
  98. local function quarry()
  99. for z = 1, math.huge do -- Keep going until bedrock
  100. for w = 1, width do
  101. for l = 1, length - 1 do
  102. if isInventoryFull() then
  103. returnToStartAndUnload()
  104. end
  105. turtle.digDown() -- Quarry digs down each block it moves over
  106. safeForward()
  107. end
  108. -- Check if the turtle needs to move to the next row
  109. if w < width then
  110. if w % 2 == 1 then
  111. turnRight()
  112. if isInventoryFull() then
  113. returnToStartAndUnload()
  114. end
  115. turtle.digDown()
  116. safeForward()
  117. turnRight()
  118. else
  119. turnLeft()
  120. if isInventoryFull() then
  121. returnToStartAndUnload()
  122. end
  123. turtle.digDown()
  124. safeForward()
  125. turnLeft()
  126. end
  127. end
  128. end
  129. -- When a full layer is done, dig down to the next layer
  130. if turtle.detectDown() then -- If bedrock or no block below
  131. print("Reached bedrock or obstruction")
  132. break
  133. else
  134. digDown()
  135. if z % 2 == 0 then
  136. turtle.dig() -- Digging stair every second layer
  137. safeForward()
  138. end
  139. end
  140. end
  141. -- Return to starting position when done
  142. returnToStartAndUnload()
  143. end
  144.  
  145. -- Run the quarry function
  146. quarry()
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement