9551

3x3 tunnel digger

Nov 13th, 2021 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. print("how long 3x3 tunel do you want ?")
  2. local lenght = tonumber(read()) or 1
  3. local lDig = function()
  4.     turtle.dig()
  5.     turtle.turnRight()
  6.     turtle.turnRight()
  7.     turtle.dig()
  8. end
  9. local rDig = function()
  10.     turtle.dig()
  11.     turtle.turnLeft()
  12.     turtle.turnLeft()
  13.     turtle.dig()
  14. end
  15. local makeStep1 = function()
  16.     turtle.dig()
  17.     turtle.forward()
  18.     turtle.turnLeft()
  19.     lDig()
  20.     turtle.digUp()
  21.     turtle.up()
  22.     rDig()
  23.     turtle.digUp()
  24.     turtle.up()
  25.     lDig()
  26. end
  27. local makeStep2 = function()
  28.     turtle.turnLeft()
  29.     turtle.dig()
  30.     turtle.forward()
  31.     turtle.turnLeft()
  32.     lDig()
  33.     turtle.digDown()
  34.     turtle.down()
  35.     rDig()
  36.     turtle.digDown()
  37.     turtle.down()
  38.     lDig()
  39. end
  40. local refuel = function()
  41.     local fuelUp
  42.     fuelUp = function()
  43.         if turtle.getFuelLevel() < 40 then
  44.             turtle.select(16)
  45.             turtle.refuel(1)
  46.             fuelUp()
  47.             print("out of fuel. trying to refuel")
  48.             sleep(0.5)
  49.         else print("turtle fuel: " .. turtle.getFuelLevel()) end
  50.     end
  51.     fuelUp()
  52. end
  53. local goBack = function(len)
  54.     for i = 1, len do
  55.         refuel()
  56.         turtle.forward()
  57.     end
  58. end
  59. local returnHome = function(len)
  60.     if len % 2 == 1 then
  61.         turtle.down()
  62.         turtle.down()
  63.         turtle.turnRight()
  64.     else turtle.turnRight() end
  65.     goBack(len)
  66.     for i = 1, 15 do
  67.         turtle.select(i)
  68.         turtle.drop(64)
  69.     end
  70.     turtle.turnRight()
  71.     turtle.turnRight()
  72. end
  73. local countUp
  74. for i = 1, lenght do
  75.     countUp = i
  76.     refuel()
  77.     if i % 2 == 1 then
  78.         makeStep1()
  79.     else
  80.         makeStep2()
  81.         if not (i >= lenght) then turtle.turnLeft() end
  82.     end
  83. end
  84. returnHome(countUp)
Add Comment
Please, Sign In to add comment