Advertisement
Guest User

Invert Quarry 1.0

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