Advertisement
Maxello_

tutel5 fuel test

Aug 22nd, 2024 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 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. turtle.select(slot)
  25. local itemDetail = turtle.getItemDetail()
  26. if itemDetail and isTrash(itemDetail.name) then
  27. turtle.dropDown()
  28. end
  29. end
  30. end
  31.  
  32. -- Function to ensure the block in front is cleared before moving forward
  33. local function ensureClearAhead()
  34. while turtle.detect() do
  35. turtle.dig()
  36. dropTrash() -- Check for trash after digging a block
  37. sleep(0.5) -- Small delay to allow any falling blocks to settle
  38. end
  39. end
  40.  
  41. -- Function to check and refuel if needed
  42. local function checkAndRefuel()
  43. if turtle.getFuelLevel() < minimumFuel then
  44. print("Low fuel! Please add fuel to the turtle's inventory and type 'y' to continue.")
  45. repeat
  46. -- Try to refuel from any slot
  47. for slot = 1, 16 do
  48. turtle.select(slot)
  49. turtle.refuel()
  50. end
  51. -- Check if enough fuel is added
  52. local input = read()
  53. until turtle.getFuelLevel() >= minimumFuel or input == "y"
  54. end
  55. end
  56.  
  57. -- Function to dig straight down in one column
  58. local function digColumn(depth)
  59. for d = 1, depth do
  60. -- Check fuel level before digging down
  61. checkAndRefuel()
  62.  
  63. -- Dig down and move down
  64. if turtle.detectDown() then
  65. turtle.digDown()
  66. dropTrash() -- Check for trash after digging a block
  67. end
  68. turtle.down()
  69.  
  70. -- Avoid bedrock
  71. local success, data = turtle.inspectDown()
  72. if success and data.name == "minecraft:bedrock" then
  73. return false
  74. end
  75. end
  76. return true
  77. end
  78.  
  79. -- Function to return to the top of the column
  80. local function returnToTop(depth)
  81. for i = 1, depth do
  82. turtle.up()
  83. end
  84. end
  85.  
  86. -- Function to dig a quarry straight down
  87. local function quarry(width, length, depth)
  88. local x, z = 0, 0 -- Track position within the quarry
  89.  
  90. for l = 1, length do
  91. for w = 1, width do
  92. local continue = digColumn(depth)
  93. if not continue then
  94. return
  95. end
  96.  
  97. returnToTop(depth)
  98.  
  99. -- Move to the next position
  100. if w < width then
  101. ensureClearAhead() -- Ensure the next column is clear
  102. turtle.forward()
  103. x = x + 1
  104. end
  105. end
  106.  
  107. -- Move to the next row
  108. if l < length then
  109. if l % 2 == 1 then
  110. turtle.turnRight()
  111. ensureClearAhead() -- Ensure the next column is clear
  112. turtle.forward()
  113. turtle.turnRight()
  114. z = z + 1
  115. else
  116. turtle.turnLeft()
  117. ensureClearAhead() -- Ensure the next column is clear
  118. turtle.forward()
  119. turtle.turnLeft()
  120. z = z + 1
  121. end
  122. end
  123. end
  124. end
  125.  
  126. -- Function to display fuel level and wait for user input before starting
  127. local function displayFuelLevel()
  128. local fuelLevel = turtle.getFuelLevel()
  129. print("Current fuel level: " .. fuelLevel)
  130. print("Type 'y' to start the quarry operation.")
  131. repeat
  132. local input = read()
  133. until input == "y"
  134. end
  135.  
  136. -- Get quarry dimensions from the user
  137. print("Enter quarry width:")
  138. local width = tonumber(read())
  139.  
  140. print("Enter quarry length:")
  141. local length = tonumber(read())
  142.  
  143. print("Enter quarry depth:")
  144. local depth = tonumber(read())
  145.  
  146. -- Display fuel level and wait for user confirmation
  147. displayFuelLevel()
  148.  
  149. -- Run the quarry function with user-provided dimensions
  150. quarry(width, length, depth)
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement