Advertisement
Alex1979

baby digging

Apr 8th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. local MIN_FUEL = 300
  2. local AUTO_REFUEL = true
  3.  
  4. local function  refuel()
  5.     for i = 1, 16 do
  6.         turtle.select(i)
  7.         turtle.refuel()
  8.     end
  9.     turtle.select(1)       
  10. end
  11.  
  12. local function clearDrop()
  13.     if AUTO_REFUEL and turtle.getFuelLevel() < MIN_FUEL then refuel() end
  14.     for slot = 1, 16 do
  15.         turtle.select(slot)
  16.         turtle.dropDown()
  17.     end
  18. end
  19.  
  20. function  forward()
  21.         while not turtle.forward() do
  22.             turtle.attack()
  23.             sleep(1)
  24.         end
  25. end
  26. local function  up()
  27.     while not turtle.up() do
  28.         if not turtle.digUp() then
  29.             turtle.attackUp()
  30.             sleep(1)
  31.         end
  32.     end
  33.     h = h+1
  34. end
  35.  
  36. local function  down()
  37.     while not turtle.down() do
  38.         if not turtle.digDown() then
  39.             turtle.attackDown()
  40.             sleep(1)
  41.         end
  42.     end
  43.     h = h-1
  44. end
  45.  
  46. local function  left()
  47.     turtle.turnLeft()
  48. end
  49.  
  50. local function  right()
  51.     turtle.turnRight()
  52. end
  53.  
  54. local function around()
  55.         right()
  56.         right()
  57. end
  58.  
  59. local function  returnWall()
  60.     while true do
  61.     local state, typeblock = turtle.inspect()  
  62.         if typeblock.name ~= 'minecraft:cobblestone' then
  63.             forward()
  64.         else
  65.             right()
  66.             break
  67.         end
  68.     end
  69. end
  70.  
  71. local function  returnMatka()
  72.     while true do
  73.         forward()
  74.     end
  75. end
  76.  
  77. local function digHole()
  78.         h = 0
  79.         while true do
  80.             local state, typeblock = turtle.inspectDown()
  81.             if typeblock.name ~= 'minecraft:bedrock' then
  82.                 down()
  83.                 turtle.dig()
  84.             else
  85.                 break                              
  86.             end
  87.         end                
  88. end
  89.  
  90. local function returnSurface()
  91.     while h~=0 do
  92.         turtle.dig()
  93.         up()      
  94.     end
  95. end
  96.  
  97. local function  main()
  98.     os.setComputerLabel("BABY-"..os.getComputerID())
  99.     term.clear()
  100.     term.setCursorPos(1,1)
  101.     print('Fuel level: ', turtle.getFuelLevel())
  102.     print('Easy dig running!')
  103.     peripheral.call('left','turnOn')
  104.     peripheral.call('right','turnOn')
  105.     refuel()
  106.         if turtle.getFuelLevel() < MIN_FUEL then
  107.             error('Fatal ERROR, put fuel in any slot end PRESS Ctrl+R!')
  108.         end
  109.     digHole()
  110.     around()
  111.     for i = 1, 4 do up()  end
  112.     while turtle.detect() do turtle.dig() end
  113.     forward()
  114.     while true do
  115.             local state, typeblock = turtle.inspectDown()
  116.             if typeblock.name ~= 'minecraft:bedrock' then
  117.                 down()
  118.             else
  119.                 break                              
  120.             end
  121.         end        
  122.     returnSurface()
  123.     around()
  124.     returnWall()
  125.     clearDrop()
  126.     returnMatka()
  127. end
  128.  
  129. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement