Advertisement
Guest User

Untitled

a guest
Apr 16th, 2019
1,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.95 KB | None | 0 0
  1. SIDE_WIDTH = 10
  2. TRASH = { 'minecraft:stone', 'minecraft:cobblestone', 'minecraft:gravel', 'minecraft:dirt', 'chisel:basalt2' }
  3. ORE_ITEMS = {
  4. { 'minecraft:coal_ore', 'minecraft:coal' },
  5. { 'minecraft:diamond_ore', 'minecraft:diamond' },
  6. { 'minecraft:restone_ore', 'minecraft:restone' },
  7. { 'galacticraftcore:basic_block_ore', 'galacticcraftcore:basic_item' },
  8. { 'minecraft:quarz_ore', 'minecraft:quarz' },
  9. { 'minecraft:nether_quarz_ore', 'minecraft:nether_quarz' },
  10. { 'appliedenergistics:quartz_ore', 'appliedenergistsics2:material' },
  11. { 'appliedenergistics:charged_quartz_ore', 'appliedenergistics:material' }
  12. }
  13. EXTRA_ORE_NAMES = {
  14. 'galacticraftcore:basic_block_core',
  15. 'ic2:resource',
  16. 'thermalfoundation:ore'
  17. }
  18.  
  19. t = turtle
  20.  
  21.  
  22. function contains(list, element)
  23. i = 0
  24. while i < #list do
  25. i = i + 1
  26. if list[i] == element then
  27. return true
  28. end
  29. end
  30. return false
  31. end
  32.  
  33.  
  34. function getItemName(data)
  35. name = data['name']
  36. if name == 'minecraft:stone' and data['metadata'] == 0 then
  37. return 'minecraft:cobblestone'
  38. end
  39.  
  40. i = 1
  41. while i <= #ORE_ITEMS do
  42. if ORE_ITEMS[i][1] == name then
  43. return ORE_ITEMS[i][2]
  44. end
  45. i = i + 1
  46. end
  47. return name
  48. end
  49.  
  50. function isChest(data)
  51. if data == nil or not (type(data) == 'table') then
  52. return false
  53. end
  54.  
  55. return not (string.find(data['name'], 'chest') == nil)
  56. end
  57.  
  58. function selectChest()
  59. slot = 1
  60. while slot <= 16 do
  61. if t.getItemCount(slot) > 0 and isChest(t.getItemDetail(slot)) then
  62. t.select(slot)
  63. return true
  64. end
  65. slot = slot + 1
  66. end
  67. return false
  68. end
  69.  
  70. function autoRefuel()
  71. slot = 1
  72. while slot <= 16 do
  73. if t.getFuelLevel() > 3000 then
  74. return
  75. end
  76. if t.getItemCount(slot) > 0 then
  77. if t.getItemDetail(slot)['name'] == 'minecraft:coal' then
  78. t.select(slot)
  79. neededCoal = math.floor((3000 - t.getFuelLevel()) / 80) + 1
  80. if t.getItemCount() < neededCoal then
  81. neededCoal = t.getItemCount()
  82. end
  83.  
  84. t.refuel(neededCoal)
  85. print('Refueled to ' .. t.getFuelLevel() .. ' using ' .. neededCoal .. ' Coal')
  86. end
  87. end
  88. slot = slot + 1
  89. end
  90. print('Running low on fuel: ' .. t.getFuelLevel())
  91. end
  92.  
  93. function countCobble()
  94. totalCount = 0
  95. slot = 1
  96. while slot <= 16 do
  97. data = t.getItemDetail(slot)
  98. if data and data['name'] == 'minecraft:cobblestone' then
  99. totalCount = totalCount + t.getItemCount(slot)
  100. end
  101. slot = slot + 1
  102. end
  103. return totalCount
  104. end
  105.  
  106. function selectCobble()
  107. totalCount = 0
  108. slot = 1
  109. while slot <= 16 do
  110. data = t.getItemDetail(slot)
  111. if data and data['name'] == 'minecraft:cobblestone' then
  112. t.select(slot)
  113. return true
  114. end
  115. slot = slot + 1
  116. end
  117.  
  118. return false
  119. end
  120.  
  121. function stackInv()
  122. slot = 1
  123. while slot <= 16 do
  124. if t.getItemCount(slot) > 0 then
  125. otherSlot = slot + 1
  126. t.select(slot)
  127. while otherSlot <= 16 and t.getItemSpace(slot) > 0 do
  128. if t.compareTo(otherSlot) then
  129. t.select(otherSlot)
  130. t.transferTo(slot, t.getItemSpace(slot))
  131. t.select(slot)
  132. end
  133. otherSlot = otherSlot + 1
  134. end
  135. end
  136. slot = slot + 1
  137. end
  138. end
  139.  
  140. function hasGravity(data)
  141. if data == nil or not (type(data) == 'table') then
  142. return false
  143. end
  144. name = data['name']
  145. if name == 'minecraft:gravel' or name == 'minecraft:sand' then
  146. return true
  147. else
  148. return false
  149. end
  150. end
  151.  
  152.  
  153. function preDig()
  154. if not (t.getSelectedSlot() == 1) then
  155. t.select(1)
  156. end
  157. end
  158.  
  159. function countFreeSlots()
  160. freeSlots = 0
  161. slot = 1
  162. while slot <= 16 do
  163. if t.getItemCount(slot) == 0 then
  164. freeSlots = freeSlots + 1
  165. end
  166. slot = slot + 1
  167. end
  168. return freeSlots
  169. end
  170.  
  171. function disposeTrash()
  172. slot = 1
  173. while slot <= 16 do
  174. if t.getItemCount(slot) > 0 then
  175. name = t.getItemDetail(slot)['name']
  176. if contains(TRASH, name) or not (string.find(name, 'botania:') == nil) then
  177. t.select(slot)
  178. t.drop()
  179. end
  180. end
  181. slot = slot + 1
  182. end
  183. end
  184.  
  185. function isOre(data)
  186. if data == nil or not (type(data) == 'table') then
  187. return false
  188. end
  189. if not (string.find(data['name'], 'ore') == nil) then
  190. return true
  191. end
  192. i = 1
  193. while i <= #EXTRA_ORE_NAMES do
  194. if data['name'] == EXTRA_ORE_NAMES[i] then
  195. return true
  196. end
  197. i = i + 1
  198. end
  199. i = 1
  200. while i <= #ORE_ITEMS do
  201. if data['name'] == ORE_ITEMS[i][1] then
  202. return true
  203. end
  204. i = i + 1
  205. end
  206. return false
  207. end
  208.  
  209. function checkOreAndMine(dir)
  210. -- Mines for ores recursivly
  211. if dir == 'down' then
  212. _, data = t.inspectDown()
  213. if isOre(data) then
  214. digDownCorrect()
  215. t.down()
  216. checkOreAndMine('down')
  217. checkOreAndMine('front')
  218. t.turnRight()
  219. checkOreAndMine('front')
  220. t.turnRight()
  221. checkOreAndMine('front')
  222. t.turnRight()
  223. checkOreAndMine('front')
  224. t.turnRight()
  225. t.up()
  226. end
  227. elseif dir == 'up' then
  228. _, data = t.inspectUp()
  229. if isOre(data) then
  230. digUpCorrect()
  231. t.up()
  232. checkOreAndMine('up')
  233. checkOreAndMine('front')
  234. t.turnRight()
  235. checkOreAndMine('front')
  236. t.turnRight()
  237. checkOreAndMine('front')
  238. t.turnRight()
  239. checkOreAndMine('front')
  240. t.turnRight()
  241. t.down()
  242. end
  243. elseif dir == 'front' then
  244. _, data = t.inspect()
  245. if isOre(data) then
  246. digAndMoveCorrect()
  247. --digCorrect()
  248. checkOreAndMine('front')
  249. checkOreAndMine('down')
  250. checkOreAndMine('up')
  251. t.turnRight()
  252. checkOreAndMine('front')
  253. t.turnRight()
  254. t.turnRight()
  255. checkOreAndMine('front')
  256. t.turnRight()
  257.  
  258. t.back()
  259. end
  260. end
  261. end
  262.  
  263.  
  264. function digSide(length)
  265. preDig()
  266. digUpCorrect()
  267. local pos = 0
  268. checkOreAndMine('down')
  269. while pos < length do
  270. --digCorrect()
  271. --t.forward()
  272. digAndMoveCorrect()
  273. checkOreAndMine('down')
  274. digUpCorrect()
  275. --disposeTrash()
  276. pos = pos + 1
  277. end
  278.  
  279. checkOreAndMine('front')
  280. t.up()
  281. digUpCorrect()
  282. checkOreAndMine('front')
  283. t.up()
  284. digUpCorrect()
  285. checkOreAndMine('front')
  286. t.up()
  287. checkOreAndMine('front')
  288. t.turnLeft()
  289. t.turnLeft()
  290. --disposeTrash()
  291.  
  292. local pos2 = 0
  293. checkOreAndMine('up')
  294. while pos2 < length do
  295. --digCorrect()
  296. --t.forward()
  297. digAndMoveCorrect()
  298. checkOreAndMine('up')
  299. digDownCorrect()
  300. --disposeTrash()
  301. pos2 = pos2 + 1
  302. end
  303.  
  304. digDownCorrect()
  305. t.down()
  306. digDownCorrect()
  307. t.down()
  308. t.down()
  309. disposeTrash()
  310. end
  311.  
  312. function digAndMoveCorrect()
  313. t.select(1)
  314. while t.detect() do
  315. t.dig()
  316. end
  317. while not t.forward() do
  318. print('FAILED TO MOVE')
  319. t.dig()
  320. end
  321. end
  322.  
  323. function digCorrect()
  324. keep_digging = true
  325. while keep_digging do
  326. keep_digging = false
  327. t.dig()
  328. if hasGravity(data) then
  329. sleep(1)
  330. keep_digging = true
  331. else
  332. return true
  333. end
  334. end
  335. return false
  336. end
  337.  
  338. function digDownCorrect()
  339. t.digDown()
  340. return true
  341. end
  342.  
  343. function digUpCorrect()
  344. t.digUp()
  345. return true
  346. end
  347.  
  348. stateChecked = 0
  349. while true do
  350. stateChecked = stateChecked - 1
  351. if stateChecked <= 0 then
  352. stateChecked = 5
  353. autoRefuel() -- Keeps fuel at 1000
  354. stackInv() -- Only very rarely needed
  355. preDig()
  356. end
  357.  
  358. --digCorrect()
  359. checkOreAndMine('down')
  360. --t.forward()
  361. digAndMoveCorrect()
  362. --disposeTrash()
  363. t.turnRight()
  364. digSide(SIDE_WIDTH)
  365. --stackInv() -- Recover stack fails
  366. digSide(SIDE_WIDTH)
  367. --disposeTrash()
  368. --stackInv() -- Recover stack fails
  369. t.turnLeft()
  370.  
  371. if t.getFuelLevel() < ((SIDE_WIDTH*4*2) + (4*3) + 20) then
  372. print('Out of fuel!')
  373. print('Add fuel and run area_mine again')
  374. break
  375. end
  376.  
  377. if countFreeSlots() < 3 then
  378. if selectChest() then
  379. t.turnRight()
  380. t.turnRight()
  381. t.place()
  382. slot = 1
  383. totalDeposited = 0
  384. while slot <= 16 do
  385. itemData = t.getItemDetail(slot)
  386. if t.getItemCount(slot) > 0 and not isChest(itemData) and not (itemData['name'] == 'minecraft:coal') then
  387. t.select(slot)
  388. count = t.getItemCount()
  389. t.drop(count)
  390. totalDeposited = totalDeposited + count
  391. end
  392. slot = slot + 1
  393. end
  394. print('Deposited ' .. totalDeposited .. ' items into a chest.')
  395. t.turnRight()
  396. t.turnRight()
  397. else
  398. print('Inventory is too full and no chest is available!')
  399. print('Clear inv, (add chests) and run area_mine again')
  400. break
  401. end
  402. end
  403.  
  404. --if true then
  405. -- break
  406. --end
  407. end
  408.  
  409. print('Stopped')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement