Hydrogen6246

Untitled

Aug 4th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. local tunnelLength = 100
  2. local cycles = 0
  3.  
  4. local ENUM_ORES = {"ore", "uranium","coal", "iron", "copper", "silver", "ruby", "tin", "redstone", "emerald", "diamond", "lapis", "gold", "yellorite", "sapphire", "ruby", "galena"}
  5.  
  6. function work()
  7. while true do
  8. subIterator = 1
  9. while subIterator <= tunnelLength do
  10. if turtle.getFuelLevel() < 150 then
  11. detail = turtle.getItemDetail(1)
  12. detail = detail or {}
  13.  
  14. if detail.name ~= "minecraft:coal" then
  15. print("We're out of fuel :(")
  16. os.sleep(10)
  17. end
  18.  
  19. turtle.select(1)
  20. turtle.refuel(1)
  21. end
  22.  
  23. if subIterator % 15 == 0 then
  24. turtle.back()
  25. turtle.select(2)
  26. turtle.placeDown()
  27. for k=2,16 do
  28. itemDetail = turtle.getItemDetail(k)
  29. if itemDetail ~= nil then
  30. if not isAnOre(itemDetail) then
  31. turtle.select(k)
  32. turtle.drop()
  33. elseif itemDetail.name == "minecraft:coal" then
  34. turtle.select(k)
  35. turtle.transferTo(1)
  36. end
  37. end
  38. end
  39. end
  40.  
  41.  
  42. forward(1)
  43. while followVein() do end
  44. up(1)
  45. while followVein() do end
  46. down(1)
  47. down(1)
  48. while followVein() do end
  49. up(1)
  50. subIterator = subIterator + 1
  51. end
  52.  
  53. turtle.turnLeft()
  54. turtle.turnLeft()
  55. forward(tunnelLength)
  56.  
  57. if cycles > 0 then
  58. turtle.turnLeft()
  59. forward((cycles * 2)+1)
  60. turtle.turnRight()
  61. end
  62.  
  63. success,blockData = turtle.inspect()
  64.  
  65. if not success then return false end
  66. --if blockData.name ~= "minecraft:chest" then return false end
  67.  
  68. for k=2,16 do
  69. itemDetail = turtle.getItemDetail(k)
  70. if itemDetail ~= nil then
  71. if isAnOre(itemDetail) then
  72. turtle.select(k)
  73. turtle.drop()
  74. elseif itemDetail.name == "minecraft:coal" then
  75. turtle.select(k)
  76. turtle.transferTo(1)
  77. end
  78. end
  79. end
  80.  
  81. cycles = cycles + 1
  82.  
  83. turtle.turnRight()
  84. for i=0,cycles*2 do
  85. forward(1)
  86. digUp(1)
  87. digDown(1)
  88. end
  89. turtle.turnRight()
  90. end
  91. end
  92.  
  93. instructions = {}
  94.  
  95. function followVein()
  96. instructions = {}
  97. lastFound = 0
  98. oresFound = 0
  99.  
  100. while true do
  101. if isBlockAnOre(turtle.inspect()) then
  102. forward(1)
  103. insertIntoTable("fwd")
  104. lastFound = 0
  105. oresFound = oresFound + 1
  106. elseif isBlockAnOre(turtle.inspectUp()) then
  107. up(1)
  108. insertIntoTable("up")
  109. lastFound = 0
  110. oresFound = oresFound + 1
  111. elseif isBlockAnOre(turtle.inspectDown()) then
  112. down(1)
  113. insertIntoTable("down")
  114. lastFound = 0
  115. oresFound = oresFound + 1
  116. else
  117. lastFound = lastFound + 1
  118. if lastFound == 1 then
  119. turtle.turnLeft()
  120. insertIntoTable("tl")
  121. elseif lastFound == 2 then
  122. turtle.turnRight()
  123. turtle.turnRight()
  124. insertIntoTable("tr")
  125. insertIntoTable("tr")
  126. else
  127. turtle.turnLeft()
  128. insertIntoTable("tl")
  129. break
  130. end
  131. end
  132. end
  133.  
  134. for k,v in pairs(instructions) do
  135. print("Print: ["..k.."] Backtracking: "..v)
  136. if v == "fwd" then
  137. turtle.back()
  138. elseif v == "up" then
  139. down(1)
  140. elseif v == "down" then
  141. up(1)
  142. elseif v == "tr" then
  143. turtle.turnLeft()
  144. elseif v == "tl" then
  145. turtle.turnRight()
  146. end
  147. end
  148.  
  149. return oresFound > 0
  150. end
  151.  
  152.  
  153. function insertIntoTable(dataString)
  154.  
  155. if table.getn(instructions) == 0 then
  156. table.insert(instructions, 1, dataString)
  157. return
  158. end
  159.  
  160. lastInstruction = instructions[1]
  161.  
  162. if lastInstruction ~= nil
  163. and (lastInstruction == "up" and dataString == "down"
  164. or lastInstruction == "down"and dataString == "up"
  165. or lastInstruction == "tl" and dataString == "tr"
  166. or lastInstruction == "tr" and dataString == "tl") then
  167. table.remove(instructions, 1)
  168. else
  169. table.insert(instructions, 1, dataString)
  170. end
  171.  
  172. end
  173.  
  174. function isBlockAnOre(success, data)
  175. if not success then return false end
  176.  
  177. print("Testing"..data.name)
  178. name = string.lower(data.name)
  179. for k,v in pairs(ENUM_ORES) do
  180. if string.find(name, v) then
  181. return true
  182. end
  183. end
  184. end
  185.  
  186. function isAnOre(data)
  187. name = string.lower(data.name)
  188. for k,v in pairs(ENUM_ORES) do
  189. if string.find(name, v) then
  190. return true
  191. end
  192. end
  193. end
  194.  
  195. function down(amount)
  196. for i=1,amount do
  197. while not turtle.down() do
  198. digDown()
  199. end
  200. end
  201. end
  202.  
  203. function up(amount)
  204. for i=1,amount do
  205. while not turtle.up() do
  206. digUp()
  207. end
  208. end
  209. end
  210.  
  211. function forward(amount)
  212. for i=1,amount do
  213. while not turtle.forward() do
  214. dig()
  215. end
  216. end
  217. end
  218.  
  219. function digUp()
  220. while turtle.detectUp() do
  221. turtle.digUp()
  222. os.sleep(0.3)
  223. end
  224. end
  225.  
  226. function digDown()
  227. while turtle.detectDown() do
  228. turtle.digDown()
  229. os.sleep(0.3)
  230. end
  231. end
  232.  
  233. function dig()
  234. while turtle.detect() do
  235. turtle.dig()
  236. os.sleep(0.3)
  237. end
  238. end
  239.  
  240. work()
Advertisement
Add Comment
Please, Sign In to add comment