Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. config_finished = 'All done master.'
  2. config_refuel = 'I am refueling!'
  3. config_turn_around = 'I am turning 180!'
  4. config_finished_mining = 'I am all done, getting back!'
  5. config_success = 'Starting mining!'
  6.  
  7. config_block_length = 30
  8.  
  9. function checkFuel(steps)
  10.     if turtle.getFuelLevel() <= steps - 1 then
  11.         turtle.select(1)
  12.         coalToConsume = turtle.getItemCount(1) - 1
  13.         print(config_refuel)
  14.         turtle.refuel(coalToConsume)
  15.     end --if
  16. end --checkFuel()
  17.  
  18. function turnAround()
  19.     print(config_turn_around)
  20.     turtle.turnRight()
  21.     turtle.turnRight() 
  22. end --turnAround()
  23.  
  24. function stopMining(steps)
  25.     turnAround()
  26.     print(config_finished_mining)
  27.     for index = 1, steps do
  28.         turtle.forward()
  29.     end --for
  30.     print(config_finished)
  31. end --stopMining()
  32.  
  33. function mineForward(blockLength)
  34.     for i = 1, blockLength do
  35.         turtle.dig()
  36.         turtle.forward()
  37.     end --for
  38. end
  39.  
  40. function mineToSide()
  41.     turtle.turnLeft()
  42.     mineForward(15)
  43.     stopMining(15)
  44.     turtle.turnLeft()  
  45. end
  46.  
  47. function miningAlgo(blockLength)
  48.     stepsTaken = 0
  49.     for index = 1, blockLength do
  50.         stepsTaken = stepsTaken + 1
  51.         checkFuel(stepsTaken)
  52.         turtle.forward()       
  53.         turtle.dig()
  54.  
  55.         if stepsTaken >= turtle.getFuelLevel() or stepsTaken + 1 == blockLength then
  56.             stopMining(stepsTaken)
  57.             return true
  58.         end --if
  59.  
  60.         if index % 3 == 1 and turtle.getFuelLevel() >= 30 then
  61.             mineToSide()           
  62.         end --if
  63.     end --for
  64. end
  65.  
  66. function main()
  67.     miningAlgo(config_block_length)
  68.     print(config_success)
  69.     print('I will mine forward for: ' + config_block_length + ' Blocks!')
  70. end --main
  71.  
  72. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement