daily pastebin goal
76%
SHARE
TWEET

Quarry 3.0.4

a guest May 6th, 2013 383 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[TO DO:
  2. Version 3.0.4
  3. Recent Changes:
  4.    Everything has been drastically updated. Now mines three at a time.
  5.    -Try quarry -help ! Its pretty awesome
  6.    -doCheckFuel argument changed to a true or false after
  7.    -rednet argument changed to a true or false after
  8.    -Now will go back to start when it hits bedrock
  9.    -Renamed "openSlots" to "keepOpen" in arguments
  10.    -Changed "-DEFAULT-" to "-DEFAULT" to match others
  11. ]]
  12. --[[ToDo:
  13. 1. Session Persistence (do for 3.0.5, see idea below)
  14. 2. Fuel Usage Check. Make a more advanced algorithm (Evan is working on it)
  15. 3. Maybe send basic commands from receiver program e.g. Stop
  16. ]]
  17. --Defining things
  18.  
  19. -------Defaults for Arguments----------
  20. --Arguments assignable by text
  21. local x,y,z = 3,3,3 --These are just in case tonumber fails
  22. local inverted = false --False goes from top down, true goes from bottom up [Default false]
  23. local rednetEnabled = false --Default rednet on or off  [Default false]
  24. --Arguments assignable by tArgs
  25. local dropSide = "front" --Side it will eject to when full or done [Default "front"]
  26. local careAboutResources = true --Will not stop mining once inventory full if false [Default true]
  27. local doCheckFuel = true --Perform fuel check [Default true]
  28. local doRefuel = false --Whenever it comes to start location will attempt to refuel from inventory [Default false]
  29. local invCheckFreq = 10 --Will check for inventory full every <-- moved spaces [Default 10]
  30. local keepOpen = 1 --How many inventory slots it will attempt to keep open at all times [Default 1]
  31. --Standard rednet channels
  32. local channels = {
  33. send = os.getComputerID()  ,
  34. receive = 10 ,
  35. confirm = "Confirm"
  36. }
  37.  
  38. local help_paragraph = [[
  39. -DEFAULT: This will ignore all arguments and prompts and use defaults
  40. -vanilla: This will ignore all arguments except for dimensions
  41. -dim: [num] [num] [num] This sets the dimensions of the quarry
  42. -invert: [t/f] This sets whether invert is true or false
  43. -rednet: [t/f] This sets whether it will attempt to make a rednet connection
  44. -sendChannel: [num] This sets the channel the turtle will attempt to send on
  45. -receiveChannel: [num] This sets the channel the turtle will attempt to receive on
  46. -doRefuel: Changes whether or not the turtle will refuel itself with coal when it finishes (opposite of written config)
  47. -doCheckFuel: Changes whether or not the turtle will check its fuel level before running (opposite of written config)
  48. -chest: [chest side] Changes what side turtle will output to
  49. -keepOpen: [num] How many slots of the inventory turtle will try to keep open (Will then auto-empty)
  50. -invCheckFreq: [num] How many blocks before full inventory checks
  51. Examples [1]:
  52.  The minimum amount necessary to start a turtle automatically would be one of these two
  53.  ---------
  54.  quarry -dim 3 3 3 -invert false -rednet false
  55.  ---------
  56.  quarry -dim 3 3 3 -vanilla
  57.  ---------
  58. Examples [2]:
  59.  If you wanted start a quarry that has
  60.  rednet on channels 500 and 501, outputs
  61.  to a chest below itself, is inverted,
  62.  and has the dimesions 5x5x21, then here
  63.  is what you would type: (Remember that
  64.  order does not matter)
  65.  ----------
  66.  quarry -recieveChannel 501 -sendChannel 500 -invert true -dim 5 5 21 -chest bottom -rednet true
  67. Examples [2] (cont.):
  68.  Now, this may be very long, but it is meant for people who want to make automated quarries with
  69.  the same settings every time (or with variable setting)
  70. Examples [3]:
  71.  If you are playing softcore then you
  72.  can do
  73.  ---------
  74.  quarry -doCheckFuel false
  75.  ---------
  76.  Followed by any other arguments
  77. Tips:
  78.  You don't actually have to type out "false" or "true" if you don't want. It actaully just checks if the first
  79.  letter is "t", so you (usually) don't have to put anything at all. Putting the whole word just helps with clarity
  80. Internal Config:
  81.  At the top of the program, right below the changelog is a written config. Anything not specified by arguments
  82.  will be taken from here. If you have a quarry setup you use a lot, you could just edit the config and then
  83.  type in the following:
  84.  ----------
  85.  quarry -DEFAULT
  86. ]]
  87.  
  88. --[[Idea for session persistence:
  89. If there is an argument "-restore" then check for the restart file. The restart file will be
  90. called e.g. CivilQuarryRestore..turtle.getComputerID() or something It will contain all the pos data
  91. as well as relxpos, and all the arguments that were changed in the first. Also, it will automatically
  92. set doCheckFuel to false ]]
  93.  
  94. --Parsing help for display
  95. --[[The way the help table works:
  96. All help indexes are numbered. There is a help[i].title that contains the title,
  97. and the other lines are in help[i][1] - help[i][#help[i] ]
  98. Different lines (e.g. other than first) start with a space.
  99. As of now, the words are not wrapped, fix that later]]
  100. local help = {}
  101. local i = 0
  102. local titlePattern = ".-%:" --Find the beginning of the line, then characters, then a ":"
  103. local textPattern = "%:.+" --Find a ":", then characters until the end of the line
  104. for a in help_paragraph:gmatch("\n?.-\n") do --Matches in between newlines
  105. local current = string.sub(a,1,-2).."" --Concatenate Trick
  106. if string.sub(current,1,1) ~= " " then
  107. i = i + 1
  108. help[i] = {}
  109. help[i].title = string.sub(string.match(current, titlePattern),1,-2)..""
  110. help[i][1] = string.sub(string.match(current,textPattern) or " ",3,-1)
  111. elseif string.sub(current,1,1) == " " then
  112. table.insert(help[i], string.sub(current,2, -1).."")
  113. end
  114. end
  115.  
  116.  
  117. local supportsRednet = (peripheral.wrap("right") ~= nil)
  118.  
  119. local tArgs = {...}
  120. --You don't care about these
  121. local xPos,yPos,zPos,facing,percent,mined,moved,relxPos, rowCheck, connected, isInPath
  122.     = 0,   1,   1,   0,     0,      0,    0,    1,       "right",  false,     true
  123.  
  124. local totals = {cobble = 0, fuel = 0, other = 0} -- Total for display (cannot go inside function)
  125. function count() --Done any time inventory dropped and at end
  126. slot = {}        --1: Cobble 2: Fuel 3:Other
  127. for i=1, 16 do   --[1] is type, [2] is number
  128. slot[i] = {}
  129. slot[i][2] = turtle.getItemCount(i)
  130. end
  131. slot[1][1] = 1   -- = Assumes Cobble/Main
  132. for i=1, 16 do   --Cobble Check
  133. turtle.select(i)
  134. if turtle.compareTo(1)  then
  135. slot[i][1] = 1
  136. totals.cobble = totals.cobble + slot[i][2]
  137. elseif turtle.refuel(0) then
  138. slot[i][1] = 2
  139. totals.fuel = totals.fuel + slot[i][2]
  140. else
  141. slot[i][1] = 3
  142. totals.other = totals.other + slot[i][2]
  143. end
  144. end
  145. turtle.select(1)
  146. end
  147. local function checkFuel()
  148. return turtle.getFuelLevel()
  149. end
  150. local function isFull(slots)
  151. slots = slots or 16
  152. local numUsed = 0
  153. sleep(0.5)
  154. for i=1, slots do
  155. if turtle.getItemCount(i) > 0 then numUsed = numUsed + 1 end
  156. end
  157. if numUsed >= slots then return true end
  158. return false
  159. end
  160.  
  161.  -----------------------------------------------------------------
  162. --Input Phase
  163. local function screen(xPos,yPos)
  164. xPos, yPos = xPos or 1, yPos or 1
  165. term.setCursorPos(xPos,yPos); term.clear(); end
  166. local function screenLine(xPos,yPos)
  167. term.setCursorPos(xPos,yPos); term.clearLine(); end
  168.  
  169. screen(1,1)
  170. print("----- Welcome to Quarry! -----")
  171. print("")
  172.  
  173. local sides = {top = "top", right = "right", left = "left", bottom = "bottom", front = "front"} --Used to whitelist sides
  174. local errorT = {num = "Numbers not recognized", zero = "Variable is out of range" }
  175. local changedT = {}
  176. changedT.new = function(key, value) changedT[#changedT+1] = {[key] = value} end
  177. changedT.getPair = function(i) for a, b in pairs(changedT[i]) do return a, b end end
  178. local function capitalize(text) return (string.upper(string.sub(text,1,1))..string.sub(text,2,-1)) end
  179. local function assert(condition, message, section) section = section or "[Blank]"; if condition then return condition else error("Error: "..message.."\nin section "..section, 0) end end
  180. local function checkNum(number, section) return assert(tonumber(number),errorT.num, section) end
  181. tArgs.checkStart = function(num) tArgs[tArgs[num]] = num end
  182. --tArgs.checkStart = function(num) tArgs.t[tArgs[num]] = {num, tArgs.t[num]} end --If you think this is needed
  183. for i=1, #tArgs do tArgs.checkStart(i) end
  184.  
  185. if tArgs["help"] or tArgs["-help"] or tArgs["-?"] then
  186. print("You have selected help, press any key to continue"); print("Use arrow keys to naviate, q to quit"); os.pullEvent("key")
  187. local pos = 1
  188. local key = 0
  189. while pos <= #help and key ~= keys.q do
  190. if pos < 1 then pos = 1 end
  191. screen(1,1)
  192. print(help[pos].title)
  193. for a=1, #help[pos] do print(help[pos][a]) end
  194. repeat
  195. _, key = os.pullEvent("key")
  196. until key == 200 or key == 208 or key == keys.q
  197. if key == 200 then pos = pos - 1 end
  198. if key == 208 then pos = pos + 1 end
  199. end
  200. error("",0)
  201. end
  202.  
  203. if not tArgs["-DEFAULT"] then
  204. local section = "Dimensions"
  205. --Dimesnions
  206. if tArgs["-dim"] then local num = tArgs["-dim"];
  207. x = checkNum(tArgs[num + 1],section); z = checkNum(tArgs[num + 2],section); y = checkNum(tArgs[num + 3],section)
  208. else
  209. print("What dimensions?")
  210. print("")
  211. --This will protect from negatives, letters, and decimals
  212. term.write("Length: ")
  213. x = math.floor(math.abs(tonumber(io.read()) or x))
  214. term.write("Width: ")
  215. z = math.floor(math.abs(tonumber(io.read()) or z))
  216. term.write("Height: ")
  217. y = math.floor(math.abs(tonumber(io.read()) or y))
  218. end
  219. changedT.new("x",x); changedT.new("z",z); changedT.new("y",y)
  220. assert(x~=0, errorT.zero, section); assert(z~=0, errorT.zero, section); assert(y~=0, errorT.zero, section)
  221. assert(not(x == 1 and y == 1 and z == 1) ,"1, 1, 1 dosen't work well at all, try again", section)
  222. if not tArgs["-vanilla"] then
  223. --Invert
  224. if tArgs["-invert"] then
  225. inverted = (string.lower(string.sub(tArgs[tArgs["-invert"]+1] or "",1,1)) == "t") else
  226. term.write("Inverted? ")
  227. inverted = (string.lower(string.sub(io.read(),1,1)) == "y")
  228. end
  229. changedT.new("Inverted", inverted)
  230. --Rednet
  231. if supportsRednet then
  232. if tArgs["-rednet"] then
  233. rednetEnabled = (string.lower(string.sub(tArgs[tArgs["-rednet"]+1] or "",1,1)) == "t")
  234. else term.write("Rednet? "); rednetEnabled = (string.lower(string.sub(io.read(),1,1)) == "y")
  235. end
  236. changedT.new("Rednet Enabled", rednetEnabled)
  237. if tArgs["-sendChannel"] then
  238. channels.send = assert(tonumber(tArgs[tArgs["-sendChannel"]+1]), errorT.num)
  239. assert(channels.send > 0 and channels.send < 65535, errorT.zero)
  240. changedT.new("Send Channel",channels.send) end
  241. if tArgs["-receiveChannel"] then
  242. channels.receive = assert(tonumber(tArgs[tArgs["-receiveChannel"]+1]), errorT.num)
  243. assert(channels.receive > 0 and channels.receive < 65535 and channels.receive ~= channels.send, errorT.zero)
  244. changedT.new("Receive Channel",channels.receive) end
  245. end
  246. --Fuel
  247. if tArgs["-doRefuel"] then doRefuel = not doRefuel; changedT.new("Do Refuel",doRefuel) end
  248. if tArgs["-doCheckFuel"] then
  249. doCheckFuel = (string.lower(string.sub(tArgs[tArgs["-doCheckFuel"]+1] or "",1,1)) == "t"); changedT.new("Do Check Fuel", doCheckFuel) end
  250. if tArgs["-chest"] then
  251. dropSide = sides[tArgs[tArgs["-chest"]+1]] or dropSide; changedT.new("Chest Side",dropSide) end
  252. --Misc
  253. if tArgs["-invCheckFreq"] then
  254. invCheckFreq = math.abs(math.floor(checkNum(tArgs[tArgs["-invCheckFreq"]+1],"Inventory Check Frequency")))
  255. changedT.new("Inventory Check Frequency",invCheckFreq) end
  256. assert(invCheckFreq ~= 0, errorT.zero, "Inventory Check Frequency")
  257. if tArgs["-keepOpen"] then
  258. keepOpen = math.abs(math.floor(checkNum(tArgs[tArgs["-keepOpen"]+1],"Open Slots")))
  259. changedT.new("Slots to keep open", keepOpen) end
  260. assert(keepOpen ~= 0 and keepOpen < 16, errorT.zero, "Open Slots")if tArgs["-ignoreResources"] then careAboutResources = false end
  261. end; end
  262.  
  263. local area = x*z
  264. local volume = x*y*z
  265. local lastHeight = y%3
  266. local dispY = y
  267. y = math.floor(y/3)*3
  268. local moveVolume = (area*(y/3 + math.ceil(lastHeight/2)))
  269.  
  270. --Getting Fuel
  271. if doCheckFuel then --Calculating Needed Fuel
  272. local neededFuel = moveVolume
  273. if neededFuel < 100 then
  274. neededFuel = 100 else neededFuel = neededFuel * 2 --Placeholder algorithm until Evan is done
  275. end
  276. if checkFuel() < neededFuel then
  277. screen(1,1)
  278. print("More Fuel Needed")
  279. print("Current Fuel: ",checkFuel()," Needed: ",neededFuel)
  280. print("Place fuel in Bottom Right, press any key")
  281. os.pullEvent("char")
  282. turtle.select(16)
  283. while checkFuel() < neededFuel do
  284. if not turtle.refuel(1) then
  285. term.clearLine()
  286. print("Still too little fuel")
  287. term.clearLine()
  288. print("Press a key to resume fueling")
  289. os.pullEvent("char")
  290. end
  291. local x,y = term.getCursorPos()
  292. print(checkFuel().." Fuel")
  293. term.setCursorPos(x,y)
  294. end
  295. print(checkFuel().." Units of Fuel")
  296. sleep(3)
  297. turtle.select(1)
  298. end
  299. end
  300. --Initial Rednet Handshake
  301. if rednetEnabled then
  302. screen(1,1)
  303. print("Rednet is Enabled")
  304. print("The Channel to open is "..channels.send)
  305. modem = peripheral.wrap("right")
  306. modem.open(channels.receive)
  307. local i = 0
  308. repeat
  309. local id = os.startTimer(3)
  310. i=i+1
  311. print("Sending Initial Message "..i)
  312. modem.transmit(channels.send, channels.receive, "{ 'Initial' }")
  313. local message
  314. repeat
  315. local event, idCheck, channel,_,locMessage, distance = os.pullEvent()
  316. message = locMessage
  317. until (event == "timer" and idCheck == id) or (event == "modem_message" and channel == channels.receive and message == channels.confirm)
  318. until message == channels.confirm
  319. connected = true
  320. print("Connection Confirmed!")
  321. sleep(1.5)
  322. end
  323. local function biometrics(sendChannel)
  324. local commands = { Confirm = "Confirm" }
  325. local toSend = { ["x"] = x, ["y"] = (y/3 + math.ceil(lastHeight/2)),
  326.      ["z"] = z,                     --The y calc is weird...
  327.     ["xPos"] = xPos, ["yPos"] = yPos, ["zPos"] = zPos,
  328.     ["percent"] = percent, ["mined" ]= mined,
  329.     ["fuel"] = checkFuel(), ["moved"] = moved,
  330.     ["remainingBlocks"] = (volume-mined), ["ID"] = os.getComputerID(),
  331.     ["isInPath"] = isInPath, --Whether it is going back to start
  332.     ["volume"] = volume, ["area"] = area}
  333. modem.transmit(channels.send, channels.receive, textutils.serialize(toSend))
  334. id = os.startTimer(0.1)
  335. local event, message
  336. repeat
  337. local locEvent, idCheck, confirm, _, locMessage, distance = os.pullEvent()
  338. event, message = locEvent, locMessage
  339. until (event == "timer" and idCheck == id) or (event == "modem_message" and confirm == channels.receive)
  340. if event == "modem_message" then connected = true else connected = false end
  341. --Stuff to do for different commands
  342. end
  343.  
  344. --Showing changes to settings
  345. screen(1,1)
  346. print("Your selected settings:")
  347. if #changedT == 0 then
  348. print("Completely Default")
  349. else
  350. for i=1, #changedT do
  351. local title, value = changedT.getPair(i)
  352. print(capitalize(title)..": ",value)
  353. end
  354. end
  355. print("\nStarting in 3"); sleep(1); print("2"); sleep(1); print("1"); sleep(1.5)
  356.  
  357. ----------------------------------------------------------------
  358. --Mining Phase
  359. local function display()
  360. screen(1,1)
  361. print("Total Blocks Mined: "..mined)
  362. print("Current Fuel Level: "..turtle.getFuelLevel())
  363. print("Cobble: "..totals.cobble)
  364. print("Usable Fuel: "..totals.fuel)
  365. print("Other: "..totals.other)
  366. if rednetEnabled then
  367. print("")
  368. print("Sent Stop Message")
  369. finalTable = {{["Mined: "] = mined}, {["Cobble: "] = totals.cobble}, {["Fuel: "] = totals.fuel},
  370.     {["Other: "] = totals.other}, {["Fuel: "] = checkFuel()} }
  371. modem.transmit(channels.send,channels.receive,"stop")
  372. modem.transmit(channels.send,channels.receive,textutils.serialize(finalTable))
  373. modem.close(channels.receive)
  374. end
  375. end
  376. local function updateDisplay() --Runs in Mine(), display information to the screen in a certain place
  377. screen(1,1)
  378. print("Blocks Mined")
  379. print(mined)
  380. print("Percent Complete")
  381. print(percent.."%")
  382. if rednetEnabled then
  383. screenLine(1,6)
  384. print("Connected: "..tostring(connected))
  385. end
  386. end
  387. local function mine(digDown, digUp, outOfPath,doCheckInv) -- Basic Move Forward
  388. if doCheckInv == nil then doCheckInv = true end
  389. if digDown == nil then digDown = true end
  390. if digUp == nil then digUp = true end
  391.  
  392. local count = 0
  393. while not turtle.forward() do count = count + 1
  394. if turtle.dig() then mined = mined + 1; else turtle.attack(); end
  395. if count > 20 then if
  396. turtle.getFuelLevel() > 0 then
  397. bedrock() else
  398.  error("No Fuel",0) end end
  399. end
  400. if facing == 0 then xPos = xPos +1
  401. elseif facing == 2 then xPos = xPos-1
  402. elseif facing == 1 then zPos = zPos+1
  403. elseif facing == 3 then zPos = zPos-1; end
  404. if digUp then
  405. local count = 0
  406. while turtle.detectUp() do count = count + 1
  407. if turtle.digUp() then mined = mined + 1; end
  408. if count > 20 then bedrock() end; end
  409. end
  410. if digDown then
  411. if turtle.digDown() then mined = mined + 1; end
  412. end
  413. if outOfPath then isInPath = false; else isInPath = true; moved = moved + 1; end
  414. if rowCheck == "right" then relxPos = xPos else relxPos = (x-xPos)+1 end --Maybe adjust this for out of path
  415. percent = math.ceil(moved/moveVolume*100)
  416. updateDisplay()
  417. local whereGoing
  418. if doCheckInv and careAboutResources then
  419. if moved%invCheckFreq == 0 then
  420.  if isFull(16-keepOpen) then dropOff() end
  421. end; end
  422. if rednetEnabled then biometrics() end
  423. end
  424. --Direction: Front = 0, Right = 1, Back = 2, Left = 3
  425. local function facingF(num)
  426. facing = facing + num
  427. if facing > 3 then facing = 0 end
  428. if facing < 0 then facing = 3 end
  429. end
  430.  
  431. if up then local temp1 = up end --Just in case another program uses this
  432. if down then local temp2 = down end
  433. function up(num, sneak)
  434. num = num or 1
  435. sneak = sneak or 1
  436. if inverted and sneak == 1 then
  437.     down(num, -1)
  438. else
  439.     for i=1, num do while not turtle.up() do
  440.         while not turtle.digUp() do
  441.         turtle.attackUp(); sleep(0.5); end
  442.         mined = mined + 1
  443.     end; yPos = yPos - sneak; end
  444. end
  445. end
  446. function down(num, sneak)
  447. num = num or 1
  448. sneak = sneak or 1
  449. if inverted and sneak == 1 then
  450.     up(num, -1)
  451. else
  452.     for i=1, num do local count = 0
  453.         while not turtle.down() do
  454.         count = count + 1
  455.         if not turtle.digDown() then
  456.         turtle.attackDown(); sleep(0.2); end
  457.         mined = mined+1
  458.         if count > 20 then bedrock() end
  459.     end; yPos = yPos + sneak; end
  460. end
  461. end
  462. local function right(num)
  463. num = num or 1
  464. for i=1, num do turtle.turnRight(); facingF(1); end
  465. end
  466. local function left(num)
  467. num = num or 1
  468. for i=1, num do turtle.turnLeft(); facingF(-1) end
  469. end
  470. local function goto(x,z,y, toFace)
  471. x = x or 1; y = y or 1; z = z or 1; toFace = toFace or facing
  472. if yPos > y then while yPos~=y do up() end end
  473.  if zPos > z then
  474.  while facing ~= 3 do left() end
  475.  elseif zPos < z then while facing ~= 1 do left() end
  476.  end
  477.  while zPos ~= z do mine(false,false,true,false) end
  478.   if xPos> x then
  479.   while facing ~= 2 do left() end
  480.   elseif xPos < x then while facing ~= 0 do left() end
  481.   end
  482.   while xPos ~= x do mine(false,false,true,false) end
  483. if yPos < y then while yPos~=y do down() end end
  484. while facing ~= toFace do right() end
  485. end
  486. local function turnTo(num)
  487. num = num or 1; goto(xPos,zPos,yPos,num)
  488. end
  489. local function drop(side, final, allowSkip)
  490. side = sides[side] or "front"    --The final number means that it will
  491. if final then final = 0 else final = 1 end --drop a whole stack at the end
  492. local allowSkip = allowSkip or (final == 0) --This will allow drop(side,t/f, rednetConnected)
  493.   count()
  494.   if doRefuel then
  495.   for i=1, 16 do
  496.   if slot[i][1] == 2 then
  497.   turtle.select(i); turtle.refuel()
  498.   end; end; end
  499. if side == "right" then turnTo(1) end
  500. if side == "left" then turnTo(3) end
  501. local whereDetect, whereDrop
  502. local _1 = tostring(slot[1][2] - final)
  503. if side == "top" then
  504. whereDetect = "turtle.detectUp()" ; whereDrop1 = "turtle.dropUp(".._1..")"; whereDropAll = "turtle.dropUp()"
  505. elseif side == "bottom" then
  506. whereDetect = "turtle.detectDown()" ; whereDrop1 = "turtle.dropDown(".._1..")"; whereDropAll = "turtle.dropDown()"
  507. else
  508. whereDetect = "turtle.detect()" ; whereDrop1 = "turtle.drop(".._1..")"; whereDropAll = "turtle.drop()" end
  509. repeat
  510. local detected = loadstring("return "..whereDetect)()
  511. if detected then
  512. assert(loadstring("if "..whereDetect.." then "
  513. ..whereDrop1..[[
  514. for i=2, 16 do
  515. if turtle.getItemCount(i) > 0 then turtle.select(i); ]]..whereDropAll.." end end end"))()
  516. elseif not allowSkip then
  517. print("Waiting for chest placement, press a key to continue")
  518. os.pullEvent("char")
  519. end
  520. until detected or allowSkip
  521. if not allowSkip then totals.cobble = totals.cobble - 1 end
  522. turtle.select(1)
  523. turnTo(0)
  524. end
  525. function dropOff() --Not local because called in mine()
  526. local currX,currZ,currY,currFacing = xPos, zPos, yPos, facing
  527. goto(0,1,1,2)
  528. drop(dropSide,false)
  529. mine(false,false,true, false)
  530. goto(1,1,1, 0)
  531. goto(currX,currZ,currY,currFacing)
  532. end
  533. function bedrock()
  534. local origin = {x = xPos, y = yPos, z = zPos}
  535. print("Bedrock Detected")
  536. if turtle.detectUp() then
  537. print("Block Above")
  538. local var
  539. if facing == 0 then var = 2 elseif facing == 2 then var = 0 else error("Was facing left or right on bedrock") end
  540. goto(xPos,zPos,yPos,var)
  541. for i=1, relxPos do mine(true,true); end
  542. end
  543. goto(0,1,1,2)
  544. drop(dropSide, true)
  545. display()
  546. print("\nFound bedrock at these coordinates: ")
  547. print(origin.x," Was position in row\n",origin.z," Was row in layer\n",origin.y," Blocks down from start")
  548. error("",0)
  549. end
  550. -------------------------------------------------------------------------------------
  551. local doDigDown, doDigUp
  552. if not inverted then doDigDown , doDigUp = (lastHeight ~= 1), false
  553. else doDigUp, doDigDown = (lastHeight ~= 1) , false; end --Used in lastHeight
  554. a=1
  555. mine(false,false, true)
  556. if y ~= 0 then down() end
  557. --Mining Loops
  558. turtle.select(1)
  559. while a <= y do -------------Height---------
  560. moved = moved + 1
  561. rowCheck = "right" --At the end of this row it will turn right
  562. if rowCheck == "right" then relxPos = xPos else relxPos = (x-xPos)+1 end
  563. while zPos <= z do -------------Width----------
  564. while relxPos < x do ------------Length---------
  565. mine()
  566.  
  567. end ---------------Length End-------
  568. if zPos ~= z then
  569. if rowCheck == "right" and zPos ~= z then --Swithcing to next row
  570. rowCheck = "left"; right(); mine(); right()
  571. else
  572. rowCheck = "right"; left(); mine(); left()
  573. end
  574. else break
  575. end
  576. end ---------------Width End--------
  577. goto(1,1,yPos,0)
  578. if yPos+1 ~= y then down(3) end
  579. a=a+3; end ---------------Height End-------
  580. if lastHeight ~= 0 then ---------LAST ROW--------- (copied from above)
  581. moved = moved + 1
  582. if y ~= 0 then down(2) end
  583. rowCheck = "right"
  584. if rowCheck == "right" then relxPos = xPos else relxPos = (x-xPos)+1 end
  585. while zPos <= z do -------------Width----------
  586. while relxPos < x do ------------Length---------
  587. mine(doDigDown, doDigUp)
  588. end ---------------Length End-------
  589. if zPos ~= z then
  590. if rowCheck == "right" and zPos ~= z then --Swithcing to next row
  591. rowCheck = "left"; right(); mine(doDigDown, doDigUp); right()
  592. else
  593. rowCheck = "right"; left(); mine(doDigDown, doDigUp); left()
  594. end
  595. else break
  596. end
  597. end ---------------Width End--------
  598. goto(1,1,yPos,0)
  599. end
  600. if not inverted then
  601.     if doDigDown then if turtle.digDown() then mined = mined + 1 end end
  602.   else
  603.     if doDigUp then if turtle.digUp() then mined = mined + 1 end end
  604. end
  605. goto(0,1,1,2)
  606.  
  607. --Output to a chest or sit there
  608. drop(dropSide, true)
  609. --Display was moved above to be used in bedrock function
  610. display()
  611.  
  612. --The only global variables I had to use
  613. if temp1 then up = temp1 end
  614. if temp2 then down = temp2 end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top