Advertisement
angrymasteryoda

miner

Sep 12th, 2022 (edited)
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. local distance = 0
  2. local direction = 0
  3. local times = 0
  4. local torches = 0
  5. local chest = 0
  6. local itemFuel = 0
  7.  
  8. local td = 0 -- temp distance for
  9. local gap = 3
  10.  
  11. local err = 0
  12.  
  13. local function ioread()
  14.     input = io.read();
  15.     return input
  16. end
  17.  
  18. local function fuelup()
  19.     need = 0
  20.     repeat
  21.         if turtle.getFuelLevel() == "unlimited" then
  22.             print( "NO NEED FOR FUEL" )
  23.             need = 0
  24.         elseif turtle.getFuelLevel() < 100 then
  25.             turtle.select( 3 )
  26.             turtle.refuel( 1 )
  27.             need = 1
  28.             itemFuel = itemFuel - 1
  29.         elseif need == 1 then
  30.             need = 0
  31.         end
  32.     until need == 0
  33. end
  34.  
  35. local function precheck()
  36.     if torch == 0 then
  37.         print( "no torches" )
  38.     end
  39.    
  40.     if chest == 0 then
  41.         print( "no chests" )
  42.         err = 1
  43.     end
  44.    
  45.     if itemFuel == 0 then
  46.         print( "no fuel" )
  47.         err = 1
  48.     end
  49.    
  50.     fuelup()   
  51. end
  52.  
  53. local function forward()
  54.     light = 0
  55.     repeat
  56.         if turtle.detect() then
  57.             turtle.dig()
  58.         end
  59.        
  60.         if turtle.forward() then
  61.             td = td - 1
  62.             light = light + 1
  63.         end
  64.        
  65.         if turtle.detectUp() then
  66.             turtle.digUp()
  67.         end
  68.         if turtle.detectDown() then
  69.             turtle.digDown()
  70.         end
  71.        
  72.         --torch placer
  73.         if light == 8 and torches > 0 then
  74.             turtle.select(1)
  75.             turtle.placeDown()
  76.             torches = torches - 1
  77.             light = light - 8
  78.         end
  79.        
  80.         --chest placer
  81.         if turtle.getItemCount(16) > 0 then
  82.         --todo what if runs out of chest dont just die
  83.             if chest > 0 then
  84.                 turtle.select( 2 )
  85.                 if turtle.detectDown() then
  86.                     turtle.digDown()
  87.                 end
  88.                 turtle.placeDown()
  89.                 chest = chest - 1
  90.                 for slot = 4, 16 do
  91.                     turtle.select( slot )
  92.                     turtle.dropDown()
  93.                     sleep( 1.5 )
  94.                 end
  95.                 turtle.select( 4 )
  96.             else
  97.                 print( "no chests refuel into slot 2" )
  98.                 os.shutdown()
  99.             end
  100.         end
  101.         fuelup()   
  102.     until td == 0
  103. end
  104.  
  105. local function back()
  106.     turtle.turnLeft()
  107.     turtle.turnLeft()
  108.     d = distance
  109.     repeat
  110.         if turtle.forward() then
  111.             d = d - 1
  112.         end
  113.         if turtle.detect() then
  114.             if d ~= 0 then
  115.                 turtle.dig()
  116.             end
  117.         end
  118.     until d == 0
  119.     if direction == 1 then
  120.         turtle.turnLeft()
  121.     else
  122.         turtle.turnRight()
  123.     end
  124. end
  125.  
  126. local function prepare()
  127.     x = gap
  128.     repeat
  129.         if turtle.detect() then
  130.             turtle.dig()
  131.         end
  132.        
  133.         if turtle.forward() then
  134.             x = x - 1
  135.         end
  136.        
  137.         if turtle.detectUp() then
  138.             turtle.digUp()
  139.         end
  140.         if turtle.detectDown() then
  141.             turtle.digDown()
  142.         end
  143.     until x == 0
  144.     if direction == 1 then
  145.         turtle.turnLeft()
  146.     else
  147.         turtle.turnRight()
  148.     end
  149.     if times == 0 then
  150.         print( "turtle is done" )
  151.     else
  152.         times = times - 1
  153.     end
  154. end
  155.  
  156.  
  157. local function mine()
  158.     td = distance
  159.     repeat
  160.         forward()
  161.        
  162.         back()
  163.  
  164.         prepare()
  165.         td = distance
  166.     until times == 0
  167. end
  168.  
  169.  
  170. --start the program
  171. torches = turtle.getItemCount( 1 )
  172. chest = turtle.getItemCount( 2 )
  173. itemFuel = turtle.getItemCount( 3 )
  174. print( "strip miner")
  175. print( "enter distance" )
  176. distance = tonumber( ioread() )
  177.  
  178. print( "what direction left=0 or right=1" )
  179. direction = tonumber( ioread() )
  180.  
  181. print( "how many times" );
  182. times = tonumber( ioread() );
  183.  
  184. precheck()
  185. if Error == 1 then
  186.     print( "failed to start" )
  187. else
  188.     mine()
  189. end
  190.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement