Advertisement
GauHelldragon

GauSubway v0.5

May 9th, 2014
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. -- A digging turtle program that will make a tunnel
  2. -- The tunnel will attempt to contour to the ground, but if it reaches a slope higher than 1 block
  3. --  it will start digging or placing filler blocks.
  4.  
  5. -- The turtle will likely error out of it runs out of fuel or any type of block
  6.  
  7. -- Cover blocks ( try glass! ) : Slots 1-4
  8. -- Filler blocks ( try gravel!) : Slots 5-6
  9. -- Floor blocks ( try stone bricks!) : Slots 7-9
  10. --  Note: Filler blocks must be affected by gravity for it to work ( ie. gravel, sand, etc. )
  11.  
  12.  
  13. -- Settings
  14.  
  15. -- You can change how many slots to use of the inventory and for which types of blocks by changing these numbers
  16. local coverSpotEnd = 8
  17. local fillerSpotEnd = 10
  18. local floorSpotEnd = 12
  19.  
  20. -- Change the height of the tunnel
  21. local height = 4
  22.  
  23. -- Change the length of the tunnel
  24. local distance = 100
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. -- Used by program
  32. local currentCover = 1
  33. local currentFiller = coverSpotEnd + 1
  34. local currentFloor = fillerSpotEnd + 1
  35.  
  36. local FORWARD = 1
  37. local UP = 2
  38.  
  39. function refuel()
  40.   local slot = 1
  41.   while ( turtle.getFuelLevel() < 100 and slot < 16 ) do
  42.     slot = slot + 1
  43.     turtle.select(slot)
  44.     turtle.refuel(10)
  45.   end
  46.   turtle.select(1)
  47. end
  48.  
  49. function goForward()
  50.   refuel()
  51.   if ( turtle.getFuelLevel() < 100 ) then
  52.     print "Ran out of fuel!"
  53.     os.exit()
  54.   end
  55.   while ( not turtle.forward() ) do
  56.     turtle.dig()
  57.     os.sleep(1)
  58.   end
  59. end
  60.  
  61. function goUp()
  62.   refuel()
  63.   if ( turtle.getFuelLevel() < 100 ) then
  64.     print "Ran out of fuel!"
  65.     os.exit()
  66.   end
  67.   while ( not turtle.up() ) do
  68.     turtle.digUp()
  69.     os.sleep(1)
  70.   end
  71. end
  72.  
  73. function goDown()
  74.   refuel()
  75.   if ( turtle.getFuelLevel() < 100 ) then
  76.     print "Ran out of fuel!"
  77.     os.exit()
  78.   end
  79.   while ( not turtle.down() ) do
  80.     turtle.digDown()
  81.     os.sleep(1)
  82.   end
  83. end
  84.  
  85. function PlaceFiller()
  86.     turtle.select(currentFiller)
  87.     while ( turtle.getItemCount(currentFiller) < 1 ) do
  88.         currentFiller = currentFiller + 1
  89.         if ( currentFiller > 16 or currentFiller > fillerSpotEnd ) then
  90.             print( "Ran out of filler blocks!" )
  91.             os.exit()
  92.         end
  93.         turtle.select(currentFiller)
  94.     end
  95.     turtle.placeDown()
  96. end
  97.  
  98. function MoveForward()
  99.     -- Block in front of us, go up
  100.     if ( turtle.detect() ) then
  101.         goUp()
  102.     end
  103.     goForward()
  104.     -- Nothing below us, go down
  105.     if ( not turtle.detectDown() ) then
  106.         goDown()
  107.     end
  108.    
  109.     -- Still nothing below us, drop filler
  110.     while ( not turtle.detectDown() ) do
  111.         PlaceFiller()
  112.     end
  113.    
  114.    
  115.  
  116. end
  117.  
  118. function PlaceCover(direction)
  119.     turtle.select(currentCover)
  120.     while ( turtle.getItemCount(currentCover) < 1 ) do
  121.         currentCover = currentCover + 1
  122.         if ( currentCover > 16 or currentCover > coverSpotEnd ) then
  123.             print( "Ran out of cover blocks!" )
  124.             os.exit()
  125.         end
  126.         turtle.select(currentCover)
  127.     end
  128.     if (direction == FORWARD) then
  129.         turtle.place()
  130.     elseif ( direction == UP ) then
  131.         turtle.placeUp()
  132.     end
  133. end
  134.  
  135.  
  136. function BuildCover()
  137.     for h = 1,height do
  138.         turtle.turnLeft()
  139.         PlaceCover(FORWARD)
  140.         turtle.turnRight()
  141.         turtle.turnRight()
  142.         PlaceCover(FORWARD)
  143.         turtle.turnLeft()
  144.         goUp()
  145.     end
  146.     goDown()
  147.     PlaceCover(UP)
  148.     for h = 2,height do
  149.         goDown()
  150.     end
  151. end
  152.  
  153. function BuildFloor()
  154.     turtle.select(currentFloor)
  155.     while ( turtle.getItemCount(currentFloor) < 1 ) do
  156.         currentFloor = currentFloor + 1
  157.         if ( currentFloor > 16 or currentFloor > floorSpotEnd ) then
  158.             print( "Ran out of floor blocks!" )
  159.             os.exit()
  160.         end
  161.         turtle.select(currentFloor)
  162.     end
  163.     turtle.digDown()
  164.     turtle.placeDown()
  165. end
  166.  
  167. function BuildTunnel()
  168.     BuildCover()
  169.     BuildFloor()
  170.  
  171. end
  172.  
  173. for dist = 1,distance do
  174.     BuildTunnel()
  175.     MoveForward()
  176. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement