Advertisement
Maxello_

tutel v6

Aug 22nd, 2024 (edited)
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.77 KB | Gaming | 0 0
  1. -- Define the trash items
  2. local trashItems = {
  3.     "minecraft:dirt",
  4.     "minecraft:cobblestone",
  5.     "minecraft:diorite",
  6.     "minecraft:cobbled_deepslate",
  7.     "minecraft:andesite",
  8.     "minecraft:gravel",
  9.     "minecraft:sand",
  10.     "minecraft:granite",
  11.     "minecraft:amethyst_block",
  12.    
  13. }
  14.  
  15. -- Minimum fuel level required to start or continue mining
  16. local minimumFuel = 100
  17.  
  18. -- Function to check if an item is trash
  19. local function isTrash(item)
  20.     for _, trash in ipairs(trashItems) do
  21.         if item == trash then
  22.             return true
  23.         end
  24.     end
  25.     return false
  26. end
  27.  
  28. -- Function to automatically drop trash items from the inventory (thank you u/fatboychummy for helping with performance)
  29. local function dropTrash()
  30.   for slot = 1, 16 do
  31.     local itemDetail = turtle.getItemDetail(slot) -- Get details about a slot without selecting it.
  32.     if itemDetail and isTrash(itemDetail.name) then
  33.       turtle.select(slot) -- Only select the slot if it has trash.
  34.       turtle.dropDown()
  35.     end
  36.   end
  37. end
  38.  
  39. -- Function to ensure the block in front is cleared before moving forward
  40. local function ensureClearAhead()
  41.     while turtle.detect() do
  42.         turtle.dig()
  43.         dropTrash()  -- Check for trash after digging a block
  44.         sleep(0.5)  -- Small delay to allow any falling blocks to settle
  45.     end
  46. end
  47.  
  48. -- Function to check and refuel if needed
  49. local function checkAndRefuel()
  50.     if turtle.getFuelLevel() < minimumFuel then
  51.         print("Low fuel! Please add fuel to the turtle's inventory and type 'y' to continue.")
  52.         repeat
  53.             -- Try to refuel from any slot
  54.             for slot = 1, 16 do
  55.                 turtle.select(slot)
  56.                 turtle.refuel()
  57.             end
  58.             -- Check if enough fuel is added
  59.             local input = read()
  60.         until turtle.getFuelLevel() >= minimumFuel or input == "y"
  61.     end
  62. end
  63.  
  64. -- Function to dig straight down in one column
  65. local function digColumn(depth)
  66.     local successfulDownMoves = 0
  67.  
  68.     for d = 1, depth do
  69.         -- Check fuel level before digging down
  70.         checkAndRefuel()
  71.  
  72.         -- Detect and handle bedrock
  73.         local success, data = turtle.inspectDown()
  74.         if success and data.name == "minecraft:bedrock" then
  75.             print("Bedrock detected, skipping block...")
  76.             dropTrash()  -- Check for trash after detecting bedrock
  77.             break  -- Stop moving down further in this column
  78.         else
  79.             -- Dig down and move down
  80.             if turtle.detectDown() then
  81.                 turtle.digDown()
  82.                 dropTrash()  -- Check for trash after digging a block
  83.             end
  84.             turtle.down()
  85.             successfulDownMoves = successfulDownMoves + 1
  86.         end
  87.     end
  88.  
  89.     return successfulDownMoves
  90. end
  91.  
  92. -- Function to return to the top of the column, adjusting for bedrock
  93. local function returnToTop(successfulDownMoves)
  94.     for i = 1, successfulDownMoves do
  95.         turtle.up()
  96.     end
  97. end
  98.  
  99. -- Function to dig a quarry straight down
  100. local function quarry(width, length, depth)
  101.     local x, z = 0, 0 -- Track position within the quarry
  102.  
  103.     for l = 1, length do
  104.         for w = 1, width do
  105.             local successfulDownMoves = digColumn(depth)
  106.             returnToTop(successfulDownMoves)
  107.  
  108.             -- Move to the next position
  109.             if w < width then
  110.                 ensureClearAhead()  -- Ensure the next column is clear
  111.                 turtle.forward()
  112.                 x = x + 1
  113.             end
  114.         end
  115.  
  116.         -- Move to the next row
  117.         if l < length then
  118.             if l % 2 == 1 then
  119.                 turtle.turnRight()
  120.                 ensureClearAhead()  -- Ensure the next column is clear
  121.                 turtle.forward()
  122.                 turtle.turnRight()
  123.                 z = z + 1
  124.             else
  125.                 turtle.turnLeft()
  126.                 ensureClearAhead()  -- Ensure the next column is clear
  127.                 turtle.forward()
  128.                 turtle.turnLeft()
  129.                 z = z + 1
  130.             end
  131.         end
  132.     end
  133. end
  134.  
  135. -- Function to display fuel level and wait for user input before starting
  136. local function displayFuelLevel()
  137.     local fuelLevel = turtle.getFuelLevel()
  138.     print("Current fuel level: " .. fuelLevel)
  139.     print("Type 'y' to start the quarry operation.")
  140.     repeat
  141.         local input = read()
  142.     until input == "y"
  143. end
  144.  
  145. -- Get quarry dimensions from the user
  146. print("Enter quarry width:")
  147. local width = tonumber(read())
  148.  
  149. print("Enter quarry length:")
  150. local length = tonumber(read())
  151.  
  152. print("Enter quarry depth:")
  153. local depth = tonumber(read())
  154.  
  155. -- Display fuel level and wait for user confirmation
  156. displayFuelLevel()
  157.  
  158. -- Run the quarry function with user-provided dimensions
  159. quarry(width, length, depth)
  160.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement