EphemeralKap

Untitled

Dec 4th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. local distance = 0
  2.  
  3. function MoveFront()
  4. if turtle.detect() then
  5. turtle.dig()
  6. if turtle.forward() == false then
  7. MoveFront()
  8. end
  9. else
  10. turtle.forward()
  11. end
  12. end
  13.  
  14. function PlaceTorch()
  15. turtle.select(3)
  16. turtle.placeDown()
  17. end
  18.  
  19. function DigUp()
  20. if turtle.detectUp() then
  21. turtle.digUp()
  22. end
  23. end
  24.  
  25. function DigDown()
  26. if turtle.detectDown() then
  27. turtle.digDown()
  28. end
  29. end
  30.  
  31. -- Mines 3x3 infront of the turtle.
  32. function Mine()
  33. MoveFront()
  34. DigUp()
  35. DigDown()
  36. turtle.turnLeft()
  37. MoveFront()
  38. DigUp()
  39. DigDown()
  40. turtle.turnRight()
  41. turtle.turnRight()
  42. MoveFront()
  43. MoveFront()
  44. DigUp()
  45. DigDown()
  46. turtle.back()
  47. turtle.turnLeft()
  48. end
  49.  
  50. -- Checks if chests are present in slot 2, and if torches are present in slot 3.
  51. function CheckForItem(n)
  52. --chest checking
  53. if n == 1 then
  54. if turtle.getItemDetail(2).name == "minecraft:chest" then
  55. return true
  56. else
  57. return false
  58. end
  59. end
  60.  
  61. --torch checking
  62. if n == 2 then
  63. if turtle.getItemDetail(3).name == "minecraft:torch" then
  64. return true
  65. else
  66. return false
  67. end
  68. end
  69. end
  70.  
  71. function CheckGround()
  72. turtle.down()
  73. if turtle.detectDown() then
  74. turtle.up()
  75. return true
  76. else
  77. --find cobble, then place
  78. for i = 4,16 do
  79. if turtle.getItemDetail(i).name == "minecraft:cobblestone" then
  80. turtle.select(i)
  81. turtle.placeDown()
  82. break
  83. else
  84. return false
  85. end
  86. end
  87. turtle.up()
  88. return true
  89. end
  90. end
  91.  
  92.  
  93. -- true if it can drop off items, false if it cant due to no chests
  94. function Deposit()
  95. if CheckForItem(1) and CheckGround() then
  96. turtle.turnLeft()
  97. turtle.turnLeft()
  98. turtle.select(2)
  99. turtle.placeDown()
  100. turtle.select(1)
  101. for i = 4,16 do
  102. if turtle.getItemCount(i) > 0 then
  103. turtle.select(i)
  104. turtle.dropDown()
  105. end
  106. end
  107. turtle.select(1)
  108. turtle.turnLeft()
  109. turtle.turnLeft()
  110. return true
  111. else
  112. return false
  113. end
  114. end
  115.  
  116.  
  117. function Refuel()
  118. for i = 1,16 do
  119. if turtle.getItemCount(i) > 0 then
  120. turtle.select(i)
  121. if turtle.refuel(2) then
  122. break
  123. end
  124. end
  125. end
  126. turtle.select(1)
  127. end
  128.  
  129. -- deposit -> refuel -> mine
  130. while true do
  131. if turtle.getItemCount(16) > 0 and distance % 8 ~= 0 then
  132. if CheckForItem(1) then
  133. Deposit()
  134. else
  135. break --stop the turtle if it can't store items
  136. end
  137. elseif turtle.getFuelLevel() < 5 then
  138. Refuel()
  139. else
  140. Mine()
  141. distance = distance + 1 -- place torch every 8th block
  142. if distance % 8 == 0 then
  143. if CheckForItem(2) then
  144. PlaceTorch()
  145. end
  146. end
  147. end
  148. end
Advertisement
Add Comment
Please, Sign In to add comment