djst3rios

Mining Script part 3

Oct 24th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | Gaming | 0 0
  1. local MAXTRIES = 100
  2.  
  3. function turnAround()
  4.     local success = false
  5.    
  6.     success = turtle.turnRight()
  7.     success = success and turtle.turnRight()
  8.    
  9.     return success
  10. end
  11.  
  12. function dig()
  13.     local tries = 0
  14.    
  15.     while turtle.detect() do
  16.  
  17.         local s, data = turtle.inspect()
  18.         if data.name == "minecraft:bedrock" then
  19.             printError("Hit bedrock forwards!")
  20.             return false
  21.         end
  22.        
  23.         turtle.dig()
  24.         sleep(0.4)
  25.        
  26.         tries = tries+1
  27.         if tries > MAXTRIES then
  28.  
  29.             printError("Can't dig forward")
  30.             return false
  31.            
  32.         end
  33.     end
  34.    
  35.     return true
  36. end
  37.  
  38. function digDown()
  39.     local tries = 0
  40.    
  41.     while turtle.detectDown() do
  42.  
  43.         local s, data = turtle.inspectDown()
  44.         if data.name == "minecraft:bedrock" then
  45.             printError("Hit bedrock below!")
  46.             return false
  47.         end
  48.    
  49.         turtle.digDown()
  50.         sleep(0.4)
  51.        
  52.         tries = tries+1
  53.         if tries > MAXTRIES then
  54.             printError("Can't dig down")
  55.             return false
  56.         end
  57.     end
  58.    
  59.     return true
  60. end
  61.  
  62. function digUp()
  63.     local tries = 0
  64.    
  65.     while turtle.detectUp() do
  66.  
  67.         local s, data = turtle.inspectUp()
  68.         if data.name == "minecraft:bedrock" then
  69.             printError("Hit bedrock above!")
  70.             return false
  71.         end
  72.    
  73.         turtle.digUp()
  74.         sleep(0.4)
  75.        
  76.         tries = tries+1
  77.         if tries > MAXTRIES then
  78.             printError("Can't dig up")
  79.             return false
  80.         end
  81.     end
  82.    
  83.     return true
  84. end
  85.  
  86.  
  87. function fw(l)
  88.     l=l or 1
  89.    
  90.     for i=1, l do
  91.    
  92.         local tries = 0
  93.        
  94.         while turtle.forward() ~= true do
  95.            
  96.             turtle.dig()
  97.             turtle.attack()
  98.             sleep(0.2)
  99.            
  100.             tries = tries+1
  101.             if tries > MAXTRIES then
  102.                 printError("Can't move forward")
  103.                 return false
  104.             end
  105.         end
  106.     end
  107.    
  108.     return true
  109. end
  110.  
  111. function up(l)
  112.     l=l or 1
  113.    
  114.     for i=1, l do
  115.    
  116.         local tries = 0
  117.        
  118.         while turtle.up() ~= true do
  119.            
  120.             turtle.digUp()
  121.             turtle.attackUp()
  122.             sleep(0.2)
  123.            
  124.             tries = tries+1
  125.             if tries > MAXTRIES then
  126.                 printError("Can't move up")
  127.                 return false
  128.             end
  129.         end
  130.     end
  131.    
  132.     return true
  133. end
  134.  
  135. function down(l)
  136.     l=l or 1
  137.    
  138.     for i=1, l do
  139.    
  140.         local tries = 0
  141.    
  142.         while turtle.down() ~= true do
  143.    
  144.             turtle.digDown()
  145.             turtle.attackDown()
  146.             sleep(0.2)
  147.        
  148.             tries = tries+1
  149.             if tries > MAXTRIES then
  150.                 printError("Can't move down")
  151.                 return false
  152.             end
  153.         end
  154.     end
  155.    
  156.     return true
  157. end
  158.  
  159. function back(l)
  160.     l=l or 1
  161.    
  162.     for i=1, l do
  163.    
  164.         if turtle.back() ~= true then
  165.             turnAround()
  166.             fw()
  167.             turnAround()
  168.         end
  169.     end
  170. end
Add Comment
Please, Sign In to add comment