Advertisement
Fatherless

tunnel

Dec 6th, 2024 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. --[[
  2.  
  3.     This program tells a turtle to tunnel forward by a specified amount.
  4.     The tunnel will be 3 blocks tall, 1 block above and 1 block below the turtle.
  5.     The turtle returns to the starting position.
  6.  
  7. ]]
  8.  
  9. --[[ Functions ]]
  10.  
  11. local function fwd()
  12.     while not turtle.forward() do
  13.         turtle.dig()
  14.     end
  15.     turtle.digUp()
  16.     turtle.digDown()
  17. end
  18.  
  19. local function enoughFuel(x)
  20.     if turtle.getFuelLevel() < 2 * x then
  21.         return false
  22.     else
  23.         return true
  24.     end
  25. end
  26.  
  27. --[[ Main ]]
  28.  
  29. -- Query user
  30. print("How much in front of me would you like me to dig?")
  31. local x = read()
  32.  
  33. -- Check for fuel
  34. if not enoughFuel(x) then
  35.     print("Please refuel. I need at least " .. x * 2 .. " units for that job")
  36.     return
  37. end
  38.  
  39. -- Dig
  40. for i = 1, x do
  41.     fwd()
  42. end
  43.  
  44. -- Come back
  45. for i = 1, x do
  46.     turtle.back()
  47. end
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement