Advertisement
makmoud98

Untitled

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