hyprunz

Digger Tunnel Turtle for Minecraft

May 13th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.36 KB | None | 0 0
  1. --Own Tunnel Turtle same size 2X3 but with feature bring items in chest, set torches and refill the border with cobble stone
  2.  
  3. length = 100
  4. torchPl = 5
  5. torchCounter = 0
  6. layerCounter = 0
  7.  
  8. function layerDig()    
  9.     leftLayer()
  10.     refillCopple()
  11.     rightLayer()
  12.     refillCopple()
  13.     checkItemsAndGoEmpty()
  14.        
  15. end
  16.  
  17. function leftLayer()
  18.     Dig()
  19.     ForwardDown()
  20.     checkLeftBorder()
  21.     DigUp()
  22.     MoveUppest()
  23.     checkFrontBorder()
  24.     turn180()
  25.     Dig()
  26.     ForwardUp()
  27.     DigDown()
  28.     MoveLowest()
  29.     Dig()
  30.     ForwardDown()
  31.     checkFrontBorder()
  32.     DigUp()
  33.     MoveUppest()
  34.     checkFrontBorder()
  35.     layerCounter = layerCounter + 1
  36.     placeTorch()
  37.     turtle.turnLeft()
  38. end
  39.  
  40. function rightLayer()
  41.     Dig()
  42.     ForwardUp()
  43.     checkRightBorder()
  44.     DigDown()
  45.     MoveLowest()
  46.     checkFrontBorder()
  47.     turn180()
  48.     Dig()
  49.     ForwardDown()
  50.     DigUp()
  51.     MoveUppest()
  52.     Dig()
  53.     ForwardUp()
  54.     checkFrontBorder()
  55.     placeTorch()
  56.     DigDown()
  57.     MoveLowest()
  58.     checkFrontBorder()
  59.     layerCounter = layerCounter + 1
  60.     turtle.turnRight()
  61. end
  62.  
  63. function Dig()
  64.     while turtle.detect() do
  65.         turtle.dig()
  66.         sleep(0.4)
  67.     end
  68. end
  69.  
  70. function DigUp()
  71.     while turtle.detectUp() do
  72.         turtle.digUp()
  73.         sleep(0.4)
  74.     end
  75. end
  76.  
  77. function DigDown()
  78.     while turtle.detectDown() do
  79.         turtle.digDown()
  80.         sleep(0.4)
  81.     end
  82. end
  83.  
  84. function BackToChest()
  85.     turn180()
  86.     for i=1, layerCounter, 1 do
  87.         Dig()
  88.         turtle.forward()
  89.     end
  90.     Drop()
  91.     turn180()
  92. end
  93.  
  94. function BackToLayer()
  95.     for i=1, layerCounter, 1 do
  96.         Dig()
  97.         turtle.forward()
  98.     end
  99. end
  100.  
  101. function Drop()
  102.     for i=1, 14, 1 do
  103.         turtle.select(i)
  104.         turtle.drop(64)
  105.     end
  106. end
  107.  
  108. function ForwardDown()
  109.     turtle.forward()
  110.     if(turtle.detectDown() == false) then
  111.         turtle.select(15)
  112.         turtle.placeDown()
  113.     end
  114. end
  115.  
  116. function ForwardUp()
  117.     turtle.forward()
  118.     if(turtle.detectUp() == false) then
  119.         turtle.select(15)
  120.         turtle.placeUp()
  121.     end
  122. end
  123.  
  124. function MoveUppest()
  125.     turtle.up()
  126.     if(turtle.detectUp() == false) then
  127.         turtle.select(15)
  128.         turtle.placeUp()
  129.     end
  130. end
  131.  
  132. function MoveLowest()
  133.     turtle.down()
  134.     if(turtle.detectDown() == false) then
  135.         turtle.select(15)
  136.         turtle.placeDown()
  137.     end
  138. end
  139.  
  140. function turn180()
  141.     turtle.turnLeft()
  142.     turtle.turnLeft()
  143. end
  144.  
  145. function checkLeftBorder()
  146.     turtle.turnLeft()
  147.     checkFrontBorder()
  148. end
  149.  
  150. function checkRightBorder()
  151.     turtle.turnRight()
  152.     checkFrontBorder()
  153. end
  154.  
  155. function checkFrontBorder()
  156.     if(turtle.detect() == false) then
  157.         turtle.select(15)
  158.         turtle.place()
  159.     end
  160. end
  161.  
  162. function placeTorch()
  163.     if(torchCounter == torchPl) then
  164.         turn180()
  165.         turtle.forward()
  166.         turtle.select(16)
  167.         turtle.place()
  168.         torchCounter = 0
  169.         turn180()
  170.         turtle.forward()
  171.     else
  172.         torchCounter = torchCounter + 1
  173.     end
  174. end
  175.  
  176. function checkItemsAndGoEmpty()
  177.     haveToEmpty = 1
  178.    
  179.     for i = 1, 14, 1 do
  180.         if (turtle.getItemCount(i) == 0) then
  181.             haveToEmpty = 0
  182.         end
  183.     end
  184.    
  185.     if (haveToEmpty == 1) then
  186.         BackToChest()
  187.         BackToLayer()
  188.     end
  189. end
  190.  
  191. function refillCopple()
  192.     local cnt = turtle.getItemCount(15)
  193.     if cnt < 8 then
  194.         for i=1, 15, 1 do
  195.             turtle.select(i)
  196.             local comp = turtle.compareTo(16)
  197.             if comp == true then
  198.                 turtle.transferTo(16)
  199.             end
  200.         end
  201.     end
  202. end
  203.  
  204. function start()
  205.     local input = 1
  206.     shell.run("clear")
  207.     while input == 1 do
  208.         term.setCursorPos(1,1)
  209.         print("Menu:")
  210.         print("=======================================")
  211.         term.setCursorPos(1,3)
  212.         term.clearLine()
  213.         print("Length of the tunnel: "..length)
  214.         term.clearLine()
  215.         term.setCursorPos(1,5)
  216.         term.clearLine()
  217.         print("Enter [S] for start or [C] for change settings - [Q] quit:")
  218.         term.clearLine()
  219.        
  220.         local inputstring = read()
  221.        
  222.         if inputstring == 'S' or inputstring == 's' then
  223.             if checkStartConditions() == 1 then
  224.                 run()
  225.             end
  226.         elseif inputstring == 'C' or inputstring == 'c' then
  227.             setting()
  228.         elseif inputstring == 'Q' or inputstring == 'q' then
  229.             input = 0
  230.             shell.run("clear")
  231.         else
  232.             term.setCursorPos(1,10)
  233.             term.clear()
  234.             print("Invalid Input")
  235.         end
  236.     end
  237. end
  238.  
  239. function checkStartConditions()
  240.     term.setCursorPos(1,10)
  241.     term.clear()
  242.     local retValue = 1
  243.     local torchCount = turtle.getItemCount(16)
  244.     local cobbleCount = turtle.getItemCount(15)
  245.     if torchCount == 0 then
  246.         print("No torches found!")
  247.         retValue = 0
  248.     else
  249.         print("Number of found torches: "..torchCount)
  250.     end
  251.    
  252.     if cobbleCount == 0 then
  253.         print("No cobble stone found!")
  254.         retValue = 0
  255.     else
  256.         print("Number of found cobble stone: "..cobbleCount)
  257.     end
  258.    
  259.     if retValue == 0 then
  260.         print("Start conditions not correct - please fill torches in slot 16 and cobblestone in slot 15")
  261.         return 0
  262.     else
  263.         return 1
  264.     end
  265. end
  266.  
  267. function setting()
  268.     local setting = 1
  269.     local invalidCounter = 0
  270.     shell.run("clear")
  271.     while setting == 1 do
  272.         term.setCursorPos(1,1)
  273.         print("Setting:")
  274.         print("=======================================")
  275.         term.setCursorPos(1,3)
  276.         term.clearLine()
  277.         print("Actual using tunnel length: "..length)
  278.         term.setCursorPos(1,5)
  279.         term.clearLine()
  280.         print("Enter the new length of the tunnel:")
  281.         local inputstring = read()
  282.        
  283.         if(tonumber(inputstring) ~= nil) then
  284.             length = tonumber(inputstring)
  285.             setting = 0
  286.         else
  287.             term.setCursorPos(1,10)
  288.             term.clear()
  289.             print("Invalid Input")
  290.             invalidCounter = invalidCounter + 1
  291.         end
  292.        
  293.         if invalidCounter == 3 then
  294.             setting = 0
  295.         end
  296.     end
  297.     shell.run("clear")
  298. end
  299.  
  300. function run()
  301.     for i=1, length / 2, 1 do
  302.         layerDig()
  303.     end
  304.    
  305.     BackToChest()
  306. end
  307.  
  308. start()
Advertisement
Add Comment
Please, Sign In to add comment