iJinxIt

MiningTurtle

Apr 22nd, 2021 (edited)
344
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --ToDo:
  2. --Make the Torch algorythm better
  3. --Make it lava and water proof
  4. --Learn and use the Table thingy for the wasteblocks
  5. --Log Diamonds
  6.  
  7. local distance = 0
  8.  
  9. function safeDig() --Prevents the turtle from getting stuck on gravel or sand
  10.     turtle.dig()
  11.     os.sleep(0.5)
  12.     if turtle.detect() == true then
  13.         safeDig()
  14.     end
  15. end
  16.  
  17. function goMining() --Main function
  18.     for i=1,32 do
  19.         if i%6 == 0 then
  20.             branches(0, true)
  21.         elseif i%11 == 0 then
  22.             branches(1, true)
  23.         else
  24.             branches(0, false)
  25.         end
  26.  
  27.         checkIfFull()
  28.         safeDig()
  29.         turtle.forward()
  30.         distance = distance + 1        
  31.     end
  32.     returnToChestEnd()
  33. end
  34.  
  35. function checkFuel() --If the fuel level is under 100 use the coal in slot one to fill yourself up but dont use all of it so the mined coal will still go in slot 1
  36.     if turtle.getFuelLevel() <= 100 then
  37.         turtle.select(1)
  38.         turtle.refuel(turtle.getItemCount(1)-1)
  39.     end
  40. end
  41.  
  42. function dropWaste() --Drops the blocks listed below
  43.     for i=1,16 do
  44.         turtle.select(i)
  45.         if turtle.getItemCount() == 0
  46.         or turtle.getItemDetail().name == "minecraft:cobblestone"
  47.         or turtle.getItemDetail().name == "minecraft:dirt"
  48.         or turtle.getItemDetail().name == "byg:rocky_stone"
  49.         or turtle.getItemDetail().name == "byg:scoria_cobblestone"
  50.         or turtle.getItemDetail().name == "minecraft:gravel"      
  51.         or turtle.getItemDetail().name == "create:weathered_limestone"
  52.         or turtle.getItemDetail().name == "byg:soapstone"
  53.         then
  54.             turtle.drop()        
  55.         end
  56.     end
  57.     turtle.select(1)
  58. end
  59.  
  60. function placeTorch() --Digs down and places a torch that is in slot 2
  61.     turtle.select(2)
  62.     turtle.digDown()
  63.     turtle.placeDown()
  64.     turtle.select(1)
  65. end
  66.  
  67. function branches(torchPatterns, doIt)
  68.     turtle.turnRight()
  69.     dropWaste()
  70.  
  71.     for x=1,32 do
  72.         safeDig()
  73.         turtle.forward()
  74.         if torchPatterns == 0 and doIt == true then
  75.             if x/8 == 1 then
  76.                 placeTorch()
  77.             elseif x/18 == 1 then
  78.                 placeTorch()
  79.             elseif x/28 == 1 then
  80.                 placeTorch()
  81.             end
  82.         elseif torchPatterns == 1 and doIt == true then
  83.             if x/3 == 1 then
  84.                 placeTorch()
  85.             elseif x/13 == 1 then
  86.                 placeTorch()
  87.             elseif x/23 == 1 then
  88.                 placeTorch()
  89.             end
  90.         end
  91.     end
  92.  
  93.     turtle.turnRight()
  94.     turtle.turnRight()
  95.    
  96.     for x=1,32 do
  97.         turtle.forward()
  98.     end
  99.    
  100.     dropWaste()
  101.  
  102.     for x=1,32 do
  103.         safeDig()
  104.         turtle.forward()
  105.         if torchPatterns == 0 and doIt == true then
  106.             if x/8 == 1 then
  107.                 placeTorch()
  108.             elseif x/18 == 1 then
  109.                 placeTorch()
  110.             elseif x/28 == 1 then
  111.                 placeTorch()
  112.             end
  113.         elseif torchPatterns == 1 and doIt == true then
  114.             if x/3 == 1 then
  115.                 placeTorch()
  116.             elseif x/13 == 1 then
  117.                 placeTorch()
  118.             elseif x/23 == 1 then
  119.                 placeTorch()
  120.             end
  121.         end
  122.     end
  123.  
  124.     turtle.turnRight()
  125.     turtle.turnRight()
  126.    
  127.     for x=1,32 do
  128.         turtle.forward()
  129.     end
  130.  
  131.     turtle.turnLeft()
  132.     dropWaste()
  133.     checkFuel()
  134. end
  135.  
  136. function checkIfFull()
  137.     local x = 0
  138.     for i=1,16 do
  139.         if turtle.getItemCount(i)>0 then
  140.             x = x + 1
  141.         end
  142.     end
  143.     if x >= 13 then
  144.         turtle.select(1)
  145.         returnToChest()
  146.     end
  147.     turtle.select(1)
  148. end
  149.  
  150. function returnToChest()
  151.     turtle.turnRight()
  152.     turtle.turnRight()
  153.  
  154.     if distance > 0 then
  155.         for i=1,distance do
  156.             turtle.forward()
  157.         end
  158.     end
  159.  
  160.     for x=3,16 do
  161.         turtle.select(x)
  162.         turtle.dropDown(64)
  163.     end
  164.  
  165.     turtle.turnRight()
  166.     turtle.turnRight()
  167.    
  168.     for x=1,distance do
  169.         turtle.forward()
  170.     end
  171. end
  172.  
  173. function returnToChestEnd()
  174.     turtle.turnRight()
  175.     turtle.turnRight()
  176.  
  177.     if distance > 0 then
  178.         for i=1,distance do
  179.             turtle.forward()
  180.         end
  181.     end
  182.  
  183.     for x=3,16 do
  184.         turtle.select(x)
  185.         turtle.dropDown(64)
  186.     end
  187.  
  188.     turtle.turnRight()
  189.     turtle.turnRight()
  190. end
  191.  
  192. goMining()
RAW Paste Data