Advertisement
EphemeralKap

Untitled

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