Creep4Play

ComputerCraft Mining Turtle - Tunnel

May 27th, 2013
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.64 KB | None | 0 0
  1. function digU()
  2.   while turtle.detectUp() do
  3.     turtle.digUp()
  4.   end
  5. end
  6.  
  7. function digF()
  8.   while turtle.detect() do
  9.     turtle.dig()
  10.   end
  11. end
  12.  
  13. function digD()
  14.   while turtle.detectDown() do
  15.     turtle.digDown()
  16.   end
  17. end
  18.  
  19. function goU()
  20.   repeat
  21.     digU()
  22.     proofFuel()
  23.   until turtle.up()
  24. end
  25.  
  26. function goF()
  27.   repeat
  28.     digF()
  29.     proofFuel()
  30.   until turtle.forward()
  31. end
  32.  
  33. function goD()
  34.   repeat
  35.     digD()
  36.     proofFuel()
  37.   until turtle.down()
  38. end
  39.  
  40. function status()
  41.   term.clear()
  42.   term.setCursorPos(1,1)
  43.   print("Dig Tunnel:")
  44.   print("")
  45.   print("H: "..height.." W: "..width.." L: "..length)
  46.   print("")
  47.   print(dug.."/"..blocks.." dug, "..(blocks-dug).." left.")
  48. end
  49.  
  50. function proofFuel()
  51.   if turtle.getFuelLevel()==0 then
  52.     turtle.select(16)
  53.     while turtle.refuel(1)==false do
  54.       term.clear()
  55.       term.setCursorPos(1,1)
  56.       print("Dig tunnel:")
  57.       print("")
  58.       print("Put coal on slot 16.")
  59.       os.sleep(4)
  60.       turtle.select(16)
  61.     end
  62.     turtle.select(1)
  63.   end
  64. end
  65.  
  66. function place()
  67.   if not turtle.detectDown() then
  68.     if turtle.getItemCount(1)>1 then
  69.       turtle.placeDown()
  70.       return
  71.     end
  72.     for i=2,13 do
  73.       if turtle.compareTo(i) then
  74.         turtle.select(i)
  75.         turtle.placeDown()
  76.         turtle.select(1)
  77.         return
  78.       end    
  79.     end
  80.   end
  81. end
  82.  
  83. function invFull()
  84.   for i=1,13 do
  85.     if turtle.getItemCount(i)==0 then
  86.       return false
  87.     end
  88.   end
  89.   return true
  90. end
  91.  
  92. turtle.select(1)
  93. term.clear()
  94. term.setCursorPos(1,1)
  95. print("Dig tunnel:")
  96. print("")
  97. print("Put bottom block on slot 1")
  98. print("Put chests on slot 14.")
  99. print("Put torches on slot 15.")
  100. print("Put coal on slot 16.")
  101. print("Height:")
  102. repeat
  103.   term.setCursorPos(9,7)
  104.   print("          ")
  105.   term.setCursorPos(9,7)
  106.   height=tonumber(read())
  107. until height>0
  108. term.setCursorPos(1,8)
  109. print("Width:")
  110. repeat
  111.   term.setCursorPos(8,8)
  112.   print("          ")
  113.   term.setCursorPos(8,8)
  114.   width=tonumber(read())
  115. until width>0
  116. term.setCursorPos(1,9)
  117. print("Length:")
  118. repeat
  119.   term.setCursorPos(9,9)
  120.   print("          ")
  121.   term.setCursorPos(9,9)
  122.   length=tonumber(read())
  123. until length>0
  124. term.setCursorPos(1,10)
  125. print("Torch every:")
  126. repeat
  127.   term.setCursorPos(14,10)
  128.   print("          ")
  129.   term.setCursorPos(14,10)
  130.   torchspc=tonumber(read())
  131. until torchspc>0
  132. torchin=torchspc
  133. blocks=height*width*length
  134. dug=0
  135. horzPos=0
  136. vertPos=0
  137. torchPos=0
  138. for iL=1,length do
  139.   goF()
  140.   if width>1 then
  141.     if horzPos==0 then
  142.       turtle.turnRight()
  143.     else
  144.       turtle.turnLeft()
  145.     end
  146.   end
  147.   for iW=1,width do
  148.     dug=dug+1
  149.     status()
  150.     if vertPos==0 then
  151.       place()
  152.       for iH=2,height do
  153.         goU()
  154.         dug=dug+1
  155.         status()
  156.       end
  157.     else
  158.       for iH=2,height do
  159.         goD()
  160.         dug=dug+1
  161.         status()
  162.       end
  163.       place()
  164.     end
  165.     if iW~=width then
  166.       goF()
  167.     end
  168.     vertPos=(vertPos*-1)+1
  169.   end
  170.   if width>1 then
  171.     if horzPos==0 then
  172.       turtle.turnLeft()
  173.     else
  174.       turtle.turnRight()
  175.     end
  176.   end
  177.   horzPos=(horzPos*-1)+1
  178.   torchin=torchin-1
  179.   if torchin==0 then
  180.     if vertPos==1 then
  181.       for i=2,height do
  182.         goD()
  183.       end
  184.       vertPos=0
  185.     end
  186.     if horzPos==0 then
  187.       turtle.turnRight()
  188.       if torchPos==1 then
  189.         for i2=2,width do
  190.           goF()
  191.         end
  192.         horzPos=1
  193.       end
  194.       turtle.turnRight()
  195.     else
  196.       turtle.turnLeft()
  197.       if torchPos==0 then
  198.         for i2=2,width do
  199.           goF()
  200.         end
  201.         horzPos=0
  202.       end
  203.       turtle.turnLeft()
  204.     end
  205.     goF()
  206.     turtle.select(15)
  207.     turtle.placeUp()
  208.     turtle.select(1)
  209.     turtle.turnRight()
  210.     turtle.turnRight()
  211.     goF()
  212.     torchin=torchspc
  213.     torchPos=(torchPos*-1)+1
  214.   end
  215.   if invFull() then
  216.     if vertPos==1 then
  217.       for i2=2,height do
  218.         goD()
  219.       end
  220.       vertPos=0
  221.     end
  222.     if horzPos==1 then
  223.       if width>1 then
  224.         turtle.turnLeft()
  225.         for i2=2,width do
  226.           goF()
  227.         end
  228.         turtle.turnRight()
  229.         horzPos=0
  230.       end
  231.     end
  232.     turtle.turnRight()
  233.     if width==1 then
  234.       goU()
  235.       digF()
  236.       goD()
  237.     end
  238.     local placed=false
  239.     digF()
  240.     turtle.select(14)
  241.     if turtle.place() then
  242.       for i2=2,13 do
  243.         turtle.select(i2)
  244.         turtle.drop()
  245.       end
  246.       turtle.select(1)
  247.     end
  248.     turtle.turnLeft()
  249.   end
  250. end
  251. turtle.turnLeft()
  252. if vertPos==1 then
  253.   goD()
  254. end
  255. if horzPos==1 then
  256.   for i=2,width do
  257.     goF()
  258.   end
  259. end
  260. turtle.turnLeft()
  261. for i=1,length do
  262.   goF()
  263. end
  264. turtle.turnLeft()
  265. turtle.turnLeft()
Advertisement
Add Comment
Please, Sign In to add comment