Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Pastebin code: cqYxFLsC; name: mc_branch
- --Position this device in the branch tunnel one block above ground level
- local tArgs = { ... } -- obtain tunnel length and turn around options
- if #tArgs ~= 2 then
- print( "Usage: mc_branch followed by the tunnel <length>, and then whether to turn around: <y> or <n>" )
- return
- end
- local length = tonumber( tArgs[1] ) -- Check if the tunnel length is > 0
- if length < 1 then
- print( "Tunnel length must be positive" )
- return
- end
- local turn = ( tArgs[2] ) -- Check if the turtle turn around option is y or n
- if not( turn == ( "y" ) or turn == ( "n" )) then
- print( "Indicate whether to have the turtle turn around and return to start with a <y> or <n>" )
- return
- end
- local fuel = turtle.getFuelLevel()
- if fuel < 80 then
- print("Fuel < 80, you must add more fuel")
- return
- end
- --definition of functions follows
- local function tryDig() -- This function digs forward one block
- while turtle.detect() do
- if turtle.dig() then
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp() -- This function digs up one block
- while turtle.detectUp() do
- if turtle.digUp() then
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown() -- This function digs down one block
- while turtle.detectDown() do
- if turtle.digDown() then
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- -- This section is the main control section of the program
- tryDigUp()
- tryDigDown()
- for i = 1, length do -- This is the main control function
- tryDig()
- turtle.forward()
- tryDigUp()
- tryDigDown()
- end
- if turn == "y" then
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, length do -- This is the return function
- turtle.forward()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment