BioPrince

lave tunnel safe

May 15th, 2022 (edited)
1,253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. if #tArgs == 0 then
  4.     print("Usage: <blocks> to create tunnel")
  5.     return
  6. end
  7.    
  8.     --Number of blocks to travel to get the lava
  9. local maxDistance = tArgs[1]
  10.      
  11.     --local counter for how far the turtle has travle
  12. local traveled = 0
  13.      
  14.     --A helper function to try and move forward, it will attempt to dig if it is blocked.
  15. local function moveForward()
  16.     if turtle.forward() == false then
  17.             --Failed to move, see if we can dig our way forward
  18.         while turtle.dig() do
  19.             --Keep digging till we can't dig any more, in case gravel is falling.
  20.         end
  21.         if turtle.forward() == false then
  22.             print("I am either blocked or out of fuel.")
  23.             return false
  24.         end
  25.     end
  26.     return true
  27. end
  28.      
  29.     --A helper function to try and move down, it will attempt to dig if it is blocked.
  30. local function moveDown()
  31.     if turtle.down() == false then
  32.             --Failed to move, see if we can dig our way down
  33.         turtle.digDown()
  34.         if turtle.down() == false then
  35.             print("I am either blocked or out of fuel.")
  36.             return false
  37.         end
  38.     end
  39.     return true  
  40. end
  41.  
  42.  
  43.     --A helper function to try and move down, it will attempt to dig if it is blocked.
  44. local function moveUp()
  45.     if turtle.up() == false then
  46.             --Failed to move, see if we can dig our way down
  47.         while turtle.digUp() do
  48.             --Keep digging till we can't dig any more, in case gravel is falling.
  49.         end
  50.         if turtle.up() == false then
  51.             print("I am either blocked or out of fuel.")
  52.             return false
  53.         end
  54.     end
  55.     return true  
  56. end
  57.  
  58.     --A helper function to build safe walls around tunnel.
  59.  
  60. local function walls()
  61.     turtle.select(1)  
  62.     turtle.placeDown()
  63.     turtle.turnRight()
  64.     turtle.select(2)
  65.     turtle.place()
  66.     moveUp()
  67.     turtle.select(3)
  68.     turtle.place()
  69.     turtle.turnRight()
  70.     turtle.select(4)
  71.     turtle.placeUp()
  72.     turtle.turnRight()
  73.     turtle.select(5)
  74.     turtle.place()
  75.     moveDown()
  76.     turtle.select(6)
  77.     turtle.place()
  78.     turtle.turnRight()
  79. end
  80.  
  81.     --Attempt to travel to max distance for getting lava
  82. for i = 1, maxDistance do
  83.  
  84.     if moveForward() == false then
  85.         print("Could not move forward the full requested distance, starting U-Turn early.")
  86.         break
  87.     end
  88.    
  89.     traveled = traveled + 1
  90.      
  91.       --change to placeing blocks
  92.     walls()
  93. end
  94.      
  95.     --Turn around move a block over and get more lava
  96.     moveForward()
  97.     turtle.select(1)
  98.     turtle.placeUp()
  99.     turtle.turnRight()
  100.     moveForward()
  101.     turtle.turnLeft()
  102.     turtle.turnLeft()
  103.     turtle.place()
  104.     turtle.turnLeft()
  105.     turtle.turnLeft()
  106.     moveForward()
  107.     turtle.turnRight()
  108.      
  109.     --Travel back the same number of blocks we came
  110. --
  111.     --Travel back the same number of blocks we came
  112. for i = 1, traveled do
  113.     if moveForward() == false then
  114.     end
  115. end
  116.      
  117. turtle.turnRight()
  118. moveForward()
  119. moveForward()
  120. turtle.turnRight()
  121. turtle.turnRight()
  122. turtle.place()
  123. turtle.turnLeft()
  124. print(turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment