Advertisement
Maxello_

tutel v7 test

Aug 23rd, 2024 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. -- Define the trash items
  2. local trashItems = {
  3. "minecraft:dirt",
  4. "minecraft:cobblestone",
  5. "minecraft:diorite"
  6. }
  7.  
  8. -- Minimum fuel level required to start or continue mining
  9. local minimumFuel = 100
  10.  
  11. -- Function to check if an item is trash
  12. local function isTrash(item)
  13. for _, trash in ipairs(trashItems) do
  14. if item == trash then
  15. return true
  16. end
  17. end
  18. return false
  19. end
  20.  
  21. -- Function to automatically drop trash items from the inventory
  22. local function dropTrash()
  23. for slot = 1, 16 do
  24. local itemDetail = turtle.getItemDetail(slot) -- Get details about a slot without selecting it.
  25. if itemDetail and isTrash(itemDetail.name) then
  26. turtle.select(slot) -- Only select the slot if it has trash.
  27. turtle.dropDown()
  28. end
  29. end
  30. end
  31.  
  32. -- Function to check and refuel if needed
  33. local function checkAndRefuel()
  34. if turtle.getFuelLevel() < minimumFuel then
  35. -- Try to refuel from any slot
  36. for slot = 1, 16 do
  37. turtle.select(slot)
  38. turtle.refuel()
  39. end
  40.  
  41. -- Check if the fuel level is still below the required threshold
  42. if turtle.getFuelLevel() < minimumFuel then
  43. print("Low fuel! Please add fuel to the turtle's inventory and type 'y' to continue.")
  44. repeat
  45. local input = read()
  46. -- Try to refuel again in case fuel was added
  47. for slot = 1, 16 do
  48. turtle.select(slot)
  49. turtle.refuel()
  50. end
  51. until turtle.getFuelLevel() >= minimumFuel or input == "y"
  52. end
  53. end
  54. end
  55.  
  56. -- Function to automatically drop non-coal items into a chest
  57. local function depositItems()
  58. for slot = 1, 16 do
  59. turtle.select(slot)
  60. local itemDetail = turtle.getItemDetail()
  61. if itemDetail and itemDetail.name ~= "minecraft:coal" then
  62. turtle.dropUp()
  63. end
  64. end
  65. end
  66.  
  67. -- Function to handle full inventory by placing a chest above and depositing items
  68. local function handleFullInventory()
  69. print("Inventory full! Moving up to place chest and deposit items.")
  70. turtle.up() -- Move up before placing the chest
  71.  
  72. turtle.select(1) -- Assume the chest is in slot 1
  73. if turtle.getItemDetail().name == "minecraft:chest" then
  74. turtle.placeUp()
  75. depositItems()
  76. else
  77. print("No chest found in the first slot! Please add a chest and type 'y' to continue.")
  78. repeat
  79. local input = read()
  80. until input == "y"
  81. turtle.placeUp()
  82. depositItems()
  83. end
  84.  
  85. turtle.down() -- Move back down to resume mining
  86. end
  87.  
  88. -- Function to check if the inventory is full
  89. local function isInventoryFull()
  90. for slot = 1, 16 do
  91. if turtle.getItemCount(slot) == 0 then
  92. return false
  93. end
  94. end
  95. return true
  96. end
  97.  
  98. -- Function to mine a single layer horizontally
  99. local function mineLayer(width, length)
  100. for l = 1, length do
  101. for w = 1, width do
  102. -- Check fuel level before continuing
  103. checkAndRefuel()
  104.  
  105. -- Handle full inventory by placing a chest and depositing items
  106. if isInventoryFull() then
  107. handleFullInventory()
  108. end
  109.  
  110. -- Dig forward and move forward, but skip digging the last block of the row
  111. if w < width then
  112. if turtle.detect() then
  113. turtle.dig()
  114. dropTrash()
  115. end
  116. turtle.forward()
  117. elseif w == width then
  118. if l < length then
  119. -- Turn around without digging the last block
  120. if l % 2 == 1 then
  121. turtle.turnRight()
  122. turtle.forward()
  123. turtle.turnRight()
  124. else
  125. turtle.turnLeft()
  126. turtle.forward()
  127. turtle.turnLeft()
  128. end
  129. end
  130. end
  131. end
  132. end
  133. end
  134.  
  135. -- Function to mine the perimeter horizontally, layer by layer
  136. local function quarryHorizontal(width, length, depth)
  137. for d = 1, depth do
  138. mineLayer(width, length)
  139. if d < depth then
  140. -- Move down to the next layer
  141. turtle.digDown()
  142. turtle.down()
  143. end
  144. end
  145. end
  146.  
  147. -- Function to mine vertically, column by column
  148. local function digColumn(depth)
  149. local successfulDownMoves = 0
  150.  
  151. for d = 1, depth do
  152. -- Check fuel level before digging down
  153. checkAndRefuel()
  154.  
  155. -- Handle full inventory by placing a chest and depositing items
  156. if isInventoryFull() then
  157. handleFullInventory()
  158. end
  159.  
  160. -- Detect and handle bedrock
  161. local success, data = turtle.inspectDown()
  162. if success and data.name == "minecraft:bedrock" then
  163. print("Bedrock detected, skipping block...")
  164. dropTrash() -- Check for trash after detecting bedrock
  165. break -- Stop moving down further in this column
  166. else
  167. -- Dig down and move down
  168. if turtle.detectDown() then
  169. turtle.digDown()
  170. dropTrash() -- Check for trash after digging a block
  171. end
  172. turtle.down()
  173. successfulDownMoves = successfulDownMoves + 1
  174. end
  175. end
  176.  
  177. return successfulDownMoves
  178. end
  179.  
  180. -- Function to return to the top of the column, adjusting for bedrock
  181. local function returnToTop(successfulDownMoves)
  182. for i = 1, successfulDownMoves do
  183. turtle.up()
  184. end
  185. end
  186.  
  187. -- Function to dig a quarry vertically (column by column)
  188. local function quarryVertical(width, length, depth)
  189. local x, z = 0, 0 -- Track position within the quarry
  190.  
  191. for l = 1, length do
  192. for w = 1, width do
  193. local successfulDownMoves = digColumn(depth)
  194. returnToTop(successfulDownMoves)
  195.  
  196. -- Move to the next position
  197. if w < width then
  198. ensureClearAhead() -- Ensure the next column is clear
  199. turtle.forward()
  200. x = x + 1
  201. end
  202. end
  203.  
  204. -- Move to the next row
  205. if l < length then
  206. if l % 2 == 1 then
  207. turtle.turnRight()
  208. ensureClearAhead() -- Ensure the next column is clear
  209. turtle.forward()
  210. turtle.turnRight()
  211. z = z + 1
  212. else
  213. turtle.turnLeft()
  214. ensureClearAhead() -- Ensure the next column is clear
  215. turtle.forward()
  216. turtle.turnLeft()
  217. z = z + 1
  218. end
  219. end
  220. end
  221. end
  222.  
  223. -- Function to display fuel level and wait for user input before starting
  224. local function displayFuelLevel()
  225. local fuelLevel = turtle.getFuelLevel()
  226. print("Current fuel level: " .. fuelLevel)
  227. print("Type 'y' to start the quarry operation.")
  228. repeat
  229. local input = read()
  230. until input == "y"
  231. end
  232.  
  233. -- Get quarry dimensions from the user
  234. print("Enter quarry width:")
  235. local width = tonumber(read())
  236.  
  237. print("Enter quarry length:")
  238. local length = tonumber(read())
  239.  
  240. print("Enter quarry depth:")
  241. local depth = tonumber(read())
  242.  
  243. -- Ask the user which mining style to use
  244. print("Select mining style: (v)ertical or (h)orizontal")
  245. local miningStyle = read()
  246.  
  247. -- Display fuel level and wait for user confirmation
  248. displayFuelLevel()
  249.  
  250. -- Run the selected quarry function based on user input
  251. if miningStyle == "v" then
  252. quarryVertical(width, length, depth)
  253. elseif miningStyle == "h" then
  254. quarryHorizontal(width, length, depth)
  255. else
  256. print("Invalid mining style selected. Please restart the program and choose 'v' for vertical or 'h' for horizontal.")
  257. end
  258.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement