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 skipedRows == nil do
- term.setCursorPos(1, 4)
- term.clearLine()
- term.write("Skip Rows: ")
- skipedRows = tonumber(read())
- end
- if tunnelHeight > 1 then
- while lightSpacing == nil do
- term.setCursorPos(1, 5)
- term.clearLine()
- term.write("Light spacing (0 for no lights): ")
- lightSpacing = tonumber(read())
- if lightSpacing == 1 then
- print(" - Must be greater then 1")
- lightSpacing = nil
- end
- end
- else
- lightSpacing = 0
- end
- local estimatedFuelUsage = tunnelWidth*2*tunnelLength*tunnelHeight
- estimatedFuelUsage = tunnelHeight*2*tunnelLength + estimatedFuelUsage + tunnelLength
- estimatedFuelUsage = skipedRows*2 + estimatedFuelUsage
- estimatedFuelUsage = math.ceil(estimatedFuelUsage)
- term.clear()
- term.setCursorPos(1,1)
- print(""..tunnelLength.." blocks long, "..tunnelWidth.." blocks wide, and "..tunnelHeight.." blocks tall")
- if lightSpacing == 0 then
- print("No lights will be placed")
- else
- print("A light will be placed from slot 16 every "..lightSpacing.." blocks, place a chest to the right to refill")
- 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> to start over or type <exit> to exit program")
- term.write("Confirm: ")
- confirmStart = read()
- if confirmStart == "restart" then
- shell.exit()
- shell.run(shell.getRunningProgram())
- return
- end
- if confirmStart == "exit" then
- term.clear()
- term.setCursorPos(1,1)
- return
- end
- term.clear()
- term.setCursorPos(1, 1)
- local fuelUsed = 0
- local blocksBroken = 0
- local blocksToBreak = tunnelWidth*tunnelHeight*tunnelLength
- local currentTunnelLength = 1
- local turtlePosX = 1
- local turtlePosY = 1
- local turtlePosZ = 0
- local notification = ""
- local startTime = os.epoch("utc")/1000
- function digWidth(w)
- for u = 1, w-1 do
- if shouldPlaceLight() then
- placeLight()
- end
- while turtle.dig() == true do
- blocksBroken = blocksBroken + 1
- sleep(0.6)
- end
- if turtle.forward() == false then
- turtle.dig()
- blocksBroken = blocksBroken + 1
- end
- if turtlePosY%2 == 1 then
- turtlePosX = turtlePosX + 1
- else
- turtlePosX = turtlePosX - 1
- end
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function reverse(w)
- for u = 1, w-1 do
- turtle.back()
- turtlePosX = turtlePosX - 1
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function prepForNextRow()
- while turtle.digUp() == true do
- blocksBroken = blocksBroken + 1
- sleep(0.6)
- end
- if turtle.up() == false then
- turtle.digUp()
- blocksBroken = blocksBroken + 1
- end
- turtlePosY = turtlePosY + 1
- fuelUsed = fuelUsed + 1
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function digOutNextSection()
- while turtle.dig() == true do
- blocksBroken = blocksBroken + 1
- sleep(0.6)
- end
- if turtle.forward() == false then
- turtle.dig()
- blocksBroken = blocksBroken + 1
- end
- turtlePosZ = turtlePosZ + 1
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- turtle.turnRight()
- for h = 1, tunnelHeight do
- notification = "Digging width"
- digWidth(tunnelWidth)
- if h < tunnelHeight then
- prepForNextRow()
- end
- end
- if turtlePosY%2 == 1 then
- notification = "Reversing"
- reverse(tunnelWidth)
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- for h = 1, tunnelHeight-1 do
- while turtle.digDown() == true do
- blocksBroken = blocksBroken + 1
- sleep(0.6)
- end
- if turtle.down() == false then
- turtle.digDown()
- blocksBroken = blocksBroken + 1
- end
- turtlePosY = turtlePosY - 1
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function moveTurtleToChest()
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, currentTunnelLength do
- turtle.forward()
- turtlePosZ = turtlePosZ - 1
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function moveTurtleBackToFront()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, currentTunnelLength do
- turtle.forward()
- turtlePosZ = turtlePosZ + 1
- fuelUsed = fuelUsed + 1
- printTurtleStats()
- end
- end
- function emptyTurtleToChest()
- for i = 1, 15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- 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 shouldPlaceLight()
- if turtlePosX%lightSpacing == 0 and turtlePosZ%lightSpacing == 0 and turtlePosY == 2 then
- return true
- else
- return false
- end
- end
- function hasLights()
- return turtle.getItemCount(16) > 0
- end
- function placeLight()
- if not hasLights() then return end
- turtle.select(16)
- turtle.placeDown()
- turtle.select(1)
- end
- function lightChestAtStart()
- i,cd = turtle.inspect()
- return cd["tags"]["forge:chests"] == true
- end
- function takeLights()
- turtle.select(16)
- turtle.suck(turtle.getItemSpace())
- turtle.select(1)
- end
- function disp_time(time)
- local days = math.floor(time/86400)
- local hours = math.floor(math.mod(time, 86400)/3600)
- local minutes = math.floor(math.mod(time,3600)/60)
- local seconds = math.floor(math.mod(time,60))
- return string.format("%d:%02d:%02d:%02d",days,hours,minutes,seconds)
- end
- function printTurtleStats()
- term.clear()
- term.setCursorPos(1, 1)
- local percent = math.ceil(blocksBroken/blocksToBreak*100)
- local checkTime = os.epoch("utc")/1000
- print("Time Elapsed: "..disp_time(checkTime-startTime))
- print("Progress "..percent.."% complete ("..blocksBroken.."/"..blocksToBreak..")")
- print("Fuel used: "..fuelUsed.."/"..estimatedFuelUsage)
- print("Remaining estimated fuel usage: "..estimatedFuelUsage-fuelUsed)
- print("Fuel remaining: "..turtle.getFuelLevel())
- print("X: "..turtlePosX)
- print("Y: "..turtlePosY)
- print("Z: "..turtlePosZ)
- print(notification)
- end
- for tl = 1, tunnelLength+skipedRows do
- if currentTunnelLength > skipedRows then
- digOutNextSection()
- printTurtleStats()
- if turtleShouldEmpty() and currentTunnelLength ~= tunnelLength then
- notification = "Going to empty inventory"
- moveTurtleToChest()
- emptyTurtleToChest()
- if lightSpacing > 0 then
- turtle.turnLeft()
- if lightChestAtStart() then
- takeLights()
- end
- turtle.turnRight()
- end
- notification = "Moving back from chest"
- moveTurtleBackToFront()
- end
- else
- turtle.forward()
- turtlePosZ = turtlePosZ + 1
- fuelUsed = fuelUsed + 1
- end
- currentTunnelLength = currentTunnelLength + 1
- end
- currentTunnelLength = currentTunnelLength - 1
- moveTurtleToChest()
- printTurtleStats()
- emptyTurtleToChest()
- turtle.turnLeft()
- turtle.turnLeft()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement