Advertisement
hornedcommando

tmine + forbiddenblocks

Apr 12th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.90 KB | None | 0 0
  1. --{program="tClear",version="1.00",date="2021-03-28"}
  2.  
  3. ---------------------------------------
  4.  
  5. -- tClear by Kaikaku
  6.  
  7. -- 2021-03-28, v1.00 three-way digging
  8.  
  9. -- 2016-03-13, v0.90 dig on way back
  10.  
  11. -- 2014-09-27, v0.80 dig sand
  12.  
  13. -- 2013-09-01, v0.10 initial
  14.  
  15. ---------------------------------------
  16.  
  17.  
  18.  
  19. ---------------------------------------
  20.  
  21. ---- DESCRIPTION ----------------------
  22.  
  23. ---------------------------------------
  24.  
  25. -- Mining turtle digs specified cuboid
  26.  
  27. -- (x,y,z) without leaving the area,
  28.  
  29. -- using tripple dig :)
  30.  
  31. -- Incl. option to missus as strip miner.
  32.  
  33.  
  34.  
  35.  
  36.  
  37. ---------------------------------------
  38.  
  39. ---- ASSUMPTIONS ----------------------
  40.  
  41. ---------------------------------------
  42.  
  43. -- Requires a mininng turtle
  44.  
  45.  
  46.  
  47.  
  48.  
  49. ---------------------------------------
  50.  
  51. ---- VARIABLES: template --------------
  52.  
  53. ---------------------------------------
  54.  
  55. local cVersion ="v1.00"
  56.  
  57. local cPrgName ="tClear"
  58.  
  59. local cMinFuel =110
  60.  
  61. local blnAskForParameters =true
  62.  
  63. local blnShowUsage =false
  64.  
  65. local blnDebugPrint =false--true
  66.  
  67. local blnTurtle
  68.  
  69. local isComputer =false
  70.  
  71. local baseColor=colors.blue
  72.  
  73.  
  74.  
  75.  
  76.  
  77. ---------------------------------------
  78.  
  79. ---- VARIABLES: specific --------------
  80.  
  81. ---------------------------------------
  82.  
  83. local slotFuel=16
  84.  
  85.  
  86.  
  87. local digDeep=3 -- all but 0 are okay
  88.  
  89. local digWide=3 -- all but -1,0,1 -- if wide <=-1 then depth needs to be >=2
  90.  
  91. local digHeight=1 -- all but 0
  92.  
  93. local digWideOrg
  94.  
  95. local digDeepOrg
  96.  
  97. local blnLayerByLayer=false
  98.  
  99. local blnStartWithin =false
  100.  
  101. local blnStripMine =false
  102.  
  103.  
  104.  
  105. ---------------------------------------
  106.  
  107. ---- Early UI functions ---------------
  108.  
  109. ---------------------------------------
  110.  
  111. local function swapColors()
  112.  
  113. local backColor=term.getBackgroundColor()
  114.  
  115. local textColor=term.getTextColor()
  116.  
  117.  
  118.  
  119. term.setBackgroundColor(textColor)
  120.  
  121. term.setTextColor(backColor)
  122.  
  123. end
  124.  
  125.  
  126.  
  127. local function printUI(strInput)
  128.  
  129. if strInput==ni then strInput="" end
  130.  
  131.  
  132.  
  133. if strInput=="header" then
  134.  
  135. term.write("—ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ") swapColors() print("”") swapColors()
  136.  
  137. elseif strInput=="line" then
  138.  
  139. term.write("ŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒ") swapColors() print("‘") swapColors()
  140.  
  141. elseif strInput=="footer" then
  142.  
  143. term.write("ŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŒŽ") print()
  144.  
  145. else
  146.  
  147. term.write("•")
  148.  
  149. strInput=strInput.." "
  150.  
  151. term.write(string.sub(strInput,1,37))
  152.  
  153. swapColors() print("•") swapColors()
  154.  
  155. end
  156.  
  157. end
  158.  
  159.  
  160.  
  161. local function coloredTextAt(inputText,outputRow,outputCol,textColor,backColor)
  162.  
  163. -- writes and colors text to coordinates
  164.  
  165. local oldRow, oldCol = term.getCursorPos()
  166.  
  167. local oldTextColor=term.getTextColor()
  168.  
  169. local oldBackColor=term.getBackgroundColor()
  170.  
  171. if textColor==nil then textColor=term.getTextColor() end
  172.  
  173. if backColor==nil then backColor=term.getBackgroundColor() end
  174.  
  175.  
  176.  
  177. term.setTextColor(textColor)
  178.  
  179. term.setBackgroundColor(backColor)
  180.  
  181. term.setCursorPos(outputRow,outputCol)
  182.  
  183. term.write(inputText)
  184.  
  185. term.setCursorPos(oldRow, oldCol)
  186.  
  187. term.setTextColor(oldTextColor)
  188.  
  189. term.setBackgroundColor(oldBackColor)
  190.  
  191. end
  192.  
  193.  
  194.  
  195. ---------------------------------------
  196.  
  197. ---- tArgs ----------------------------
  198.  
  199. ---------------------------------------
  200.  
  201. local tArgs = {...}
  202.  
  203. term.clear() term.setCursorPos(1,1)
  204.  
  205.  
  206.  
  207. local parameterShowSleep=1
  208.  
  209.  
  210.  
  211. if #tArgs~=0 then
  212.  
  213. -- header
  214.  
  215. blnAskForParameters=false
  216.  
  217. term.clear() term.setCursorPos(1,1)
  218.  
  219. printUI("header")
  220.  
  221. printUI(""..cPrgName..", "..cVersion..", by Kaikaku. Enjoy!")
  222.  
  223. printUI("line")
  224.  
  225. coloredTextAt(cPrgName,2,2,baseColor)
  226.  
  227. print("Starting...")
  228.  
  229.  
  230.  
  231. if tArgs[1]~=nil then
  232.  
  233. digDeep=math.floor(tonumber(tArgs[1]))
  234.  
  235. if digDeep<=0 then
  236.  
  237. print("Parameter correction (depths must be >=1)!")
  238.  
  239. sleep(2)
  240.  
  241. parameterShowSleep=parameterShowSleep+2
  242.  
  243. digDeep=1
  244.  
  245. end
  246.  
  247. end
  248.  
  249. if tArgs[2]~=nil then
  250.  
  251. digWide=math.floor(tonumber(tArgs[2]))
  252.  
  253. if digWide==0 or digWide==1 or digWide==-1 then
  254.  
  255. print("Parameter correction (width not 0 or 1)!")
  256.  
  257. sleep(2)
  258.  
  259. parameterShowSleep=parameterShowSleep+2
  260.  
  261. digWide=2
  262.  
  263. end
  264.  
  265. end
  266.  
  267. if tArgs[3]~=nil then
  268.  
  269. digHeight=math.floor(tonumber(tArgs[3]))
  270.  
  271. if digHeight==0 then
  272.  
  273. print("Parameter correction (height not 0)!")
  274.  
  275. sleep(2)
  276.  
  277. parameterShowSleep=parameterShowSleep+2
  278.  
  279. digHeight=1
  280.  
  281. end
  282.  
  283. end
  284.  
  285.  
  286.  
  287. --check combinations of min values
  288.  
  289. if digDeep==1 and digWide<0 then
  290.  
  291. error("Parameter combination not allowed: depth=1 with width<0! Hint: increase depths or move turtle to use positive width.")
  292.  
  293. end
  294.  
  295.  
  296.  
  297. -- further parameters 4+
  298.  
  299. for i=4,#tArgs,1 do
  300.  
  301. if string.lower(tArgs[i])=="layerbylayer" or string.lower(tArgs[i])=="layer" or string.lower(tArgs[i])=="singlelayer" then
  302.  
  303. blnLayerByLayer=true
  304.  
  305. end
  306.  
  307. if string.lower(tArgs[i])=="startwithin" or string.lower(tArgs[i])=="within" or string.lower(tArgs[i])=="in" then
  308.  
  309. blnStartWithin=true
  310.  
  311. end
  312.  
  313. if string.lower(tArgs[i])=="stripmine" or string.lower(tArgs[i])=="strip" or string.lower(tArgs[i])=="mine" then
  314.  
  315. blnStripMine=true
  316.  
  317. end
  318.  
  319. end
  320.  
  321.  
  322.  
  323. -- show parameters
  324.  
  325. print("Clear depth = "..digDeep)
  326.  
  327. print("Clear width = "..digWide)
  328.  
  329. print("Clear height= "..digHeight)
  330.  
  331. term.write("Option LayerByLayert= ") if blnLayerByLayer then print("on") else print("off") end
  332.  
  333. term.write("Option StartWithin = ") if blnStartWithin then print("on") else print("off") end
  334.  
  335. term.write("Option StripMine = ") if blnStripMine then print("on") else print("off") end
  336.  
  337. sleep(parameterShowSleep)
  338.  
  339. end
  340.  
  341.  
  342.  
  343. if blnShowUsage then
  344.  
  345. term.clear() term.setCursorPos(1,1)
  346.  
  347. printUI("header")
  348.  
  349. printUI(""..cPrgName..", by Kaikaku")
  350.  
  351. printUI("footer")
  352.  
  353. print("Usage: ",cPrgName," depth, width [height ['LayerByLayer'] ['StartWithin'] ['StripMine']] ")
  354.  
  355. print()
  356.  
  357. print("If called with any parameter, then")
  358.  
  359. print(" there will be no info screen. Turtle")
  360.  
  361. print(" starts immediately.")
  362.  
  363. return
  364.  
  365. end
  366.  
  367.  
  368.  
  369.  
  370.  
  371. ---------------------------------------
  372.  
  373. -- basic functions for turtle control -
  374.  
  375. ---------------------------------------
  376.  
  377. -- 2021-03-28 partly tPos (from tClear)
  378.  
  379. -- 2021-03-20 arrangeArray, printArray (from tLoader)
  380.  
  381. -- 2021-03-13 askForNumber, pressKeyNoSpecials, checkInventory(u), getFirstEmptySlot, identifyTool, findModem, ensureModem
  382.  
  383. -- 2021-03-05 gfr -
  384.  
  385. -- 2021-02-06 select+place -
  386.  
  387. -- 2021-01-29 save turtle go func -
  388.  
  389. -- checkInventory w/ exit -
  390.  
  391. -- refuelManager -
  392.  
  393. ---------------------------------------
  394.  
  395. local function gf(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.forward() do end end end
  396.  
  397. local function gb(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.back() do end end end
  398.  
  399. local function gu(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.up() do end end end
  400.  
  401. local function gd(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.down() do end end end
  402.  
  403. local function gl(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.turnLeft() do end end end
  404.  
  405. local function gr(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.turnRight() do end end end
  406.  
  407. local function isForbiddenBlock(blockName)
  408. local forbiddenBlocks = {
  409. "forbidden_arcanus:stella_arcanum"
  410. }
  411. for _, forbiddenBlock in ipairs(forbiddenBlocks) do
  412. if blockName == forbiddenBlock then
  413. return true
  414. end
  415. end
  416. return false
  417. end
  418.  
  419. local function df()
  420. success, block = turtle.inspect()
  421. if not isForbiddenBlock(block.name) then
  422. turtle.dig()
  423. end
  424. end
  425.  
  426. local function du() turtle.digUp() end
  427.  
  428. local function dd() turtle.digDown() end
  429.  
  430.  
  431.  
  432. local function dfs() while turtle.dig() do end end
  433.  
  434. local function dus() while turtle.digUp() do end end
  435.  
  436. local function dds() while turtle.digDown() do end end
  437.  
  438.  
  439.  
  440. local function pf() return turtle.place() end
  441.  
  442. local function pu() return turtle.placeUp() end
  443.  
  444. local function pd() return turtle.placeDown() end
  445.  
  446.  
  447.  
  448. local function sf() turtle.suck() end
  449.  
  450. local function su() turtle.suckUp() end
  451.  
  452. local function sd() turtle.suckDown() end
  453.  
  454. local function Df() turtle.drop() end
  455.  
  456. local function Du(n) turtle.dropUp(n) end
  457.  
  458. local function Dd() turtle.dropDown() end
  459.  
  460. local function ss(s) turtle.select(s) end
  461.  
  462. local function gic(s) return turtle.getItemCount(s) end
  463.  
  464.  
  465.  
  466. local function gfs(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.forward() do df() end end end
  467.  
  468. local function gbs(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.back() do gl() gl() df() gr() gr() end end end
  469.  
  470. local function gus(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.up() do du() end end end
  471.  
  472. local function gds(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.down() do dd() end end end
  473.  
  474. local function pfs() df() turtle.place() end
  475.  
  476. local function pus() du() turtle.placeUp() end
  477.  
  478. local function pds() dd() turtle.placeDown() end
  479.  
  480.  
  481.  
  482. local function gfr() return turtle.forward() end
  483.  
  484. local function gbr() return turtle.back() end
  485.  
  486. local function gur() return turtle.up() end
  487.  
  488. local function gdr() return turtle.down() end
  489.  
  490.  
  491.  
  492. local tPos={}
  493.  
  494.  
  495.  
  496. local function glPos(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.turnLeft() do end end end --tPos[4]=(tPos[4]-1)%4 end end
  497.  
  498. local function grPos(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.turnRight() do end end end --tPos[4]=(tPos[4]+1)%4 end end
  499.  
  500. local function gfPos(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.forward() do df() end end end --pCF(1) end end
  501.  
  502. local function gbPos(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.back() do gl() gl() df() gr() gr() end end end--pCF(-1) end end
  503.  
  504. local function guPos(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.up() do du() end tPos[3]=tPos[3]+1 end end
  505.  
  506. local function gdPos(n) if n==nil then n=1 end for i=1,n,1 do while not turtle.down() do dd() end tPos[3]=tPos[3]-1 end end
  507.  
  508.  
  509.  
  510.  
  511.  
  512. local function spd(s,blnForward)
  513.  
  514. if s==nil then s=turtle.currentSlot() end
  515.  
  516. if blnForward==nil then blnForward=true end
  517.  
  518. ss(s) pd() if blnForward then gf() end
  519.  
  520. end
  521.  
  522. local function spu(s,blnForward)
  523.  
  524. if s==nil then s=turtle.currentSlot() end
  525.  
  526. if blnForward==nil then blnForward=true end
  527.  
  528. ss(s) pu() if blnForward then gf() end
  529.  
  530. end
  531.  
  532. local function spf(s,blnBack)
  533.  
  534. if s==nil then s=turtle.currentSlot() end
  535.  
  536. if blnBack==nil then blnBack=true end
  537.  
  538. ss(s) pf() if blnBack then gb() end
  539.  
  540. end
  541.  
  542.  
  543.  
  544. local function waitKey(strText)
  545.  
  546. local event, scancode
  547.  
  548. write(strText)
  549.  
  550. event, scancode = os.pullEvent("key")
  551.  
  552. print()
  553.  
  554. end
  555.  
  556.  
  557.  
  558. local function askForInputText(textt)
  559.  
  560. local at=""
  561.  
  562. -- check prompting texts
  563.  
  564. if textt==nil then textt="Enter text:" end
  565.  
  566.  
  567.  
  568. -- ask for input
  569.  
  570. write(textt)
  571.  
  572. at=read()
  573.  
  574. return at
  575.  
  576. end
  577.  
  578.  
  579.  
  580. local function askForNumber(askText, minValue, maxValue)
  581.  
  582. -- gets entered data, ensures it's a number and returns it
  583.  
  584. -- keeps asking if entry is not a number
  585.  
  586. -- adapts to min and max values
  587.  
  588. -- allways writes in screen line 13 (last for turtles)
  589.  
  590. -- calls askForInputText
  591.  
  592. local blnReask=true
  593.  
  594. local returnNumber=nil
  595.  
  596. if minValue==nil then minValur=1 end
  597.  
  598. if maxValue==nil then maxValue=100 end
  599.  
  600. if askText==nil then askText="Key in number and press Enter: " end
  601.  
  602. while blnReask do
  603.  
  604. term.setCursorPos(1,13)
  605.  
  606. returnNumber=askForInputText(askText)
  607.  
  608. if returnNumber==nil then
  609.  
  610. blnReask=true
  611.  
  612. else
  613.  
  614. returnNumber=tonumber(returnNumber)
  615.  
  616. if returnNumber==nil then
  617.  
  618. blnReask=true
  619.  
  620. else
  621.  
  622. returnNumber=math.floor(returnNumber)
  623.  
  624. if returnNumber>maxValue then returnNumber=maxValue end
  625.  
  626. if returnNumber<minValue then returnNumber=minValue end
  627.  
  628. blnReask=false
  629.  
  630. end
  631.  
  632. end
  633.  
  634. end
  635.  
  636. return returnNumber
  637.  
  638. end
  639.  
  640.  
  641.  
  642. local function pressKeyNoSpecials(askText)
  643.  
  644. -- excludes ctrl / alt / shifts
  645.  
  646. -- catches windows
  647.  
  648. -- retruns the key number (if needed at all)
  649.  
  650. local tmpEvent, tmpKey
  651.  
  652. if askText==nil then askText="Press key to START! (stop w/ ctrl+t) " end
  653.  
  654. tmpKey=341
  655.  
  656. while tmpKey>=340 and tmpKey<=346 do -- ctrls, alts, shifts
  657.  
  658. term.write(askText) tmpEvent, tmpKey = os.pullEvent("key")
  659.  
  660. if tmpKey==nil then tmpKey=341 end -- win
  661.  
  662. end
  663.  
  664. return tmpKey
  665.  
  666. end
  667.  
  668.  
  669.  
  670. local function checkFuel()
  671.  
  672. local tmp=turtle.getFuelLevel()
  673.  
  674. return tmp
  675.  
  676. end
  677.  
  678.  
  679.  
  680. local function checkTurtle(blnOnlyIdentify)
  681.  
  682. if blnOnlyIdentify==nil then blnOnlyIdentify=false end
  683.  
  684. -- turtle?
  685.  
  686. local turtleOk, turtleVal = pcall(checkFuel)
  687.  
  688. if not turtleOk then
  689.  
  690. blnTurtle=false
  691.  
  692. if not blnOnlyIdentify then
  693.  
  694. term.clear() term.setCursorPos(1,1)
  695.  
  696. printUI("header")
  697.  
  698. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  699.  
  700. printUI("line")
  701.  
  702. printUI("This is a turtle program.")
  703.  
  704. printUI(" Please, execute it with a turtle!")
  705.  
  706. printUI("footer")
  707.  
  708.  
  709.  
  710. coloredTextAt(cPrgName,2,2,baseColor)
  711.  
  712. error()
  713.  
  714. end
  715.  
  716. else
  717.  
  718. blnTurtle=true
  719.  
  720. end
  721.  
  722. end
  723.  
  724.  
  725.  
  726. local function sleepDots(sec, duration)
  727.  
  728. if sec==nil then sec=10 end
  729.  
  730. if sec<1 then return end
  731.  
  732. if duration==nil then duration=1 end -- shorten durtation for more dots
  733.  
  734.  
  735.  
  736. for i=1,sec-1 do
  737.  
  738. sleep(1*duration)
  739.  
  740. term.write(".")
  741.  
  742. end
  743.  
  744.  
  745.  
  746. sleep(1)
  747.  
  748. print(".")
  749.  
  750. end
  751.  
  752.  
  753.  
  754. local function checkInventory(s, nMin, nMax, textt, blnExitOnFalse, blnRepeat)
  755.  
  756. -- checks if in slot s are not less than nMin and not more than nMax items
  757.  
  758. -- returns true if okay
  759.  
  760. -- if not displays textt
  761.  
  762. -- blnExitOnFalse=true raises an error
  763.  
  764. -- blnRepeat=true repeatedly sks to put in the right number of items (overrides blnExitOnFalse)
  765.  
  766. local oldSlot = turtle.getSelectedSlot()
  767.  
  768. if s==nil then s=turtle.getSelectedSlot() end
  769.  
  770. if nMin==nil then nMin=0 end
  771.  
  772. if nMax==nil then nMax=64 end
  773.  
  774. if blnExitOnFalse==nil then blnExitOnFalse=false end
  775.  
  776. if blnRepeat==nil then blnRepeat=false end
  777.  
  778. if blnRepeat~=true then blnRepeat=false end
  779.  
  780.  
  781.  
  782. while true do
  783.  
  784.  
  785.  
  786. if turtle.getItemCount(s)<nMin or turtle.getItemCount(s)>nMax then
  787.  
  788. print(textt)
  789.  
  790. if not blnRepeat then
  791.  
  792. -- single check ends with this
  793.  
  794. if blnExitOnFalse then
  795.  
  796. error()
  797.  
  798. else
  799.  
  800. ss(oldSlot) return false
  801.  
  802. end
  803.  
  804. end
  805.  
  806. -- repeated check
  807.  
  808. ss(s)
  809.  
  810. sleepDots(3)
  811.  
  812. else
  813.  
  814. -- everything is fine
  815.  
  816. ss(oldSlot) return true
  817.  
  818. end
  819.  
  820. end
  821.  
  822. end
  823.  
  824.  
  825.  
  826. local function refuelFromSlot(s, n) -- slot, amount to consume
  827.  
  828. if s==nil then s=16 end
  829.  
  830. if n==nil then n=64 end
  831.  
  832. local currentSlot = turtle.getSelectedSlot()
  833.  
  834. local fuelItems = turtle.getItemCount(s)
  835.  
  836. local returnValue = false
  837.  
  838.  
  839.  
  840. if fuelItems>0 then
  841.  
  842. ss(s)
  843.  
  844. returnValue=turtle.refuel(n)
  845.  
  846. ss(currentSlot)
  847.  
  848. end
  849.  
  850. return returnValue
  851.  
  852. end
  853.  
  854.  
  855.  
  856. local function refuelManager(setMinFuel,setSlotFuel,waitTime)
  857.  
  858. local currentSlotSelected=turtle.getSelectedSlot()
  859.  
  860. ss(setSlotFuel)
  861.  
  862. while turtle.getFuelLevel()<setMinFuel do
  863.  
  864. print("Need more fuel ("..turtle.getFuelLevel().."/"..setMinFuel..").")
  865.  
  866. if not refuelFromSlot(setSlotFuel) then
  867.  
  868. -- unsucessfull try
  869.  
  870. print(" Please, put fuel items in slot "..setSlotFuel.."!")
  871.  
  872. term.write(" Sleeping "..waitTime.." seconds")
  873.  
  874. sleepDots(waitTime)
  875.  
  876. else
  877.  
  878. print("Refueled...")
  879.  
  880. end
  881.  
  882. end
  883.  
  884. ss(currentSlotSelected)
  885.  
  886. end
  887.  
  888.  
  889.  
  890. local function debugPrint(str)
  891.  
  892. if blnDebugPrint then print(str) end
  893.  
  894. end
  895.  
  896.  
  897.  
  898. local function inspectFor(blockArray, strDirection) -- <<-- from TreeFarm
  899.  
  900. if strDirection==nil then strDirection="f" end
  901.  
  902. local blnOk, data
  903.  
  904.  
  905.  
  906. -- inspect
  907.  
  908. if strDirection=="d" then blnOk, data = turtle.inspectDown()
  909.  
  910. elseif strDirection=="u" then blnOk, data = turtle.inspectUp()
  911.  
  912. elseif strDirection=="f" then blnOk, data = turtle.inspect()
  913.  
  914. else
  915.  
  916. print("Warning: Unknown direction '",strDirection,"' in inspectFor, taking (f)orward instead.")
  917.  
  918. strDirection="f"
  919.  
  920. blnOk, data = turtle.inspect()
  921.  
  922. end
  923.  
  924. if data.name~=nil then debugPrint("Found:"..string.lower(data.name)) end
  925.  
  926. -- compare
  927.  
  928. local i=1
  929.  
  930. while blockArray[i]~=nil do
  931.  
  932. debugPrint("Compare to:"..string.lower(blockArray[i]))
  933.  
  934. if data.name~=nil then
  935.  
  936. if string.lower(data.name) == string.lower(blockArray[i]) then return true end
  937.  
  938. end
  939.  
  940. i=i+1
  941.  
  942. end
  943.  
  944.  
  945.  
  946. return false -- reached a nil value
  947.  
  948. end
  949.  
  950.  
  951.  
  952.  
  953.  
  954. local function getFirstEmptySlot(startAt)
  955.  
  956. if startAt==nil then startAt=1 end
  957.  
  958. if startAt>16 or startAt<1 then return nil end
  959.  
  960.  
  961.  
  962. for i=startAt,16,1 do
  963.  
  964. if gic(i)==0 then return i end
  965.  
  966. end
  967.  
  968. for i=1,startAt,1 do
  969.  
  970. if gic(i)==0 then return i end
  971.  
  972. end
  973.  
  974. return nil
  975.  
  976. end
  977.  
  978.  
  979.  
  980. local function identifyTool(toolSide)
  981.  
  982. -- returns name of tool at side toolSide
  983.  
  984. -- returns no_tool if there is none
  985.  
  986. -- requires at least one empty slot for tool check (throws error)
  987.  
  988. if toolSide==nil then toolSide="right" end
  989.  
  990. if toolSide~="right" and toolSide~="r" then toolSide="left" end
  991.  
  992. local slotNumber = getFirstEmptySlot()
  993.  
  994. local slotSelected=turtle.getSelectedSlot()
  995.  
  996. local toolName="no_tool"
  997.  
  998.  
  999.  
  1000. if slotNumber==nil then error("Couldn't find empty slot to check tool on side '"..toolSide.."'!") end
  1001.  
  1002. ss(slotNumber)
  1003.  
  1004. -- step 1: get name
  1005.  
  1006. if toolSide=="right" or toolSide=="r" then
  1007.  
  1008. turtle.equipRight()
  1009.  
  1010. else
  1011.  
  1012. turtle.equipLeft()
  1013.  
  1014. end
  1015.  
  1016. -- step 2: get name
  1017.  
  1018. local data = turtle.getItemDetail()
  1019.  
  1020. if data~=nil then toolName=data.name end
  1021.  
  1022. -- step 3: re-equipget name
  1023.  
  1024. if toolSide=="right" or toolSide=="r" then
  1025.  
  1026. turtle.equipRight()
  1027.  
  1028. else
  1029.  
  1030. turtle.equipLeft()
  1031.  
  1032. end
  1033.  
  1034. ss(slotSelected)
  1035.  
  1036. return toolName
  1037.  
  1038. end
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044. local function findModem() -- <<-- delete if no modem used
  1045.  
  1046. for _, p in pairs( rs.getSides() ) do
  1047.  
  1048. if peripheral.isPresent(p) and peripheral.getType(p) == "modem" then return true,p end
  1049.  
  1050. end
  1051.  
  1052. return false,nil
  1053.  
  1054. end
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. ------------------------------------------------------------------------------
  1061.  
  1062. -- main: description ---------------------------------------------------------
  1063.  
  1064. ------------------------------------------------------------------------------
  1065.  
  1066. checkTurtle()
  1067.  
  1068.  
  1069.  
  1070. if blnAskForParameters then
  1071.  
  1072. term.clear() term.setCursorPos(1,1)
  1073.  
  1074. local iPage=0
  1075.  
  1076. local iPageMax=5
  1077.  
  1078. local event, key, isHeld
  1079.  
  1080. local blnLoop=true
  1081.  
  1082.  
  1083.  
  1084. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  1085.  
  1086. printUI("header")
  1087.  
  1088. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  1089.  
  1090. printUI("line")
  1091.  
  1092. -- 1234567890123456789012345678901234567
  1093.  
  1094. printUI("Program features:")
  1095.  
  1096. printUI("* Quick: mines 3 layers in 1 go")
  1097.  
  1098. printUI("* Precise: mines and moves only ")
  1099.  
  1100. printUI(" within the specified area")
  1101.  
  1102. printUI("* Versatile: place turtle at any")
  1103.  
  1104. printUI(" corner or within corner to start")
  1105.  
  1106. printUI("* Lava sparing: with layer by layer")
  1107.  
  1108. printUI("* Stripmine: may be misused for this")
  1109.  
  1110. printUI("footer")
  1111.  
  1112.  
  1113.  
  1114. coloredTextAt(cPrgName,2,2,baseColor)
  1115.  
  1116. coloredTextAt("Quick",4,5,baseColor)
  1117.  
  1118. coloredTextAt("Precise",4,6,baseColor)
  1119.  
  1120. coloredTextAt("Versatile",4,8,baseColor)
  1121.  
  1122. coloredTextAt("Lava sparing",4,10,baseColor)
  1123.  
  1124. coloredTextAt("Stripmine",4,11,baseColor)
  1125.  
  1126.  
  1127.  
  1128. pressKeyNoSpecials("Press key to START! (stop w/ ctrl+t) ")
  1129.  
  1130. ---
  1131.  
  1132.  
  1133.  
  1134. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  1135.  
  1136. printUI("header")
  1137.  
  1138. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  1139.  
  1140. printUI("line")
  1141.  
  1142. -- 1234567890123456789012345678901234567
  1143.  
  1144. printUI("Program mines all blocks of a")
  1145.  
  1146. printUI(" d * w * h cuboid. ")
  1147.  
  1148. printUI(" ")
  1149.  
  1150. printUI(" height="..digHeight)
  1151.  
  1152. printUI("  ¸ ")
  1153.  
  1154. printUI(" | / depth="..digDeep)
  1155.  
  1156. printUI(" |/ ")
  1157.  
  1158. printUI(" +---- width="..digWide)
  1159.  
  1160. printUI("footer")
  1161.  
  1162. term.write("Key in depth and press Enter: ")
  1163.  
  1164.  
  1165.  
  1166. coloredTextAt(cPrgName,2,2,baseColor)
  1167.  
  1168. coloredTextAt("<-- enter (d>=1)",18,9,baseColor)
  1169.  
  1170. event, key, isHeld = os.pullEvent("key")
  1171.  
  1172. digDeep=askForNumber("Key in depth and press Enter: ",1,999)
  1173.  
  1174. ---
  1175.  
  1176.  
  1177.  
  1178. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  1179.  
  1180. printUI("header")
  1181.  
  1182. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  1183.  
  1184. printUI("line")
  1185.  
  1186. -- 1234567890123456789012345678901234567
  1187.  
  1188. printUI("Program mines all blocks of a")
  1189.  
  1190. printUI(" d * w * h cuboid. ")
  1191.  
  1192. printUI(" ")
  1193.  
  1194. printUI(" height="..digHeight)
  1195.  
  1196. printUI("  ¸ ")
  1197.  
  1198. printUI(" | / depth=")
  1199.  
  1200. printUI(" |/ ")
  1201.  
  1202. printUI(" +---- width="..digWide)
  1203.  
  1204. printUI("footer")
  1205.  
  1206. term.write("Key in width and press Enter: ")
  1207.  
  1208.  
  1209.  
  1210. coloredTextAt(cPrgName,2,2,baseColor)
  1211.  
  1212. coloredTextAt( "(w>=2 or",31,10,baseColor)
  1213.  
  1214. coloredTextAt("<-- enter w<=-2)",21,11,baseColor)
  1215.  
  1216. coloredTextAt(digDeep,14,9,baseColor)
  1217.  
  1218. event, key, isHeld = os.pullEvent("key")
  1219.  
  1220. digWide=askForNumber("Key in width and press Enter: ",-999,999)
  1221.  
  1222. if digWide==-1 or digWide==0 or digWide==1 then digWide=2 end
  1223.  
  1224. ---
  1225.  
  1226.  
  1227.  
  1228. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  1229.  
  1230. printUI("header")
  1231.  
  1232. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  1233.  
  1234. printUI("line")
  1235.  
  1236. -- 1234567890123456789012345678901234567
  1237.  
  1238. printUI("Program mines all blocks of a")
  1239.  
  1240. printUI(" d * w * h cuboid. ")
  1241.  
  1242. printUI(" ")
  1243.  
  1244. printUI(" height="..digHeight)
  1245.  
  1246. printUI("  ¸ ")
  1247.  
  1248. printUI(" | / depth=")
  1249.  
  1250. printUI(" |/ ")
  1251.  
  1252. printUI(" +---- width=")
  1253.  
  1254. printUI("footer")
  1255.  
  1256. term.write("Key in height and press Enter: ")
  1257.  
  1258.  
  1259.  
  1260. coloredTextAt(cPrgName,2,2,baseColor)
  1261.  
  1262. coloredTextAt("<-- enter (h<>0)",15,7,baseColor)
  1263.  
  1264. coloredTextAt(digDeep,14,9,baseColor)
  1265.  
  1266. coloredTextAt(digWide,17,11,baseColor)
  1267.  
  1268. event, key, isHeld = os.pullEvent("key")
  1269.  
  1270. digHeight=askForNumber("Key in height and press Enter: ",-999,999)
  1271.  
  1272. if digHeight==0 then digHeight=1 end
  1273.  
  1274. ---
  1275.  
  1276.  
  1277.  
  1278. term.clear() term.setCursorPos(1,1) iPage=iPage+1
  1279.  
  1280. printUI("header")
  1281.  
  1282. printUI(""..cPrgName..", "..cVersion..", by Kaikaku ("..iPage.."/"..iPageMax..")")
  1283.  
  1284. printUI("line")
  1285.  
  1286. -- 1234567890123456789012345678901234567
  1287.  
  1288. printUI("Program mines all blocks of a")
  1289.  
  1290. printUI(" d * w * h cuboid. ")
  1291.  
  1292. printUI(" ")
  1293.  
  1294. printUI(" height= Options:")
  1295.  
  1296. printUI("  ¸ layer by layer: ")
  1297.  
  1298. printUI(" | / depth= start within: ")
  1299.  
  1300. printUI(' |/ "strip mine": ')
  1301.  
  1302. printUI(" +---- width=")
  1303.  
  1304. printUI("footer")
  1305.  
  1306. term.write("Toggle options or ENTER to start: ")
  1307.  
  1308.  
  1309.  
  1310. coloredTextAt(cPrgName,2,2,baseColor)
  1311.  
  1312. coloredTextAt("Options:",18,7,baseColor)
  1313.  
  1314. coloredTextAt("l",20,8,baseColor)
  1315.  
  1316. coloredTextAt("w",26,9,baseColor)
  1317.  
  1318. coloredTextAt("m",27,10,baseColor)
  1319.  
  1320. coloredTextAt(digDeep,14,9,baseColor)
  1321.  
  1322. coloredTextAt(digWide,17,11,baseColor)
  1323.  
  1324. coloredTextAt(digHeight,11,7,baseColor)
  1325.  
  1326.  
  1327.  
  1328. while blnLoop do
  1329.  
  1330. -- color toggles
  1331.  
  1332. if blnLayerByLayer then
  1333.  
  1334. coloredTextAt("on ",36,8,baseColor)
  1335.  
  1336. else
  1337.  
  1338. coloredTextAt("off",36,8,colors.white)
  1339.  
  1340. end
  1341.  
  1342. if blnStartWithin then
  1343.  
  1344. coloredTextAt("on ",36,9,baseColor)
  1345.  
  1346. else
  1347.  
  1348. coloredTextAt("off",36,9,colors.white)
  1349.  
  1350. end
  1351.  
  1352. if blnStripMine then
  1353.  
  1354. coloredTextAt("on ",36,10,baseColor)
  1355.  
  1356. else
  1357.  
  1358. coloredTextAt("off",36,10,colors.white)
  1359.  
  1360. end
  1361.  
  1362. -- get key
  1363.  
  1364. event, key, isHeld = os.pullEvent("key")
  1365.  
  1366. -- evaluate key
  1367.  
  1368. if key~=nil then
  1369.  
  1370. if keys.getName(key)=="l" then
  1371.  
  1372. blnLayerByLayer= not blnLayerByLayer
  1373.  
  1374. elseif keys.getName(key)=="m" then
  1375.  
  1376. blnStripMine= not blnStripMine
  1377.  
  1378. elseif keys.getName(key)=="w" then
  1379.  
  1380. blnStartWithin = not blnStartWithin
  1381.  
  1382. elseif keys.getName(key)=="enter" then
  1383.  
  1384. blnLoop=false
  1385.  
  1386. end
  1387.  
  1388. end
  1389.  
  1390. end
  1391.  
  1392.  
  1393.  
  1394. end
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400. ---------------------------------------
  1401.  
  1402. -- additional functions -
  1403.  
  1404. ---------------------------------------
  1405.  
  1406.  
  1407.  
  1408. local blnDigUp=false
  1409.  
  1410. local blnDigDown=false
  1411.  
  1412.  
  1413.  
  1414. local function digUpDown()
  1415.  
  1416. if blnDigUp then dus() end
  1417.  
  1418. if blnDigDown then dds() end
  1419.  
  1420. end
  1421.  
  1422.  
  1423.  
  1424. local function gfPosDig(n)
  1425.  
  1426. if n==nil then n=1 end
  1427.  
  1428. for i=1,n,1 do
  1429.  
  1430. gfPos() digUpDown()
  1431.  
  1432. end
  1433.  
  1434. end
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440. ------------------------------------------------------------------------------
  1441.  
  1442. -- main: pre-main options ----------------------------------------------------
  1443.  
  1444. ------------------------------------------------------------------------------
  1445.  
  1446.  
  1447.  
  1448. local selfCall=""
  1449.  
  1450. local selfLayer=""
  1451.  
  1452. if blnStripMine then
  1453.  
  1454. -- let's missuse this beautiful program for strip mining
  1455.  
  1456.  
  1457.  
  1458. -- srtip mine step 1: main corridor
  1459.  
  1460. if blnLayerByLayer then selfLayer=" LayerByLayer" end
  1461.  
  1462. selfCall="tClear "..digDeep.." -2 "..digHeight..selfLayer
  1463.  
  1464.  
  1465.  
  1466. if blnStripMine then selfCall=selfCall.." within" end
  1467.  
  1468.  
  1469.  
  1470. --print(selfCall)
  1471.  
  1472. shell.run(selfCall)
  1473.  
  1474.  
  1475.  
  1476. -- strip mine step 2: mining shafts right side
  1477.  
  1478. -- step inside
  1479.  
  1480. if not blnStartWithin then gfPos() end
  1481.  
  1482. -- mine shafts
  1483.  
  1484. for i=1,digDeep,4 do
  1485.  
  1486. -- get on position
  1487.  
  1488. if i>1 then
  1489.  
  1490. gfPos(4)
  1491.  
  1492. end
  1493.  
  1494. -- mining shafts
  1495.  
  1496. selfCall="tClear 1 "..(digWide+1).." "..digHeight.." within"..selfLayer
  1497.  
  1498. print(selfCall)
  1499.  
  1500. --sleep(3)
  1501.  
  1502. shell.run(selfCall)
  1503.  
  1504. end
  1505.  
  1506.  
  1507.  
  1508. -- strip mine step 3: mining shafts left side
  1509.  
  1510. -- get on position
  1511.  
  1512. gl() gfPos() gl()
  1513.  
  1514. -- mine shafts
  1515.  
  1516. for i=1,digDeep,4 do
  1517.  
  1518. -- get on position
  1519.  
  1520. if i>1 then
  1521.  
  1522. gfPos(4)
  1523.  
  1524. end
  1525.  
  1526.  
  1527.  
  1528. -- mining shafts
  1529.  
  1530. selfCall="tClear 1 "..(digWide+1).." "..digHeight.." within"..selfLayer
  1531.  
  1532. print(selfCall)
  1533.  
  1534. --sleep(3)
  1535.  
  1536. shell.run(selfCall)
  1537.  
  1538. end
  1539.  
  1540.  
  1541.  
  1542. -- strip mine step 4: return
  1543.  
  1544. -- to entrance
  1545.  
  1546. gl() gfPos() gl()
  1547.  
  1548. -- step outside
  1549.  
  1550. if not blnStartWithin then gbPos() end
  1551.  
  1552.  
  1553.  
  1554. -- done
  1555.  
  1556. return
  1557.  
  1558. end
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564. ------------------------------------------------------------------------------
  1565.  
  1566. -- main: program -------------------------------------------------------------
  1567.  
  1568. ------------------------------------------------------------------------------
  1569.  
  1570. term.clear() term.setCursorPos(1,1)
  1571.  
  1572.  
  1573.  
  1574. ---- step 0: check fuel ----
  1575.  
  1576. print("step 0: checking fuel...")
  1577.  
  1578. -- fuel
  1579.  
  1580. -- estimate consumption
  1581.  
  1582. if not blnLayerByLayer then
  1583.  
  1584. cMinFuel=math.floor(digHeight/3)
  1585.  
  1586. else
  1587.  
  1588. cMinFuel=math.floor(digHeight)
  1589.  
  1590. end
  1591.  
  1592. cMinFuel=cMinFuel*(math.abs(digDeep)+1)*(math.abs(digWide)+1)+(digHeight*2)
  1593.  
  1594. cMinFuel=math.floor(cMinFuel*1.1) + 20 -- extra
  1595.  
  1596.  
  1597.  
  1598. refuelManager(cMinFuel,slotFuel,10)
  1599.  
  1600. print("... done")
  1601.  
  1602.  
  1603.  
  1604.  
  1605.  
  1606. ---- step 1: do deal with negative values ----
  1607.  
  1608. term.write("step 1: deal with negative values...")
  1609.  
  1610.  
  1611.  
  1612. -- first dig block is 1,1,1
  1613.  
  1614. tPos[1]=1 tPos[2]=0 tPos[3]=1 tPos[4]=0 -- starting position
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620. -- save inital values for end report
  1621.  
  1622. digWideOrg=digWide
  1623.  
  1624. digDeepOrg=digDeep
  1625.  
  1626.  
  1627.  
  1628. --- check negative width
  1629.  
  1630. local blnNegativeWidth=false
  1631.  
  1632. if digWide<0 then
  1633.  
  1634. blnNegativeWidth=true
  1635.  
  1636. digWide=digDeepOrg
  1637.  
  1638. digDeep=-digWideOrg
  1639.  
  1640. end
  1641.  
  1642.  
  1643.  
  1644. --- check negative height
  1645.  
  1646. local blnNegativeHeight=false
  1647.  
  1648. local remainingDigHeight=digHeight
  1649.  
  1650. if digHeight<0 then
  1651.  
  1652. blnNegativeHeight=true
  1653.  
  1654. remainingDigHeight=-digHeight
  1655.  
  1656. end
  1657.  
  1658. print(" done")
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664. ---- step 2: enter and go up ----
  1665.  
  1666. term.write("step 2: enter and go up...")
  1667.  
  1668. -- step inside area
  1669.  
  1670. if not blnStartWithin then
  1671.  
  1672. -- move into cuboid
  1673.  
  1674. gfPosDig()
  1675.  
  1676. else
  1677.  
  1678. -- I'm already there
  1679.  
  1680. tPos[2]=1
  1681.  
  1682. end
  1683.  
  1684.  
  1685.  
  1686. -- positive or negative inital width?
  1687.  
  1688. if not blnNegativeWidth then
  1689.  
  1690. grPos() -- turn to show progress
  1691.  
  1692. else
  1693.  
  1694. -- orientation is already okay, due to negative inital width
  1695.  
  1696. end
  1697.  
  1698. print(" done")
  1699.  
  1700.  
  1701.  
  1702. -- step 3: starting height
  1703.  
  1704. term.write("step 3: starting height...")
  1705.  
  1706. if not blnLayerByLayer then
  1707.  
  1708. -- normal 3 layer dig mode
  1709.  
  1710. if digHeight>2 then
  1711.  
  1712. -- get to right inital digging height
  1713.  
  1714. guPos(digHeight-2)
  1715.  
  1716. elseif digHeight<-1 then
  1717.  
  1718. -- get to right inital negative digging height
  1719.  
  1720. gdPos(1)
  1721.  
  1722. end
  1723.  
  1724. else
  1725.  
  1726. -- layer by layer
  1727.  
  1728. if digHeight>1 then
  1729.  
  1730. -- go to very top
  1731.  
  1732. guPos(digHeight-1)
  1733.  
  1734. else
  1735.  
  1736. -- just stay where you are
  1737.  
  1738. end
  1739.  
  1740. end
  1741.  
  1742. print(" done")
  1743.  
  1744.  
  1745.  
  1746.  
  1747.  
  1748. while remainingDigHeight>0 do
  1749.  
  1750.  
  1751.  
  1752. -- step 4: set dig up/down
  1753.  
  1754. term.write("step 4: set dig up/down...")
  1755.  
  1756. if not blnLayerByLayer then
  1757.  
  1758. -- normal 3 layer dig mode
  1759.  
  1760. if not blnNegativeHeight then
  1761.  
  1762. -- positive dig height
  1763.  
  1764. if tPos[3]>1 then
  1765.  
  1766. -- gone up to tripple dig
  1767.  
  1768. blnDigUp=true
  1769.  
  1770. blnDigDown=true
  1771.  
  1772. elseif remainingDigHeight==2 then
  1773.  
  1774. blnDigUp=true
  1775.  
  1776. blnDigDown=false
  1777.  
  1778. else
  1779.  
  1780. blnDigUp=false
  1781.  
  1782. blnDigDown=false
  1783.  
  1784. end
  1785.  
  1786. else
  1787.  
  1788. -- negative dig hight
  1789.  
  1790. if tPos[3]>=digHeight+3 then
  1791.  
  1792. -- gone down to tripple dig
  1793.  
  1794. blnDigUp=true
  1795.  
  1796. blnDigDown=true
  1797.  
  1798. elseif remainingDigHeight==2 then
  1799.  
  1800. blnDigUp=true--false
  1801.  
  1802. blnDigDown=false--true
  1803.  
  1804. else
  1805.  
  1806. blnDigUp=false
  1807.  
  1808. blnDigDown=false
  1809.  
  1810. end
  1811.  
  1812. end
  1813.  
  1814. else
  1815.  
  1816. -- layer by layer mode
  1817.  
  1818. blnDigUp=false
  1819.  
  1820. blnDigDown=false
  1821.  
  1822. end
  1823.  
  1824. print(" done")
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830. ---- step 5: digging one level ----
  1831.  
  1832. term.write("step 5: digging one level...")
  1833.  
  1834.  
  1835.  
  1836. for iy=1,digDeep,1 do
  1837.  
  1838.  
  1839.  
  1840. if iy==1 then
  1841.  
  1842. gfPosDig() -- step inside track
  1843.  
  1844. elseif iy%2==0 then
  1845.  
  1846. -- u-turn left
  1847.  
  1848. glPos() gfPosDig() glPos()
  1849.  
  1850. else
  1851.  
  1852. -- u-turn right
  1853.  
  1854. grPos() gfPosDig() grPos()
  1855.  
  1856. end
  1857.  
  1858. -- lane
  1859.  
  1860. gfPosDig(digWide-2)
  1861.  
  1862.  
  1863.  
  1864. if iy==digDeep then
  1865.  
  1866. -- return
  1867.  
  1868. if iy%2==1 then
  1869.  
  1870. -- uneven! lets return
  1871.  
  1872. glPos(2) gfPosDig(digWide-2)
  1873.  
  1874. end
  1875.  
  1876.  
  1877.  
  1878. -- dig lane y=1 back
  1879.  
  1880. gfPosDig() glPos() gfPosDig(digDeep-1) glPos()
  1881.  
  1882. end
  1883.  
  1884. end
  1885.  
  1886. print(" done")
  1887.  
  1888.  
  1889.  
  1890.  
  1891.  
  1892. ---- step 6: change level ----
  1893.  
  1894. term.write("step 6: change level...")
  1895.  
  1896.  
  1897.  
  1898. -- adjuste remainingDigHeight
  1899.  
  1900. remainingDigHeight=remainingDigHeight-1
  1901.  
  1902. if blnDigUp then remainingDigHeight=remainingDigHeight-1 end
  1903.  
  1904. if blnDigDown then remainingDigHeight=remainingDigHeight-1 end
  1905.  
  1906.  
  1907.  
  1908. -- adjust layer if there's s.th. left to dig
  1909.  
  1910. if remainingDigHeight>0 then
  1911.  
  1912. if not blnLayerByLayer then
  1913.  
  1914. -- normal 3 layer dig mode
  1915.  
  1916. -- inital dig height pos or neg?
  1917.  
  1918. if not blnNegativeHeight then
  1919.  
  1920. -- inital dig height positive
  1921.  
  1922. -- get to next dig level
  1923.  
  1924. if remainingDigHeight>=2 then
  1925.  
  1926. gdPos(3)
  1927.  
  1928. else
  1929.  
  1930. gdPos(tPos[3]-1)
  1931.  
  1932. end
  1933.  
  1934. else
  1935.  
  1936. -- inital dig height negative
  1937.  
  1938. -- get to next dig level
  1939.  
  1940. if remainingDigHeight>=2 then
  1941.  
  1942. gdPos(3)
  1943.  
  1944. else
  1945.  
  1946. gdPos(-digHeight+tPos[3]-2)
  1947.  
  1948. end
  1949.  
  1950. end
  1951.  
  1952. else
  1953.  
  1954. -- layer by layer mode
  1955.  
  1956. gdPos(1) -- just the next one
  1957.  
  1958. end
  1959.  
  1960. end
  1961.  
  1962. print(" done")
  1963.  
  1964. end
  1965.  
  1966.  
  1967.  
  1968. ---- step 7: return to floor ----
  1969.  
  1970. term.write("step 7: return to floor...")
  1971.  
  1972.  
  1973.  
  1974. -- return to floor
  1975.  
  1976. if not blnNegativeHeight then
  1977.  
  1978. gdPos(tPos[3]-1)
  1979.  
  1980. else
  1981.  
  1982. guPos(-tPos[3]+1)
  1983.  
  1984. end
  1985.  
  1986.  
  1987.  
  1988. -- positive or negative inital width?
  1989.  
  1990. if not blnNegativeWidth then
  1991.  
  1992. glPos() -- turn to leave
  1993.  
  1994. else
  1995.  
  1996. -- orientation is already okay, due to negative inital width
  1997.  
  1998. end
  1999.  
  2000.  
  2001.  
  2002. -- step out of area
  2003.  
  2004. if not blnStartWithin then
  2005.  
  2006. -- move out of cuboid
  2007.  
  2008. gbPos()
  2009.  
  2010. else
  2011.  
  2012. -- I started there, so I'm already done
  2013.  
  2014. end
  2015.  
  2016. print(" done")
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022. ---- step 8: finishing stuff / report ----
  2023.  
  2024. print("Done with tClear "..digDeep.." "..digWide.." "..digHeight)
  2025.  
  2026. print("That looks much cleaner now! !") ss(1)
  2027.  
  2028. --sleep(0.4)
  2029.  
  2030. printUI("header")
  2031.  
  2032. printUI("Check out YouTube for more videos")
  2033.  
  2034. printUI("and turtle programs by Kaikaku :)")
  2035.  
  2036. printUI("footer")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement