Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sizeX = 1
- sizeY = 1
- sizeZ = 1
- posX = 1
- posY = 1
- posZ = 0
- torchSpace = 0
- torchCount = 0
- reverse = false
- finished = false
- function refreshDisplay()
- shell.run("clear")
- print("")
- print("Tunnel Size: " .. sizeX .. "x" .. sizeY)
- print("Target Depth: " .. sizeZ)
- if torchSpace > 0 then
- print("Torch Spacing: " .. torchSpace)
- else
- print("Torch Spacing: n/a")
- end
- print("")
- print("Current Depth: " .. posZ)sizeX = 1
- sizeY = 1
- sizeZ = 1
- posX = 1
- posY = 1
- posZ = 0
- torchSpace = 0
- torchCount = 0
- reverse = false
- finished = false
- function refreshDisplay()
- shell.run("clear")
- print("")
- print("Tunnel Size: " .. sizeX .. "x" .. sizeY)
- print("Target Depth: " .. sizeZ)
- if torchSpace > 0 then
- print("Torch Spacing: " .. torchSpace)
- else
- print("Torch Spacing: n/a")
- end
- print("")
- print("Current Depth: " .. posZ)
- print("Fuel Level: " .. turtle.getFuelLevel())
- print("Torch Count: " .. turtle.getItemCount(1))
- print("")
- print("Progress: " .. getProgress() .. "%")
- end
- function round(n)
- if n >= 0 then
- return math.floor(n + .5)
- else
- return math.ceil(ns - .5)
- end
- end
- function getProgress()
- if finished then
- return 100
- elseif posZ <= 0 then
- return 0
- else
- return round(((posZ - 1) / sizeZ) * 100)
- end
- end
- function init()
- shell.run("clear")
- -- Width
- print("")
- io.write("How wide do you want the tunnel? ")
- sizeX = io.read()
- if tonumber(sizeX) ~= nil then
- sizeX = tonumber(sizeX)
- else
- print("")
- print("You have entered an invalid width.")
- print("Terminating")
- return false
- end
- -- Height
- print("")
- io.write("How tall do you want the tunnel? ")
- sizeY = io.read()
- if tonumber(sizeY) ~= nil then
- sizeY = tonumber(sizeY)
- else
- print("")
- print("You have entered an invalid height.")
- print("Terminating")
- return false
- end
- -- Depth
- print("")
- io.write("How deep do you want the tunnel? ")
- sizeZ = io.read()
- if tonumber(sizeZ) ~= nil then
- sizeZ = tonumber(sizeZ)
- else
- print("")
- print("You have entered an invalid depth.")
- print("Terminating")
- return false
- end
- -- Torch Spacing
- print("")
- io.write("How often would you like to place torches? ")
- torchSpace = io.read()
- if tonumber(torchSpace) ~= nil then
- torchSpace = tonumber(torchSpace)
- torchCount = 1
- else
- torchSpace = 0
- end
- return true
- end
- function refuel(turns)
- if turtle.getFuelLevel() < turns then
- for p = 1, 16, 1 do
- if turtle.getItemCount(p) > 0 then
- turtle.select(p)
- if turtle.refuel(1) then
- break
- end
- end
- end
- end
- end
- function returnHome()
- if posY > 1 then
- refuel(posY - 1)
- for p = posY - 1, 1, -1 do
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- end
- end
- if posX > 1 then
- refuel(posX - 1)
- turtle.turnLeft()
- for p = posX - 1, 1, -1 do
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- end
- turtle.turnRight()
- end
- for p = posZ, 1, -1 do
- turtle.back()
- end
- end
- function shiftPos()
- refuel(1)
- if posX == 1 and sizeX > 1 then
- turtle.turnRight()
- elseif posX == sizeX and sizeX > 1 then
- turtle.turnLeft()
- end
- if posZ < sizeZ or (posX > 1 and posX < sizeX) or (posX == 1 and not reverse and sizeX > 1) or (posX == sizeX and reverse and sizeX > 1) then
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- if reverse then
- posX = posX - 1
- if posX == 0 then
- posX = 1
- posZ = posZ + 1
- if torchSpace > 0 and torchCount == torchSpace then
- torchCount = 1
- elseif torchSpace > 0 then
- torchCount = torchCount + 1
- end
- reverse = false
- end
- else
- posX = posX + 1
- if posX > sizeX then
- posX = sizeX
- posZ = posZ + 1
- if torchSpace > 0 and torchCount == torchSpace then
- torchCount = 1
- elseif torchSpace > 0 then
- torchCount = torchCount + 1
- end
- reverse = true
- end
- end
- end
- end
- function sliver()
- if posY == 1 then
- refuel(sizeY - posY)
- while posY < sizeY do
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.down()
- posY = posY + 1
- end
- shiftPos()
- elseif posY == sizeY then
- refuel(posY - 1)
- while posY > 1 do
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- posY = posY - 1
- if torchCount == 1 then
- if posY == sizeY - 1 and ((not reverse and posX == 2) or (reverse and posX == 1)) then
- turtle.select(1)
- turtle.placeDown()
- end
- end
- end
- shiftPos()
- else
- print("Unexpected position (X=" .. posX .. ", Y=" .. posY .. ", Z=" .. posZ .. ")")
- returnHome()
- end
- end
- function slice()
- for p = 1, sizeX, 1 do
- sliver()
- refreshDisplay()
- end
- end
- if init() then
- refuel(1)
- refreshDisplay()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- posZ = 1
- refreshDisplay()
- for p = 1, sizeZ, 1 do
- slice()
- end
- finished = true
- refreshDisplay()
- returnHome()
- end
- sizeY = io.read()
- if tonumber(sizeY) ~= nil then
- sizeY = tonumber(sizeY)
- else
- print("")
- print("You have entered an invalid height.")
- print("Terminating")
- return false
- end
- -- Depth
- print("")
- io.write("How deep do you want the tunnel? ")
- sizeZ = io.read()
- if tonumber(sizeZ) ~= nil then
- sizeZ = tonumber(sizeZ)
- else
- print("")
- print("You have entered an invalid depth.")
- print("Terminating")
- return false
- end
- -- Torch Spacing
- print("")
- io.write("How often would you like to place torches? ")
- torchSpace = io.read()
- if tonumber(torchSpace) ~= nil then
- torchSpace = tonumber(torchSpace)
- torchCount = 1
- else
- torchSpace = 0
- end
- return true
- end
- function refuel(turns)
- if turtle.getFuelLevel() < turns then
- for p = 1, 16, 1 do
- if turtle.getItemCount(p) > 0 then
- turtle.select(p)
- if turtle.refuel(1) then
- break
- end
- end
- end
- end
- end
- function returnHome()
- if posY > 1 then
- refuel(posY - 1)
- for p = posY - 1, 1, -1 do
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- end
- end
- if posX > 1 then
- refuel(posX - 1)
- turtle.turnLeft()
- for p = posX - 1, 1, -1 do
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- end
- turtle.turnRight()
- end
- for p = posZ, 1, -1 do
- turtle.back()
- end
- end
- function shiftPos()
- refuel(1)
- if posX == 1 and sizeX > 1 then
- turtle.turnRight()
- elseif posX == sizeX and sizeX > 1 then
- turtle.turnLeft()
- end
- if posZ < sizeZ or (posX > 1 and posX < sizeX) or (posX == 1 and not reverse and sizeX > 1) or (posX == sizeX and reverse and sizeX > 1) then
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- if reverse then
- posX = posX - 1
- if posX == 0 then
- posX = 1
- posZ = posZ + 1
- if torchSpace > 0 and torchCount == torchSpace then
- torchCount = 1
- elseif torchSpace > 0 then
- torchCount = torchCount + 1
- end
- reverse = false
- end
- else
- posX = posX + 1
- if posX > sizeX then
- posX = sizeX
- posZ = posZ + 1
- if torchSpace > 0 and torchCount == torchSpace then
- torchCount = 1
- elseif torchSpace > 0 then
- torchCount = torchCount + 1
- end
- reverse = true
- end
- end
- end
- end
- function sliver()
- if posY == 1 then
- refuel(sizeY - posY)
- while posY < sizeY do
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.down()
- posY = posY + 1
- end
- shiftPos()
- elseif posY == sizeY then
- refuel(posY - 1)
- while posY > 1 do
- if turtle.detectUp() then
- turtle.digUp()
- end
- turtle.up()
- posY = posY - 1
- if torchCount == 1 then
- if posY == sizeY - 1 and ((not reverse and posX == 2) or (reverse and posX == 1)) then
- turtle.select(1)
- turtle.placeDown()
- end
- end
- end
- shiftPos()
- else
- print("Unexpected position (X=" .. posX .. ", Y=" .. posY .. ", Z=" .. posZ .. ")")
- returnHome()
- end
- end
- function slice()
- for p = 1, sizeX, 1 do
- sliver()
- refreshDisplay()
- end
- end
- if init() then
- refuel(1)
- refreshDisplay()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- posZ = 1
- refreshDisplay()
- for p = 1, sizeZ, 1 do
- slice()
- end
- finished = true
- refreshDisplay()
- returnHome()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement