Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.30 KB | None | 0 0
  1. --var and array define area start
  2. --get distance
  3. print("How long do you want the miner to go? (unit:block(s))")
  4. times = read()
  5. hbtimes = times --have been go forward times
  6. --end
  7.  
  8. local mineral = {
  9. "minecraft:coal_ore",
  10. "minecraft:iron_ore",
  11. "minecraft:redstone_ore",
  12. "minecraft:gold_ore",
  13. "minecraft:lapis_ore",
  14. "minecraft:quartz_ore",
  15. "minecraft:diamond_ore",
  16. "minecraft:emerald_ore",
  17. "minecraft:mossy_cobblestone",
  18. "minecraft:planks",
  19. "minecraft:fence",
  20. "minecraft:nether_brick",
  21. "minecraft:stone_slab",
  22. "minecraft:double_stone_slab",
  23. "minecraft:nether_brick_fence",
  24. "minecraft:nether_brick_stairs",
  25. "minecraft:nether_wart",
  26. "thermalfoundation:ore",
  27. }
  28. local special = {}
  29.  
  30. local smsg = {
  31. "Find diamond",
  32. "Find emerald",
  33. "Find monster spawner",
  34. "Find abandoned mine shafts",
  35. "Find abandoned mine shafts",
  36. "Find nether fortresses",
  37. "Find nether fortresses",
  38. "Find nether fortresses",
  39. "Find nether fortresses",
  40. "Find nether fortresses",
  41. "Find nether fortresses",
  42. }
  43.  
  44. local fluid = {
  45. "minecraft:water",
  46. "minecraft:flowing_water",
  47. "minecraft:lava",
  48. "minecraft:flowing_lava",
  49. }
  50. --var and array area end
  51.  
  52. --function area start
  53. --[[notes of var "side" in function go(),compare(),dig():
  54. 0:forward 1:left 2:back
  55. 3:right 4:up 5:down
  56.  
  57. notes of var "side" in function dfs():
  58. 0:around 1:up 2:down
  59. ]]
  60.  
  61. function go(side)
  62. if side == 0 then
  63. -- if not turtle.detectDown() then
  64. -- place(5, isearch("minecraft:cobblestone"))
  65. -- end
  66. while not turtle.forward() do
  67. turtle.dig()
  68. end
  69. end
  70.  
  71. if side == 1 then
  72. turtle.turnLeft()
  73. while not turtle.forward() do
  74. turtle.dig()
  75. end
  76. turtle.turnRight()
  77. end
  78.  
  79. if side == 2 then
  80. while not turtle.back() do
  81. turtle.turnLeft()
  82. turtle.turnLeft()
  83. turtle.dig()
  84. turtle.turnRight()
  85. turtle.turnRight()
  86. turtle.turnRight()
  87. end
  88. end
  89.  
  90. if side == 3 then
  91. turtle.turnRight()
  92. while not turtle.forward() do
  93. turtle.dig()
  94. end
  95. turtle.turnLeft()
  96. end
  97.  
  98. if side == 4 then
  99. while not turtle.up() do
  100. turtle.digUp()
  101. end
  102. end
  103.  
  104. if side == 5 then
  105. while not turtle.down() do
  106. turtle.digDown()
  107. end
  108. end
  109. end
  110.  
  111. function compare(side)
  112. if side == 0 then
  113. success, data = turtle.inspect() --get block data
  114.  
  115. if success then --compare block data
  116. -- for i = 1, table.getn(fluid) do
  117. -- if data.name == fluid[i] then
  118. -- place(0, isearch("minecraft:cobblestone"))
  119. -- end
  120. -- end
  121. -- for i = 1, table.getn(special) do
  122. -- if data.name == special[i] then
  123. -- x, y, z = gps.locate()
  124. -- asmsg = smsg[i].."x:"..x.." y:"..y.." z:"..z
  125. -- alert(asmsg)
  126. -- asmsg = "nil"
  127. -- data = "nil"
  128. -- return "special"
  129. -- end
  130. -- end
  131.  
  132. for i = 1, table.getn(mineral) do
  133. if data.name == mineral[i] then
  134. data = "nil"
  135. return true
  136. end
  137. end
  138. else
  139. return false
  140. end
  141.  
  142. return false
  143. end
  144.  
  145. if side == 4 then
  146. success, data = turtle.inspectUp() --get block data
  147.  
  148. if success then --compare block data
  149. -- for i = 1, table.getn(fluid) do
  150. -- if data.name == fluid[i] then
  151. -- place(4, isearch("minecraft:cobblestone"))
  152. -- end
  153. -- end
  154.  
  155. for i = 1, table.getn(special) do
  156. if data.name == special[i] then
  157. asmsg = smsg[i].."x:"..x.." y:"..y.." z:"..z
  158. alert(asmsg)
  159. asmsg = "nil"
  160. data = "nil"
  161. return "special"
  162. end
  163. end
  164.  
  165. for i = 1, table.getn(mineral) do
  166. if data.name == mineral[i] then
  167. data = "nil"
  168. return true
  169. end
  170. end
  171. else
  172. return false
  173. end
  174.  
  175. return false
  176. end
  177.  
  178. if side == 5 then
  179. success, data = turtle.inspectDown() --get block data
  180.  
  181. if success then --compare block data
  182. -- for i = 1, table.getn(fluid) do
  183. -- if data.name == fluid[i] then
  184. -- place(5, isearch("minecraft:cobblestone"))
  185. -- end
  186. -- end
  187.  
  188. -- for i = 1, table.getn(special) do
  189. -- if data.name == special[i] then
  190. -- asmsg = smsg[i].."x:"..x.." y:"..y.." z:"..z
  191. -- alert(asmsg)
  192. -- asmsg = "nil"
  193. -- data = "nil"
  194. -- return "special"
  195. -- end
  196. -- end
  197.  
  198. for i = 1, table.getn(mineral) do
  199. if data.name == mineral[i] then
  200. data = "nil"
  201. return true
  202. end
  203. end
  204. else
  205. return false
  206. end
  207.  
  208. return false
  209. end
  210. end
  211.  
  212. function dig(side)
  213. if side == 0 then
  214. turtle.dig()
  215. end
  216.  
  217. if side == 1 then
  218. turtle.turnLeft()
  219. turtle.dig()
  220. turtle.turnRight()
  221. end
  222.  
  223. if side == 2 then
  224. turtle.turnLeft()
  225. turtle.turnLeft()
  226. turtle.dig()
  227. turtle.turnRight()
  228. turtle.turnRight()
  229. end
  230.  
  231. if side == 3 then
  232. turtle.turnRight()
  233. turtle.dig()
  234. turtle.turnLeft()
  235. end
  236.  
  237. if side == 4 then
  238. turtle.digUp()
  239. end
  240.  
  241. if side == 5 then
  242. turtle.digDown()
  243. end
  244. end
  245.  
  246. function dfs(side)
  247. if side == 0 then
  248. if compare(0) == "special" then
  249. return "special"
  250. end
  251.  
  252. for i = 1, 4 do
  253. if compare(0) then
  254. dig(0)
  255. go(0)
  256.  
  257. dfs(0)
  258. dfs(1)
  259. dfs(2)
  260.  
  261. go(2)
  262. place(0, isearch("minecraft:cobblestone"))
  263. end
  264. turtle.turnLeft()
  265. end
  266. end
  267.  
  268. if side == 1 then
  269. if compare(4) == "special" then
  270. return "special"
  271. end
  272.  
  273. if compare(4) then
  274. dig(4)
  275. go(4)
  276.  
  277. dfs(0)
  278. dfs(1)
  279. dfs(2)
  280.  
  281. go(5)
  282. place(4, isearch("minecraft:cobblestone"))
  283. end
  284. end
  285.  
  286. if side == 2 then
  287. if compare(5) == "special" then
  288. return "special"
  289. end
  290.  
  291. if compare(5) then
  292. dig(5)
  293. go(5)
  294.  
  295. dfs(0)
  296. dfs(1)
  297. dfs(2)
  298.  
  299. go(4)
  300. place(5, isearch("minecraft:cobblestone"))
  301. end
  302. end
  303. end
  304.  
  305. function place(side, grid)
  306. if side == 0 then
  307. turtle.select(grid)
  308. turtle.place()
  309. end
  310.  
  311. if side == 1 then
  312. turtle.turnLeft()
  313. turtle.select(grid)
  314. turtle.place()
  315. turtle.turnRight()
  316. end
  317.  
  318. if side == 2 then
  319. turtle.turnLeft()
  320. turtle.turnLeft()
  321. turtle.select(grid)
  322. turtle.place()
  323. turtle.turnRight()
  324. turtle.turnRight()
  325. end
  326.  
  327. if side == 3 then
  328. turtle.turnRight()
  329. turtle.select(grid)
  330. turtle.place()
  331. turtle.turnLeft()
  332. end
  333.  
  334. if side == 4 then
  335. turtle.select(grid)
  336. turtle.placeUp()
  337. end
  338.  
  339. if side == 5 then
  340. turtle.select(grid)
  341. turtle.placeDown()
  342. end
  343. end
  344.  
  345. function alert(message)
  346. --rednet.open("right")
  347. --rednet.broadcast(message)
  348. end
  349.  
  350. function isearch(iname) --item search, item name
  351. for i = 1, 16 do
  352. local data = turtle.getItemDetail(i)
  353. if data then
  354. if iname == data.name then
  355. iname = "nil"
  356. data = "nil"
  357. return i
  358. end
  359. end
  360. end
  361. return false
  362. end
  363. --function area end
  364.  
  365. for i = 1, 1 do
  366. alert("Starting mining...")
  367.  
  368. for i = 1, times do
  369. dig(0)
  370. go(0)
  371. dig(4)
  372. dfs(0)
  373. dfs(2)
  374. end
  375.  
  376. alert("Start backing...")
  377.  
  378. turtle.turnLeft()
  379. turtle.turnLeft()
  380. go(4)
  381. place(5, isearch("minecraft:torch"))
  382.  
  383.  
  384. for i = 1, hbtimes do
  385. go(0)
  386. dfs(0)
  387. dfs(1)
  388.  
  389. if i%8 == 0 then
  390. place(5, isearch("minecraft:torch"))
  391. end
  392. end
  393.  
  394. turtle.turnLeft()
  395. turtle.turnLeft()
  396. go(5)
  397. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement