Advertisement
makmoud98

Untitled

Feb 16th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. names = {'minecraft:chest', 'ComputerCraft:CC-Turtle','minecraft:obsidian','minecraft:flowing_lava','minecraft:flowing_water','minecraft:lava','minecraft:water','chisel:andesite','chisel:limestone','minecraft:dirt','minecraft:stone','minecraft:granite','minecraft:diorite','minecraft:andesite','minecraft:gravel', 'minecraft:sand', 'minecraft:cobblestone'}
  2.  
  3. function is_stone(success, data)
  4. if success then
  5. for i = 1, #names do
  6. if names[i] == data.name then
  7. return ""
  8. end
  9. end
  10. return data.name
  11. end
  12. return ""
  13. end
  14.  
  15. function dig_sides()
  16. turtle.turnLeft()
  17. local block_left = is_stone(turtle.inspect())
  18. if block_left ~= "" then
  19. print('found: ', block_left)
  20. dig_vein(1, {}, false)
  21. print('end of vein')
  22. end
  23. turtle.turnRight()
  24. turtle.turnRight()
  25. local block_right = is_stone(turtle.inspect())
  26. if block_right ~= "" then
  27. print('found: ', block_right)
  28. dig_vein(1, {}, false)
  29. print('end of vein')
  30. end
  31. turtle.turnLeft()
  32. end
  33.  
  34. function dig_up_down()
  35. local block_up = is_stone(turtle.inspectUp())
  36. local block_down = is_stone(turtle.inspectDown())
  37. if block_up ~= "" then
  38. print('found: ', block_up)
  39. dig_vein(1, {}, false)
  40. print('end of vein')
  41. end
  42. if block_down ~= "" then
  43. print('found: ', block_down)
  44. dig_vein(1, {}, false)
  45. print('end of vein')
  46. end
  47. end
  48.  
  49. function dig_shaft()
  50. for i = 1, 4 do
  51. if turtle.detect() then
  52. turtle.dig()
  53. end
  54. for x=0,20 do
  55. if not turtle.forward() then
  56. turtle.dig()
  57. else
  58. break
  59. end
  60. end
  61. if i ~= 1 then
  62. dig_sides()
  63. end
  64. dig_up_down()
  65. end
  66. for i = 1, 4 do
  67. turtle.back()
  68. end
  69. end
  70.  
  71. function dig_vein(i, path, moving_back)
  72. if path[i] == nil then
  73. path[i] = {}
  74. end
  75. --check up down and forward first,
  76. if not moving_back then
  77. if #path[i] == 0 then
  78. local block_up = is_stone(turtle.inspectUp())
  79. if block_up ~= "" then
  80. path[i][#path[i]+1] = 0
  81. end
  82. local block_down = is_stone(turtle.inspectDown())
  83. if block_down ~= "" then
  84. path[i][#path[i]+1] = 1
  85. end
  86. for j = 1, 4 do--forward, left, back, right
  87. local block = is_stone(turtle.inspect())
  88. if block ~= "" then
  89. path[i][#path[i]+1] = 1 + j
  90. end
  91. turtle.turnLeft()
  92. end
  93. --print("len: " .. #path[i])
  94. end
  95. if #path[i] == 0 then--go back from the path you started
  96. return dig_vein(i, path, true)
  97. else
  98. local dir = path[i][1]
  99. --print("dir: " .. dir)
  100. if dir == 0 then
  101. turtle.digUp()
  102. for x=0,20 do
  103. if not turtle.up() then
  104. turtle.digUp()
  105. else
  106. break
  107. end
  108. end
  109. elseif dir == 1 then
  110. turtle.digDown()
  111. turtle.down()
  112. elseif dir == 2 then
  113. turtle.dig()
  114. for x=0,20 do
  115. if not turtle.forward() then
  116. turtle.dig()
  117. else
  118. break
  119. end
  120. end
  121. elseif dir == 3 then
  122. turtle.turnLeft()
  123. turtle.dig()
  124. for x=0,20 do
  125. if not turtle.forward() then
  126. turtle.dig()
  127. else
  128. break
  129. end
  130. end
  131. elseif dir == 4 then
  132. turtle.turnLeft()
  133. turtle.turnLeft()
  134. turtle.dig()
  135. for x=0,20 do
  136. if not turtle.forward() then
  137. turtle.dig()
  138. else
  139. break
  140. end
  141. end
  142. elseif dir == 5 then
  143. turtle.turnRight()
  144. turtle.dig()
  145. for x=0,20 do
  146. if not turtle.forward() then
  147. turtle.dig()
  148. else
  149. break
  150. end
  151. end
  152. end
  153. i = i + 1
  154. return dig_vein(i, path, false)
  155. end
  156. else--moving back
  157. i = i - 1
  158. if i == 0 then
  159. return 0
  160. elseif #path[i] > 0 then
  161. local dir = path[i][1]
  162. if dir == 0 then
  163. turtle.down()
  164. elseif dir == 1 then
  165. for x=0,20 do
  166. if not turtle.up() then
  167. turtle.digUp()
  168. else
  169. break
  170. end
  171. end
  172. elseif dir == 2 then
  173. turtle.back()
  174. elseif dir == 3 then
  175. turtle.back()
  176. turtle.turnRight()
  177. elseif dir == 4 then
  178. turtle.back()
  179. turtle.turnLeft()
  180. turtle.turnLeft()
  181. elseif dir == 5 then
  182. turtle.back()
  183. turtle.turnLeft()
  184. end
  185. table.remove(path[i], 1)
  186. if #path[i] > 0 then
  187. return dig_vein(i, path, false)
  188. else
  189. return dig_vein(i, path, true)
  190. end
  191. end
  192. end
  193. end
  194.  
  195. function refuel(f)
  196. for k = 1, 16 do
  197. turtle.select(k)
  198. if turtle.refuel(f) then
  199. return true
  200. end
  201. end
  202. end
  203.  
  204. function dropAll()
  205. for k = 1, 16 do
  206. turtle.select(k)
  207. turtle.dropDown()
  208. end
  209. end
  210.  
  211. function hasSpace()
  212. for slot=1,16 do
  213. if turtle.getItemDetail(slot) == nil then
  214. return true
  215. end
  216. end
  217. return false
  218. end
  219.  
  220. function mine(length)
  221. for i=1,length do
  222. if i == 100 then
  223. break
  224. end
  225. if turtle.getFuelLevel() < (length*1.2) then
  226. if not refuel(2) then
  227. return false
  228. end
  229. end
  230. if not hasSpace() then
  231. for k = 2, i do
  232. turtle.back()
  233. end
  234. refuel(5)
  235. dropAll()
  236. if turtle.getFuelLevel() < (i*1.2) then
  237. return false
  238. end
  239. for k = 2, i do
  240. for x=0,20 do
  241. if not turtle.forward() then
  242. turtle.dig()
  243. else
  244. break
  245. end
  246. end
  247. end
  248. end
  249. if turtle.detect() then
  250. turtle.dig()
  251. end
  252. for x=0,20 do
  253. if not turtle.forward() then
  254. turtle.dig()
  255. else
  256. break
  257. end
  258. end
  259. dig_up_down()
  260. dig_sides()
  261. if turtle.detectDown() then
  262. turtle.digDown()
  263. end
  264. turtle.down()
  265. dig_sides()
  266. dig_up_down()
  267. for x=0,20 do
  268. if not turtle.up() then
  269. turtle.digUp()
  270. else
  271. break
  272. end
  273. end
  274. end
  275. turtle.turnLeft()
  276. turtle.turnLeft()
  277. for i = 2, length do
  278. for x=0,20 do
  279. if not turtle.forward() then
  280. turtle.dig()
  281. else
  282. break
  283. end
  284. end
  285. if turtle.getFuelLevel() == 0 then
  286. return false
  287. end
  288. end
  289. return true
  290. end
  291.  
  292. if mine(100) then
  293. dropAll()
  294. print('complete!!!')
  295. else
  296. print('ran out of fuel')
  297. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement