Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Mining Tunnel By HoffyGaming
- -- Version Alpha 1.1
- -- Config
- Version = "Alpha 1.1"
- HeightQuestion = true
- WidthQuestion = true
- LengthQuestion = true
- TorchesQuestion = false
- ChestQuestion = true
- -- Functions
- function version() -- Version function
- return Version
- end
- function clearscreen() -- Clearscreen function
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.green)
- term.clear()
- regwrite( "Mining Tunnel", 12, 1 )
- regwrite( version(), 2, 11 )
- regwrite( "By HoffyGaming", 22, 11 )
- regwrite( "Pour aydan62", 12, 13 )
- 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 casser: 0 |
- |Lumiere poser: 0 |
- |Coffre poser: 0 |
- +--------------------------------+
- | Avancement |
- |[ ]|
- | 0% |
- +--------------------------------+
- ]] )
- placedValue = 0
- minedValue = 0
- chestValue = 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, 10)
- -- Update Percentage Bar
- percentageBar = math.floor(percentage * 0.3)
- columnVar = 4
- while percentageBar > 0 do
- term.setBackgroundColor(colors.red)
- regwrite( "_", columnVar, 9 )
- percentageBar = percentageBar - 1
- columnVar = columnVar + 1
- term.setBackgroundColor(colors.white)
- end
- end
- function placechest() -- Place a chest
- if chest == true then
- if lengthSpacingVar == 0 and ( spaceFromWallVar == 0 or widthSpacingVar == 0 ) then
- turtle.select(2)
- turtle.placeUp()
- sleep(0.5)
- turtle.select(3)
- turtle.dropUp()
- turtle.select(4)
- turtle.dropUp()
- turtle.select(5)
- turtle.dropUp()
- turtle.select(6)
- turtle.dropUp()
- turtle.select(7)
- turtle.dropUp()
- turtle.select(8)
- turtle.dropUp()
- turtle.select(9)
- turtle.dropUp()
- turtle.select(10)
- turtle.dropUp()
- turtle.select(11)
- turtle.dropUp()
- turtle.select(12)
- turtle.dropUp()
- turtle.select(13)
- turtle.dropUp()
- turtle.select(14)
- turtle.dropUp()
- turtle.select(15)
- turtle.dropUp()
- turtle.select(16)
- turtle.dropUp()
- turtle.select(1)
- turtle.placeDown()
- chest = true
- if turtle.getItemCount(2) == 0 then
- noChest = true
- if turtle.getItemCount(2) == 0 then
- noTorches = true
- sleep(0.5)
- end
- spaceFromWallVar = -1
- widthSpacingVar = widthSpacing
- -- Update Torches Placed
- placedValue = placedValue + 1
- arcwrite(placedValue, 33, 5)
- -- Update chest Placer
- chestValue = chestValue + 1
- arcwrite(chestValue, 33, 6)
- end
- 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() do
- turtle.digUp()
- end
- updatetable()
- end
- function digforward() -- Dig forward and update the table
- local moved = moveforward()
- if not moved and turtle.detect() then
- repeat turtle.dig() until moveforward()
- local moved = true
- elseif not moved and not turtle.detect() then
- repeat turtle.attack() until moveforward()
- end
- updatetable()
- end
- function moveforward() -- Move forward
- return turtle.forward()
- end
- function largetunnel() -- Mine a tunnel larger then one wide
- widthvar = width - 1
- while widthvar > 0 do
- if tunnelheight == 1 then
- digdown()
- placechest()
- moveforward()
- end
- if tunnelheight == 2 then
- digdown()
- placechest()
- digforward()
- end
- if tunnelheight == 3 then
- digup()
- digdown()
- placechest()
- 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
- placechest()
- end
- -- Questions
- clearscreen()
- while HeightQuestion == true do -- Height Question
- print("Qu'elle hauteur voulez vous?")
- height = tonumber(read())
- clearscreen()
- if height == nil then
- print( "Veuillez entrez un chiffre valide." )
- elseif height >= 2 then
- HeightQuestion = false
- startheight = height - 3
- elseif height == 1 then
- term.setTextColor(colors.red)
- print( "Le tunnel doit faire 2 de hauteur minimaume." )
- elseif height == 0 then
- term.setTextColor(colors.red)
- print( "Le tunnel ne peut pas etre infinie." )
- else
- term.setTextColor(colors.red)
- print( "Le tunnel ne peut pas etre d'une hauteur negative." )
- term.setTextColor(colors.green)
- end
- end
- clearscreen()
- while WidthQuestion == true do -- Width Question
- print("Qu'elle largeur voulez vous?")
- width = tonumber(read())
- clearscreen()
- if width == nil then
- term.setTextColor(colors.red)
- print( "Veuillez entrez un chiffre valide." )
- elseif width > 0 then
- WidthQuestion = false
- elseif width == 0 then
- term.setTextColor(colors.red)
- print( "Le tunnel ne peut pas etre infinie." )
- else
- term.setTextColor(colors.red)
- print( "Le tunnel ne peut pas etre d'une largeur negative." )
- term.setTextColor(colors.green)
- end
- end
- clearscreen()
- while LengthQuestion == true do -- Length Question
- print("Qu'elle distance voulez vous?")
- length = tonumber(read())
- clearscreen()
- if length == nil then
- term.setTextColor(colors.red)
- print( "Veuillez entrez un chiffre valide." )
- elseif length > 0 then
- LengthQuestion = false
- lengthVar = 0
- elseif length == 0 then
- LengthQuestion = false
- Infinitelength = true
- TorchesQuestion = false
- TorchSpacingQuestion = false
- lengthVar = (-1)
- else
- term.setTextColor(colors.red)
- print( "Le tunnel ne peut pas etre d'une distance negative." )
- term.setTextColor(colors.greeen)
- end
- end
- clearscreen()
- while ChestQuestion == true do -- Chest Question
- print("Voulez vous placer des coffres et de la lumière ?")
- chest = string.lower(read())
- clearscreen()
- if chest == ( 'oui' ) then
- if turtle.getItemCount(2) == 0 then
- term.setTextColor(colors.red)
- print("Veuillez placer les coffres dans le deuxieme slots.")
- else
- chest = true
- ChestQuestion = false
- setspacing()
- lengthSpacingVar = 0
- end
- elseif chest == ( 'non' ) then
- chest = false
- ChestQuestion = false
- else
- term.setTextColor(colors.red)
- print("Veuillez repondre par oui ou non.")
- term.setTextColor(colors.green)
- end
- end
- clearscreen()
- while TorchesQuestion == true do -- Torch Question
- print("Voulez vous placer des torches ou de la glowstone ?")
- light = string.lower(read())
- clearscreen()
- if light == ( 'oui' ) then
- if turtle.getItemCount(1) == 0 then
- term.setTextColor(colors.red)
- print("Veuillez placer les items dans le premier slots.")
- else
- torches = true
- TorchesQuestion = false
- noTorches = false
- setspacing()
- lengthSpacingVar = 0
- end
- elseif light == ( 'non' ) then
- torches = false
- TorchesQuestion = false
- else
- term.setTextColor(colors.red)
- print("Veuillez repondre par oui ou non.")
- term.setTextColor(colors.green)
- end
- end
- -- Create the gui
- createtable()
- -- Mining Loop
- turtle.up()
- while startheight > 0 do
- local moved = turtle.up()
- if not moved and turtle.detectUp() then
- repeat turtle.digUp() until turtle.up()
- local moved = true
- elseif not moved and not turtle.detectUp() then
- repeat turtle.attackUp() until turtle.up()
- end
- startheight = startheight - 1
- end
- while lengthVar < length do
- lengthVar = lengthVar + 1
- digforward()
- if width > 1 then
- turtle.turnRight()
- end
- 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, 12 )
- term.setBackgroundColor(colors.white)
- if noTorches == true then
- term.setTextColor(colors.red)
- print ("Il n'y a plus de torche!")
- if noChest == true then
- term.setTextColor(colors.red)
- print ("Il n'y a plus de coffre!")
- term.setTextColor(colors.green)
- else
- print ("Tunnel Terminer!")
- end
- term.setCursorPos( 1, 2 )
- else
- if width > 1 then
- turtle.turnRight()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement