thorax232

Square Mine (Computer Craft)

Jun 7th, 2014
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. function driver(n) -- Drives whole program
  2.     for i = 1,3 do
  3.         tunnel(n)
  4.     end
  5.     tunnelLastWall(n)
  6.     if(n >= 6) then
  7.         for i = 1,3 do
  8.             tunnelFor()
  9.         end
  10.     end
  11. end
  12.  
  13. function tunnel(n) -- Dig a tunnel straight out
  14.     for i = 1,n-1 do
  15.         tunnelFor()
  16.     end
  17.     turtle.turnRight()
  18. end
  19.  
  20. function tunnelLastWall(n) -- Dig fourth tunnel (shorter than normal tunnel)
  21.     for i = 1,n-4 do
  22.         tunnelFor()
  23.     end
  24.     turtle.turnRight()
  25. end
  26.  
  27. function tunnelFor() -- Tunnel forward
  28.     gravelDig()
  29.     turtle.forward()
  30.     turtle.digUp()
  31.     count = count + 1
  32.     if count % 7 == 0 then
  33.         torch()
  34.     end
  35.     checkWalls()
  36. end
  37.  
  38. function checkWalls() -- Fill in walls to avoid water/lave problems
  39.     turtle.select(2)
  40.     if(turtle.detectDown() == false) then
  41.         turtle.placeDown()
  42.     end
  43.     turtle.turnLeft()
  44.     detectAndPlace()
  45.     turnAround()
  46.     detectAndPlace()
  47.     gravelDigUp()
  48.     turtle.up()
  49.     if(turtle.detectUp() == false) then
  50.         turtle.placeUp()
  51.     end
  52.     detectAndPlace()
  53.     turnAround()
  54.     detectAndPlace()
  55.     turtle.turnRight()
  56.     turtle.down()
  57. end
  58.  
  59. function torch() -- Place torch every 7 spots
  60.     turtle.select(1)
  61.     turtle.turnLeft()
  62.     gravelDig()
  63.     turtle.place()
  64.     turtle.turnRight()
  65. end
  66.  
  67. function turnAround() -- 180 degree turn
  68.     turtle.turnRight()
  69.     turtle.turnRight()
  70. end
  71.  
  72. function detectAndPlace() -- Place block if nothing there
  73.     if(turtle.detect() == false) then
  74.         turtle.place()
  75.     end
  76. end
  77.  
  78. function gravelDig() -- Dig forward, check for gravel/sand
  79.     while(turtle.detect()) do
  80.         turtle.dig()
  81.     end
  82. end
  83.  
  84. function gravelDigUp() -- Dig up, checking for gravel/sand
  85.     while(turtle.detectUp()) do
  86.         turtle.digUp()
  87.     end
  88. end
  89.  
  90. local n
  91. count = 0
  92. print("Torches in slot 1. Cobblestone in slot 2.");
  93. print("Enter size of square mine.");
  94. n = tonumber(read())
  95.  
  96. while(n >= 0) do
  97.     driver(n)
  98.     n = n - 6
  99. end
Advertisement
Add Comment
Please, Sign In to add comment