Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- while tunnelLength == nil do
- term.setCursorPos(1, 1)
- term.clearLine()
- term.write("Tunnel Length: ")
- tunnelLength = tonumber(read())
- end
- while tunnelWidth == nil do
- term.setCursorPos(1, 2)
- term.clearLine()
- term.write("Tunnel Width: ")
- tunnelWidth = tonumber(read())
- end
- while tunnelHeight == nil do
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Tunnel Height: ")
- tunnelHeight = tonumber(read())
- end
- -- while torchSpacing == nil do
- -- term.setCursorPos(1, 4)
- -- term.clearLine()
- -- term.write("Torch spacing (0 for no torches): ")
- -- torchSpacing = tonumber(read())
- -- end
- local estimatedFuelUsage = tunnelWidth*2*tunnelLength*tunnelHeight
- estimatedFuelUsage = tunnelHeight*2*tunnelLength + estimatedFuelUsage + tunnelLength
- estimatedFuelUsage = math.ceil(estimatedFuelUsage)
- term.clear()
- term.setCursorPos(1,1)
- print("This turtle will dig a tunnel "..tunnelLength.." blocks long, "..tunnelWidth.." blocks wide, and "..tunnelHeight.." blocks tall")
- -- if torchSpacing == 0 then
- -- print("No torches will be placed")
- -- else
- -- print("A torch will be placed every "..torchSpacing.." blocks")
- -- end
- print("")
- print("Current fuel: "..turtle.getFuelLevel())
- print("Estimated fuel usage: "..estimatedFuelUsage)
- if turtle.getFuelLevel() < estimatedFuelUsage then
- print("!!! Turtle may run out of fuel before finishing !!!")
- end
- print("")
- print("Press ENTER to confirm or type <restart> and press enter to start over or type <exit> and press enter to exit program")
- term.write("Confirm: ")
- confirmStart = read()
- if confirmStart == "restart" then
- shell.run(shell.getRunningProgram())
- end
- if confirmStart == "exit" then
- shell.exit()
- end
- term.clear()
- term.setCursorPos(1, 1)
- local fuelUsed = 0
- local turtleLengthProgress = 0
- local blocksBroken = 0
- local blocksToBreak = tunnelWidth*tunnelHeight*tunnelLength
- local currentTunnelLength = 1
- function digHeight(h)
- for u = 1, h-1 do
- turtle.digUp()
- blocksBroken = blocksBroken + 1
- turtle.up()
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function digWidth(w)
- for u = 1, w-1 do
- turtle.dig()
- blocksBroken = blocksBroken + 1
- turtle.forward()
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function reverse(w)
- for u = 1, w-1 do
- turtle.back()
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function digOutNextSection()
- turtle.dig()
- blocksBroken = blocksBroken + 1
- turtle.forward()
- fuelUsed = fuelUsed + 1
- digHeight(tunnelHeight)
- turtle.turnRight()
- for h = 1, tunnelHeight do
- digWidth(tunnelWidth)
- reverse(tunnelWidth)
- turtle.down()
- fuelUsed = fuelUsed + 1
- end
- turtle.turnLeft()
- end
- function moveTurtleToChest()
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, turtleLengthProgress do
- turtle.forward()
- fuelUsed = fuelUsed + 1
- end
- end
- function moveTurtleBackToFront()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, turtleLengthProgress do
- turtle.forward()
- fuelUsed = fuelUsed + 1
- end
- end
- function emptyTurtleToChest()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- i = i + 1
- end
- end
- function turtleShouldEmpty()
- local occupiedSlots = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- occupiedSlots = occupiedSlots + 1
- end
- i = i + 1
- end
- return 16 - occupiedSlots <= 4
- end
- function printTurtleStats()
- term.clear()
- term.setCursorPos(1, 1)
- local percent = math.ceil(blocksBroken/blocksToBreak*100)
- print("Progress "..percent.."% complete ("..blocksBroken.."/"..blocksToBreak..")")
- print("Fuel used: "..fuelUsed.."/"..estimatedFuelUsage)
- print("Remaining estimated fuel usage: "..estimatedFuelUsage-fuelUsed)
- print("Fuel remaining: "..turtle.getFuelLevel())
- end
- for tl = 1, tunnelLength-1 do
- digOutNextSection()
- printTurtleStats()
- turtleLengthProgress = turtleLengthProgress + 1
- if turtleShouldEmpty() then
- print("Going to empty inventory")
- moveTurtleToChest()
- emptyTurtleToChest()
- moveTurtleBackToFront()
- end
- currentTunnelLength = currentTunnelLength + 1
- end
- moveTurtleToChest()
- printTurtleStats()
- emptyTurtleToChest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement