Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Advanced Tunnel by Henness
- -- Version 1.3.1 5/5/2012
- -- Config
- Version = "v1.3.1"
- HeightQuestion = true
- WidthQuestion = true
- LengthQuestion = true
- TorchesQuestion = true
- Intro = true
- -- Functions
- function version() -- Version function
- return Version
- end
- function clearscreen() -- Clearscreen function
- term.clear()
- regwrite( "Advanced Tunnel", 12, 1 )
- regwrite( version(), 2, 12 )
- regwrite( "Designed by Henness", 17, 12 )
- term.setCursorPos( 1, 3 )
- end
- function regwrite(string, columnVar, rowVar) -- Write a string to the cords
- term.setCursorPos( columnVar, rowVar )
- write (string)
- end
- function arcwrite(number, columnVar, rowVar) -- Write a number "right to left" to the cords
- digits = math.ceil(math.log10(number))
- if 10^digits == number then
- digits = digits + 1
- end
- term.setCursorPos( columnVar, rowVar )
- while digits > 1 do
- digits = digits - 1
- columnVar = columnVar - 1
- term.setCursorPos( columnVar, rowVar )
- end
- write (number)
- end
- function createtable() -- Make a table function
- clearscreen()
- print ( [[
- +--------------------------------+
- |Blocks Mined: 0 |
- |Torches Placed: 0 |
- +--------------------------------+
- | Status |
- |[ ]|
- | 0% |
- +--------------------------------+
- ]] )
- placedValue = 0
- minedValue = 0
- end
- function updatetable() -- Update the table
- -- Update Blocks Mined
- minedValue = minedValue + 1
- arcwrite(minedValue, 33, 4)
- -- Update Percentage
- if length > 0 then
- area = (height * width * length)
- else
- area = minedValue
- end
- percentage = math.ceil((minedValue / area) * 100)
- arcwrite(percentage, 19, 9)
- -- Update Percentage Bar
- percentageBar = math.floor(percentage * 0.3)
- columnVar = 4
- while percentageBar > 0 do
- regwrite( "=", columnVar, 8 )
- percentageBar = percentageBar - 1
- columnVar = columnVar + 1
- end
- end
- function placetorch() -- Place a torch
- if torches == true then
- if lengthSpacingVar == 0 and ( spaceFromWallVar == 0 or widthSpacingVar == 0 ) then
- turtle.placeDown()
- if turtle.getItemCount(1) == 0 then
- noTorches = true
- end
- spaceFromWallVar = -1
- widthSpacingVar = widthSpacing
- -- Update Torches Placed
- placedValue = placedValue + 1
- arcwrite(placedValue, 33, 5)
- else
- spaceFromWallVar = spaceFromWallVar - 1
- widthSpacingVar = widthSpacingVar - 1
- end
- end
- end
- function widthtest() -- Test width for numbers that = 4+10n
- widthTestVar = width
- while widthTestVar > 4 do
- widthTestVar = widthTestVar - 10
- end
- if widthTestVar == 4 then
- return true
- end
- end
- function setspacing() -- Calculate spacing of torches
- if width < 6 then
- if math.fmod( width, 2 ) == 0 then -- If even
- if width == 2 then
- lengthSpacing = 9
- spaceFromWall = ( 1 + ( -1 )^placedValue ) / 2
- else
- lengthSpacing = 7
- spaceFromWall = (( 1 + ( -1 )^placedValue ) / 2 ) + 1
- end
- else -- If odd
- spaceFromWall = math.floor( width / 2 )
- if width == 5 then
- lengthSpacing = 6
- elseif width == 3 then
- lengthSpacing = 8
- else
- lengthSpacing = 10
- end
- end
- widthSpacing = -1
- else
- if math.fmod( width, 2 ) == 0 then -- If even
- widthSpacing = 4
- lengthSpacing = 4
- if widthtest() == true or width == 6 then
- spaceFromWall = 0
- else
- spaceFromWallVar = width
- while spaceFromWallVar > 7 do
- spaceFromWallVar = spaceFromWallVar - ( widthSpacing + 1 )
- end
- spaceFromWall = ( spaceFromWallVar - 1 ) / 2
- end
- else -- If odd
- widthSpacing = 5
- lengthSpacing = 4
- if width == 7 then
- spaceFromWall = 0
- else
- spaceFromWallVar = width
- while spaceFromWallVar > 7 do
- spaceFromWallVar = spaceFromWallVar - ( widthSpacing + 1 )
- end
- spaceFromWall = ( spaceFromWallVar - 1 ) / 2
- end
- end
- end
- spaceFromWallVar = spaceFromWall
- widthSpacingVar = widthSpacing
- lengthSpacingVar = lengthSpacing
- end
- function digdown() -- Dig down and update the table
- if turtle.detectDown() then
- turtle.digDown()
- end
- updatetable()
- end
- function digup() -- Dig up and update the table
- while turtle.detectUp() == true do
- turtle.digUp()
- sleep(0.4)
- end
- updatetable()
- end
- function digforward() -- Dig forward and update the table
- while turtle.detect() == true do
- turtle.dig()
- sleep(0.4)
- end
- moveforward()
- updatetable()
- end
- function moveforward() -- Move forward
- repeat
- if turtle.forward() == true then
- moved = true
- else
- moved = false
- end
- until moved == true
- end
- function largetunnel() -- Mine a tunnel larger then one wide
- widthvar = width - 1
- while widthvar > 0 do
- if tunnelheight == 1 then
- digdown()
- placetorch()
- moveforward()
- end
- if tunnelheight == 2 then
- digdown()
- placetorch()
- digforward()
- end
- if tunnelheight == 3 then
- digup()
- digdown()
- placetorch()
- digforward()
- end
- if tunnelheight > 3 then
- digup()
- digdown()
- digforward()
- end
- widthvar = widthvar - 1
- end
- if tunnelheight == 1 then
- digdown()
- tunnelheight = tunnelheight - 1
- elseif tunnelheight == 2 then
- digdown()
- tunnelheight = tunnelheight - 2
- elseif tunnelheight == 3 then
- digup()
- digdown()
- tunnelheight = tunnelheight - 3
- else
- digup()
- digdown()
- tunnelheight = tunnelheight - 3
- if tunnelheight == 1 then
- turtle.down()
- end
- if tunnelheight == 2 then
- turtle.down()
- digdown()
- turtle.down()
- end
- if tunnelheight >= 3 then
- turtle.down()
- digdown()
- turtle.down()
- digdown()
- turtle.down()
- end
- end
- end
- function smalltunnel() -- Mine a one wide tunnel
- if tunnelheight == 2 then
- digdown()
- end
- if tunnelheight == 3 then
- digup()
- digdown()
- end
- if tunnelheight > 3 then
- digup()
- digdown()
- turtle.down()
- tunnelheight = tunnelheight - 3
- while tunnelheight > 1 do
- digdown()
- turtle.down()
- tunnelheight = tunnelheight - 1
- end
- digdown()
- end
- placetorch()
- end
- -- Intro
- if Intro == true then
- term.clear()
- regwrite( [[
- d
- d8
- ]] , 1, 3 )
- sleep(0.001)
- regwrite ( [[
- d
- d8
- d88
- d88P
- d8888
- d88P
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d88
- d888
- d88P8
- d88P 8
- d88P 8
- d88P 8
- d88888888
- d88P 8
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888
- d88888
- d88P888
- d88P 888
- d88P 888 d
- d88P 888 8
- d8888888888 Y
- d88P 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888
- d88888
- d88P888
- d88P 888 .d88
- d88P 888 d88"
- d88P 888 888
- d8888888888 Y88b
- d88P 888 "Y88
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888 888
- d88888 888
- d88P888 888
- d88P 888 .d88888
- d88P 888 d88" 888
- d88P 888 888 888
- d8888888888 Y88b 888
- d88P 888 "Y88888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888 888
- d88888 888
- d88P888 888
- d88P 888 .d88888 888
- d88P 888 d88" 888 888
- d88P 888 888 888 Y88
- d8888888888 Y88b 888 Y8b
- d88P 888 "Y88888 Y8
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888 888
- d88888 888
- d88P888 888
- d88P 888 .d88888 888 888
- d88P 888 d88" 888 888 888
- d88P 888 888 888 Y88 88P
- d8888888888 Y88b 888 Y8bd8P
- d88P 888 "Y88888 Y88P
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888 888
- d88888 888
- d88P888 888
- d88P 888 .d88888 888 888 88
- d88P 888 d88" 888 888 888
- d88P 888 888 888 Y88 88P .d8
- d8888888888 Y88b 888 Y8bd8P 888
- d88P 888 "Y88888 Y88P "Y8
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888 888
- d88888 888
- d88P888 888
- d88P 888 .d88888 888 888 8888b.
- d88P 888 d88" 888 888 888 "88
- 88P 888 888 888 Y88 88P .d88888
- 888888888 Y88b 888 Y8bd8P 888 88
- P 888 "Y88888 Y88P "Y88888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- d8888 888
- 88888 888
- 8P888 888
- P 888 .d88888 888 888 8888b. 88
- 888 d88" 888 888 888 "88b 88
- 888 888 888 Y88 88P .d888888 88
- 88888 Y88b 888 Y8bd8P 888 888 88
- 888 "Y88888 Y88P "Y888888 88
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 8 888
- 8 888
- 8 888
- 8 .d88888 888 888 8888b. 88888b
- 8 d88" 888 888 888 "88b 888 "8
- 8 888 888 Y88 88P .d888888 888 8
- 8 Y88b 888 Y8bd8P 888 888 888 8
- 8 "Y88888 Y88P "Y888888 888 8
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- d88888 888 888 8888b. 88888b.
- 8" 888 888 888 "88b 888 "88b d
- 8 888 Y88 88P .d888888 888 888 8
- 8b 888 Y8bd8P 888 888 888 888 Y
- Y88888 Y88P "Y888888 888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 88
- 88
- 88
- 88 888 888 8888b. 88888b. .d88
- 88 888 888 "88b 888 "88b d88P"
- 88 Y88 88P .d888888 888 888 888
- 88 Y8bd8P 888 888 888 888 Y88b.
- 88 Y88P "Y888888 888 888 "Y88
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 88 888 8888b. 88888b. .d8888b
- 88 888 "88b 888 "88b d88P" d
- 88 88P .d888888 888 888 888 8
- Y8bd8P 888 888 888 888 Y88b. Y
- Y88P "Y888888 888 888 "Y8888P
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888 8888b. 88888b. .d8888b .d88
- 888 "88b 888 "88b d88P" d8P
- 88P .d888888 888 888 888 88888
- 8P 888 888 888 888 Y88b. Y8b.
- P "Y888888 888 888 "Y8888P "Y88
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 8888b. 88888b. .d8888b .d88b.
- "88b 888 "88b d88P" d8P Y8b d
- d888888 888 888 888 88888888 8
- 88 888 888 888 Y88b. Y8b. Y
- Y888888 888 888 "Y8888P "Y8888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- b. 88888b. .d8888b .d88b. .d88
- 88b 888 "88b d88P" d8P Y8b d88"
- 888 888 888 888 88888888 888
- 888 888 888 Y88b. Y8b. Y88b
- 888 888 888 "Y8888P "Y8888 "Y88
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- 88888b. .d8888b .d88b. .d88888
- 888 "88b d88P" d8P Y8b d88" 888
- 888 888 888 88888888 888 888
- 888 888 Y88b. Y8b. Y88b 888
- 888 888 "Y8888P "Y8888 "Y88888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- 8b. .d8888b .d88b. .d88888
- "88b d88P" d8P Y8b d88" 888
- 888 888 88888888 888 888
- 888 Y88b. Y8b. Y88b 888
- 888 "Y8888P "Y8888 "Y88888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888 888
- 888
- 888
- .d8888b .d88b. .d88888
- d88P" d8P Y8b d88" 888
- 888 88888888 888 888
- Y88b. Y8b. Y88b 888
- "Y8888P "Y8888 "Y88888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888 8888888
- 888 888
- 888 888
- 8888b .d88b. .d88888 888
- P" d8P Y8b d88" 888 888
- 88888888 888 888 888
- b. Y8b. Y88b 888 888
- 8888P "Y8888 "Y88888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888 88888888888
- 888 888
- 888 888
- b .d88b. .d88888 888 88
- d8P Y8b d88" 888 888 88
- 88888888 888 888 888 88
- Y8b. Y88b 888 888 Y8
- P "Y8888 "Y88888 888 "
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888 88888888888
- 888 888
- 888 888
- 88b. .d88888 888 888 8
- Y8b d88" 888 888 888 8
- 88888 888 888 888 888 8
- . Y88b 888 888 Y88b 8
- 8888 "Y88888 888 "Y888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888 88888888888
- 888 888
- 888 888
- .d88888 888 888 888 8
- b d88" 888 888 888 888 8
- 8 888 888 888 888 888 8
- Y88b 888 888 Y88b 888 8
- "Y88888 888 "Y88888 8
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888 88888888888
- 888 888
- 888 888
- d88888 888 888 888 88888
- 8" 888 888 888 888 888 "
- 8 888 888 888 888 888
- 8b 888 888 Y88b 888 888
- Y88888 888 "Y88888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 88 88888888888
- 88 888
- 88 888
- 88 888 888 888 88888b.
- 88 888 888 888 888 "88b
- 88 888 888 888 888 888
- 88 888 Y88b 888 888 888
- 88 888 "Y88888 888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 88888888888
- 888
- 888
- 888 888 888 88888b. 8888
- 888 888 888 888 "88b 888
- 888 888 888 888 888 888
- 888 Y88b 888 888 888 888
- 888 "Y88888 888 888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 88888888888
- 888
- 888
- 888 888 888 88888b. 88888b.
- 888 888 888 888 "88b 888 "88b
- 888 888 888 888 888 888 888
- 888 Y88b 888 888 888 888 888
- 888 "Y88888 888 888 888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 8888888
- 888
- 888
- 888 888 888 88888b. 88888b. .d
- 888 888 888 888 "88b 888 "88b d8P
- 888 888 888 888 888 888 888 888
- 888 Y88b 888 888 888 888 888 Y8b
- 888 "Y88888 888 888 888 888 "Y
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888 888 88888b. 88888b. .d88b.
- 888 888 888 "88b 888 "88b d8P Y8
- 888 888 888 888 888 888 8888888
- Y88b 888 888 888 888 888 Y8b.
- "Y88888 888 888 888 888 "Y8888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 88
- 88
- 88
- 888 88888b. 88888b. .d88b. 88
- 888 888 "88b 888 "88b d8P Y8b 88
- 888 888 888 888 888 88888888 88
- b 888 888 888 888 888 Y8b. 88
- 88888 888 888 888 888 "Y8888 88
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- 8 88888b. 88888b. .d88b. 888
- 8 888 "88b 888 "88b d8P Y8b 888
- 8 888 888 888 888 88888888 888
- 8 888 888 888 888 Y8b. 888
- 8 888 888 888 888 "Y8888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- 888b. 88888b. .d88b. 888
- 8 "88b 888 "88b d8P Y8b 888
- 8 888 888 888 88888888 888
- 8 888 888 888 Y8b. 888
- 8 888 888 888 "Y8888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- . 88888b. .d88b. 888
- 8b 888 "88b d8P Y8b 888
- 88 888 888 88888888 888
- 88 888 888 Y8b. 888
- 88 888 888 "Y8888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- 8888b. .d88b. 888
- 88 "88b d8P Y8b 888
- 88 888 88888888 888
- 88 888 Y8b. 888
- 88 888 "Y8888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- b. .d88b. 888
- 88b d8P Y8b 888
- 888 88888888 888
- 888 Y8b. 888
- 888 "Y8888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- .d88b. 888
- d8P Y8b 888
- 88888888 888
- Y8b. 888
- "Y8888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- 8b. 888
- Y8b 888
- 8888 888
- 888
- 888 888
- ]] , 1, 3 )
- sleep(0.001)
- regwrite( [[
- 888
- 888
- 888
- 888
- 888
- 888
- 888
- 888
- ]] , 1, 3 )
- term.clear()
- sleep(0.2)
- end
- -- Questions
- clearscreen()
- while HeightQuestion == true do -- Height Question
- print("Height of tunnel?")
- height = tonumber(read())
- clearscreen()
- if height == nil then
- print( "Please answer with a number." )
- elseif height >= 2 then
- HeightQuestion = false
- startheight = height - 3
- elseif height == 1 then
- print( "The tunnel height must be larger than one." )
- elseif height == 0 then
- print( "The tunnel height can't be infinite." )
- else
- print( "The tunnel height must be positive." )
- end
- end
- clearscreen()
- while WidthQuestion == true do -- Width Question
- print("Width of tunnel?")
- width = tonumber(read())
- clearscreen()
- if width == nil then
- print( "Please answer with a number." )
- elseif width > 0 then
- WidthQuestion = false
- elseif width == 0 then
- print( "The tunnel width can't be infinite." )
- else
- print( "The tunnel width must be positive." )
- end
- end
- clearscreen()
- while LengthQuestion == true do -- Length Question
- print("Length of tunnel?")
- length = tonumber(read())
- clearscreen()
- if length == nil then
- print( "Please answer with a number." )
- elseif length > 0 then
- LengthQuestion = false
- lengthVar = 0
- elseif length == 0 then
- LengthQuestion = false
- Infinitelength = true
- TorchesQuestion = false
- TorchSpacingQuestion = false
- lengthVar = (-1)
- else
- print( "The tunnel length must be positive." )
- end
- end
- clearscreen()
- while TorchesQuestion == true do -- Torch Question
- print("Place torches?")
- light = string.lower(read())
- clearscreen()
- if light == ( 'yes' ) then
- if turtle.getItemCount(1) == 0 then
- print("Please place torches in the first inventory slot.")
- else
- torches = true
- TorchesQuestion = false
- noTorches = false
- setspacing()
- lengthSpacingVar = 0
- end
- elseif light == ( 'no' ) then
- torches = false
- TorchesQuestion = false
- else
- print("Please answer yes or no.")
- end
- end
- -- Create the gui
- createtable()
- -- Mining Loop
- turtle.up()
- while startheight > 0 do
- turtle.up()
- startheight = startheight - 1
- end
- while lengthVar < length do
- lengthVar = lengthVar + 1
- digforward()
- if width > 1 then
- turtle.turnRight()
- end
- -- Mine a one wide tunnel or a larger tunnel.
- tunnelheight = height
- if width > 1 then
- while tunnelheight > 0 do
- largetunnel()
- turtle.turnRight()
- turtle.turnRight()
- if tunnelheight > 0 then
- largetunnel()
- if tunnelheight > 0 then
- turtle.turnRight()
- turtle.turnRight()
- end
- else
- widthvar = width - 1
- while widthvar > 0 do
- moveforward()
- widthvar = widthvar - 1
- end
- end
- end
- else
- smalltunnel()
- end
- if torches == true then
- if lengthSpacingVar == 0 then
- spaceFromWallVar = spaceFromWall
- widthSpacingVar = widthSpacing
- lengthSpacingVar = lengthSpacing
- else
- spaceFromWallVar = spaceFromWall
- widthSpacingVar = widthSpacing
- lengthSpacingVar = lengthSpacingVar - 1
- end
- end
- startheight = height - 3
- while startheight > 0 do
- turtle.up()
- startheight = startheight - 1
- end
- -- Infinite Length
- if Infinitelength == true then
- lengthVar = lengthVar - 1
- end
- -- Stop or Continue
- if lengthVar == length or noTorches == true then
- if width > 1 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.turnRight()
- end
- while lengthVar > 0 do
- moveforward()
- lengthVar = lengthVar - 1
- end
- while startheight < ( height - 3 ) do
- turtle.down()
- startheight = startheight + 1
- end
- turtle.turnLeft()
- turtle.turnLeft()
- lengthVar = length
- term.setCursorPos( 1, 11 )
- if noTorches == true then
- print ("Out of Torches!")
- else
- print ("Tunnel Complete!")
- end
- term.setCursorPos( 1, 2 )
- else
- if width > 1 then
- turtle.turnRight()
- end
- end
- end
Add Comment
Please, Sign In to add comment