Advertisement
EphemeralKap

Untitled

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