mdc_tjc

mc_branch

Apr 7th, 2015 (edited)
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. --Pastebin code: cqYxFLsC;  name: mc_branch
  2. --Position this device in the branch tunnel one block above ground level
  3.  
  4. local tArgs = { ... } -- obtain tunnel length and turn around options
  5. if #tArgs ~= 2 then
  6.     print( "Usage: mc_branch followed by the tunnel <length>, and then whether to turn around: <y> or <n>" )
  7.     return
  8.     end
  9.  
  10. local length = tonumber( tArgs[1] ) -- Check if the tunnel length is > 0
  11. if length < 1 then
  12.     print( "Tunnel length must be positive" )
  13.     return
  14.     end
  15.  
  16. local turn = ( tArgs[2] ) -- Check if the turtle turn around option is y or n
  17. if not( turn == ( "y" ) or turn == ( "n" )) then
  18.     print( "Indicate whether to have the turtle turn around and return to start with a <y> or <n>" )
  19.     return
  20.     end
  21.  
  22. local fuel = turtle.getFuelLevel()
  23. if fuel < 80 then
  24.     print("Fuel < 80, you must add more fuel")
  25.     return
  26.     end
  27.  
  28. --definition of functions follows
  29.  
  30. local function tryDig() -- This function digs forward one block
  31.     while turtle.detect() do
  32.         if turtle.dig() then
  33.             sleep(0.5)
  34.         else
  35.             return false
  36.         end
  37.     end
  38.     return true
  39.     end
  40.  
  41. local function tryDigUp() -- This function digs up one block
  42.     while turtle.detectUp() do
  43.         if turtle.digUp() then
  44.             sleep(0.5)
  45.         else
  46.             return false
  47.         end
  48.     end
  49.     return true
  50. end
  51.  
  52. local function tryDigDown() -- This function digs down one block
  53.     while turtle.detectDown() do
  54.         if turtle.digDown() then
  55.             sleep(0.5)
  56.         else
  57.             return false
  58.         end
  59.     end
  60.     return true
  61. end
  62.  
  63. -- This section is the main control section of the program
  64.  
  65.     tryDigUp()
  66.     tryDigDown()
  67.  
  68. for i = 1, length do -- This is the main control function
  69.     tryDig()
  70.     turtle.forward()
  71.     tryDigUp()
  72.     tryDigDown()
  73.  
  74. end
  75.  
  76. if turn == "y" then
  77.     turtle.turnLeft()
  78.     turtle.turnLeft()
  79.  
  80.     for i = 1, length do -- This is the return function
  81.         turtle.forward()
  82.     end
  83. end
Advertisement
Add Comment
Please, Sign In to add comment