Neon1432

stairdigger

Oct 30th, 2025 (edited)
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. local args = { ... }
  2. local levels = 5
  3. local safemode = true
  4. if #args ~= 0 then
  5.     if tonumber(args[1]) == nil then
  6.         error("input must be a number")
  7.     else
  8.         levels = tonumber(args[1])
  9.     end
  10.  
  11.     if args[2] ~= nil then
  12.         safemode = false
  13.     end
  14. end
  15.  
  16. local BUILDINGBLOCK = { [1] = "minecraft:cobblestone", [2] = "minecraft:cobbled_deepslate" }
  17. local LIGHTING = { [1] = "minecraft:torch" }
  18. local TORCHDISTANCE = 7
  19. local HOLEDISTANCE = 5
  20.  
  21. local levelCounter = 0
  22. local holeCounter = 0
  23. local torchCounter = 0
  24.  
  25. local function selectItem(blockGroup)
  26.     local function isItem(itemName)
  27.         local details = turtle.getItemDetail()
  28.         if details ~= nil then
  29.             if details.name == itemName then
  30.                 return true
  31.             end
  32.         end
  33.         return false
  34.     end
  35.     local function itereateAllFields(itemName)
  36.         if isItem(itemName) then return true end
  37.         for i = 1, 16, 1 do
  38.             turtle.select(i)
  39.             if isItem(itemName) then return true end
  40.         end
  41.         return false
  42.     end
  43.     if blockGroup.lastIndex ~= nil then
  44.         if itereateAllFields(blockGroup[blockGroup.lastIndex]) then return true end
  45.     end
  46.     for groupIndex = 1, #blockGroup, 1 do
  47.         if itereateAllFields(blockGroup[groupIndex]) then
  48.             blockGroup.lastIndex = groupIndex
  49.             return true
  50.         end
  51.     end
  52.     error("Item not found in List: " .. textutils.serialise(blockGroup))
  53. end
  54.  
  55. local function digHole()
  56.     if not turtle.inspect() then return false end
  57.     for i = 1, 4, 1 do
  58.         while not turtle.forward() do
  59.             turtle.dig()
  60.         end
  61.     end
  62.     turtle.back()
  63.     turtle.back()
  64.     turtle.back()
  65.     turtle.back()
  66. end
  67.  
  68. local function digLevel()
  69.     while not turtle.forward() do
  70.         turtle.dig()
  71.     end
  72.  
  73.     selectItem(BUILDINGBLOCK)
  74.     turtle.placeDown()
  75.  
  76.     if safemode then
  77.         turtle.turnRight()
  78.         selectItem(BUILDINGBLOCK)
  79.         turtle.place()
  80.         turtle.turnLeft()
  81.         turtle.turnLeft()
  82.         selectItem(BUILDINGBLOCK)
  83.         turtle.place()
  84.         turtle.turnRight()
  85.     end
  86.  
  87.     while not turtle.up() do
  88.         turtle.digUp()
  89.     end
  90.     selectItem(BUILDINGBLOCK)
  91.     turtle.placeUp()
  92. end
  93.  
  94. local function digSection()
  95.     digLevel()
  96.  
  97.     if holeCounter >= HOLEDISTANCE then
  98.         turtle.turnLeft()
  99.         digHole()
  100.         turtle.turnRight()
  101.         turtle.turnRight()
  102.         digHole()
  103.         turtle.turnLeft()
  104.         holeCounter = 0
  105.     end
  106.  
  107.     if turtle.inspectDown() then return error("not safe") end
  108.     turtle.down()
  109.     if turtle.inspectUp() then return error("not safe") end
  110.     if torchCounter >= TORCHDISTANCE then
  111.         turtle.turnRight()
  112.         turtle.turnRight()
  113.         selectItem(LIGHTING)
  114.         turtle.place()
  115.         turtle.turnLeft()
  116.         turtle.turnLeft()
  117.         torchCounter = 0
  118.     end
  119. end
  120.  
  121. while levelCounter < levels do
  122.     digSection()
  123.     levelCounter = levelCounter + 1
  124.     holeCounter = holeCounter + 1
  125.     torchCounter = torchCounter + 1
  126. end
  127.  
Advertisement
Add Comment
Please, Sign In to add comment