overshoot

Better Excavate qTK0jV0F

Mar 19th, 2024 (edited)
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = { ... }
  2. local turn_right = true
  3. local width = assert(tonumber(args[1]), "Usage: bexcavate <Width> <Depth> <Length>")
  4. local length = assert(tonumber(args[3]) - 1, "Usage: bexcavate <Width> <Depth> <Length>")
  5. local depth = assert(tonumber(args[2]), "Usage: bexcavate <Width> <Depth> <Length>")
  6.  
  7.  
  8. local function rotate_right()
  9.     turtle.turnRight()
  10.     turtle.turnRight()
  11. end
  12.  
  13.  
  14. local function torch_placement_check(x, z)
  15.     if (x % 8) == 0 and (z % 8) == 0 then
  16.         local slot = 0
  17.         local success, data = turtle.inspectDown()
  18.         if success == false then return end
  19.         for i = 1, 16, 1 do
  20.             data = turtle.getItemDetail(i)
  21.             if data ~= nil and data.name == "minecraft:torch" then
  22.                 slot = i
  23.             end
  24.         end
  25.         if slot > 0 then
  26.             turtle.select(slot)  
  27.             rotate_right()
  28.             turtle.place()
  29.             rotate_right()
  30.         end
  31.     end
  32. end
  33.  
  34.  
  35. local function forward()
  36.     while not turtle.forward() do
  37.         turtle.dig()
  38.         turtle.attack()
  39.         sleep()
  40.     end
  41. end
  42.  
  43.  
  44. local function turn_around()
  45.     if turn_right then
  46.         turtle.turnRight()
  47.         turtle.dig()
  48.         forward()
  49.         turtle.turnRight()
  50.         turn_right = false
  51.     else    
  52.         turtle.turnLeft()
  53.         turtle.dig()
  54.         forward()
  55.         turtle.turnLeft()
  56.         turn_right = true      
  57.     end
  58. end
  59.  
  60.  
  61. local function reset()
  62.     turtle.turnRight()
  63.     if turn_right then
  64.         turtle.turnRight()
  65.         for z = 1, length, 1 do
  66.             forward()
  67.         end
  68.         turtle.turnRight()
  69.     end
  70.     for x = 1, width - 1, 1 do
  71.         forward()
  72.     end
  73.     turtle.turnRight()
  74.     turtle.digDown()
  75.     turtle.down()
  76. end
  77.  
  78.  
  79. print("Better Excavate")
  80. print("https://github.com/na-stewart/Better-Excavate")
  81. print("------------------------------------")
  82. print("Excavation initiated, please monitor occasionally.")
  83. for y = 1, depth do
  84.     turtle.select(1)
  85.     turtle.refuel()
  86.     turn_right = true
  87.     for x = 1, width, 1 do
  88.         for z = 1, length, 1 do
  89.             turtle.dig()
  90.             forward()
  91.             torch_placement_check(x, z)          
  92.         end
  93.         if x < width then
  94.             turn_around()
  95.         else
  96.             reset()
  97.         end
  98.     end
  99.     print("Layer completed, " .. depth - y .." left to go.")
  100. end
  101. print("Excavation complete, enjoy :)")
Add Comment
Please, Sign In to add comment