Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. length = 600
  2. refuel_value = 2
  3.  
  4. -- If an additional argument is given, it will be used as length for the tunnel
  5. --if #arg > 2 then
  6. -- length = tonumber(arg[2])
  7. --end
  8.  
  9. function dig_full()
  10. refuelTurtle()
  11.  
  12. for i = 1, length do
  13. if turtle_is_full() then
  14. return_to_chest(i)
  15. else
  16. dig_forward()
  17. end
  18. end
  19. print('returning to chest')
  20. print(length)
  21.  
  22. -- turn around
  23. turtle.turnRight()
  24. turtle.turnRight()
  25.  
  26. for i = 1, length do
  27. refuelTurtle()
  28. turtle.forward()
  29. end
  30.  
  31. -- make sure that the turtle is in front of a chest
  32. while not turtle.detect() do
  33. turtle.forward()
  34. end
  35.  
  36. emptyInventory()
  37. end
  38.  
  39. function return_to_chest(nr_blocks)
  40. print('returning to chest')
  41. print(nr_blocks)
  42.  
  43. -- turn around
  44. turtle.turnRight()
  45. turtle.turnRight()
  46.  
  47. for i = 1, nr_blocks do
  48. refuelTurtle()
  49. turtle.forward()
  50. end
  51.  
  52. -- make sure that the turtle is in front of a chest
  53. while not turtle.detect() do
  54. turtle.forward()
  55. end
  56.  
  57. emptyInventory()
  58.  
  59. -- turn around
  60. turtle.turnRight()
  61. turtle.turnRight()
  62.  
  63. for i = 1, nr_blocks do
  64. refuelTurtle()
  65. turtle.forward()
  66. end
  67. end
  68.  
  69. function emptyInventory()
  70. for i = 2, 16 do
  71. turtle.select(i)
  72. turtle.drop()
  73. end
  74.  
  75. turtle.select(1)
  76. end
  77.  
  78. function turtle_is_full()
  79. return turtle.getItemCount(16) > 0
  80. end
  81.  
  82. function dig_small_tunnel()
  83. dig_forward()
  84. dig_down()
  85. dig_up()
  86. end
  87.  
  88. function dig_up()
  89. while turtle.detectUp() do
  90. turtle.digUp()
  91. end
  92.  
  93. turtle.up()
  94. end
  95.  
  96. function dig_down()
  97. while turtle.detectDown() do
  98. turtle.digDown()
  99. end
  100.  
  101. turtle.down()
  102. end
  103.  
  104. function dig_forward()
  105. while turtle.detect() do
  106. turtle.dig()
  107. end
  108.  
  109. while turtle.detectUp() do
  110. turtle.digUp()
  111. end
  112.  
  113. while turtle.detectDown() do
  114. turtle.digDown()
  115. end
  116.  
  117. refuelTurtle()
  118. turtle.forward()
  119. end
  120.  
  121. function refuelTurtle()
  122. -- coal has a burn value of 80, below 40 means than only half a coal is left
  123. if turtle.getFuelLevel() < 40 then
  124. print('Fuel value below 40, trying to refuel...')
  125. local success = turtle.refuel(refuel_value)
  126. if success then
  127. print('Refueled successfully')
  128. end
  129. end
  130. end
  131.  
  132. print('starting to dig')
  133. dig_full()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement