Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local length = tArgs[1]
- local numTunnels = tArgs[2]
- local inv = true
- local checkTorch = 0
- local height = 0
- -- The basic function to move forward and dig
- function tunnel()
- -- These used throughout to erase screen
- term.clear()
- term.setCursorPos(1,1)
- print("Mining...")
- for i=1,length do
- fuel()
- turtle.dig()
- -- This loop prevents gravel from screwing it all up
- while turtle.forward() == false do
- turtle.dig()
- end
- turtle.digUp()
- torch()
- end
- end
- -- The function to turn around and go the other direction down the tunnel, also clears side tunnels
- function turnAround()
- term.clear()
- term.setCursorPos(1,1)
- print("Turning around...")
- for k = 1,6 do
- fuel()
- turtle.dig()
- while turtle.forward() == false do
- turtle.dig()
- end
- turtle.digUp()
- torch()
- end
- checkInv()
- while turtle.back() == false do
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- for i = 1,3 do
- turtle.forward()
- turtle.dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i = 1,3 do
- turtle.back()
- end
- end
- turtle.back()
- turtle.back()
- end
- -- Clears the specified item from the inventory, most likely cobble
- function checkInv()
- term.clear()
- term.setCursorPos(1,1)
- print("Trashing...")
- for y = 2,16 do
- turtle.select(y)
- if turtle.compareTo(1) then
- turtle.drop()
- end
- end
- end
- -- Checks how long since the last torch, then decides to place one above or not
- function torch()
- -- Checks if low on torches
- if turtle.getItemCount(16) < 5 then
- term.clear()
- term.setCursorPos(1,1)
- print("Waiting for torches...place in bottom right.")
- while turtle.getItemCount(16) < 5 do
- sleep(2)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Mining...")
- if checkTorch == 8 then
- fuel()
- turtle.select(16)
- turtle.up()
- turtle.digUp()
- -- This if and loop will bring the turtle back down from the placed torch
- if turtle.placeUp() or turtle.getItemCount(16) == 0 then
- for i = 0,height do
- fuel()
- turtle.down()
- end
- turtle.select(1)
- checkTorch = 0
- height = 0
- else
- height = height + 1
- torch()
- end
- -- If it's too soon, dont place a torch
- else
- checkTorch = checkTorch + 1
- end
- end
- -- Checks the fuel level, asks for more if necessary
- function fuel()
- if turtle.getFuelLevel() < 50 then
- print ("Wating for fuel...place in bottom left.")
- while turtle.getFuelLevel() < 50 do
- turtle.select(13)
- turtle.refuel()
- sleep(2)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Mining...")
- turtle.select(1)
- end
- -- This function is a one time startup function, makes sure the turtle has the necessary materials
- function begin()
- turtle.select(1)
- -- Checks for trash item
- if turtle.getItemCount(1) == 0 then
- print("Please place an item to trash in the top left.")
- while turtle.getItemCount(1) == 0 do
- sleep(1)
- end
- term.clear()
- term.setCursorPos(1,1)
- begin()
- -- Confirms trashed item
- else
- print("The item in the top left will be trashed...confirm?")
- os.pullEvent("key")
- end
- term.clear()
- term.setCursorPos(1,1)
- end
- -- From here is the main code
- begin()
- -- Loops for the specified # of tunnels, one tunnel being up and back
- for j = 1,numTunnels do
- tunnel()
- turtle.turnLeft()
- turnAround()
- turtle.turnLeft()
- tunnel()
- turtle.turnRight()
- turnAround()
- turtle.turnRight()
- end
- -- Resets the screen and displays a confirmation of finishing
- term.clear()
- term.setCursorPos(1,1)
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment