Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if not (#tArgs>0 and #tArgs<3) then
- print( "Usage: tunnel <length> <distance (optional)>" )
- return
- end
- local length = tonumber( tArgs[1] )
- if length < 1 then
- print( "Tunnel length must be positive" )
- return
- end
- local destination = tonumber( tArgs[2] )
- if destination < 0 then
- print("Assuming 0")
- destination = 0
- end
- print("Moving " .. destination .. " blocks to destination...")
- n=0
- while n < destination do
- --print("Destination = "..destination)
- if not turtle.forward() then
- destination = n
- print("Destination = "..destination)
- break
- else
- n = n + 1
- end
- end
- local depth = destination
- local collected = 0
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 64) == 0 then
- print( "Mined " .. collected/64 .. " stacks." )
- end
- end
- local function tryDig()
- while turtle.dig() do
- collect()
- sleep(0.5)
- if not turtle.detect() then
- return true
- end
- end
- return not turtle.detect()
- end
- local function tryForward()
- while not turtle.forward() do
- turtle.dig()
- collect()
- sleep(0.5)
- end
- end
- local function tryDigUp()
- while turtle.digUp() do
- collect()
- sleep(0.5)
- if not turtle.detectUp() then
- return true
- end
- end
- return not turtle.detectUp()
- end
- local function tryDigDown()
- while turtle.digDown() do
- collect()
- sleep(0.5)
- if not turtle.detectDown() then
- return true
- end
- end
- return not turtle.detectDown()
- end
- local function storeItems(a)
- print("Distance to chest: "..depth)
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1,a do
- turtle.forward()
- end
- print("Storing items...")
- for i = 2,15 do
- turtle.select(i)
- turtle.drop()
- end
- print("Returning to end of tunnel...")
- turtle.turnRight()
- turtle.turnRight()
- for i = 1,a do
- turtle.forward()
- end
- end
- local function returnHome(depth)
- print("Returning home, "..depth.." blocks to travel...")
- turtle.turnLeft()
- turtle.turnLeft()
- while depth > 0 do
- if turtle.forward() then
- depth = depth - 1
- else
- turtle.dig()
- end
- end
- print("Storing items...")
- for i = 2,15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turtle.turnRight()
- turtle.turnRight()
- end
- local function returnForFuel(b)
- print("Distance to chest: "..depth)
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1,b do
- turtle.forward()
- end
- print("Awaiting fuel...")
- turtle.select(2)
- while turtle.getFuelLevel() < 2*depth do
- for i=2,15 do
- turtle.select(i)
- turtle.refuel(turtle.getItemCount())
- end
- sleep(10)
- end
- print("Returning to end of tunnel...")
- turtle.turnRight()
- turtle.turnRight()
- for i = 1,b do
- turtle.forward()
- end
- end
- local function placeBlockDown()
- turtle.select(1)
- turtle.placeDown()
- end
- local function placeTorch(d)
- if d%5 == 0 then
- turtle.select(16)
- turtle.place()
- end
- end
- print( "Tunnelling..." )
- local progressMarker = 10
- while depth < destination + length do
- if turtle.getFuelLevel() < 2*depth then
- returnForFuel(depth)
- end
- -- Advance
- tryDig()
- if not turtle.forward() then
- print( "Aborting Tunnel, could not dig" )
- break
- else
- depth = depth + 1
- progress = math.ceil(((depth-destination)*100)/length)
- if progress > progressMarker then
- print("Depth: "..depth..", "..progress.."%")
- progressMarker = progressMarker + 10
- end
- end
- -- Dig sequence
- tryDigUp()
- turtle.turnLeft()
- tryDig()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- tryDigUp()
- tryDig()
- turtle.up()
- tryDigUp()
- tryDig()
- turtle.forward()
- tryDigUp()
- tryDigDown()
- tryDig()
- turtle.forward()
- tryDigUp()
- tryDigDown()
- turtle.down()
- placeBlockDown()
- turtle.back()
- placeTorch(depth-destination)
- turtle.turnLeft()
- -- Check for full
- local checkingSlots = true
- local slotsOccupied = 1
- while checkingSlots == true do
- if turtle.getItemCount(slotsOccupied+1) > 0 then
- slotsOccupied = slotsOccupied + 1
- else
- checkingSlots = false
- end
- if slotsOccupied > 14 then
- checkingSlots = false
- storeItems(depth)
- end
- end
- end
- returnHome(depth)
- print( "Mined "..collected.." blocks total." )
Advertisement
Add Comment
Please, Sign In to add comment