Advertisement
Guest User

Quarry version 2.2.3

a guest
Jan 8th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.99 KB | None | 0 0
  1. --[[TO DO:
  2. Rednet statistics tracker coming soon
  3.  
  4. Version 2.2.3
  5. Recent changes: added an argument for which side the chest is on.
  6. Directions: If you want, place a chest right behind where you place the turtle.
  7. It will place things here when its done
  8.  
  9. Also, if auto-empty is on, it will always eject the things it has
  10. into the place where a chest is supposed to be,
  11. it just dosen't check for a chest
  12. ]]
  13.  
  14. --Check Fuel Disabling for those on softcore
  15. doCheckFuel = true
  16. --For those that find this annoying
  17. forceAutoEmpty = true
  18. --For just plain emptying large amounts of land, will not annoy you with auto-Emptying or max size restraints
  19. careAboutResources = true
  20.  
  21. --This is how many (theoretical) slots it will fill with cobble. e.g. 13 allows 13 slots for cobble (or other stack) and 2 slots for other things.
  22. --Maximum here is 16
  23. maxslots = 13
  24. --If your job is bigger than it can carry (as defined by max slots) it will default to auto-empty
  25. --Note: For counting to work properly, cobblestone must be the first block it mines, or put a cobble in slot 1
  26.  
  27. --Defining things
  28. _ = {...}
  29. if _[1] == nil then
  30. dropSide = "front"
  31. else
  32. dropSide = _[1]
  33. end
  34.  
  35. function screen(xPos,yPos)
  36. term.clear()
  37. term.setCursorPos(xPos,yPos)
  38. end
  39. function mine() -- Basic Move Forward
  40. while turtle.forward() == false do
  41. if turtle.dig() == false then
  42. turtle.attack()
  43. mined = mined - 1
  44. end
  45. mined = mined + 1
  46. end
  47. if Cdouble == 1 then
  48. if turtle.digDown() == true then
  49. mined = mined + 1
  50. end
  51. end
  52. if Cdouble == 0 then
  53. moved = moved + 1
  54. else
  55. moved = moved + 2
  56. end
  57. display()
  58. end
  59. function mineRow() -- Move a row then turn
  60. if cRows ~= 0 then -- cRows is "Rows Completed"
  61. for length=1, x do --It does this check because on the first row of a layer,
  62. mine()             --   it already occupies the first position
  63. end
  64. else
  65. for length=1, x-1 do
  66. mine()
  67. end
  68. end
  69. cRows = cRows + 1
  70. end
  71. function display() --Runs in Mine(), display information to the screen in a certain place
  72. percent = math.ceil((moved/volume)*100)
  73. term.setCursorPos(1,2)
  74. term.clearLine()
  75. print(mined)
  76. term.setCursorPos(1,4)
  77. term.clearLine()
  78. print(percent.."%")
  79. end
  80.  
  81. totals = {cobble = 0, sand = 0, other = 0} -- Total for display (cannot go inside function)
  82. function count() --Done after every row of auto-empty and at end
  83. slot = {}        --Detection of blocks code is 1: Cobble 2: Other Raw 3:Other
  84. for i=1, 16 do   --[1] is type, [2] is number
  85. slot[i] = {}
  86. slot[i][2] = turtle.getItemCount(i)
  87. end
  88. doCheckSand = false
  89. if area > 100 then
  90. doCheckSand = true
  91. end
  92.  
  93. slot[1][1] = 1   -- = Assumes Cobble/Main
  94. for i=2, 16 do   --Cobble Check
  95. turtle.select(i)
  96. if turtle.compareTo(1) then
  97. slot[i][1] = 1
  98. end
  99. end
  100. for i=2, 16 do   --Sand/Raw Check
  101. tempItemCount = turtle.getItemCount(i)
  102. if tempItemCount > 32 and doCheckSand then
  103. slot[i][1] = 2
  104. elseif tempItemCount > 0 then
  105. slot[i][1] = 3
  106. end
  107. end
  108. for i=1, 16 do
  109. if slot[i][1] == 1 then
  110. totals.cobble = slot[i][2] + totals.cobble
  111. elseif slot[i][1] == 2 then
  112. totals.sand = slot[i][2] + totals.sand
  113. else
  114. totals.other = slot[i][2] + totals.other
  115. end
  116. end
  117.  
  118. end
  119.  
  120. function endDrop(final)
  121. if final ~= false then
  122. final = true
  123. end
  124. if dropSide == "left" then --Turning
  125. turtle.turnRight()
  126. elseif dropSide == "right" then
  127. turtle.turnLeft()
  128. end
  129. turtle.select(1)
  130. if dropSide == "top" then -- Drops to top
  131. if final == false then
  132. avar = turtle.getItemCount(1) --Dosen't drop 1 cobblestone for future counting purposes if autofill
  133. turtle.dropUp(avar-1)
  134. elseif turtle.detectUp() then
  135. turtle.dropUp()
  136. for i=2, 16 do
  137. turtle.select(i)
  138. turtle.dropUp()
  139. end
  140. end
  141. elseif dropSide == "bottom" then --Drops to bottom
  142. if final == false then
  143. avar = turtle.getItemCount(1)
  144. turtle.dropDown(avar-1)
  145. elseif turtle.detectDown() then
  146. turtle.dropDown()
  147. for i=2, 16 do
  148. turtle.select(i)
  149. turtle.dropDown()
  150. end
  151. end
  152. else --Drops to front
  153. if final == false then
  154. avar = turtle.getItemCount(1)
  155. turtle.drop(avar-1)
  156. elseif turtle.detect() then
  157. turtle.drop()
  158. for i=2, 16 do
  159. turtle.select(i)
  160. turtle.drop()
  161. end
  162. end
  163. end
  164. turtle.select(1)
  165.  
  166. if dropSide == "right" then --Turning, inverted
  167. turtle.turnRight()
  168. elseif dropSide == "left" then
  169. turtle.turnLeft()
  170. end
  171.  
  172. end
  173.  
  174.  -----------------------------------------------------------------
  175. --Input Phase
  176. screen(1,1)
  177. print("----- Welcome to Quarry! -----")
  178. print("")
  179. --Dimensions of Hole
  180. print("What dimensions?")
  181. print("")
  182. term.write("Length: ")
  183. x = io.read()
  184.  
  185. term.write("Width: ")
  186. z = io.read()
  187.  
  188. term.write("Height: ")
  189. y = io.read()
  190.  
  191. if not tonumber(x) or x == 0 then
  192. x = 3
  193. end
  194. if not tonumber(y) or y == 0 then
  195. y = 2
  196. end
  197. if not tonumber(z) or z == 0 then
  198. z = 3
  199. end
  200.  
  201. x = math.abs(tonumber(x))
  202. y = math.abs(tonumber(y))
  203. z = math.abs(tonumber(z))
  204.  
  205.  
  206. Cdouble = 0
  207. --Check for if it can do doubles
  208. if math.ceil(y/2) == y/2 then
  209. Cdouble = 1
  210. end
  211.  
  212. volume = x*y*z
  213. area = x*z
  214.  
  215. if maxslots > 16 then
  216. maxslots = 16
  217. end
  218. maxsize = maxslots*64
  219. if Cdouble == 1 then
  220. maxsize = maxsize/2
  221. end
  222.  
  223. empty = 0
  224.  
  225.  
  226. --Checks if bigger than inventory: 832 blocks theoretical Assuming at least 2 are non-cobble
  227.  
  228. if forceAutoEmpty == true then
  229. if volume > maxsize then
  230. print("Job very big")
  231. print("Auto-emptying on")
  232. empty = 1
  233. sleep(2)
  234. end
  235. end
  236.  
  237. if empty ~= 1 and careAboutResources == true then
  238. print("Turn on auto-emptying? (Y/N)")
  239. ans = string.sub(string.lower(io.read()),1,1)
  240. if ans == "y" or ans == "1" then
  241. empty = 1
  242. elseif ans == "s" then
  243. print("Stop? (type \"yes\")")
  244. if io.read() == "yes" then
  245. os.shutdown()
  246. end
  247. end
  248. end
  249.  
  250. if area > maxsize then
  251. print("Area too Large, please restart program")
  252. sleep(5)
  253. os.reboot()
  254. end
  255.  
  256. if area > 256 then
  257. Rcheck = 32
  258. else
  259. Rcheck = area/4
  260. end
  261. if empty == 0 and volume > 256 then
  262. Rcheck = 32
  263. else
  264. Rcheck = area/4
  265. end
  266.  
  267. --Getting Fuel
  268. if doCheckFuel == true then
  269. neededFuel = math.ceil(volume*1.1)
  270. function checkFuel()
  271. fuelLevel = turtle.getFuelLevel()
  272. return fuelLevel
  273. end
  274.  
  275. if checkFuel() < neededFuel then
  276. term.clear()
  277. term.setCursorPos(1,1)
  278.  
  279. print("More Fuel Needed")
  280. print("Current Fuel: ",checkFuel()," Needed: ",neededFuel)
  281. print("Place in Bottom Right, press any key")
  282. os.pullEvent("char")
  283. print("I'll take a bit more, so we don't have to do this as often")
  284. turtle.select(16)
  285. while checkFuel() < neededFuel+500 do
  286. if turtle.refuel(1) == false then
  287. term.clearLine()
  288. print("Still too little fuel")
  289. term.clearLine()
  290. print("Press a key to resume fueling")
  291. os.pullEvent("char")
  292. end
  293. x,y = term.getCursorPos()
  294. print(fuelLevel.." Fuel")
  295. term.setCursorPos(x,y)
  296. end
  297. print(fuelLevel.." Units of Fuel")
  298. sleep(3)
  299. turtle.select(1)
  300. end
  301.  
  302. end
  303.  
  304. --Check Double changing the Depth y (times it goes down)
  305. if Cdouble == 1 then
  306. Dy = y/2
  307. else
  308. Dy = y
  309. end
  310.  
  311. --Height Calculation
  312. if Cdouble == 0 then
  313. b = 1
  314. else
  315. b = 2
  316. end
  317.  
  318.  
  319. --Mining Phase
  320.  
  321. turn = 1 --Turn right is 0, turn left is 1 opposite to start
  322. mined = 0 -- Total Blocks Mined
  323. moved = 0 -- Total Spaces Moved
  324.  
  325. turtle.select(1)
  326. screen(1,1)
  327. print("Blocks Mined")
  328. print("")
  329. print("Percent Complete")
  330. mine()
  331. for depth=1, Dy do
  332. for width = 1, z do
  333. cRows = 0 -- Rows completed (z)
  334. mineRow()
  335. if turn == 1 then
  336. turn = 0
  337. else
  338. turn = 1
  339. end
  340. if width ~= z then --Check if last row of set, will not turn if last
  341. if turn == 0 then
  342. turtle.turnRight()
  343. mine()
  344. turtle.turnRight()
  345. else
  346. turtle.turnLeft()
  347. mine()
  348. turtle.turnLeft()
  349. end
  350. end
  351. end
  352. if turn == 0 then --This If statement gets it back to the start of this layer
  353. turtle.turnRight()
  354. if Cdouble == 1 then
  355. if turtle.digDown() == true then
  356. mined = mined + 1
  357. end
  358. end
  359. turtle.turnRight()
  360. for i=1, x-1 do
  361. while not turtle.forward() do
  362. end
  363. end
  364. turtle.turnRight()
  365. for i=1, z-1 do
  366. while not turtle.forward() do
  367. end
  368. end
  369. else
  370. turtle.turnRight()
  371. for i=1, z-1 do
  372. while not turtle.forward() do
  373. end
  374. end
  375. end
  376. if empty == 1 and depth ~= Dy then --AutoEmptying at the end of every layer
  377. if Cdouble == 1 then
  378. AEup = depth*2
  379. else
  380. AEup = depth
  381. end
  382. for i=1, AEup-b do
  383. while not turtle.up() do
  384. end
  385. end
  386. turtle.turnLeft()
  387. while not turtle.forward() do
  388. end
  389. count()   --Counting
  390. endDrop(false) -- Drop into specified chest
  391.  
  392. turtle.turnLeft()
  393. turtle.turnLeft()
  394. while not turtle.forward() do
  395. end
  396. for i=1, AEup-b do
  397. turtle.down()
  398. end
  399. turtle.turnLeft()
  400. end
  401. if depth ~= Dy then --This checks if it is the last layer of the run
  402. for a=1, b do
  403. while not turtle.down() do
  404. turtle.digDown()
  405. mined = mined+1
  406. end
  407. moved = moved + 1
  408. end
  409. turtle.turnRight()
  410. if Cdouble == 1 then
  411. if turtle.digDown() == true then
  412. mined = mined + 1
  413. end
  414. end
  415. turn = 1
  416. end
  417. end
  418.  
  419. for i=1, y-b do --This gets the turtle back to the top layer
  420. while not turtle.up() do
  421. end
  422. end
  423. turtle.turnLeft()
  424. while not turtle.forward() do
  425. end
  426.  
  427. --Counts all blocks at the end also
  428. count()
  429.  
  430. --Output to a chest or sit there
  431. endDrop()
  432. turtle.turnRight()
  433. turtle.turnRight()
  434. turtle.select(1)
  435. --Display
  436. screen(1,1)
  437. print("Total Blocks Mined: "..mined)
  438. print("Current Fuel Level: "..turtle.getFuelLevel())
  439. print("Cobble: "..totals.cobble)
  440. print("Other Raw: "..totals.sand)
  441. print("Other: "..totals.other)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement