Lorc520

enderchest quarry

May 15th, 2025 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. -- USER INPUT
  2. print("Enter length:")
  3. local length = tonumber(read())
  4. print("Enter width:")
  5. local width = tonumber(read())
  6. print("Enter depth:")
  7. local depth = tonumber(read())
  8.  
  9. local fuelSlot = 1
  10. local outputSlot = 2
  11.  
  12. -- STATE
  13. local x, y, z = 0, 0, 0 -- relative coordinates
  14. local dir = 0 -- 0=N, 1=E, 2=S, 3=W
  15.  
  16. -- === BLACKLIST ===
  17. local blacklist = {
  18. ["minecraft:cobbled_deepslate"] = true,
  19. ["minecraft:cobblestone"] = true,
  20. ["minecraft:dirt"] = true,
  21. ["minecraft:gravel"] = true,
  22. ["minecraft:tuff"] = true,
  23. ["forbidden_arcanus:darkstone"] = true
  24. }
  25.  
  26. function dropBlacklistedItems()
  27. for i = 3, 16 do
  28. turtle.select(i)
  29. local detail = turtle.getItemDetail(i)
  30. if detail and blacklist[detail.name] then
  31. turtle.dropDown()
  32. end
  33. end
  34. end
  35.  
  36. -- === MOVEMENT HELPERS ===
  37. function tryDig() while turtle.detect() do turtle.dig(); sleep(0.4) end end
  38. function tryDigDown() while turtle.detectDown() do turtle.digDown(); sleep(0.4) end end
  39. function tryDigUp() while turtle.detectUp() do
  40. turtle.digUp(); sleep(0.4) end end
  41.  
  42. function refuel()
  43. if turtle.getFuelLevel() < 100 then
  44. tryDig()
  45. turtle.select(fuelSlot)
  46. while not turtle.place() do sleep(0.2) end
  47. while turtle.getFuelLevel() < 20000 do
  48. turtle.suck()
  49. turtle.refuel()
  50. end
  51. turtle.dropDown()
  52. tryDig()
  53. end
  54. end
  55.  
  56. function forward()
  57. refuel()
  58. tryDig()
  59. while not turtle.forward() do sleep(0.2) end
  60. if dir == 0 then z = z + 1
  61. elseif dir == 1 then x = x + 1
  62. elseif dir == 2 then z = z - 1
  63. elseif dir == 3 then x = x - 1 end
  64. end
  65.  
  66. function back()
  67. refuel()
  68. while not turtle.back() do sleep(0.2) end
  69. if dir == 0 then z = z - 1
  70. elseif dir == 1 then x = x - 1
  71. elseif dir == 2 then z = z + 1
  72. elseif dir == 3 then x = x + 1 end
  73. end
  74.  
  75. function down()
  76. refuel()
  77. tryDigDown()
  78. while not turtle.down() do sleep(0.2) end
  79. y = y - 1
  80. end
  81.  
  82. function up()
  83. refuel()
  84. tryDigUp()
  85. while not turtle.up() do sleep(0.2) end
  86. y = y + 1
  87. end
  88.  
  89. function turnLeft()
  90. turtle.turnLeft()
  91. dir = (dir - 1) % 4
  92. if dir < 0 then dir = dir + 4 end
  93. end
  94.  
  95. function turnRight()
  96. turtle.turnRight()
  97. dir = (dir + 1) % 4
  98. end
  99.  
  100. function face(target)
  101. while dir ~= target do turnRight() end
  102. end
  103.  
  104. -- === GO TO COORDINATE ===
  105. function goTo(targetX, targetY, targetZ, targetDir)
  106. -- Go up first (safety)
  107. while y < targetY do up() end
  108. while y > targetY do down() end
  109.  
  110. if x < targetX then face(1) while x < targetX do forward() end
  111. elseif x > targetX then face(3) while x > targetX do forward() end end
  112.  
  113. if z < targetZ then face(0) while z < targetZ do forward() end
  114. elseif z > targetZ then face(2) while z > targetZ do forward() end end
  115.  
  116. face(targetDir or 0)
  117. end
  118.  
  119. -- === INVENTORY HANDLING ===
  120. function isInventoryFull()
  121. for i = 3, 16 do
  122. if turtle.getItemCount(i) == 0 then return false end
  123. end
  124. return true
  125. end
  126.  
  127. function dropItems()
  128. tryDig()
  129. turtle.select(outputSlot)
  130. while not turtle.place() do sleep(0.2) end
  131. for i = 3, 16 do
  132. turtle.select(i)
  133. turtle.drop()
  134. end
  135. turtle.select(outputSlot)
  136. tryDig()
  137. end
  138.  
  139. -- === MINING FUNCTION ===
  140. function mineLayer()
  141. for row = 1, width do
  142. for col = 1, length - 1 do
  143. forward()
  144. if isInventoryFull() then dropBlacklistedItems()
  145. if isInventoryFull() then dropItems() end end
  146. end
  147. if row < width then
  148. if row % 2 == 1 then turnRight(); forward(); turnRight()
  149. else turnLeft(); forward(); turnLeft() end
  150. end
  151. end
  152. -- Return to top-left corner of next layer
  153. if width % 2 == 1 then face(2) for i = 1, length - 1 do forward() end end
  154. face(3) for i = 1, width - 1 do forward() end
  155. face(0)
  156. end
  157.  
  158. -- === MAIN EXECUTION ===
  159. print("Starting mining...")
  160. turtle.digDown()
  161. down()
  162.  
  163. for d = 1, depth do
  164. mineLayer()
  165. if d < depth then down() end
  166. end
  167.  
  168. -- Final return to origin, face chest
  169. goTo(0, 0, 0, 0)
  170. dropItems()
  171. print("Mining complete.")
Advertisement
Add Comment
Please, Sign In to add comment