Advertisement
cameron59066

Untitled

Sep 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. local history = {}
  2. local keep = {
  3. "minecraft:iron_ore",
  4. "minecraft:coal_ore",
  5. "minecraft:diamond_ore",
  6. "minecraft:redstone_ore",
  7. "minecraft:gold_ore"
  8. }
  9. local miningMode = true
  10. local stopMoving = false
  11. turtle.select(1)
  12. turtle.refuel()
  13.  
  14. function hasval(tbl, val)
  15. for i,v in ipairs(tbl) do
  16. if v == val then
  17. return true
  18. end
  19. end
  20. return false
  21. end
  22.  
  23. function checkore()
  24. for i=1,16 do
  25. turtle.select(i)
  26. local idata = turtle.getItemDetail()
  27. if idata then
  28. if hasval(keep, idata.name) == false then
  29. turtle.drop()
  30. end
  31. end
  32. end
  33. end
  34.  
  35. function postmove()
  36. checkore()
  37. if turtle.getFuelLevel() == table.getn(history) then
  38. gohome()
  39. end
  40. end
  41.  
  42. function fwd()
  43. if stopMoving then
  44. return false
  45. end
  46. if miningMode then
  47. if turtle.detect() then
  48. turtle.dig()
  49. end
  50. end
  51. table.insert(history, "f")
  52. turtle.forward()
  53. postmove()
  54. end
  55.  
  56. function left()
  57. if stopMoving then
  58. return false
  59. end
  60. turtle.turnLeft()
  61. if miningMode then
  62. if turtle.detect() then
  63. turtle.dig()
  64. end
  65. end
  66. table.insert(history, "l")
  67. turtle.forward()
  68. postmove()
  69. end
  70.  
  71. function right()
  72. if stopMoving then
  73. return false
  74. end
  75. table.insert(history, "r")
  76. turtle.turnRight()
  77. if miningMode then
  78. if turtle.detect() then
  79. turtle.dig()
  80. end
  81. end
  82. turtle.forward()
  83. postmove()
  84. end
  85.  
  86. function down()
  87. if stopMoving then
  88. return false
  89. end
  90. table.insert(history, "d")
  91. if miningMode then
  92. if turtle.detectDown() then
  93. turtle.digDown()
  94. end
  95. end
  96. turtle.down()
  97. postmove()
  98. end
  99.  
  100. function up()
  101. if stopMoving then
  102. return false
  103. end
  104. turtle.insert(history, "u")
  105. if miningMode then
  106. if turtle.detectUp() then
  107. turtle.digUp()
  108. end
  109. end
  110. turtle.up()
  111. postmove()
  112. end
  113.  
  114. function gohome()
  115. stopMoving = true
  116. for i=table.getn(history), 1,-1 do
  117. local event = history[i]
  118. print(event)
  119. if event == "f" then
  120. turtle.back()
  121. elseif event == "l" then
  122. turtle.back()
  123. turtle.turnRight()
  124. elseif event == "r" then
  125. turtle.back()
  126. turtle.turnLeft()
  127. elseif event == "u" then
  128. turtle.down()
  129. elseif event == "d" then
  130. turtle.up()
  131. end
  132. end
  133. end
  134.  
  135. fwd()
  136. for z=1,3 do
  137. down()
  138. for y=1,5 do
  139. fwd()
  140. end
  141. right()
  142. for x=1,4 do
  143. fwd()
  144. end
  145. right()
  146. right()
  147. for x=1,4 do
  148. fwd()
  149. end
  150. left()
  151. left()
  152. for x=1,4 do
  153. fwd()
  154. end
  155. right()
  156. right()
  157. for x=1,4 do
  158. fwd()
  159. end
  160. left()
  161. left()
  162. for x=1,4 do
  163. fwd()
  164. end
  165. right()
  166. right()
  167. for x=1,4 do
  168. fwd()
  169. end
  170. turtle.turnRight()
  171. end
  172. gohome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement