Advertisement
bool15

Quarry 2

Jul 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --=======================================Standard Lbrary=====================================--
  2. function smartFuel()
  3. if turtle.getFuelLevel() <= 0 then
  4. onSlot = turtle.getSelectedSlot()
  5. while not turtle.refuel(1) do
  6.  
  7. onSlot = onSlot + 1
  8. if onSlot == 17 then
  9. onSlot = 1
  10. end
  11. turtle.select(onSlot)
  12. end
  13. end
  14. end
  15.  
  16. function smartFor()
  17. while not turtle.forward() do
  18. turtle.attack()
  19. turtle.dig()
  20. smartFuel()
  21. end
  22. end
  23.  
  24. function smartUp()
  25. while not turtle.up() do
  26. turtle.attackUp()
  27. turtle.digUp()
  28. smartFuel()
  29. end
  30. end
  31.  
  32. function smartDown()
  33. while not turtle.down() do
  34. turtle.attackDown()
  35. turtle.digDown()
  36. smartFuel()
  37. cleanse()
  38. end
  39. end
  40.  
  41. function smartMove(dir)
  42. if dir == -1 then
  43. turtle.turnLeft()
  44. smartFor()
  45. elseif dir == 1 then
  46. turtle.turnRight()
  47. smartFor()
  48. elseif dir == 2 then
  49. smartFor()
  50. elseif dir == -2 then
  51. turtle.turnRight()
  52. turtle.turnRight()
  53. smartFor()
  54. elseif dir == 3 then
  55. smartUp()
  56. elseif dir == -3 then
  57. smartDown()
  58. end
  59. end
  60. --=======================================CoodLibrary==========================-
  61. --start with "initCoords
  62. --====initCoords=====--
  63. function initCoords()
  64. x = 0
  65. y = 0
  66. z = 0
  67. --0 is forwards, 1 is left, goes clockwise to 3
  68. facing = 0
  69.  
  70. --used to remember location before returning to origin
  71. tempX = 0
  72. tempY = 0
  73. tempZ = 0
  74. tempFacing = 0
  75. end
  76.  
  77. function trackedFor()
  78. smartFor()
  79. if facing == 0 then
  80. y = y+1
  81. elseif facing == 1 then
  82. x = x+1
  83. elseif facing == 2 then
  84. y = y-1
  85. elseif facing == 3 then
  86. x = x-1
  87. end
  88. end
  89.  
  90. function trackedUp()
  91. smartUp()
  92. z = z+1
  93. end
  94.  
  95. function trackedDown()
  96. smartDown()
  97. z = z-1
  98. end
  99.  
  100. function trackedRight()
  101. changeFacing(1)
  102. turtle.turnRight()
  103. end
  104.  
  105. function trackedLeft()
  106. changeFacing(-1)
  107. turtle.turnLeft()
  108. end
  109. function trackedMove(dir)
  110. if dir == -1 then
  111. trackedLeft()
  112. trackedFor()
  113. elseif dir == 1 then
  114. trackedRight()
  115. trackedFor()
  116. elseif dir == 2 then
  117. trackedFor()
  118. elseif dir == -2 then
  119. trackedRight()
  120. trackedRight()
  121. trackedFor()
  122. elseif dir == 3 then
  123. trackedUp()
  124. elseif dir == -3 then
  125. trackedDown()
  126. end
  127. end
  128.  
  129. function changeFacing(change)
  130. facing = facing + change
  131. facing = facing % 4
  132. end
  133.  
  134. function face(targetFacing)
  135. while facing ~= targetFacing do
  136. turtle.turnRight()
  137. changeFacing(1)
  138.  
  139. end
  140. end
  141.  
  142. function toCoords(tarX,tarY,tarZ,tarFace)
  143.  
  144.  
  145. if z > tarZ then
  146. for i=tarZ+1,z do
  147. trackedMove(-3)
  148. end
  149. elseif z < tarZ then
  150. for i=z,tarZ-1 do
  151. trackedMove(3)
  152. end
  153. end
  154.  
  155. if y > tarY then
  156. face(2)
  157. for i=tarY+1,y do
  158. trackedMove(2)
  159. end
  160. elseif y < tarY then
  161. face(0)
  162. for i=y,tarY-1 do
  163. trackedMove(2)
  164. end
  165. end
  166.  
  167. if x > tarX then
  168. face(3)
  169. for i=tarX+1,x do
  170. trackedMove(2)
  171. end
  172. elseif x < tarX then
  173. face(1)
  174. for i=x,tarX-1 do
  175. trackedMove(2)
  176. end
  177. end
  178.  
  179. face(tarFace)
  180.  
  181. end
  182.  
  183. function saveCoords()
  184. tempX = x
  185. tempY = y
  186. tempZ = z
  187. tempFacing = facing
  188. end
  189.  
  190. function toSavedCoords()
  191. toCoords(tempX,tempY,tempZ,tempFacing)
  192. end
  193. --=======================================Quarry Functions=====================================--
  194. --======inputVars======--
  195. function inputVars()
  196. print("For the program to work, make sure the turtle's fuel is placed in the upper-left slot, and a chest is placed directly behind the turtle's starting position.")
  197. print("How far forwards from the turtle do you want the quarry to go?")
  198. CHUNKS = tonumber(read())/4
  199. print("How far to the left of the turtle do you want the quarry to go?")
  200. PITS = tonumber(read())/5
  201. print("How far do you want the turtle to dive before starting the quarry?")
  202. DIVE = tonumber(read())
  203. print("How deep is the quarry?")
  204. DEPTH = tonumber(read())
  205. coalEstimate = math.ceil(((((((6+(DEPTH*2))*CHUNKS)*2)*PITS)+(DIVE*2))/80)*1.1)
  206. print("This quarry will require approximately " .. tostring(coalEstimate) .. " coal to complete. Is what you entered correct? Enter 'N' to re enter input, or any other button to start quarry")
  207. if read() == "N" then
  208. inputVars()
  209. end
  210. end
  211.  
  212.  
  213.  
  214.  
  215. DEPTH = 1
  216. --how deep do I go before I start the quarry?
  217. DIVE = 0
  218.  
  219.  
  220. --which ores not to mine
  221. blackList = {"minecraft:stone","minecraft:grass","minecraft:dirt","minecraft:sand","minecraft:gravel","minecraft:sandstone","minecraft:cobblestone"}
  222. --copper, uran,yellorite,marble,tin,lead, alu, silver, quartz
  223. --======dump======--
  224. function dump()
  225.  
  226. --becomes true if every slot has non-blacklisted items
  227. local full = true
  228. for x = 1,16 do
  229. itemData = turtle.getItemDetail(x)
  230. if itemData then
  231. if onBlackList(itemData.name) then
  232. turtle.select(x)
  233. turtle.drop()
  234. full = false
  235. end
  236. end
  237. end
  238. if full then
  239. saveCoords()
  240. toCoords(0,0,0,2)
  241. storeGoods()
  242. toSavedCoords()
  243. end
  244. end
  245. --======hasRoom======--
  246. --returns if no slot is empty
  247. function hasRoom()
  248. for x = 1,16 do
  249. if turtle.getItemCount(x) == 0 then
  250. return true
  251. end
  252. end
  253.  
  254. return false
  255. end
  256. --======onBlackList======--
  257. function onBlackList(target)
  258. for z = 0,table.getn(blackList) do
  259. if target == blackList[z] then
  260. return true
  261. end
  262. end
  263.  
  264. return false
  265. end
  266. --======smartComp======--
  267. function smartComp()
  268. local sucess, data = turtle.inspect()
  269. if sucess then
  270. if not onBlackList(data.name) then
  271. turtle.dig()
  272. end
  273. end
  274. end
  275.  
  276. --=====storeGoods======--
  277. --excludes slot 1, saved for fuel
  278. --call when facing chest
  279. function storeGoods()
  280. for c = 2, 16 do
  281. turtle.select(c)
  282. turtle.drop()
  283. end
  284. end
  285. --======Store======--
  286. function store()
  287. turtle.dig()
  288. turtle.select(1)
  289. turtle.place()
  290. dropAll()
  291. turtle.select(1)
  292. turtle.dig()
  293. end
  294. --======cleanse======--
  295. function cleanse()
  296. data = turtle.getItemDetail(16)
  297. if data then
  298. dump()
  299. --store()
  300. end
  301. end
  302. --======smartMine======--
  303. function smartMine(dir)
  304. trackedMove(3*dir)
  305. smartComp()
  306. turtle.turnRight()
  307. smartComp()
  308. turtle.turnRight()
  309. smartComp()
  310. turtle.turnRight()
  311. smartComp()
  312. turtle.turnRight()
  313. end
  314. --======Scale======--
  315. --must be facing "east"
  316. function scale(dir)
  317.  
  318. for i = 0, DEPTH, 1 do
  319. if dir == -1 then
  320. smartMine(-1)
  321. elseif dir == 1 then
  322. smartMine(1)
  323. end
  324. end
  325. trackedMove(1)
  326. trackedMove(-1)
  327. trackedMove(2)
  328. end
  329.  
  330. --======chunk(2 holes in the ground)======--
  331. function chunk()
  332. scale(-1)
  333. scale(1)
  334. end
  335. --======Slice(a line of some chunks)======--
  336. --1 is west, -1 is east
  337. function slice(dir)
  338. for j = 0,CHUNKS-1 do
  339. chunk()
  340. end
  341.  
  342. if dir == 1 then
  343. trackedMove(-1)
  344. trackedMove(2)
  345. trackedMove(2)
  346. trackedMove(-1)
  347. elseif dir == -1 then
  348. trackedMove(1)
  349. trackedMove(2)
  350. trackedMove(1)
  351. end
  352.  
  353. end
  354.  
  355. --======goBack======--
  356. function goBack()
  357.  
  358. trackedMove(1)
  359. for v = 1, (PITS*5)-1 do
  360. trackedMove(2)
  361. end
  362. end
  363. --======pit(one or more slices)======--
  364. function pit()
  365. slice(1)
  366. slice(-1)
  367. end
  368.  
  369.  
  370. --===================Function Start========================-
  371. initCoords()
  372. inputVars()
  373. for i = 1, DIVE do
  374. trackedMove(-3)
  375. end
  376. for l = 1, PITS do
  377. pit()
  378.  
  379. end
  380. --goBack()
  381. --for i = 1, DIVE do
  382. -- trackedMove(3)
  383. --end
  384. toCoords(0,0,0,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement