Advertisement
MrHoffyGaming

Mining Tunnel A-1

Oct 25th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.86 KB | None | 0 0
  1. -- Mining Tunnel By HoffyGaming
  2. -- Version Alpha 1.1
  3.  
  4. -- Config
  5. Version = "Alpha 1.1"
  6. HeightQuestion = true
  7. WidthQuestion = true
  8. LengthQuestion = true
  9. TorchesQuestion = false
  10. ChestQuestion = true
  11.  
  12. -- Functions
  13. function version() -- Version function
  14.         return Version
  15. end
  16.  
  17. function clearscreen() -- Clearscreen function
  18.         term.setBackgroundColor(colors.white)
  19.         term.setTextColor(colors.green)
  20.         term.clear()
  21.         regwrite( "Mining Tunnel", 12, 1 )
  22.         regwrite( version(), 2, 11 )
  23.         regwrite( "By HoffyGaming", 22, 11 )
  24.         regwrite( "Pour aydan62", 12, 13 )
  25.         term.setCursorPos( 1, 3 )
  26. end
  27.  
  28. function regwrite(string, columnVar, rowVar) -- Write a string to the cords
  29.         term.setCursorPos( columnVar, rowVar )
  30.         write (string)
  31. end
  32.  
  33. function arcwrite(number, columnVar, rowVar) -- Write a number "right to left" to the cords
  34.         digits = math.ceil(math.log10(number))
  35.         if 10^digits == number then
  36.                 digits = digits + 1
  37.         end
  38.         term.setCursorPos( columnVar, rowVar )
  39.         while digits > 1 do
  40.                 digits = digits - 1
  41.                 columnVar = columnVar - 1
  42.                 term.setCursorPos( columnVar, rowVar )
  43.         end
  44.         write (number)
  45. end
  46.  
  47. function createtable() -- Make a table function
  48. clearscreen()
  49. print ( [[
  50.  +--------------------------------+
  51.  |Blocks casser:                0 |
  52.  |Lumiere poser:                0 |
  53.  |Coffre poser:                 0 |
  54.  +--------------------------------+
  55.  |           Avancement           |
  56.  |[                              ]|
  57.  |                0%              |
  58.  +--------------------------------+
  59. ]] )
  60. placedValue = 0
  61. minedValue = 0
  62. chestValue = 0
  63. end
  64.  
  65. function updatetable() -- Update the table
  66.         -- Update Blocks Mined
  67.         minedValue = minedValue + 1
  68.         arcwrite(minedValue, 33, 4)
  69.        
  70.         -- Update Percentage
  71.         if length > 0 then
  72.                 area = (height * width * length)
  73.         else
  74.                 area = minedValue
  75.         end
  76.         percentage = math.ceil((minedValue / area) * 100)
  77.         arcwrite(percentage, 19, 10)
  78.        
  79.         -- Update Percentage Bar
  80.         percentageBar = math.floor(percentage * 0.3)
  81.         columnVar = 4
  82.         while percentageBar > 0 do
  83.         term.setBackgroundColor(colors.red)
  84.                 regwrite( "_", columnVar, 9 )
  85.                 percentageBar = percentageBar - 1
  86.                 columnVar = columnVar + 1
  87. term.setBackgroundColor(colors.white)
  88.         end
  89. end
  90.  
  91. function placechest() -- Place a chest
  92.         if chest == true then
  93.                 if lengthSpacingVar == 0 and ( spaceFromWallVar == 0 or widthSpacingVar == 0 ) then
  94.                 turtle.select(2)
  95.                         turtle.placeUp()
  96.                         sleep(0.5)
  97.                         turtle.select(3)
  98.                         turtle.dropUp()
  99.                         turtle.select(4)
  100.                         turtle.dropUp()
  101.                         turtle.select(5)
  102.                         turtle.dropUp()
  103.                         turtle.select(6)
  104.                         turtle.dropUp()
  105.                         turtle.select(7)
  106.                         turtle.dropUp()
  107.                         turtle.select(8)
  108.                         turtle.dropUp()
  109.                         turtle.select(9)
  110.                         turtle.dropUp()
  111.                         turtle.select(10)
  112.                         turtle.dropUp()
  113.                         turtle.select(11)
  114.                         turtle.dropUp()
  115.                         turtle.select(12)
  116.                         turtle.dropUp()
  117.                         turtle.select(13)
  118.                         turtle.dropUp()
  119.                         turtle.select(14)
  120.                         turtle.dropUp()
  121.                         turtle.select(15)
  122.                         turtle.dropUp()
  123.                         turtle.select(16)
  124.                         turtle.dropUp()
  125.                         turtle.select(1)
  126.                         turtle.placeDown()
  127.                        
  128.                         chest = true
  129.                         if turtle.getItemCount(2) == 0 then
  130.                         noChest = true
  131.                         if turtle.getItemCount(2) == 0 then
  132.                         noTorches = true
  133.                         sleep(0.5)
  134.                         end
  135.                         spaceFromWallVar = -1
  136.                         widthSpacingVar = widthSpacing
  137.                        
  138.                         -- Update Torches Placed
  139.                         placedValue = placedValue + 1
  140.                         arcwrite(placedValue, 33, 5)
  141.                        
  142.                         -- Update chest Placer
  143.                         chestValue = chestValue + 1
  144.                         arcwrite(chestValue, 33, 6)
  145.                         end
  146.                 end
  147.         end
  148. end
  149.  
  150. function widthtest() -- Test width for numbers that = 4+10n
  151.         widthTestVar = width
  152.         while widthTestVar > 4 do
  153.                 widthTestVar = widthTestVar - 10
  154.         end
  155.         if widthTestVar == 4 then
  156.                 return true
  157.         end
  158. end
  159.  
  160. function setspacing() -- Calculate spacing of torches
  161.         if width < 6 then
  162.                 if math.fmod( width, 2 ) == 0 then -- If even
  163.                         if width == 2 then
  164.                                 lengthSpacing = 9
  165.                                 spaceFromWall = ( 1 + ( -1 )^placedValue ) / 2
  166.                         else
  167.                                 lengthSpacing = 7
  168.                                 spaceFromWall = (( 1 + ( -1 )^placedValue ) / 2 ) + 1
  169.                         end
  170.                 else -- If odd
  171.                         spaceFromWall = math.floor( width / 2 )
  172.                         if width == 5 then
  173.                                 lengthSpacing = 6
  174.                         elseif width == 3 then
  175.                                 lengthSpacing = 8
  176.                         else
  177.                                 lengthSpacing = 10
  178.                         end
  179.                 end
  180.                 widthSpacing = -1
  181.         else
  182.                 if math.fmod( width, 2 ) == 0 then -- If even
  183.                         widthSpacing = 4
  184.                         lengthSpacing = 4
  185.                         if widthtest() == true or width == 6 then
  186.                                 spaceFromWall = 0                      
  187.                         else
  188.                                 spaceFromWallVar = width
  189.                                 while spaceFromWallVar > 7 do
  190.                                         spaceFromWallVar = spaceFromWallVar - ( widthSpacing + 1 )
  191.                                 end
  192.                                 spaceFromWall = ( spaceFromWallVar - 1 ) / 2
  193.                         end
  194.                 else -- If odd
  195.                         widthSpacing = 5
  196.                         lengthSpacing = 4
  197.                         if width == 7 then
  198.                                 spaceFromWall = 0
  199.                         else
  200.                                 spaceFromWallVar = width
  201.                                 while spaceFromWallVar > 7 do
  202.                                         spaceFromWallVar = spaceFromWallVar - ( widthSpacing + 1 )
  203.                                 end
  204.                                 spaceFromWall = ( spaceFromWallVar - 1 ) / 2
  205.                         end
  206.                 end
  207.         end
  208.         spaceFromWallVar = spaceFromWall
  209.         widthSpacingVar = widthSpacing
  210.         lengthSpacingVar = lengthSpacing
  211. end
  212.  
  213. function digdown() -- Dig down and update the table
  214.         if turtle.detectDown() then
  215.                 turtle.digDown()
  216.         end
  217.         updatetable()
  218. end
  219.  
  220. function digup() -- Dig up and update the table
  221.         while turtle.detectUp() do
  222.                 turtle.digUp()
  223.         end
  224.         updatetable()
  225. end
  226.  
  227. function digforward() -- Dig forward and update the table
  228.         local moved = moveforward()
  229.         if not moved and turtle.detect() then
  230.                 repeat turtle.dig() until moveforward()
  231.                 local moved = true
  232.         elseif not moved and not turtle.detect() then
  233.                 repeat turtle.attack() until moveforward()
  234.         end
  235.         updatetable()
  236. end
  237.  
  238. function moveforward() -- Move forward
  239.         return turtle.forward()
  240. end
  241.  
  242. function largetunnel() -- Mine a tunnel larger then one wide
  243.         widthvar = width - 1
  244.         while widthvar > 0 do
  245.                 if tunnelheight == 1 then
  246.                         digdown()
  247.                         placechest()
  248.                         moveforward()
  249.                 end
  250.                 if tunnelheight == 2 then
  251.                         digdown()
  252.                         placechest()
  253.                         digforward()
  254.                 end
  255.                 if tunnelheight == 3 then
  256.                         digup()
  257.                         digdown()
  258.                         placechest()
  259.                         digforward()
  260.                 end
  261.                 if tunnelheight > 3 then
  262.                         digup()
  263.                         digdown()
  264.                         digforward()
  265.                 end
  266.                 widthvar = widthvar - 1
  267.         end
  268.         if tunnelheight == 1 then
  269.                 digdown()
  270.                 tunnelheight = tunnelheight - 1
  271.         elseif tunnelheight == 2 then
  272.                 digdown()
  273.                 tunnelheight = tunnelheight - 2
  274.         elseif tunnelheight == 3 then
  275.                 digup()
  276.                 digdown()
  277.                 tunnelheight = tunnelheight - 3
  278.         else
  279.                 digup()
  280.                 digdown()
  281.                 tunnelheight = tunnelheight - 3
  282.                 if tunnelheight == 1 then
  283.                         turtle.down()
  284.                 end
  285.                 if tunnelheight == 2 then
  286.                         turtle.down()
  287.                         digdown()
  288.                         turtle.down()
  289.                 end
  290.                 if tunnelheight >= 3 then
  291.                         turtle.down()
  292.                         digdown()
  293.                         turtle.down()
  294.                         digdown()
  295.                         turtle.down()
  296.                 end
  297.         end
  298. end
  299.  
  300. function smalltunnel() -- Mine a one wide tunnel
  301.         if tunnelheight == 2 then
  302.                 digdown()
  303.         end
  304.         if tunnelheight == 3 then
  305.                 digup()
  306.                 digdown()
  307.         end
  308.         if tunnelheight > 3 then
  309.                 digup()
  310.                 digdown()
  311.                 turtle.down()
  312.                 tunnelheight = tunnelheight - 3
  313.                 while tunnelheight > 1 do
  314.                         digdown()
  315.                         turtle.down()
  316.                         tunnelheight = tunnelheight - 1
  317.                 end
  318.                 digdown()
  319.         end
  320.         placechest()
  321. end
  322.  
  323. -- Questions
  324. clearscreen()
  325. while HeightQuestion == true do -- Height Question
  326.         print("Qu'elle hauteur voulez vous?")
  327.         height = tonumber(read())
  328.         clearscreen()
  329.         if height == nil then
  330.                 print( "Veuillez entrez un chiffre valide." )
  331.         elseif height >= 2 then
  332.                 HeightQuestion = false
  333.                 startheight = height - 3
  334.         elseif height == 1 then
  335.                 term.setTextColor(colors.red)
  336.                 print( "Le tunnel doit faire 2 de hauteur minimaume." )
  337.         elseif height == 0 then
  338.                 term.setTextColor(colors.red)
  339.                 print( "Le tunnel ne peut pas etre infinie." )
  340.         else
  341.                 term.setTextColor(colors.red)
  342.                 print( "Le tunnel ne peut pas etre d'une hauteur negative." )
  343.                 term.setTextColor(colors.green)
  344.         end
  345. end
  346.  
  347. clearscreen()
  348. while WidthQuestion == true do -- Width Question
  349.         print("Qu'elle largeur voulez vous?")
  350.         width = tonumber(read())
  351.         clearscreen()
  352.         if width == nil then
  353.                 term.setTextColor(colors.red)
  354.                 print( "Veuillez entrez un chiffre valide." )
  355.         elseif width > 0 then
  356.                 WidthQuestion = false
  357.         elseif width == 0 then
  358.                 term.setTextColor(colors.red)
  359.                 print( "Le tunnel ne peut pas etre infinie." )
  360.         else
  361.                 term.setTextColor(colors.red)
  362.                 print( "Le tunnel ne peut pas etre d'une largeur negative." )
  363.                 term.setTextColor(colors.green)
  364.         end
  365. end
  366.  
  367. clearscreen()
  368. while LengthQuestion == true do -- Length Question
  369.         print("Qu'elle distance voulez vous?")
  370.         length = tonumber(read())
  371.         clearscreen()
  372.         if length == nil then
  373.                 term.setTextColor(colors.red)
  374.                 print( "Veuillez entrez un chiffre valide." )
  375.         elseif length > 0 then
  376.                 LengthQuestion = false
  377.                 lengthVar = 0  
  378.         elseif length == 0 then
  379.                 LengthQuestion = false
  380.                 Infinitelength = true
  381.                 TorchesQuestion = false
  382.                 TorchSpacingQuestion = false
  383.                 lengthVar = (-1)
  384.         else
  385.                 term.setTextColor(colors.red)
  386.                 print( "Le tunnel ne peut pas etre d'une distance negative." )
  387.                 term.setTextColor(colors.greeen)
  388.         end
  389. end
  390.  
  391. clearscreen()
  392. while ChestQuestion == true do -- Chest Question
  393.         print("Voulez vous placer des coffres et de la lumière ?")
  394.         chest = string.lower(read())
  395.         clearscreen()
  396.         if chest == ( 'oui' ) then
  397.                 if turtle.getItemCount(2) == 0 then
  398.                 term.setTextColor(colors.red)
  399.                         print("Veuillez placer les coffres dans le deuxieme slots.")
  400.                 else
  401.                 chest = true
  402.                 ChestQuestion = false
  403.                 setspacing()
  404.                 lengthSpacingVar = 0
  405.                 end
  406.         elseif chest == ( 'non' ) then
  407.                 chest = false
  408.                 ChestQuestion = false
  409.         else
  410.                 term.setTextColor(colors.red)
  411.                 print("Veuillez repondre par oui ou non.")
  412.                 term.setTextColor(colors.green)
  413.         end
  414. end
  415.  
  416.  
  417. clearscreen()
  418. while TorchesQuestion == true do -- Torch Question
  419.         print("Voulez vous placer des torches ou de la glowstone ?")
  420.         light = string.lower(read())
  421.         clearscreen()
  422.         if light == ( 'oui' ) then
  423.                 if turtle.getItemCount(1) == 0 then
  424.                 term.setTextColor(colors.red)
  425.                         print("Veuillez placer les items dans le premier slots.")
  426.                 else
  427.                 torches = true
  428.                 TorchesQuestion = false
  429.                 noTorches = false
  430.                 setspacing()
  431.                 lengthSpacingVar = 0
  432.                 end
  433.         elseif light == ( 'non' ) then
  434.                 torches = false
  435.                 TorchesQuestion = false
  436.         else
  437.                 term.setTextColor(colors.red)
  438.                 print("Veuillez repondre par oui ou non.")
  439.                 term.setTextColor(colors.green)
  440.         end
  441. end
  442.  
  443. -- Create the gui
  444. createtable()
  445.  
  446. -- Mining Loop
  447. turtle.up()
  448. while startheight > 0 do
  449.         local moved = turtle.up()
  450.         if not moved and turtle.detectUp() then
  451.                 repeat turtle.digUp() until turtle.up()
  452.                 local moved = true
  453.         elseif not moved and not turtle.detectUp() then
  454.                 repeat turtle.attackUp() until turtle.up()
  455.         end
  456.         startheight = startheight - 1
  457. end
  458. while lengthVar < length do
  459.         lengthVar = lengthVar + 1
  460.         digforward()
  461.         if width > 1 then
  462.                 turtle.turnRight()
  463.         end
  464.         end
  465.  
  466.         -- Mine a one wide tunnel or a larger tunnel.
  467.         tunnelheight = height
  468.         if width > 1 then
  469.                 while tunnelheight > 0 do
  470.                         largetunnel()
  471.                         turtle.turnRight()
  472.                         turtle.turnRight()
  473.                         if tunnelheight > 0 then
  474.                                 largetunnel()
  475.                                 if tunnelheight > 0 then
  476.                                         turtle.turnRight()
  477.                                         turtle.turnRight()
  478.                                 end
  479.                         else
  480.                                 widthvar = width - 1
  481.                                 while widthvar > 0 do
  482.                                         moveforward()
  483.                                         widthvar = widthvar - 1
  484.                                 end
  485.                         end
  486.                 end
  487.         else
  488.                 smalltunnel()
  489.         end
  490.         if torches == true then
  491.                 if lengthSpacingVar == 0 then
  492.                         spaceFromWallVar = spaceFromWall
  493.                         widthSpacingVar = widthSpacing
  494.                         lengthSpacingVar = lengthSpacing
  495.                 else
  496.                         spaceFromWallVar = spaceFromWall
  497.                         widthSpacingVar = widthSpacing
  498.                         lengthSpacingVar = lengthSpacingVar - 1
  499.                 end
  500.         end
  501.         startheight = height - 3
  502.         while startheight > 0 do
  503.                 turtle.up()
  504.                 startheight = startheight - 1
  505.         end
  506.  
  507.         -- Infinite Length
  508.         if Infinitelength == true then
  509.                 lengthVar = lengthVar - 1
  510.         end
  511.  
  512.         -- Stop or Continue
  513.         if lengthVar == length or noTorches == true then
  514.                 if width > 1 then
  515.                         turtle.turnLeft()
  516.                 else
  517.                         turtle.turnRight()
  518.                         turtle.turnRight()
  519.                 end
  520.                 while lengthVar > 0 do
  521.                         moveforward()
  522.                         lengthVar = lengthVar - 1
  523.                 end
  524.                 while startheight < ( height - 3 ) do
  525.                         turtle.down()
  526.                         startheight = startheight + 1
  527.                 end
  528.                 turtle.turnLeft()
  529.                 turtle.turnLeft()
  530.                 lengthVar = length
  531.                 term.setCursorPos( 1, 12 )
  532.                 term.setBackgroundColor(colors.white)
  533.                 if noTorches == true then
  534.                 term.setTextColor(colors.red)
  535.                         print ("Il n'y a plus de torche!")
  536.                 if noChest == true then
  537.                 term.setTextColor(colors.red)
  538.                         print ("Il n'y a plus de coffre!")
  539.                 term.setTextColor(colors.green)
  540.                 else
  541.                         print ("Tunnel Terminer!")
  542.                 end
  543.                 term.setCursorPos( 1, 2 )
  544.         else
  545.                 if width > 1 then
  546.                         turtle.turnRight()
  547.                 end
  548.         end
  549. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement