EphemeralKap

Untitled

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