Advertisement
Maxello_

Test Quarry turtle

Aug 22nd, 2024 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | Gaming | 0 0
  1. -- Define the trash items
  2. local trashItems = {
  3.     "minecraft:dirt",
  4.     "minecraft:cobblestone",
  5.     "minecraft:diorite"
  6. }
  7.  
  8. -- Function to check if an item is trash
  9. local function isTrash(item)
  10.     for _, trash in ipairs(trashItems) do
  11.         if item == trash then
  12.             return true
  13.         end
  14.     end
  15.     return false
  16. end
  17.  
  18. -- Function to deposit items into the chest
  19. local function depositItems()
  20.     for slot = 1, 16 do
  21.         turtle.select(slot)
  22.         local itemDetail = turtle.getItemDetail()
  23.         if itemDetail then
  24.             if isTrash(itemDetail.name) then
  25.                 turtle.dropDown() -- Dispose of trash items
  26.             else
  27.                 turtle.drop() -- Deposit other items in chest
  28.             end
  29.         end
  30.     end
  31. end
  32.  
  33. -- Function to check if the inventory is full
  34. local function isInventoryFull()
  35.     for slot = 1, 16 do
  36.         if turtle.getItemCount(slot) == 0 then
  37.             return false
  38.         end
  39.     end
  40.     return true
  41. end
  42.  
  43. -- Function to return to starting point (assumed as 0,0,0) and deposit items
  44. local function returnToStartAndDeposit(x, y, z, direction)
  45.     -- Return to the chest
  46.     turtle.up(y)
  47.     turtle.turnRight(direction)
  48.     turtle.forward(x)
  49.     turtle.turnRight()
  50.     turtle.forward(z)
  51.     -- Deposit items
  52.     depositItems()
  53.     -- Return to the mining position
  54.     turtle.back(z)
  55.     turtle.turnLeft()
  56.     turtle.forward(x)
  57.     turtle.turnLeft(direction)
  58.     turtle.down(y)
  59. end
  60.  
  61. -- Function to dig straight down in one column
  62. local function digColumn(depth)
  63.     for d = 1, depth do
  64.         -- Check if inventory is full
  65.         if isInventoryFull() then
  66.             return true
  67.         end
  68.  
  69.         -- Dig down and move down
  70.         if turtle.detectDown() then
  71.             turtle.digDown()
  72.         end
  73.         turtle.down()
  74.  
  75.         -- Avoid bedrock
  76.         local success, data = turtle.inspectDown()
  77.         if success and data.name == "minecraft:bedrock" then
  78.             return false
  79.         end
  80.     end
  81.     return true
  82. end
  83.  
  84. -- Function to return to the top of the column
  85. local function returnToTop(depth)
  86.     for i = 1, depth do
  87.         turtle.up()
  88.     end
  89. end
  90.  
  91. -- Function to dig a quarry straight down
  92. local function quarry(width, length, depth)
  93.     for l = 1, length do
  94.         for w = 1, width do
  95.             local continue = digColumn(depth)
  96.             if not continue then
  97.                 return
  98.             end
  99.  
  100.             returnToTop(depth)
  101.  
  102.             -- Move to the next position
  103.             if w < width then
  104.                 turtle.dig()
  105.                 turtle.forward()
  106.             end
  107.         end
  108.  
  109.         -- Move to the next row
  110.         if l < length then
  111.             if l % 2 == 1 then
  112.                 turtle.turnRight()
  113.                 turtle.dig()
  114.                 turtle.forward()
  115.                 turtle.turnRight()
  116.             else
  117.                 turtle.turnLeft()
  118.                 turtle.dig()
  119.                 turtle.forward()
  120.                 turtle.turnLeft()
  121.             end
  122.         end
  123.     end
  124.  
  125.     -- Return to the chest and deposit final items
  126.     returnToStartAndDeposit(0, 0, 0, 0)
  127. end
  128.  
  129. -- Get quarry dimensions from the user
  130. print("Enter quarry width:")
  131. local width = tonumber(read())
  132.  
  133. print("Enter quarry length:")
  134. local length = tonumber(read())
  135.  
  136. print("Enter quarry depth:")
  137. local depth = tonumber(read())
  138.  
  139. -- Run the quarry function with user-provided dimensions
  140. quarry(width, length, depth)
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement