Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- get arguments
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: basicTunne; <Tunnel Length>" )
- return
- end
- local tunnelLength = tonumber( tArgs[1] )
- if tunnelLength < 1 then
- print( "Tunnel Length must be positive!" )
- return
- end
- -- stolen collect function
- local function collect()
- local bFull = true
- local nTotalItems = 0
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount == 0 then
- bFull = false
- end
- nTotalItems = nTotalItems + nCount
- end
- if nTotalItems > collected then
- collected = nTotalItems
- if math.fmod(collected + unloaded, 50) == 0 then
- print( "Mined "..(collected + unloaded).." items." )
- end
- end
- if bFull then
- print( "No empty slots left." )
- return false
- end
- return true
- end
- -- function to tunnel 1x3 directly in front
- local function digInFront ()
- if turtle.detectUp() then
- if turtle.digUp() then
- if not collect() then
- error()
- end
- end
- end
- if turtle.detect() then
- if turtle.dig() then
- if not collect() then
- error()
- end
- end
- end
- if turtle.detectDown() then
- if turtle.digDown() then
- if not collect() then
- error()
- end
- end
- end
- end
- -- function to move x blocks in given direction (left / right) maintaining orientation
- local function move(numToMove, orientation)
- local cleanNumToMove = tonumber( numToMove )
- if orientation == "left" then
- if turtle.turnLeft() then
- for i = 1, cleanNumToMove, 1 do
- turtle.forward()
- end
- turtle.turnRight()
- end
- end
- if orientation == "right" then
- if turtle.turnRight() then
- for i = 1, cleanNumToMove, 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- end
- end
- -- program start
- local done = false
- while not done do
- for n = 1, tunnelLength/2 do
- digInFront()
- move(1, "right")
- digInFront()
- move(1, "right")
- digInFront()
- turtle.forward()
- digInFront()
- move(1, "left")
- digInFront()
- move(1, "left")
- digInFront()
- end
- done = true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement