Advertisement
HarvDad

allfiles

Apr 18th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 218.34 KB | None | 0 0
  1. *** addroof
  2. local function forward(nBlocks)
  3. for i=1,nBlocks do
  4. turtle.forward()
  5. end
  6. end
  7.  
  8. turtle.up()
  9. forward(6)
  10. turtle.turnRight()
  11. forward(6)
  12. turtle.turnRight()
  13. shell.run("pattern roof10x10")
  14. forward(6)
  15. turtle.turnRight()
  16. forward(6)
  17. turtle.turnRight()
  18. *** b
  19. -- b
  20. -- Moves the turtle the specified distance backwards
  21. -- Written by HarvDad, March 2014
  22.  
  23. args = {...}
  24. nArgs = #args
  25.  
  26. x = 0
  27. y = 0
  28. z = 0
  29. face = 0
  30. minimumFuel = 100
  31. abort = false
  32. local currentFuelLevel = turtle.getFuelLevel()
  33. distance = 1;
  34.  
  35. if (nArgs == 1 and args[1]== "help") then
  36. print("Moves the turtle the specified distance backwards")
  37. print("Usage: f [distance]")
  38. return
  39. end
  40.  
  41. if nArgs == 1 then
  42. distance = tonumber(args[1])
  43. if distance == nil then
  44. print(args[1], " is not a valid distance")
  45. return
  46. end
  47. end
  48.  
  49. -- MAIN PROGRAM
  50.  
  51. turtle.select(1)
  52.  
  53. if currentFuelLevel ~= "unlimited" then
  54. if currentFuelLevel < minimumFuel then
  55. if not turtle.refuel() then
  56. print("No fuel")
  57. return
  58. end
  59. end
  60. end
  61.  
  62. for i=1,distance do
  63. turtle.back()
  64. end
  65. *** bivalve
  66. -- valve
  67. -- Pours and retrieves water at specified time intervals
  68. -- Written by HarvDad, June 2014
  69.  
  70. args = {...}
  71. nArgs = #args
  72.  
  73. version = "valve: Rev 1.0"
  74. mission = "Pour and retrieve water at intervals."
  75. instructions = "Place full bucket in slot 1, empty bucket in slot 2."
  76. usage1 = "usage: valve <direction> <t1> <t2>"
  77. usage2 = " direction = up, down, forward"
  78. usage3 = " t1 = seconds after pour"
  79. usage4 = " t2 = seconds after retrieval"
  80.  
  81.  
  82. secondsAfterPouring = 10
  83. secondsAfterRetrieving = 30
  84.  
  85. up = 0
  86. down = 1
  87. forward = 2
  88. direction = 0
  89.  
  90. abort = false
  91.  
  92. function synchWithServerTime()
  93. print("Waiting for synch...")
  94. while true do
  95. time = os.time()
  96. timeStr = tostring(time)
  97. tailStr = string.sub(timeStr, -3)
  98. tail = tonumber(tailStr)
  99. if tail > 995 then
  100. break
  101. end
  102. sleep(0)
  103. end
  104. end
  105.  
  106. function needWater(direction)
  107. if direction == up then
  108. turtle.select(1)
  109. if turtle.compareTo(3) then
  110. return true
  111. end
  112. elseif direction == down then
  113. turtle.select(2)
  114. if turtle.compareTo(3) then
  115. return true
  116. end
  117. end
  118. return false
  119. end
  120.  
  121. -- prep: Retrieve any water possibly left over from previous run
  122.  
  123. function prep()
  124. turtle.select(1)
  125. if turtle.compareTo(3) then
  126. if needWater(up) then
  127. turtle.placeUp()
  128. end
  129. if needWater(down) then
  130. turtle.placeDown()
  131. end
  132. end
  133. end
  134.  
  135. function updateWater()
  136. turtle.select(1)
  137. turtle.placeUp()
  138. turtle.select(2)
  139. turtle.placeDown()
  140. end
  141.  
  142. function doTheRightThing()
  143. local naptime = 0
  144.  
  145. turtle.select(1)
  146. if turtle.compareTo(3) then
  147. napTime = secondsAfterRetrieving
  148. -- print("Retrieving water. napTime = ", napTime)
  149. else
  150. napTime = secondsAfterPouring
  151. -- print("Pouring water. napTime = ", napTime)
  152. end
  153. updateWater()
  154.  
  155. return napTime
  156. end
  157.  
  158. -- Main program
  159.  
  160.  
  161. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  162. print(version)
  163. print(instructions)
  164. print(usage1)
  165. print(usage2)
  166. print(usage3)
  167. print(usage4)
  168. return
  169. end
  170.  
  171. if nArgs < 2 or nArgs > 2 then
  172. print(usage1)
  173. print(usage2)
  174. print(usage3)
  175. print(usage4)
  176. return
  177. end
  178.  
  179. secondsAfterPouring = tonumber(args[1])
  180. if secondsAfterPouring == nil then
  181. print("\"", args[1], "\" is not a valid time interval")
  182. return
  183. end
  184. if secondsAfterPouring < 1 then
  185. print("t1 must be a positive integer")
  186. return
  187. end
  188.  
  189. secondsAfterRetrieving= tonumber(args[2])
  190. if secondsAfterRetrieving == nil then
  191. print("\"", args[2], "\" is not a valid time interval")
  192. return
  193. end
  194. if secondsAfterRetrieving < 1 then
  195. print("t2 must be a positive integer")
  196. return
  197. end
  198.  
  199. if turtle.getItemCount(1) == 0 or turtle.getItemCount(2) == 0 then
  200. print("If no water running yet,")
  201. print(" place full bucket in slot 1.")
  202. print("If water is already running,")
  203. print(" place empty bucket in slot 1.")
  204. print("Always have empty bucket in slot 2 as comparitor.")
  205. return
  206. end
  207.  
  208. prep()
  209. --synchWithServerTime()
  210.  
  211. -- Main loop
  212.  
  213.  
  214. print("Beginning loop...")
  215. print("secondsAfterPouring: ", secondsAfterPouring, " secondsAfterRetrieving: ", secondsAfterRetrieving)
  216. while true do
  217. if abort then
  218. break
  219. end
  220. napTime = doTheRightThing()
  221. sleep(napTime)
  222. end
  223.  
  224.  
  225.  
  226. *** branch
  227. -- branch
  228. -- Creates a 1x1x3 tunnel of the length specified by the user
  229. -- then mines 3 blocks to the right and tunnels back
  230. -- Torches, if supplied, will be placed on the right-hand wall at 8 block intervals
  231. -- Written by HarvDad, March 2014
  232.  
  233. args = {...}
  234. nArgs = #args
  235.  
  236. print("branch: Rev 1.3")
  237.  
  238. loop = 0;
  239. x = 0
  240. y = 0
  241. z = 0
  242. face = 0
  243. minimumFuel = 100
  244. missionMessage = "Mission complete."
  245. abort = false
  246. local currentFuelLevel = turtle.getFuelLevel()
  247.  
  248. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  249. print("Creates a 2x2 tunnel with sealed sides.")
  250. print("Place fuel in slot 1")
  251. print("Place patch material (like cobblestone) in slot 2.")
  252. print("If torches are desired, place torches in slot 16.")
  253. print("Usage: branch <length>")
  254. return
  255. end
  256.  
  257. if nArgs ~= 1 then
  258. print("Usage: branch <length>")
  259. return
  260. end
  261.  
  262. length = tonumber(args[1])
  263. if length == nil then
  264. print("\"", args[1], "\" is not a valid length")
  265. return
  266. end
  267. if length < 1 then
  268. print("length must be a positive number greater than zero")
  269. end
  270.  
  271. targetArea = length
  272. areaCovered = 1;
  273.  
  274.  
  275. function left()
  276. if face == 0 then face = 1 turtle.turnLeft() return end
  277. if face == 1 then face = 2 turtle.turnLeft() return end
  278. if face == 2 then face = 3 turtle.turnLeft() return end
  279. if face == 3 then face = 0 turtle.turnLeft() return end
  280. print("function left\(\): Bad face value: ", face)
  281. end
  282.  
  283. function right()
  284. if face == 0 then face = 3 turtle.turnRight() return end
  285. if face == 1 then face = 0 turtle.turnRight() return end
  286. if face == 2 then face = 1 turtle.turnRight() return end
  287. if face == 3 then face = 2 turtle.turnRight() return end
  288. print("function right\(\): Bad face value: ", face)
  289. end
  290.  
  291. function up()
  292. success = false
  293.  
  294. repeat
  295. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  296. turtle.digUp()
  297. end
  298. success = turtle.up()
  299. until success
  300. y = y+1
  301. end
  302.  
  303. function rise(nBlocks)
  304. local i
  305. for i=1,nBlocks do
  306. up()
  307. end
  308. end
  309.  
  310. function descend(nBlocks)
  311. local i
  312. for i=1,nBlocks do
  313. down()
  314. end
  315. end
  316.  
  317. function down()
  318. if turtle.detectDown() then
  319. turtle.digDown()
  320. end
  321. turtle.down()
  322. y = y-1
  323. end
  324.  
  325.  
  326. function forward()
  327. while turtle.detect() do -- This loop added in case of falling sand or whatever
  328. turtle.dig()
  329. end
  330. for i=1,10 do
  331. if turtle.forward() then
  332. break
  333. end
  334. turtle.attack()
  335. sleep(2)
  336. end
  337. if face == 0 then z = z+1 return end
  338. if face == 1 then x = x-1 return end
  339. if face == 2 then z = z-1 return end
  340. if face == 3 then x = x+1 return end
  341. end
  342.  
  343. function patch()
  344. turtle.select(2)
  345. turtle.place()
  346. end
  347.  
  348. function patchUp()
  349. turtle.select(2)
  350. turtle.placeUp()
  351. end
  352.  
  353. function patchDown()
  354. turtle.select(2)
  355. turtle.placeDown()
  356. end
  357.  
  358. addTorch = true
  359. torchSpacing = 8
  360. torchSpot = 6
  361.  
  362. function mineForward()
  363. forward()
  364.  
  365. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  366. turtle.digUp()
  367. -- turtle.suckUp()
  368. end
  369.  
  370. if turtle.detectDown() then
  371. turtle.digDown()
  372. -- turtle.suckDown()
  373. end
  374.  
  375. if addTorch then
  376. if (torchSpot % torchSpacing) == 0 then
  377. left()
  378. left()
  379. turtle.select(16)
  380. turtle.place()
  381. right()
  382. right()
  383. end
  384. end
  385. torchSpot = torchSpot + 1
  386. end
  387.  
  388. function setFace(f)
  389. if f == 0 then
  390. if face == 0 then return end
  391. if face == 1 then right() return end
  392. if face == 2 then right() right() return end
  393. if face == 3 then left() return end
  394. end
  395.  
  396. if f == 1 then
  397. if face == 0 then left() return end
  398. if face == 1 then return end
  399. if face == 2 then right() return end
  400. if face == 3 then right() right() return end
  401. end
  402.  
  403. if f == 2 then
  404. if face == 0 then left() left() return end
  405. if face == 1 then left() return end
  406. if face == 2 then return end
  407. if face == 3 then right() return end
  408. end
  409.  
  410. if f == 3 then
  411. if face == 0 then right() return end
  412. if face == 1 then left() left() return end
  413. if face == 2 then left() return end
  414. if face == 3 then return end
  415. end
  416. end
  417.  
  418. function checkFuel()
  419. if currentFuelLevel == "unlimited" then
  420. return true
  421. end
  422.  
  423. if currentFuelLevel < minimumFuel then
  424. if not turtle.refuel(200) then
  425. areaCovered = targetArea
  426. missionMessage = "Mission aborted due to low fuel."
  427. abort = true
  428. return false
  429. end
  430. end
  431. return true
  432. end
  433.  
  434. function home(targetY)
  435. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  436. if x < 0 then
  437. setFace(3)
  438. while x < 0 do
  439. forward()
  440. end
  441. else
  442. if x > 0 then
  443. setFace(1)
  444. while x > 0 do
  445. forward()
  446. end
  447. end
  448. end
  449.  
  450. if z < 0 then
  451. setFace(0)
  452. while z < 0 do
  453. forward()
  454. end
  455. else
  456. if z > 0 then
  457. setFace(2)
  458. while z > 0 do
  459. forward()
  460. end
  461. end
  462. end
  463. end
  464.  
  465. function dump()
  466. for i=2,14 do
  467. turtle.select(i)
  468. turtle.dropDown()
  469. end
  470. end
  471.  
  472. function branchLoop()
  473. torchSpot = 6
  474. local i
  475.  
  476. for i=1,length do
  477. mineForward()
  478. end
  479.  
  480. right()
  481.  
  482. for i=1,3 do
  483. mineForward()
  484. end
  485.  
  486. right()
  487.  
  488. for i=1,length do
  489. mineForward()
  490. end
  491.  
  492. setFace(0)
  493. down()
  494.  
  495. if turtle.detectDown() then
  496. turtle.select(15)
  497. if not turtle.compareDown() then
  498. turtle.digDown()
  499. -- turtle.suckDown()
  500. turtle.placeDown()
  501. end
  502. end
  503. if turtle.compareDown() then
  504. dump()
  505. end
  506. end
  507.  
  508. -- MAIN PROGRAM
  509.  
  510. turtle.select(1)
  511.  
  512. print("Current Fuel Level: ", currentFuelLevel)
  513.  
  514. if currentFuelLevel ~= "unlimited" then
  515. if currentFuelLevel < minimumFuel then
  516. if not turtle.refuel() then
  517. print("No fuel")
  518. return
  519. end
  520. end
  521. end
  522.  
  523. for loop=1,5 do
  524. addTorch = false
  525.  
  526. rise(1)
  527. for i=1,5 do
  528. mineForward()
  529. end
  530. turtle.back()
  531. turtle.back()
  532. left()
  533. addTorch = true
  534. branchLoop()
  535. end
  536.  
  537.  
  538. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
  539.  
  540. *** build
  541. -- build: Build predifined structures
  542. -- Rev 2.1
  543.  
  544.  
  545. args = {...}
  546. nArgs = #args
  547. version = "build: Rev 2.1"
  548. usage = "Usage: build <structure name>"
  549.  
  550. -- Locations
  551.  
  552. origin = {0, 0, 0}
  553. center = {0, 0, 15}
  554.  
  555. -- length, width, xOffset, zOffset, yOffset
  556.  
  557. base = {15, 15, 0, 0, 150}
  558. tower = {5, 5, 0, 0, 150}
  559. ladderChute = {1, 1, 0, -8, 0}
  560. drainFloor = {15, 15, 0, 0, 190}
  561. conveyors = {3, 3, 0, -1, 190}
  562. quicksand = {13, 13, 0, 0, 193}
  563. chamber = {15, 15, 0, 0, 190}
  564. roof = {15, 15, 0, 0, 198}
  565.  
  566.  
  567. -- Global Origin
  568.  
  569. gX = 0
  570. gY = 0
  571. gZ = 0
  572.  
  573. -- Base Origin
  574.  
  575. bX = 5
  576. bY = 0
  577. bZ = 5
  578.  
  579. -- Drain Origin
  580.  
  581. dX = 0
  582. dY = 0
  583. dZ = 0
  584.  
  585. -- Tower Origin
  586.  
  587. tX = 0
  588. tY = 0
  589. tZ = 0
  590.  
  591. -- Cobble Chest
  592.  
  593. ccX = 0
  594. ccY = 0
  595. ccZ = 0
  596.  
  597. -- Quicksand Chest
  598.  
  599. qcX = -2
  600. qcY = 0
  601. qcZ = 0
  602.  
  603. -- Slab Chest
  604.  
  605. scX = -2
  606. scY = 0
  607. scZ = 0
  608.  
  609. -- Conveyor Chest
  610.  
  611. cvcX = -3
  612. cvcY = 0
  613. cvcZ = 0
  614.  
  615. -- Ladder Chest
  616.  
  617. lcX = -4
  618. lcY = 0
  619. lcZ = 0
  620.  
  621. -- Torch Chest
  622.  
  623. tcX = -5
  624. tcY = 0
  625. tcZ = 0
  626.  
  627. x = gX
  628. y = gY
  629. z = gZ
  630.  
  631. -- The following 'face' directions are relative to the starting position of the turtle in this program
  632.  
  633. north = 0
  634. west = 1
  635. south = 2
  636. east = 3
  637.  
  638. function goToStartPt(data)
  639. length = data[1]
  640. width = data[2]
  641. xOffset = data[3]
  642. zOffset = data[4]
  643. yOffset = data[5]
  644.  
  645. print("l: ", length, ", w: ", width)
  646. if width > 1 then
  647. targetX = center[1] + ((width - 1) / 2) + xOffset
  648. else
  649. targetX = center[1] + xOffset
  650. end
  651. if length > 1 then
  652. targetZ = center[3] - ((length - 1) / 2) + zOffset
  653. else
  654. targetZ = center[3] + zOffset
  655. end
  656.  
  657. targetY = center[2] + yOffset
  658.  
  659. print("xOff: ", xOffset, ", zOff: ", zOffset, ", yOff: ", yOffset)
  660. print("center[2]: ", center[2], " tX: ", targetX, ", tY: ", targetY, ", tZ: ", targetZ)
  661.  
  662. moveTo(targetX, targetY, targetZ)
  663. end
  664.  
  665. function goToStructure(structure)
  666. local x = 0
  667. local y = 0
  668. local z = 0
  669.  
  670. if structure == "origin" then
  671. x = origin[1]
  672. y = origin[2]
  673. z = origin[3]
  674. elseif structure == "tower" then
  675. x = tower[1]
  676. y = tower[2]
  677. z = tower[3]
  678. elseif structure == "base" then
  679. x = base[1]
  680. y = base[2]
  681. z = base[3]
  682. elseif structure == "ladderChute" then
  683. x = ladderChute[1]
  684. y = ladderChute[2]
  685. z = ladderChute[3]
  686. elseif structure == "drainFloor" then
  687. x = drainFloor[1]
  688. y = drainFloor[2]
  689. z = drainFloor[3]
  690. elseif structure == "conveyors" then
  691. x = conveyors[1]
  692. y = conveyors[2]
  693. z = conveyors[3]
  694. elseif structure == "quicksand" then
  695. x = quicksand[1]
  696. y = quicksand[2]
  697. z = quicksand[3]
  698. elseif structure == "chamber" then
  699. x = chamber[1]
  700. y = chamber[2]
  701. z = chamber[3]
  702. elseif structure == "roof" then
  703. x = roof[1]
  704. y = roof[2]
  705. z = roof[3]
  706. end
  707.  
  708. moveTo(x, y, z)
  709. end
  710.  
  711. function moveUp()
  712.  
  713. for i=1,10 do -- Keep trying in case something is temporarily in the way
  714. if turtle.up() then
  715. y = y + 1
  716. break
  717. else
  718. sleep(2)
  719. end
  720. end
  721. end
  722.  
  723. function moveDown()
  724.  
  725. for i=1,10 do -- Keep trying in case something is temporarily in the way
  726. if turtle.down() then
  727. y = y - 1
  728. break
  729. else
  730. sleep(2)
  731. end
  732. end
  733. end
  734.  
  735. function moveTo(X, Y, Z)
  736. print("moveTo(", X, ", ", Y, ", ", Z, ") y: ", y)
  737. if y == nil then print("y is nil") end
  738. if Y == nil then print("Y is nil") end
  739.  
  740. if y ~= Y then
  741. if y < Y then
  742. while y < Y do
  743. moveUp()
  744. end
  745. else
  746. while y > Y do
  747. moveDown()
  748. end
  749. end
  750. end
  751.  
  752. if x ~= X then
  753. if x < X then
  754. setFace(east)
  755. while x < X do
  756. go(1)
  757. end
  758. else
  759. setFace(west)
  760. while x > X do
  761. go(1)
  762. end
  763. end
  764. end
  765.  
  766. if z ~= Z then
  767. if z < Z then
  768. setFace(north)
  769. while z < Z do
  770. go(1)
  771. end
  772. else
  773. setFace(south)
  774. while z > Z do
  775. go(1)
  776. end
  777. end
  778. end
  779. end
  780.  
  781. function goToChest(chest)
  782. if chest == cobbleChest then
  783. moveTo(ccX, ccY, ccZ)
  784. elseif chest == quicksandChest then
  785. moveTo(qcX, qcY, qcZ)
  786. elseif chest == slabChest then
  787. moveTo(scX, scY, scZ)
  788. elseif chest == conveyorChest then
  789. moveTo(cvcX, cvcY, cvcZ)
  790. elseif chest == ladderChest then
  791. moveTo(lcX, lcY, lcZ)
  792. elseif chest == torchChest then
  793. moveTo(tcX, tcY, tcZ)
  794. end
  795. end
  796.  
  797. function setFace(f)
  798. if f == 0 then
  799. if face == 0 then return end
  800. if face == 1 then right() return end
  801. if face == 2 then right() right() return end
  802. if face == 3 then left() return end
  803. end
  804.  
  805. if f == 1 then
  806. if face == 0 then left() return end
  807. if face == 1 then return end
  808. if face == 2 then right() return end
  809. if face == 3 then right() right() return end
  810. end
  811.  
  812. if f == 2 then
  813. if face == 0 then left() left() return end
  814. if face == 1 then left() return end
  815. if face == 2 then return end
  816. if face == 3 then right() return end
  817. end
  818.  
  819. if f == 3 then
  820. if face == 0 then right() return end
  821. if face == 1 then left() left() return end
  822. if face == 2 then left() return end
  823. if face == 3 then return end
  824. end
  825. end
  826.  
  827. function back(nBlocks)
  828. local failed = true
  829.  
  830. for i=1,nBlocks do
  831. for j=1,10 do -- multiple tries in case something is temporarily in the way
  832. if turtle.back() then
  833. failed = false
  834. break
  835. else
  836. sleep(2)
  837. end
  838. end
  839. end
  840.  
  841. if face == north then z = z - nBlocks end
  842. if face == south then z = z + nBlocks end
  843. if face == east then x = x - nBlocks end
  844. if face == west then x = x + nBlocks end
  845. end
  846.  
  847. function go(nBlocks)
  848. local failed = true
  849.  
  850. for i=1,nBlocks do
  851. for j=1,10 do -- multiple tries in case something is temporarily in the way
  852. if turtle.forward() then
  853. failed = false
  854. break
  855. else
  856. sleep(2)
  857. end
  858. end
  859. end
  860. if failed then
  861. return
  862. end
  863.  
  864. if face == north then z = z + nBlocks end
  865. if face == south then z = z - nBlocks end
  866. if face == east then x = x + nBlocks end
  867. if face == west then x = x - nBlocks end
  868. end
  869.  
  870. function left()
  871. if face == 0 then face = 1 turtle.turnLeft() return end
  872. if face == 1 then face = 2 turtle.turnLeft() return end
  873. if face == 2 then face = 3 turtle.turnLeft() return end
  874. if face == 3 then face = 0 turtle.turnLeft() return end
  875. print("function left\(\): Bad face value: ", face)
  876. end
  877.  
  878. function right()
  879. if face == 0 then face = 3 turtle.turnRight() return end
  880. if face == 1 then face = 0 turtle.turnRight() return end
  881. if face == 2 then face = 1 turtle.turnRight() return end
  882. if face == 3 then face = 2 turtle.turnRight() return end
  883. print("function right\(\): Bad face value: ", face)
  884. end
  885.  
  886. function globalHome()
  887. print("globalHome...")
  888. moveTo(gX, gY, gZ)
  889. setFace(north)
  890. end
  891.  
  892. function xzHome()
  893. local X = gX
  894. local Z = gZ
  895.  
  896. if x ~= X then
  897. if x < X then
  898. setFace(east)
  899. while x < X do
  900. go(1)
  901. end
  902. else
  903. setFace(west)
  904. while x > X do
  905. go(1)
  906. end
  907. end
  908. end
  909.  
  910. if z ~= Z then
  911. if z < Z then
  912. setFace(north)
  913. while z < Z do
  914. go(1)
  915. end
  916. else
  917. setFace(south)
  918. while z > Z do
  919. go(1)
  920. end
  921. end
  922. end
  923. end
  924.  
  925. function zxHome()
  926. zHome()
  927. xHome()
  928. end
  929.  
  930. function xHome()
  931. local X = gX
  932.  
  933. if x ~= X then
  934. if x < X then
  935. setFace(east)
  936. while x < X do
  937. go(1)
  938. end
  939. else
  940. setFace(west)
  941. while x > X do
  942. go(1)
  943. end
  944. end
  945. end
  946. end
  947.  
  948. function zHome()
  949. local Z = gZ
  950.  
  951. if z ~= Z then
  952. if z < Z then
  953. setFace(north)
  954. while z < Z do
  955. go(1)
  956. end
  957. else
  958. setFace(south)
  959. while z > Z do
  960. go(1)
  961. end
  962. end
  963. end
  964. end
  965.  
  966. function yHome()
  967. local Y = gY
  968.  
  969. if y ~= Y then
  970. if y < Y then
  971. while y < Y do
  972. turtle.up()
  973. y = y + 1
  974. end
  975. else
  976. while y > Y do
  977. turtle.down()
  978. y = y - 1
  979. end
  980. end
  981. end
  982. end
  983.  
  984. function grabStuff(stuffSlot)
  985. turtle.select(stuffSlot)
  986. turtle.suckDown()
  987. for i=5,16 do
  988. turtle.select(i)
  989. if not turtle.compareTo(stuffSlot) then
  990. turtle.dump()
  991. end
  992. turtle.suckDown()
  993. end
  994. turtle.select(stuffSlot)
  995. turtle.suckDown()
  996. end
  997.  
  998. function dropStuff(stuffSlot)
  999. qty = turtle.getItemCount(stuffSlot) - 1
  1000. turtle.dropDown(qty)
  1001. for i=5,16 do
  1002. turtle.select(i)
  1003. if (turtle.compareTo(stuffSlot)) then
  1004. turtle.dropDown()
  1005. end
  1006. end
  1007. end
  1008.  
  1009. function grabCobble()
  1010. turtle.select(cobbleSlot)
  1011. for i=5,16 do
  1012. turtle.suckDown()
  1013. qty = turtle.getItemCount(cobbleSlot) - 1
  1014. turtle.transferTo(i, qty)
  1015. end
  1016. end
  1017.  
  1018. function dropCobble()
  1019. qty = turtle.getItemCount(cobbleSlot) - 1
  1020. turtle.dropDown(qty)
  1021. for i=5,16 do
  1022. turtle.select(i)
  1023. if (turtle.compareTo(cobbleSlot)) then
  1024. turtle.dropDown()
  1025. end
  1026. end
  1027. end
  1028.  
  1029. function floorHole(length, width)
  1030. for i = 1,width do
  1031. for j = 1,length do
  1032. turtle.digDown()
  1033. if j < length then
  1034. turtle.forward()
  1035. if face == north then
  1036. z = z + 1
  1037. elseif face == south then
  1038. z = z - 1
  1039. end
  1040. end
  1041. end
  1042. if i < width then
  1043. if face == north then
  1044. left()
  1045. turtle.forward()
  1046. x = x - 1
  1047. left()
  1048. elseif face == south then
  1049. right()
  1050. turtle.forward()
  1051. x = x - 1
  1052. right()
  1053. end
  1054. end
  1055. end
  1056. end
  1057.  
  1058. function nextSpot()
  1059. end
  1060.  
  1061. function sprinkleTorches(length, width, interval)
  1062. turtle.up()
  1063. y = y + 1
  1064. turtle.select(16)
  1065. lengthSpan = length - (2 * interval) - 1
  1066. widthSpan = width - (2 * interval) - 1
  1067.  
  1068. left()
  1069. for i = 1,interval do
  1070. go(1)
  1071. end
  1072. right()
  1073. for i = 1,interval do
  1074. go(1)
  1075. end
  1076. turtle.placeDown()
  1077.  
  1078. for i = 1,lengthSpan do
  1079. go(1)
  1080. end
  1081. turtle.placeDown()
  1082.  
  1083. left()
  1084. for i = 1,widthSpan do
  1085. go(1)
  1086. end
  1087. turtle.placeDown()
  1088.  
  1089. left()
  1090. for i = 1,lengthSpan do
  1091. go(1)
  1092. end
  1093. turtle.placeDown()
  1094.  
  1095. left()
  1096. for i = 1,widthSpan + interval do
  1097. go(1)
  1098. end
  1099.  
  1100. right()
  1101. for i = 1,lengthSpan + interval do
  1102. go(1)
  1103. end
  1104.  
  1105. turtle.down()
  1106. y = y - 1
  1107. end
  1108.  
  1109. function sprinkleSurface(length, width, interval)
  1110. totalPlaced = 0
  1111.  
  1112. turtle.up()
  1113. y = y + 1
  1114. turtle.select(16)
  1115. for i = 1,width do
  1116. for j = 1,length do
  1117. if j < length then
  1118. if (i % interval == 0 and j % interval == 0) then
  1119. turtle.placeDown()
  1120. end
  1121. turtle.forward()
  1122. totalPlaced = totalPlaced + 1
  1123. if face == north then
  1124. z = z + 1
  1125. elseif face == south then
  1126. z = z - 1
  1127. end
  1128. end
  1129. end
  1130. if i < width then
  1131. if face == north then
  1132. left()
  1133. while i % interval ~= 0 do
  1134. turtle.forward()
  1135. x = x - 1
  1136. i = i + 1
  1137. end
  1138. left()
  1139. elseif face == south then
  1140. right()
  1141. while i % interval ~= 0 do
  1142. turtle.forward()
  1143. x = x - 1
  1144. i = i + 1
  1145. end
  1146. right()
  1147. end
  1148. end
  1149. end
  1150. end
  1151.  
  1152. function load(chest, startSlot, endSlot)
  1153. goToChest(chest)
  1154. for slot=startSlot, endSlot do
  1155. turtle.select(slot)
  1156. turtle.suckDown()
  1157. end
  1158. end
  1159.  
  1160. function dump(chest, startSlot, endSlot)
  1161. goToChest(chest)
  1162. for slot=startSlot, endSlot do
  1163. turtle.select(slot)
  1164. turtle.dropDown()
  1165. end
  1166. end
  1167.  
  1168. saveX = 0
  1169. saveY = 0
  1170. saveZ = 0
  1171. saveFace = 0
  1172.  
  1173. function saveXYZ()
  1174. saveX = x
  1175. saveY = y
  1176. saveZ = z
  1177. saveFace = face
  1178. print("Saved xyz as ", saveX, ", ", saveY, ", ", saveZ, ", face: ", saveFace)
  1179. end
  1180.  
  1181. function restoreXYZ()
  1182. x = saveX
  1183. y = saveY
  1184. z = saveZ
  1185. face = saveFace
  1186. print("Restored xyz as ", x, ", ", y, ", ", z, ", face: ", face)
  1187. end
  1188.  
  1189. function run(script)
  1190. saveXYZ()
  1191. shell.run(script)
  1192. restoreXYZ()
  1193. end
  1194.  
  1195.  
  1196. cobbleChest = 1
  1197. quicksandChest = 2
  1198. conveyorChest = 3
  1199. ladderChest = 4
  1200. torchChest = 5
  1201.  
  1202. slabChest = 2
  1203.  
  1204. cobbleSlot = 1
  1205. quicksandSlot = 2
  1206. conveyorSlot = 3
  1207. torchSlot = 3
  1208.  
  1209. --grabStuff(cobbleSlot)
  1210. --sleep(3)
  1211. --dropStuff(cobbleSlot)
  1212.  
  1213.  
  1214.  
  1215. -- BUILD SKYSCRAPER QUICKSAND MOB TRAP
  1216.  
  1217.  
  1218. function buildSandTrap()
  1219. load(cobbleChest, 1, 8)
  1220. load(torchChest, 16, 16)
  1221. goToStartPt(base)
  1222. run("floor 15 15")
  1223. print("Base completed")
  1224. setFace(north)
  1225. sprinkleTorches(15, 15, 3)
  1226. xzHome()
  1227. yHome()
  1228. dump(cobbleChest, 1, 8)
  1229. dump(torchChest, 16, 16)
  1230.  
  1231. load(cobbleChest, 1, 13)
  1232. load(ladderChest, 14, 16)
  1233. globalHome()
  1234. goToStartPt(ladderChute)
  1235. setFace(north)
  1236. run("chute -150 true")
  1237. z = z - 1 -- The 'chute' program finishes one block back from start
  1238. print("Ladder chute completed")
  1239. dump(cobbleChest, 1, 13)
  1240. dump(ladderChest, 14, 16)
  1241.  
  1242. load(cobbleChest, 1, 16)
  1243. globalHome()
  1244. goToStartPt(tower)
  1245. run("walls 5 5 40")
  1246. z = z - 1 -- The 'walls' program finishes one block back from start
  1247. print("Tower completed")
  1248. xzHome()
  1249. print("xzHome completed")
  1250. yHome()
  1251. dump(cobbleChest, 1, 16)
  1252.  
  1253. load(cobbleChest, 1, 8)
  1254. goToStartPt(drainFloor)
  1255. run("floor 15 15")
  1256.  
  1257. left()
  1258. for i = 1,6 do
  1259. go(1)
  1260. end
  1261. right()
  1262. for i = 1,6 do
  1263. go(1)
  1264. end
  1265. floorHole(3, 3)
  1266. xzHome()
  1267. yHome()
  1268. xzHome()
  1269. dump(cobbleChest, 1, 8)
  1270.  
  1271. load(conveyorChest, 1, 3)
  1272. goToStartPt(conveyors)
  1273. run("fabdrain")
  1274. y = y + 1 -- The 'fabdrain' program finishes one block up from start
  1275. xzHome()
  1276. yHome()
  1277. dump(conveyorChest, 1, 3)
  1278.  
  1279. load(quicksandChest, 1, 3)
  1280. goToStartPt(quicksand)
  1281. run("floor 13 13")
  1282. xzHome()
  1283. yHome()
  1284. dump(quicksandChest, 1, 3)
  1285.  
  1286. load(cobbleChest, 1, 12)
  1287. goToStartPt(chamber)
  1288. run("walls 15 15 7")
  1289. z = z - 1 -- The 'walls' program finishes one block back from start
  1290. xzHome()
  1291. yHome()
  1292. dump(cobbleChest, 1, 12)
  1293.  
  1294. load(cobbleChest, 1, 8)
  1295. load(torchChest, 16, 16)
  1296. goToStartPt(roof)
  1297. run("floor 15 15")
  1298. setFace(north)
  1299. sprinkleTorches(15, 15, 3)
  1300. xzHome()
  1301. yHome()
  1302. dump(cobbleChest, 1, 8)
  1303. dump(torchChest, 16, 16)
  1304.  
  1305. globalHome()
  1306. end
  1307.  
  1308. torchSlot = 16
  1309.  
  1310. function goXZ(startFace, newX, newZ)
  1311. setFace(startFace)
  1312.  
  1313. if face == east then
  1314. while x > newX do
  1315. go(1)
  1316. end
  1317. elseif face == west then
  1318. while x < newX do
  1319. go(1)
  1320. end
  1321. else
  1322. end
  1323.  
  1324. if face == north then
  1325. while z < newZ do
  1326. go(1)
  1327. end
  1328. elseif face == south then
  1329. while z > newZ do
  1330. go(1)
  1331. end
  1332. else
  1333. end
  1334. end
  1335.  
  1336. function goZX(startFace, newX, newZ)
  1337. setFace(startFace)
  1338.  
  1339. if face == north then
  1340. while z < newZ do
  1341. go(1)
  1342. end
  1343. elseif face == south then
  1344. while z > newZ do
  1345. go(1)
  1346. end
  1347. else
  1348. end
  1349.  
  1350. if face == east then
  1351. while x > newX do
  1352. go(1)
  1353. end
  1354. elseif face == west then
  1355. while x < newX do
  1356. go(1)
  1357. end
  1358. else
  1359. end
  1360. end
  1361.  
  1362. function layTorches(distance, spacing)
  1363. turtle.select(torchSlot)
  1364.  
  1365. for i=1,distance do
  1366. if i % spacing == 0 then
  1367. turtle.placeDown()
  1368. end
  1369. if i < distance then
  1370. go(1)
  1371. end
  1372. end
  1373. end
  1374.  
  1375. function lightPlatform()
  1376. goToStartPt(platform)
  1377. turtle.up()
  1378. y = y + 1
  1379. turtle.select(torchSlot)
  1380.  
  1381. setFace(west)
  1382. go(3)
  1383. setFace(north)
  1384. back(1)
  1385. layTorches(platform[2], 4)
  1386.  
  1387. setFace(west)
  1388. go(5)
  1389. setFace(south)
  1390. back(2)
  1391. layTorches(11, 4)
  1392. turtle.placeDown()
  1393.  
  1394. setFace(west)
  1395. go(2)
  1396. setFace(south)
  1397. go(8)
  1398. setFace(east)
  1399. go(1)
  1400. turtle.placeDown()
  1401. go(2)
  1402. turtle.placeDown()
  1403.  
  1404. -- setFace(south)
  1405. -- go(1)
  1406. setFace(west)
  1407. go(5)
  1408. setFace(north)
  1409. layTorches(17, 4)
  1410.  
  1411. setFace(west)
  1412. go(4)
  1413. setFace(south)
  1414. back(2)
  1415. layTorches(17, 4)
  1416. end
  1417.  
  1418. function buildMobGrinder()
  1419.  
  1420. center = {-6, 0, 20}
  1421.  
  1422. -- length, width, xOffset, zOffset, yOffset
  1423.  
  1424. base = {21, 23, 0, 0, 160}
  1425. platform = {17, 17, 0, -2, base[5]-40}
  1426. torch1 = {9, 9, 0, 0, base[5]+1}
  1427. torch2 = {17, 17, 0, 0, base[5]+1}
  1428. dropTower = {3, 3, 0, 0, platform[5]}
  1429. ladderChute1 = {1, 1, 0, -11, 0}
  1430. ladderChute2 = {1, 1, -6, 0, platform[5]}
  1431. dropChute = {1, 1, 0, -6, platform[5]}
  1432. torch3 = {9, 15, -3, -5, platform[5]+1}
  1433.  
  1434. floorA = {13, 7, 4, 0, base[5]+4}
  1435. wallA = {1, 5, 0, 0, floorA[5]}
  1436. trapWallsA = {13, 7, 4, 0, floorA[5]}
  1437. trapRoofA = {13, 7, 4, 0, floorA[5] + 4}
  1438. trapSlabsA = {13, 7, 4, 0, trapRoofA[5] + 1}
  1439.  
  1440. floorB = {13, 7, -4, 0, base[5] + 4}
  1441. wallB = {1, 5, -4, 0, floorB[5]}
  1442. trapWallsB = {13, 7, -4, 0, floorB[5]}
  1443. trapRoofB = {13, 7, -4, 0, floorB[5] + 4}
  1444. trapSlabsB = {13, 7, -4, 0, trapRoofB[5] + 1}
  1445.  
  1446. drainFloor = {15, 15, 0, 0, 190}
  1447. conveyors = {3, 3, 0, -1, 190}
  1448. quicksand = {13, 13, 0, 0, 193}
  1449. chamber = {15, 15, 0, 0, 190}
  1450. roof = {15, 15, 0, 0, 198}
  1451.  
  1452. -- Begin the build
  1453.  
  1454.  
  1455. -- LADDER CHUTE FROM GROUND TO PLATFORM
  1456.  
  1457. load(cobbleChest, 1,12)
  1458. load(ladderChest, 14, 16)
  1459. goToStartPt(ladderChute1)
  1460. run("chute " .. -platform[5] .. " true")
  1461. z = z - 1 -- The 'chute' program finishes one block back from start
  1462. globalHome()
  1463. dump(ladderChest, 14, 16)
  1464. dump(cobbleChest, 1, 12)
  1465.  
  1466. -- PLATFORM
  1467.  
  1468. setFace(north)
  1469. load(cobbleChest, 1, 12)
  1470. load(torchChest, 16, 16)
  1471.  
  1472. goToStartPt(platform)
  1473. run("floor " .. platform[1] .. " " .. platform[2])
  1474.  
  1475. -- TORCHES ON PLATFORM
  1476.  
  1477. lightPlatform()
  1478.  
  1479. zxHome()
  1480. yHome()
  1481.  
  1482. dump(torchChest, 16, 16)
  1483. dump(cobbleChest, 1, 12)
  1484.  
  1485. -- DROP CHUTE
  1486.  
  1487. load(cobbleChest, 1, 12)
  1488. load(ladderChest, 14, 16)
  1489. goToStartPt(dropChute)
  1490. setFace(north)
  1491. height = platform[5] - base[5]
  1492. run("chute " .. height .. " false") -- No ladders needed in drop chute
  1493. z = z - 1 -- The 'chute' program finishes one block back from start
  1494.  
  1495. -- LADDER CHUTE FROM PLATFORM TO BASE
  1496.  
  1497. goToStartPt(ladderChute2)
  1498. setFace(west)
  1499. height = platform[5] - base[5]
  1500. run("chute " .. height .. " true")
  1501. x = x + 1 -- The 'chute' program finishes one block back from start
  1502. zxHome()
  1503. dump(ladderChest, 15, 16)
  1504. dump(cobbleChest, 1, 12)
  1505.  
  1506. -- BASE
  1507.  
  1508. load(cobbleChest, 1, 12)
  1509. load(torchChest, 16, 16)
  1510. goToStartPt(base)
  1511. setFace(north)
  1512. run("floor " .. base[1] .. " " .. base[2])
  1513.  
  1514. -- TORCHES ON BASE
  1515.  
  1516. moveTo(center[1], torch1[5], center[3])
  1517. turtle.select(16)
  1518. turtle.placeDown()
  1519. goToStartPt(torch1)
  1520. setFace(north)
  1521. run("sprinkle " .. torch1[1] .. " " .. torch1[2])
  1522. goToStartPt(torch2)
  1523. setFace(north)
  1524. run("sprinkle " .. torch2[1] .. " " .. torch2[2])
  1525.  
  1526. goToStartPt(floorB)
  1527. run("floor " .. floorB[1] .. " " .. floorB[2])
  1528.  
  1529. goToStartPt(floorA)
  1530. setFace(north)
  1531. run("floor " .. floorA[1] .. " " .. floorA[2])
  1532.  
  1533. zxHome()
  1534. yHome()
  1535. dump(cobbleChest, 1, 12)
  1536. dump(torchChest, 16, 16)
  1537. load(cobbleChest, 1, 16)
  1538.  
  1539. goToStartPt(wallB)
  1540. setFace(west)
  1541. run("wall 5 3")
  1542. x = x + 1 -- The 'wall' program finishes one block back from start
  1543.  
  1544. goToStartPt(wallA)
  1545. setFace(east)
  1546. run("wall 5 3")
  1547. x = x - 1 -- The 'wall' program finishes one block back from start
  1548.  
  1549. setFace(south)
  1550. go(6)
  1551.  
  1552. goToStartPt(trapWallsB)
  1553. setFace(north)
  1554. run("walls " .. trapWallsB[1] .. " " .. trapWallsB[2] .. " " .. 3)
  1555. z = z - 1 -- The 'walls' program finishes one block back from start
  1556.  
  1557. setFace(south)
  1558. go(1)
  1559. xHome()
  1560.  
  1561. goToStartPt(trapWallsA)
  1562. setFace(north)
  1563. run("walls " .. trapWallsA[1] .. " " .. trapWallsA[2] .. " " .. 3)
  1564. z = z - 1 -- The 'walls' program finishes one block back from start
  1565.  
  1566. goToStartPt(trapRoofB)
  1567. setFace(north)
  1568. run("floor " .. trapRoofB[1] .. " " .. trapRoofB[2])
  1569.  
  1570. goToStartPt(trapRoofA)
  1571. setFace(north)
  1572. run("floor " .. trapRoofA[1] .. " " .. trapRoofA[2])
  1573.  
  1574. zxHome()
  1575. yHome()
  1576. dump(cobbleChest, 1, 16)
  1577.  
  1578. load(slabChest, 1, 3)
  1579. goToStartPt(trapSlabsB)
  1580. setFace(north)
  1581. run("floor " .. trapSlabsB[1] .. " " .. trapSlabsB[2])
  1582.  
  1583. goToStartPt(trapSlabsA)
  1584. setFace(north)
  1585. run("floor " .. trapSlabsA[1] .. " " .. trapSlabsA[2])
  1586.  
  1587. zxHome()
  1588. setFace(north)
  1589. yHome()
  1590.  
  1591. dump(slabChest, 1, 3)
  1592.  
  1593. globalHome()
  1594.  
  1595. end
  1596.  
  1597. function buildWaterHut()
  1598. --[[
  1599. for i=1,6 do
  1600. turtle.down()
  1601. end
  1602. run("floor 5 5")
  1603. run("walls 5 5 3")
  1604. for i=1,4 do
  1605. turtle.up()
  1606. end
  1607. go(1)
  1608. run("floor 5 5")
  1609. --]]
  1610.  
  1611. while turtle.down() do
  1612. y = y - 1
  1613. end
  1614. height = y + 1
  1615. run("chute " .. height)
  1616. back(1)
  1617. yHome()
  1618. end
  1619.  
  1620. -- MAIN PROGRAM
  1621.  
  1622. if nArgs ~= 1 then
  1623. print(usage)
  1624. return
  1625. end
  1626.  
  1627. face = north
  1628.  
  1629. if args[1] == "sandtrap" then
  1630. buildSandTrap()
  1631. elseif args[1] == "mobgrinder" then
  1632. buildMobGrinder()
  1633. elseif args[1] == "waterhut" then
  1634. buildWaterHut()
  1635. else
  1636. print("Unknown structure: \"", args[1], "\"")
  1637. end
  1638. *** bwb
  1639. -- bwb (branch with bark)
  1640. -- Creates a 1x1x3 tunnel with branches at intervals
  1641. -- Each branch is the of the length specified by the user
  1642. -- Seals all sides of tunnel against monsters
  1643. -- Torches, if supplied, will be placed on the wall at 8 block interval
  1644. -- Chests, if supplied, are placed at the end of each branch
  1645. -- Written by HarvDad, March 2014
  1646.  
  1647. args = {...}
  1648. nArgs = #args
  1649. usage = "Usage: bwb <length>"
  1650.  
  1651. print("bwb: Rev 1.2")
  1652.  
  1653. loop = 0;
  1654. x = 0
  1655. y = 0
  1656. z = 0
  1657. face = 0
  1658. patchSlot = 1
  1659. minimumFuel = 100
  1660. missionMessage = "Mission complete."
  1661. abort = false
  1662. local currentFuelLevel = turtle.getFuelLevel()
  1663.  
  1664. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  1665. print("Creates a 1x3 tunnel with sealed sides.")
  1666. print("Place patch material, like cobblestone, in slot", patchSlot)
  1667. print("If torches are desired, place torches in slot 16.")
  1668. printf("Chests, if supplied, are placed at the end of each branch")
  1669. print("Usage: branch <length>")
  1670. return
  1671. end
  1672.  
  1673. if nArgs ~= 1 then
  1674. print("Usage: branch <length>")
  1675. return
  1676. end
  1677.  
  1678. length = tonumber(args[1])
  1679. if length == nil then
  1680. print("\"", args[1], "\" is not a valid length")
  1681. return
  1682. end
  1683. if length < 1 then
  1684. print("length must be a positive number greater than zero")
  1685. end
  1686.  
  1687. targetArea = length
  1688. areaCovered = 1;
  1689.  
  1690.  
  1691. function left()
  1692. if face == 0 then face = 1 turtle.turnLeft() return end
  1693. if face == 1 then face = 2 turtle.turnLeft() return end
  1694. if face == 2 then face = 3 turtle.turnLeft() return end
  1695. if face == 3 then face = 0 turtle.turnLeft() return end
  1696. print("function left\(\): Bad face value: ", face)
  1697. end
  1698.  
  1699. function right()
  1700. if face == 0 then face = 3 turtle.turnRight() return end
  1701. if face == 1 then face = 0 turtle.turnRight() return end
  1702. if face == 2 then face = 1 turtle.turnRight() return end
  1703. if face == 3 then face = 2 turtle.turnRight() return end
  1704. print("function right\(\): Bad face value: ", face)
  1705. end
  1706.  
  1707. function up()
  1708. success = false
  1709.  
  1710. repeat
  1711. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  1712. turtle.digUp()
  1713. end
  1714. success = turtle.up()
  1715. until success
  1716. y = y+1
  1717. end
  1718.  
  1719. function rise(nBlocks)
  1720. local i
  1721. for i=1,nBlocks do
  1722. up()
  1723. end
  1724. end
  1725.  
  1726. function descend(nBlocks)
  1727. local i
  1728. for i=1,nBlocks do
  1729. down()
  1730. end
  1731. end
  1732.  
  1733. function down()
  1734. if turtle.detectDown() then
  1735. turtle.digDown()
  1736. end
  1737. turtle.down()
  1738. y = y-1
  1739. end
  1740.  
  1741.  
  1742. function forward()
  1743. while turtle.detect() do -- This loop added in case of falling sand or whatever
  1744. turtle.dig()
  1745. end
  1746. for i=1,10 do
  1747. if turtle.forward() then
  1748. break
  1749. end
  1750. turtle.attack()
  1751. sleep(2)
  1752. end
  1753. if face == 0 then z = z+1 return end
  1754. if face == 1 then x = x-1 return end
  1755. if face == 2 then z = z-1 return end
  1756. if face == 3 then x = x+1 return end
  1757. end
  1758.  
  1759. function patch()
  1760. turtle.select(2)
  1761. turtle.place()
  1762. gatherPatchMaterial(false);
  1763. end
  1764.  
  1765. function patchUp()
  1766. turtle.select(2)
  1767. turtle.placeUp()
  1768. gatherPatchMaterial(false);
  1769. end
  1770.  
  1771. function patchDown()
  1772. turtle.select(2)
  1773. turtle.placeDown()
  1774. gatherPatchMaterial(false);
  1775. end
  1776.  
  1777. function slurp()
  1778. local i
  1779. print("slurp...")
  1780.  
  1781. for i=2,13 do
  1782. turtle.select(i)
  1783. if turtle.suck() then
  1784. print("Sucky success for slot ", i)
  1785. break
  1786. else
  1787. end
  1788. end
  1789. print("Total sucky failure")
  1790. end
  1791.  
  1792. function slurpUp()
  1793. local i
  1794.  
  1795. for i=2,13 do
  1796. turtle.select(i)
  1797. if turtle.suckUp() then
  1798. break
  1799. end
  1800. end
  1801. end
  1802.  
  1803. function slurpDown()
  1804. local i
  1805.  
  1806. for i=2,13 do
  1807. turtle.select(i)
  1808. if turtle.suckDown() then
  1809. break
  1810. end
  1811. end
  1812. end
  1813.  
  1814. function gatherPatchMaterial(force)
  1815. local i
  1816. patchCount = turtle.getItemCount(patchSlot)
  1817.  
  1818. if (patchCount < 30) or force then
  1819. print("Attempting to refill slot ", patchSlot)
  1820. for i=1,14 do
  1821. turtle.select(i)
  1822. if turtle.compareTo(patchSlot) then
  1823. turtle.transferTo(patchSlot, 64-patchCount)
  1824. print("Transferred ", 64 - patchCount, " cobble to slot ", patchSlot)
  1825. end
  1826. end
  1827. end
  1828. turtle.select(patchSlot)
  1829. end
  1830.  
  1831. addTorch = true
  1832. torchSpacing = 8
  1833. torchSpot = 6
  1834.  
  1835. function _mineForward()
  1836. forward()
  1837.  
  1838. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  1839. turtle.digUp()
  1840. -- slurpUp()
  1841. end
  1842.  
  1843. if turtle.detectDown() then
  1844. turtle.digDown()
  1845. -- slurpDown()
  1846. end
  1847.  
  1848. if addTorch then
  1849. if (torchSpot % torchSpacing) == 0 then
  1850. left()
  1851. left()
  1852. turtle.select(16)
  1853. turtle.place()
  1854. right()
  1855. right()
  1856. end
  1857. end
  1858. torchSpot = torchSpot + 1
  1859. end
  1860.  
  1861. function mineForwardUp()
  1862. forward()
  1863. -- slurp()
  1864. if not turtle.detectDown() then
  1865. patchDown()
  1866. end
  1867. patchSides()
  1868.  
  1869. up()
  1870. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  1871. turtle.digUp()
  1872. -- slurpUp()
  1873. end
  1874. patchSides()
  1875.  
  1876. torchCheck()
  1877.  
  1878. up()
  1879. if not turtle.detectUp() then
  1880. patchUp()
  1881. end
  1882. patchSides()
  1883.  
  1884. torchSpot = torchSpot + 1
  1885. end
  1886.  
  1887. function mineForwardDown()
  1888. forward()
  1889. -- slurp()
  1890. if not turtle.detectUp() then
  1891. patchUp()
  1892. end
  1893. patchSides()
  1894.  
  1895. down()
  1896. patchSides()
  1897.  
  1898. torchCheck()
  1899.  
  1900. down()
  1901. if not turtle.detectDown() then
  1902. patchDown()
  1903. end
  1904. patchSides()
  1905.  
  1906. torchSpot = torchSpot + 1
  1907. end
  1908.  
  1909. function patchCeiling()
  1910. end
  1911.  
  1912. function patchFloor()
  1913. end
  1914.  
  1915. function patchSides()
  1916. if x == 0 then
  1917. return
  1918. end
  1919.  
  1920. local currentFace = face
  1921. left()
  1922.  
  1923. if not turtle.detect() then
  1924. patch()
  1925. end
  1926.  
  1927. right()
  1928. right()
  1929.  
  1930. if not turtle.detect() then
  1931. patch()
  1932. end
  1933.  
  1934. setFace(currentFace)
  1935. end
  1936.  
  1937. function _patchSides()
  1938. local currentFace = face
  1939. left()
  1940. if not turtle.detect() then
  1941. if face == 0 and x ~= -1 then
  1942. patch()
  1943. end
  1944. end
  1945. right()
  1946. right()
  1947. if not turtle.detect() then
  1948. if face == 0 and x ~= -1 then
  1949. patch()
  1950. else
  1951. print("patchSides: opted to NOT patch, face = ", face, ", x = ", x)
  1952. end
  1953. end
  1954. setFace(currentFace)
  1955. -- left()
  1956. end
  1957.  
  1958. function torchCheck()
  1959. if addTorch then
  1960. if (torchSpot % torchSpacing) == 0 then
  1961. right()
  1962. right()
  1963. turtle.select(16)
  1964. turtle.place()
  1965. left()
  1966. left()
  1967. end
  1968. end
  1969. end
  1970.  
  1971. function setFace(f)
  1972. if f == 0 then
  1973. if face == 0 then return end
  1974. if face == 1 then right() return end
  1975. if face == 2 then right() right() return end
  1976. if face == 3 then left() return end
  1977. end
  1978.  
  1979. if f == 1 then
  1980. if face == 0 then left() return end
  1981. if face == 1 then return end
  1982. if face == 2 then right() return end
  1983. if face == 3 then right() right() return end
  1984. end
  1985.  
  1986. if f == 2 then
  1987. if face == 0 then left() left() return end
  1988. if face == 1 then left() return end
  1989. if face == 2 then return end
  1990. if face == 3 then right() return end
  1991. end
  1992.  
  1993. if f == 3 then
  1994. if face == 0 then right() return end
  1995. if face == 1 then left() left() return end
  1996. if face == 2 then left() return end
  1997. if face == 3 then return end
  1998. end
  1999. end
  2000.  
  2001. function checkFuel()
  2002. if currentFuelLevel == "unlimited" then
  2003. return true
  2004. end
  2005.  
  2006. if currentFuelLevel < minimumFuel then
  2007. if not turtle.refuel(200) then
  2008. areaCovered = targetArea
  2009. missionMessage = "Mission aborted due to low fuel."
  2010. abort = true
  2011. return false
  2012. end
  2013. end
  2014. return true
  2015. end
  2016.  
  2017. function home(targetY)
  2018. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  2019. if x < 0 then
  2020. setFace(3)
  2021. while x < 0 do
  2022. forward()
  2023. end
  2024. else
  2025. if x > 0 then
  2026. setFace(1)
  2027. while x > 0 do
  2028. forward()
  2029. end
  2030. end
  2031. end
  2032.  
  2033. if z < 0 then
  2034. setFace(0)
  2035. while z < 0 do
  2036. forward()
  2037. end
  2038. else
  2039. if z > 0 then
  2040. setFace(2)
  2041. while z > 0 do
  2042. forward()
  2043. end
  2044. end
  2045. end
  2046. end
  2047.  
  2048. function dump()
  2049. gatherPatchMaterial(true)
  2050. for i=2,14 do
  2051. turtle.select(i)
  2052. turtle.dropDown()
  2053. end
  2054. end
  2055.  
  2056. function mineAhead()
  2057. if y == 0 then
  2058. mineForwardUp()
  2059. else
  2060. mineForwardDown()
  2061. end
  2062. end
  2063.  
  2064. function branchLoop()
  2065. torchSpot = 6
  2066. local i
  2067.  
  2068. for i=1,length do
  2069. mineAhead()
  2070. end
  2071.  
  2072. right()
  2073.  
  2074. for i=1,3 do
  2075. mineAhead()
  2076. end
  2077.  
  2078. right()
  2079.  
  2080. for i=1,length do
  2081. mineAhead()
  2082. end
  2083.  
  2084. setFace(0)
  2085. while y > 0 do
  2086. down()
  2087. end
  2088.  
  2089. if turtle.detectDown() then
  2090. turtle.select(15)
  2091. if not turtle.compareDown() then
  2092. turtle.digDown()
  2093. -- slurpDown()
  2094. turtle.placeDown()
  2095. end
  2096. end
  2097. if turtle.compareDown() then
  2098. dump()
  2099. turtle.select(2)
  2100. end
  2101. end
  2102.  
  2103. -- MAIN PROGRAM
  2104.  
  2105. turtle.select(1)
  2106.  
  2107. print("Current Fuel Level: ", currentFuelLevel)
  2108.  
  2109. if currentFuelLevel ~= "unlimited" then
  2110. if currentFuelLevel < minimumFuel then
  2111. if not turtle.refuel() then
  2112. print("No fuel")
  2113. return
  2114. end
  2115. end
  2116. end
  2117.  
  2118. for loop=1,5 do
  2119. addTorch = false
  2120.  
  2121. -- rise(1)
  2122. for i=1,5 do
  2123. mineAhead()
  2124. end
  2125. turtle.back()
  2126. turtle.back()
  2127. left()
  2128. addTorch = true
  2129. branchLoop()
  2130. end
  2131.  
  2132.  
  2133. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
  2134. *** cactus
  2135. -- cactus
  2136. -- Harvests the top 2 blocks of cacti from the top
  2137. -- Turtle returns to its starting point when mission is completed or fuel runs low
  2138. -- Written by HarvDad, April 2014
  2139.  
  2140. args = {...}
  2141. nArgs = #args
  2142.  
  2143. print("cactus: Rev 1.2")
  2144.  
  2145. x = 0
  2146. y = 0
  2147. z = 0
  2148. face = 0
  2149. cactusSlot = 1
  2150. minimumFuel = 100
  2151. missionMessage = "Mission complete."
  2152. abort = false
  2153. local currentFuelLevel = turtle.getFuelLevel()
  2154.  
  2155. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  2156. print("length, width, and height")
  2157. print("Usage: cactus <length> <width>")
  2158. return
  2159. end
  2160.  
  2161. if nArgs ~= 2 then
  2162. print("Usage: clear <length> <width>")
  2163. return
  2164. end
  2165.  
  2166. length = tonumber(args[1])
  2167. if length == nil then
  2168. print("\"", args[1], "\" is not a valid length")
  2169. return
  2170. end
  2171. if length < 1 then
  2172. print("length must be a positive number greater than zero")
  2173. end
  2174.  
  2175. width = tonumber(args[2])
  2176. if width == nil then
  2177. print("\"", args[2], "\" is not a valid width")
  2178. return
  2179. end
  2180. if width < 1 then
  2181. print("width must be a positive number greater than zero")
  2182. end
  2183.  
  2184. targetArea = length * width
  2185. areaCovered = 1;
  2186.  
  2187. function chomp()
  2188. turtle.select(cactusSlot)
  2189. if turtle.compareDown() then
  2190. turtle.digDown()
  2191. end
  2192. areaCovered = areaCovered+1
  2193. end
  2194.  
  2195. direction = "left"
  2196.  
  2197. local clock = os.clock
  2198. function sleep(n) -- seconds
  2199. local t0 = clock()
  2200. while clock() - t0 <= n do end
  2201. end
  2202.  
  2203. function left()
  2204. if face == 0 then face = 1 turtle.turnLeft() return end
  2205. if face == 1 then face = 2 turtle.turnLeft() return end
  2206. if face == 2 then face = 3 turtle.turnLeft() return end
  2207. if face == 3 then face = 0 turtle.turnLeft() return end
  2208. print("function left\(\): Bad face value: ", face)
  2209. end
  2210.  
  2211. function right()
  2212. if face == 0 then face = 3 turtle.turnRight() return end
  2213. if face == 1 then face = 0 turtle.turnRight() return end
  2214. if face == 2 then face = 1 turtle.turnRight() return end
  2215. if face == 3 then face = 2 turtle.turnRight() return end
  2216. print("function right\(\): Bad face value: ", face)
  2217. end
  2218.  
  2219. function up()
  2220. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  2221. turtle.digUp()
  2222. end
  2223. turtle.up()
  2224. y = y+1
  2225. end
  2226.  
  2227. function rise(nBlocks)
  2228. local i
  2229. for i=1,nBlocks do
  2230. up()
  2231. end
  2232. end
  2233.  
  2234. function down()
  2235. if turtle.detectDown() then
  2236. turtle.digDown()
  2237. end
  2238. turtle.down()
  2239. y = y-1
  2240. end
  2241.  
  2242. function turn()
  2243. if direction == "left" then
  2244. left()
  2245. else
  2246. right()
  2247. end
  2248. chomp()
  2249. forward()
  2250. if direction == "left" then
  2251. left()
  2252. direction = "right"
  2253. else
  2254. right()
  2255. direction = "left"
  2256. end
  2257. end
  2258.  
  2259. function forward()
  2260. while turtle.detect() do -- This loop added in case of falling sand or whatever
  2261. turtle.dig()
  2262. end
  2263. for i=1,10 do
  2264. if turtle.forward() then
  2265. break
  2266. end
  2267. turtle.attack()
  2268. sleep(2)
  2269. end
  2270. if face == 0 then z = z+1 return end
  2271. if face == 1 then x = x-1 return end
  2272. if face == 2 then z = z-1 return end
  2273. if face == 3 then x = x+1 return end
  2274. end
  2275.  
  2276. function setFace(f)
  2277. if f == 0 then
  2278. if face == 0 then return end
  2279. if face == 1 then right() return end
  2280. if face == 2 then right() right() return end
  2281. if face == 3 then left() return end
  2282. end
  2283.  
  2284. if f == 1 then
  2285. if face == 0 then left() return end
  2286. if face == 1 then return end
  2287. if face == 2 then right() return end
  2288. if face == 3 then right() right() return end
  2289. end
  2290.  
  2291. if f == 2 then
  2292. if face == 0 then left() left() return end
  2293. if face == 1 then left() return end
  2294. if face == 2 then return end
  2295. if face == 3 then right() return end
  2296. end
  2297.  
  2298. if f == 3 then
  2299. if face == 0 then right() return end
  2300. if face == 1 then left() left() return end
  2301. if face == 2 then left() return end
  2302. if face == 3 then return end
  2303. end
  2304. end
  2305.  
  2306. function home(targetY)
  2307. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  2308. if x < 0 then
  2309. setFace(3)
  2310. while x < 0 do
  2311. forward()
  2312. end
  2313. else
  2314. if x > 0 then
  2315. setFace(1)
  2316. while x > 0 do
  2317. forward()
  2318. end
  2319. end
  2320. end
  2321.  
  2322. if z < 0 then
  2323. setFace(0)
  2324. while z < 0 do
  2325. forward()
  2326. end
  2327. else
  2328. if z > 0 then
  2329. setFace(2)
  2330. while z > 0 do
  2331. forward()
  2332. end
  2333. end
  2334. end
  2335. setFace(0)
  2336.  
  2337. if (targetY == 0) then
  2338. while y < 0 do
  2339. up()
  2340. end
  2341. end
  2342. end
  2343.  
  2344. function harvest(nBlocks)
  2345. local i
  2346. for i=1,nBlocks do
  2347. chomp()
  2348. checkFuel()
  2349. if abort then
  2350. areaCovered = targetArea
  2351. end
  2352.  
  2353. if areaCovered < targetArea then
  2354. forward()
  2355. end
  2356. end
  2357. end
  2358.  
  2359.  
  2360. function checkFuel()
  2361. if currentFuelLevel == "unlimited" then
  2362. return true
  2363. end
  2364.  
  2365. if currentFuelLevel < minimumFuel then
  2366. if not turtle.refuel() then
  2367. areaCovered = targetArea
  2368. missionMessage = "Mission aborted due to low fuel."
  2369. abort = true
  2370. return false
  2371. end
  2372. end
  2373. return true
  2374. end
  2375.  
  2376. -- MAIN PROGRAM
  2377.  
  2378. turtle.select(1)
  2379.  
  2380. print("fuelLevel = ", currentFuelLevel)
  2381. print("length = ", length)
  2382. print("width = ", width)
  2383. up()
  2384. up()
  2385. up()
  2386.  
  2387. height = 2
  2388.  
  2389. for d=1,height do
  2390. for w=1,width do
  2391. harvest(length-1)
  2392. if areaCovered < targetArea then
  2393. turn()
  2394. end
  2395. if abort then
  2396. home(0)
  2397. end
  2398. end
  2399. home(99)
  2400. if d < height then
  2401. down()
  2402. direction = "left"
  2403. areaCovered = 1;
  2404. end
  2405. end
  2406.  
  2407. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
  2408. home(0)
  2409. down()
  2410. down()
  2411.  
  2412. *** chute
  2413. -- chute
  2414. -- Creates a ladder chute to the height or depth specified
  2415. -- If supplied, ladder is placed
  2416. -- Written by HarvDad, March 2014
  2417.  
  2418. args = {...}
  2419. nArgs = #args
  2420.  
  2421. print("chute: Rev 2.0")
  2422. x = 0
  2423. y = 0
  2424. z = 0
  2425. face = 0
  2426. minimumFuel = 100
  2427. minLevel = 6
  2428. missionMessage = "Mission complete."
  2429. abort = false
  2430. local currentFuelLevel = turtle.getFuelLevel()
  2431. patchSlot = 1
  2432. ladderSlot = 16
  2433. goingUp = false
  2434. useLadders = true
  2435.  
  2436. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  2437. print("Creates a ladder chute straight up or down.")
  2438. print("This program assumes turtle is pre-fueled.")
  2439. print("Usage: chute <height> <useLadders>")
  2440. print("Place ladder in slot ", ladderSlot, ".")
  2441. return
  2442. end
  2443.  
  2444. if nArgs ~= 2 then
  2445. print("Usage: chute <height> <useLadders>")
  2446. return
  2447. end
  2448.  
  2449. targetDepth = tonumber(args[1])
  2450. if targetDepth == nil then
  2451. print("\"", args[1], "\" is not a valid depth")
  2452. return
  2453. end
  2454.  
  2455. if args[2] == "true" then
  2456. useLadders = true
  2457. elseif args[2] == "false" then
  2458. useLadders = false
  2459. else
  2460. print("Second argument must be true or false")
  2461. return
  2462. end
  2463.  
  2464. if (targetDepth < 0) then
  2465. targetDepth = targetDepth + 1
  2466. goingUp = true
  2467. end
  2468.  
  2469. depth = 0
  2470.  
  2471.  
  2472. function left()
  2473. if face == 0 then face = 1 turtle.turnLeft() return end
  2474. if face == 1 then face = 2 turtle.turnLeft() return end
  2475. if face == 2 then face = 3 turtle.turnLeft() return end
  2476. if face == 3 then face = 0 turtle.turnLeft() return end
  2477. print("function left\(\): Bad face value: ", face)
  2478. end
  2479.  
  2480. function right()
  2481. if face == 0 then face = 3 turtle.turnRight() return end
  2482. if face == 1 then face = 0 turtle.turnRight() return end
  2483. if face == 2 then face = 1 turtle.turnRight() return end
  2484. if face == 3 then face = 2 turtle.turnRight() return end
  2485. print("function right\(\): Bad face value: ", face)
  2486. end
  2487.  
  2488. function patchWalls()
  2489. if turtle.getItemCount(patchSlot) < 4 then
  2490. gatherPatchMaterial()
  2491. end
  2492.  
  2493. turtle.select(patchSlot)
  2494.  
  2495. left()
  2496. turtle.place()
  2497. right()
  2498. turtle.place()
  2499. right()
  2500. turtle.place()
  2501. left()
  2502. end
  2503.  
  2504. function up()
  2505. attackCount = 0
  2506. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  2507. turtle.digUp()
  2508. end
  2509. for i=1,10 do -- This loop tries to handle pests (mob) that might be in the way
  2510. if turtle.up() then
  2511. break
  2512. end
  2513. sleep(2)
  2514. end
  2515. if attackCount > 1 then
  2516. turtle.attackUp()
  2517. end
  2518.  
  2519. gatherPatchMaterial()
  2520.  
  2521. patchWalls()
  2522.  
  2523. setFace(north)
  2524. depth = depth-1
  2525. y = y+1
  2526. end
  2527.  
  2528. function down()
  2529. attackCount = 0
  2530.  
  2531. if depth >= targetDepth then
  2532. print("Hit target depth")
  2533. return
  2534. end
  2535.  
  2536. if turtle.detectDown() then
  2537. turtle.digDown()
  2538. end
  2539. for i=1,10 do -- This loop trys to handle pests (mobs) that might be in the way
  2540. if turtle.down() then
  2541. break
  2542. end
  2543. turtle.attackDown()
  2544. attackCount = attackCount + 1
  2545. sleep(2)
  2546. end
  2547.  
  2548. if attackCount > 1 then
  2549. turtle.suckDown()
  2550. turtle.suckUp()
  2551. end
  2552.  
  2553. gatherPatchMaterial()
  2554.  
  2555. turtle.select(patchSlot)
  2556. if not turtle.detect() then
  2557. turtle.place()
  2558. end
  2559.  
  2560. turtle.turnLeft()
  2561. if not turtle.detect() then
  2562. turtle.place()
  2563. end
  2564.  
  2565. turtle.turnLeft()
  2566. if not turtle.detect() then
  2567. turtle.place()
  2568. end
  2569.  
  2570. turtle.turnLeft()
  2571. if not turtle.detect() then
  2572. turtle.place()
  2573. end
  2574.  
  2575. turtle.turnLeft()
  2576. depth = depth+1
  2577. y = y-1
  2578. end
  2579.  
  2580. function rise(nBlocks)
  2581. local i
  2582. for i=1,nBlocks do
  2583. turtle.up()
  2584. y = y+1
  2585. end
  2586. end
  2587.  
  2588. function gatherPatchMaterial()
  2589. local i
  2590. patchCount = turtle.getItemCount(patchSlot)
  2591.  
  2592. if patchCount < 5 then
  2593. -- print("Attempting to refill slot ", patchSlot)
  2594. for i=2,13 do
  2595. turtle.select(i)
  2596. if turtle.compareTo(patchSlot) then
  2597. turtle.transferTo(patchSlot, 64-patchCount)
  2598. -- print("Transferred ", 64 - patchCount, " cobble to slot ", patchSlot)
  2599. end
  2600. end
  2601. end
  2602. turtle.select(patchSlot)
  2603. end
  2604.  
  2605. function setFace(f)
  2606. if f == 0 then
  2607. if face == 0 then return end
  2608. if face == 1 then right() return end
  2609. if face == 2 then right() right() return end
  2610. if face == 3 then left() return end
  2611. end
  2612.  
  2613. if f == 1 then
  2614. if face == 0 then left() return end
  2615. if face == 1 then return end
  2616. if face == 2 then right() return end
  2617. if face == 3 then right() right() return end
  2618. end
  2619.  
  2620. if f == 2 then
  2621. if face == 0 then left() left() return end
  2622. if face == 1 then left() return end
  2623. if face == 2 then return end
  2624. if face == 3 then right() return end
  2625. end
  2626.  
  2627. if f == 3 then
  2628. if face == 0 then right() return end
  2629. if face == 1 then left() left() return end
  2630. if face == 2 then left() return end
  2631. if face == 3 then return end
  2632. end
  2633. end
  2634.  
  2635. moreLadder = true
  2636.  
  2637. function placeLadder()
  2638. if not useLadders then
  2639. return
  2640. end
  2641.  
  2642. if turtle.getItemCount(ladderSlot) > 0 then
  2643. turtle.select(ladderSlot)
  2644. elseif turtle.getItemCount(ladderSlot-1) > 0 then
  2645. turtle.select(ladderSlot-1)
  2646. elseif turtle.getItemCount(ladderSlot-2) > 0 then
  2647. turtle.select(ladderSlot-2)
  2648. else
  2649. moreLadder = false
  2650. end
  2651.  
  2652. print("placeLadder: Ladder count = ", turtle.getItemCount(ladderSlot), " moreLadder = ", moreLadder)
  2653. if moreLadder then
  2654. turtle.place()
  2655. end
  2656. end
  2657.  
  2658. function placeLadderUp()
  2659. if turtle.getItemCount(ladderSlot) < 1 then
  2660. ladderSlot = ladderSlot - 1
  2661. if turtle.getItemCount(ladderSlot) < 1 then
  2662. ladderSlot = ladderSlot - 1
  2663. if turtle.getItemCount(ladderSlot) < 1 then
  2664. ladderSlot = ladderSlot - 1
  2665. if turtle.getItemCount(ladderSlot) < 1 then
  2666. end
  2667. end
  2668. end
  2669. end
  2670. turtle.select(ladderSlot)
  2671. turtle.placeUp()
  2672. end
  2673.  
  2674. function homeUp()
  2675. setFace(north)
  2676. turtle.select(ladderSlot)
  2677. turtle.suckUp() -- in case we have monster guts on top of us
  2678. while y < 0 do
  2679. turtle.up()
  2680. if not turtle.detectDown() then
  2681. turtle.placeDown()
  2682. end
  2683. y = y+1
  2684. end
  2685. end
  2686.  
  2687. function ladderDown()
  2688. setFace(north)
  2689. turtle.back()
  2690. z = z - 1
  2691. firstLadder = true
  2692. while y >= 0 do
  2693. placeLadder()
  2694. if turtle.getItemCount(patchSlot) < 4 then
  2695. gatherPatchMaterial()
  2696. end
  2697. if (not firstLadder and y ~= 0) then
  2698. turtle.select(patchSlot)
  2699. turtle.placeUp()
  2700. end
  2701. firstLadder = false
  2702. if y > 0 then
  2703. turtle.down()
  2704. y = y - 1
  2705. else
  2706. break
  2707. end
  2708. end
  2709. end
  2710.  
  2711. function homeDown()
  2712. setFace(north)
  2713. turtle.select(ladderSlot)
  2714. turtle.suckDown() -- in case we have monster guts on top of us
  2715. while y > 0 do
  2716. turtle.down()
  2717. if not turtle.detectDown() then
  2718. placeLadderUp()
  2719. end
  2720. y = y-1
  2721. end
  2722. end
  2723.  
  2724. -- Main program loop
  2725.  
  2726. if goingUp then
  2727. patchWalls()
  2728. while depth > targetDepth do
  2729. up()
  2730. end
  2731. ladderDown()
  2732. else
  2733. while depth < targetDepth do
  2734. down()
  2735. end
  2736. homeUp()
  2737. end
  2738.  
  2739.  
  2740.  
  2741. setFace(north)
  2742. print(missionMessage)
  2743. *** clear
  2744. -- clear
  2745. -- Mines a clear space to the dimensions supplied by the user
  2746. -- Turtle returns to its starting point when mission is completed or fuel runs low
  2747. -- Written by HarvDad, March 2014 Last update: May 22, 2014
  2748.  
  2749. args = {...}
  2750. nArgs = #args
  2751.  
  2752. print("clear: Rev 5.0")
  2753. x = 0
  2754. y = 0
  2755. z = 0
  2756. face = 0
  2757. minimumFuel = 100
  2758. missionMessage = "Mission complete."
  2759. abort = false
  2760. local currentFuelLevel = turtle.getFuelLevel()
  2761. lowestLevel = 0
  2762. highestLevel = 0
  2763.  
  2764. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  2765. print("Clear an area specified by the given length, width, and height")
  2766. print("Usage: clear <length><width><height>")
  2767. return
  2768. end
  2769.  
  2770. if nArgs ~= 3 then
  2771. print("Usage: clear <length><width><height>")
  2772. return
  2773. end
  2774.  
  2775. length = tonumber(args[1])
  2776. if length == nil then
  2777. print("\"", args[1], "\" is not a valid length")
  2778. return
  2779. end
  2780. if length < 1 then
  2781. print("length must be a positive number greater than zero")
  2782. end
  2783.  
  2784. width = tonumber(args[2])
  2785. if width == nil then
  2786. print("\"", args[2], "\" is not a valid width")
  2787. return
  2788. end
  2789. if width < 1 then
  2790. print("width must be a positive number greater than zero")
  2791. end
  2792.  
  2793. height = tonumber(args[3])
  2794. if height == nil then
  2795. print("\"", args[3], "\" is not a valid height")
  2796. return
  2797. end
  2798. --[[
  2799. if height < 1 then
  2800. print("height must be a positive number greater than zero")
  2801. end
  2802. --]]
  2803.  
  2804. if height > 0 then
  2805. highestLevel = height
  2806. lowestLevel = 0
  2807. elseif height < 0 then
  2808. highestLevel = 0
  2809. lowestLevel = 0 + height
  2810. else
  2811. highestLevel = 0
  2812. lowestLevel = 0
  2813. end
  2814.  
  2815. print("highestLevel = ", highestLevel, ", lowestLevel = ", lowestLevel)
  2816.  
  2817. targetArea = length * width
  2818. areaCovered = 1;
  2819.  
  2820. function chomp()
  2821. if turtle.detect() then
  2822. turtle.dig()
  2823. if y - 1 <= highestLevel then
  2824. turtle.digUp()
  2825. end
  2826. if y - 1 >= lowestLevel then
  2827. turtle.digDown()
  2828. end
  2829. end
  2830. areaCovered = areaCovered+1
  2831. end
  2832.  
  2833. direction = "left"
  2834.  
  2835. local clock = os.clock
  2836. function sleep(n) -- seconds
  2837. local t0 = clock()
  2838. while clock() - t0 <= n do end
  2839. end
  2840.  
  2841. function left()
  2842. if face == 0 then face = 1 turtle.turnLeft() return end
  2843. if face == 1 then face = 2 turtle.turnLeft() return end
  2844. if face == 2 then face = 3 turtle.turnLeft() return end
  2845. if face == 3 then face = 0 turtle.turnLeft() return end
  2846. print("function left\(\): Bad face value: ", face)
  2847. end
  2848.  
  2849. function right()
  2850. if face == 0 then face = 3 turtle.turnRight() return end
  2851. if face == 1 then face = 0 turtle.turnRight() return end
  2852. if face == 2 then face = 1 turtle.turnRight() return end
  2853. if face == 3 then face = 2 turtle.turnRight() return end
  2854. print("function right\(\): Bad face value: ", face)
  2855. end
  2856.  
  2857. function up()
  2858. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  2859. turtle.digUp()
  2860. end
  2861. turtle.up()
  2862. y = y+1
  2863. end
  2864.  
  2865. function rise(nBlocks)
  2866. local i
  2867. for i=1,nBlocks do
  2868. up()
  2869. end
  2870. end
  2871.  
  2872. function down()
  2873. if turtle.detectDown() then
  2874. turtle.digDown()
  2875. end
  2876. turtle.down()
  2877. y = y-1
  2878. end
  2879.  
  2880. function turn()
  2881. if direction == "left" then
  2882. left()
  2883. else
  2884. right()
  2885. end
  2886. chomp()
  2887. forward()
  2888. if direction == "left" then
  2889. left()
  2890. direction = "right"
  2891. else
  2892. right()
  2893. direction = "left"
  2894. end
  2895. end
  2896.  
  2897. function forward()
  2898. while turtle.detect() do -- This loop added in case of falling sand or whatever
  2899. turtle.dig()
  2900. end
  2901. for i=1,10 do
  2902. if turtle.forward() then
  2903. break
  2904. end
  2905. turtle.attack()
  2906. sleep(2)
  2907. end
  2908. if face == 0 then z = z+1 return end
  2909. if face == 1 then x = x-1 return end
  2910. if face == 2 then z = z-1 return end
  2911. if face == 3 then x = x+1 return end
  2912. end
  2913.  
  2914. function setFace(f)
  2915. if f == 0 then
  2916. if face == 0 then return end
  2917. if face == 1 then right() return end
  2918. if face == 2 then right() right() return end
  2919. if face == 3 then left() return end
  2920. end
  2921.  
  2922. if f == 1 then
  2923. if face == 0 then left() return end
  2924. if face == 1 then return end
  2925. if face == 2 then right() return end
  2926. if face == 3 then right() right() return end
  2927. end
  2928.  
  2929. if f == 2 then
  2930. if face == 0 then left() left() return end
  2931. if face == 1 then left() return end
  2932. if face == 2 then return end
  2933. if face == 3 then right() return end
  2934. end
  2935.  
  2936. if f == 3 then
  2937. if face == 0 then right() return end
  2938. if face == 1 then left() left() return end
  2939. if face == 2 then left() return end
  2940. if face == 3 then return end
  2941. end
  2942. end
  2943.  
  2944. function home(targetY)
  2945. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  2946. if x < 0 then
  2947. setFace(3)
  2948. while x < 0 do
  2949. forward()
  2950. end
  2951. else
  2952. if x > 0 then
  2953. setFace(1)
  2954. while x > 0 do
  2955. forward()
  2956. end
  2957. end
  2958. end
  2959.  
  2960. if z < 0 then
  2961. setFace(0)
  2962. while z < 0 do
  2963. forward()
  2964. end
  2965. else
  2966. if z > 0 then
  2967. setFace(2)
  2968. while z > 0 do
  2969. forward()
  2970. end
  2971. end
  2972. end
  2973. setFace(0)
  2974.  
  2975. if (targetY == 0) then
  2976. while y < 0 do
  2977. up()
  2978. end
  2979. end
  2980. end
  2981.  
  2982. function strip(nBlocks)
  2983. local i
  2984. -- print("strip ", nBlocks)
  2985. for i=1,nBlocks do
  2986. chomp()
  2987. checkFuel()
  2988. if abort then
  2989. areaCovered = targetArea
  2990. end
  2991.  
  2992. if areaCovered < targetArea then
  2993. forward()
  2994. end
  2995. end
  2996. end
  2997.  
  2998.  
  2999. function checkFuel()
  3000. if currentFuelLevel == "unlimited" then
  3001. return true
  3002. end
  3003.  
  3004. if currentFuelLevel < minimumFuel then
  3005. if not turtle.refuel() then
  3006. areaCovered = targetArea
  3007. missionMessage = "Mission aborted due to low fuel."
  3008. abort = true
  3009. return false
  3010. end
  3011. end
  3012. return true
  3013. end
  3014.  
  3015. -- MAIN PROGRAM
  3016.  
  3017. turtle.select(1)
  3018.  
  3019. print("fuelLevel = ", currentFuelLevel)
  3020. print("length = ", length)
  3021. print("width = ", width)
  3022. print("height = ", height)
  3023. print("face = ", face)
  3024.  
  3025. print("Current Fuel Level: ", currentFuelLevel)
  3026.  
  3027. if currentFuelLevel ~= "unlimited" then
  3028. if currentFuelLevel < minimumFuel then
  3029. if not turtle.refuel() then
  3030. print("No fuel")
  3031. return
  3032. end
  3033. end
  3034. end
  3035.  
  3036.  
  3037. if height > 0 then
  3038. rise(height-1)
  3039. elseif height < 0 then
  3040. height = -height + 1 -- same vertical distance, but we don't rise first
  3041. else
  3042. return
  3043. end
  3044.  
  3045. for d=1,height do
  3046. for w=1,width do
  3047. strip(length-1)
  3048. -- print("strip: Cleared ", areaCovered, " out of ", targetArea, " blocks")
  3049. if areaCovered < targetArea then
  3050. turn()
  3051. end
  3052. if abort then
  3053. home(0)
  3054. end
  3055. end
  3056. home(99)
  3057. if d < height then
  3058. down()
  3059. direction = "left"
  3060. areaCovered = 1;
  3061. end
  3062. end
  3063.  
  3064. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
  3065. home(0)
  3066. *** collect
  3067. -- collect
  3068. -- Collects specified blocks from chests left by 'branch' and 'bwb' programs
  3069. -- Written by HarvDad, March 2014
  3070.  
  3071. args = {...}
  3072. nArgs = #args
  3073. usage = "Usage: collect"
  3074.  
  3075. print("collect: Rev 0.1")
  3076.  
  3077. loop = 0;
  3078. x = 0
  3079. y = 0
  3080. z = 0
  3081. face = 0
  3082. patchSlot = 2
  3083. minimumFuel = 100
  3084. missionMessage = "Mission complete."
  3085. abort = false
  3086. local currentFuelLevel = turtle.getFuelLevel()
  3087.  
  3088. if (nArgs == 1 and args[1]== "help") then
  3089. print("Collects specified blocks from in-ground chests")
  3090. print(" as left by the 'branch' and 'bwb' programs.")
  3091. print("Place fuel in slot 1")
  3092. print("Place at least 1 block of target material in slot 2.")
  3093. print("Turtle proceeds in straight line until it hits something")
  3094. print(usage)
  3095. return
  3096. end
  3097.  
  3098. if nArgs ~= 0 then
  3099. print(usage)
  3100. return
  3101. end
  3102.  
  3103. function suckChest()
  3104. local i
  3105.  
  3106. turtle.select(3)
  3107. for i=3,16 do
  3108. turtle.suckDown()
  3109. end
  3110. end
  3111.  
  3112. targetSlot = 2
  3113.  
  3114. function gatherTargetMaterial()
  3115. local i
  3116.  
  3117. for i=3,16 do
  3118. turtle.select(i)
  3119. if turtle.compareTo(targetSlot) then
  3120. turtle.transferTo(targetSlot)
  3121. end
  3122. end
  3123. end
  3124.  
  3125. function dumpRejects()
  3126. local i
  3127.  
  3128. turtle.select(3)
  3129. for i=3,16 do
  3130. turtle.select(i)
  3131. if not turtle.compareTo(targetSlot) then
  3132. turtle.dropDown()
  3133. end
  3134. end
  3135. end
  3136.  
  3137. function home()
  3138. while z > 0 do
  3139. turtle.back()
  3140. end
  3141. end
  3142.  
  3143. -- Main Program
  3144.  
  3145. for i=1,100 do
  3146. turtle.select(3)
  3147. if turtle.suckDown() then
  3148. turtle.dropDown()
  3149. suckChest()
  3150. dumpRejects()
  3151. gatherTargetMaterial()
  3152. end
  3153. if not turtle.forward() then
  3154. break
  3155. end
  3156. z = z+1
  3157. end
  3158.  
  3159. home()
  3160. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
  3161.  
  3162.  
  3163.  
  3164. *** convey10x10-4
  3165.  
  3166. conveyorSlot = 16
  3167. elevation = 1
  3168.  
  3169. local function forward(nBlocks)
  3170. for i=1,nBlocks do
  3171. turtle.forward()
  3172. end
  3173. end
  3174.  
  3175. local function back(nBlocks)
  3176. for i=1,nBlocks do
  3177. turtle.back()
  3178. end
  3179. end
  3180.  
  3181. local function up(nBlocks)
  3182. for i=1,nBlocks do
  3183. turtle.up()
  3184. end
  3185. end
  3186.  
  3187. local function down(nBlocks)
  3188. for i=1,nBlocks do
  3189. turtle.down()
  3190. end
  3191. end
  3192.  
  3193. local function goToStartPoint()
  3194. up(2)
  3195. elevation = 2
  3196. turtle.turnRight()
  3197. forward(4)
  3198. turtle.turnLeft()
  3199. back(5)
  3200. end
  3201.  
  3202. local function returnHome()
  3203. forward(4)
  3204. turtle.turnRight()
  3205. forward(1)
  3206. down(elevation)
  3207. end
  3208.  
  3209. function nextRow()
  3210. turtle.turnLeft()
  3211. turtle.forward()
  3212. turtle.turnRight()
  3213. end
  3214.  
  3215. function layRow(rowNumber, length)
  3216. for i=1,length do
  3217. if turtle.getItemCount(16) < 1 then
  3218. turtle.select(conveyorSlot - 1)
  3219. end
  3220. turtle.placeDown()
  3221. if i < length then
  3222. if rowNumber % 2 == 0 then
  3223. turtle.back()
  3224. else
  3225. turtle.forward()
  3226. end
  3227. end
  3228. end
  3229. end
  3230.  
  3231. function layArea(length, width)
  3232. for i=1,width do
  3233. layRow(i,length)
  3234. if i < width then
  3235. nextRow()
  3236. end
  3237. end
  3238. end
  3239.  
  3240. turtle.select(conveyorSlot)
  3241. goToStartPoint()
  3242.  
  3243. layArea(4,10)
  3244. forward(4)
  3245. turtle.turnRight()
  3246. layArea(4,2)
  3247. turtle.turnRight()
  3248. back(4)
  3249. layArea(4,10)
  3250. forward(4)
  3251. turtle.turnRight()
  3252. layArea(4,2)
  3253.  
  3254. returnHome()
  3255. *** convey12x12-4
  3256.  
  3257. conveyorSlot = 16
  3258. elevation = 1
  3259.  
  3260. local function forward(nBlocks)
  3261. for i=1,nBlocks do
  3262. turtle.forward()
  3263. end
  3264. end
  3265.  
  3266. local function back(nBlocks)
  3267. for i=1,nBlocks do
  3268. turtle.back()
  3269. end
  3270. end
  3271.  
  3272. local function up(nBlocks)
  3273. for i=1,nBlocks do
  3274. turtle.up()
  3275. end
  3276. end
  3277.  
  3278. local function down(nBlocks)
  3279. for i=1,nBlocks do
  3280. turtle.down()
  3281. end
  3282. end
  3283.  
  3284. local function goToStartPoint()
  3285. up(2)
  3286. elevation = 2
  3287. turtle.turnRight()
  3288. forward(5)
  3289. turtle.turnLeft()
  3290. back(6)
  3291. end
  3292.  
  3293.  
  3294. local function returnHome()
  3295. forward(5)
  3296. turtle.turnRight()
  3297. forward(1)
  3298. down(elevation)
  3299. end
  3300.  
  3301. function nextRow()
  3302. turtle.turnLeft()
  3303. turtle.forward()
  3304. turtle.turnRight()
  3305. end
  3306.  
  3307. function layRow(rowNumber, length)
  3308. for i=1,length do
  3309. if turtle.getItemCount(conveyorSlot) < 1 then
  3310. conveyorSlot = conveyorSlot-1
  3311. if turtle.getItemCount(conveyorSlot) < 1 then
  3312. conveyorSlot = conveyorSlot-1
  3313. end
  3314. end
  3315. turtle.select(conveyorSlot)
  3316. turtle.placeDown()
  3317. if i < length then
  3318. if rowNumber % 2 == 0 then
  3319. turtle.back()
  3320. else
  3321. turtle.forward()
  3322. end
  3323. end
  3324. end
  3325. end
  3326.  
  3327. function layArea(length, width)
  3328. for i=1,width do
  3329. layRow(i,length)
  3330. if i < width then
  3331. nextRow()
  3332. end
  3333. end
  3334. end
  3335.  
  3336. turtle.select(conveyorSlot)
  3337. --goToStartPoint()
  3338. turtle.turnRight()
  3339. up(1)
  3340.  
  3341. layArea(5,12)
  3342. forward(5)
  3343. turtle.turnRight()
  3344. layArea(5,2)
  3345. turtle.turnRight()
  3346. back(5)
  3347. layArea(5,12)
  3348. forward(5)
  3349. turtle.turnRight()
  3350. layArea(5,2)
  3351.  
  3352. returnHome()
  3353. *** copyall
  3354. -- copyall: Version 0.1
  3355. -- Copys all files from source to destination
  3356. -- Written by HarvDad, March 2014
  3357.  
  3358. args = {...}
  3359. nArgs = #args
  3360.  
  3361. usage = "Usage: copyall <src directory><dst directory>"
  3362.  
  3363. if (nArgs == 0 or args[1]== "help") then
  3364. print("Copys all files from source to destination")
  3365. print(usage)
  3366. return
  3367. end
  3368.  
  3369. if nArgs ~= 2 then
  3370. print(usage)
  3371. return
  3372. end
  3373.  
  3374. src = args[1]
  3375. dst = args[2]
  3376.  
  3377. list = fs.list(src)
  3378.  
  3379. for i=1,#list do
  3380. if not fs.isDir(list[i]) then
  3381. filename = list[i]
  3382. -- print(filename)
  3383. firstchar = string.sub(filename, 1, 1)
  3384. -- print("firstchar = ", firstchar)
  3385. if firstchar ~= "." then
  3386. srcpath = src .. "/" .. filename
  3387. dstpath = dst .. "/" .. filename
  3388. print("Copying ", srcpath, " to ", dstpath)
  3389. if fs.exists(dstpath) then
  3390. fs.delete(dstpath)
  3391. end
  3392. fs.copy(srcpath, dstpath)
  3393. else
  3394. print("Ignoring: ", filename)
  3395. end
  3396. end
  3397. end
  3398. *** craft
  3399. -- craft: Craft the named item
  3400. -- Version 2.0
  3401.  
  3402. usage = "usage: craft <itemName>"
  3403.  
  3404. recipes = {
  3405. {"2x2", 1, 1, 0, 1, 1, 0, 0, 0, 0},
  3406. {"3x3", 1, 1, 1, 1, 1, 1, 1, 1, 1},
  3407. {"chest", 1, 1, 1, 1, 0, 1, 1, 1, 1},
  3408. {"furnace", 1, 1, 1, 1, 0, 1, 1, 1, 1},
  3409. {"stairs", 1, 0, 0, 1, 1, 0, 1, 1, 1},
  3410. {"slab", 1, 1, 1, 0, 0, 0, 0, 0, 0},
  3411. {"door", 1, 1, 0, 1, 1, 0, 1, 1, 0},
  3412. {"wall", 1, 1, 1, 1, 1, 1, 0, 0, 0},
  3413. {"fence", 1, 1, 1, 1, 1, 1, 0, 0, 0},
  3414. }
  3415.  
  3416. -- getIndex: Return the array index of the entry containing <name>
  3417.  
  3418. function printList()
  3419. for i=1,#recipes do
  3420. print(" ", recipes[i][1])
  3421. end
  3422. end
  3423.  
  3424. function getIndex(name)
  3425. rv = 0 -- return value
  3426. nItems = #recipes
  3427.  
  3428. for i= 1,nItems do
  3429. if name == recipes[i][1] then
  3430. rv = i
  3431. break
  3432. end
  3433. end
  3434.  
  3435. return(rv)
  3436. end
  3437.  
  3438. function requiredQty(recipe)
  3439. qty = 0
  3440.  
  3441. for i=2,10 do
  3442. if recipe[i] > 0 then
  3443. qty = qty + 1
  3444. end
  3445. end
  3446.  
  3447. return qty
  3448. end
  3449.  
  3450. function occupiedSlotCount()
  3451. count = 0
  3452. for i=1,16 do
  3453. if turtle.getItemCount(i) > 0 then
  3454. count = count + 1
  3455. end
  3456. end
  3457.  
  3458. return count
  3459. end
  3460.  
  3461. function highestMultipleOf(number, multiplier)
  3462. return number - (number % multiplier)
  3463. end
  3464.  
  3465. function forceGoodMultiple(recipe)
  3466. req = requiredQty(recipe)
  3467. maxSlotCount = 64
  3468. slotCount = 0
  3469. maxSlotMultiple = highestMultipleOf(maxSlotCount, req)
  3470. slotMultiple = 0
  3471.  
  3472. turtle.select(1)
  3473. turtle.dropUp() -- clear this slot for a fresh start
  3474.  
  3475. turtle.suckUp()
  3476. slotCount = turtle.getItemCount(1) -- see how much we got
  3477. if slotCount > 64 then
  3478. print("Holy crap! It gave us ", slotCount)
  3479. return
  3480. else
  3481. -- print("Actual items from chest: ", slotCount)
  3482. end
  3483.  
  3484. slotMultiple = highestMultipleOf(slotCount, req)
  3485. -- overage = maxSlotMultiple - slotMultiple
  3486. overage = slotCount % req
  3487. -- print("slotCount: ", slotCount, ", req: ", req, ", slotMultiple: ", slotMultiple)
  3488. -- print(" overage = ", overage)
  3489. if overage > 0 then
  3490. turtle.dropUp(overage)
  3491. count = turtle.getItemCount(1)
  3492. end
  3493. -- print("Forced count = ", slotCount)
  3494. return count
  3495. end
  3496.  
  3497. function getMaterial(recipe)
  3498. count = forceGoodMultiple(recipe)
  3499. -- print(" Slot now contains: ", count)
  3500. sleep(3)
  3501.  
  3502. return count
  3503. end
  3504.  
  3505. function loadTable(recipe, qty)
  3506. turtle.select(1)
  3507.  
  3508. if recipe[2] > 0 then turtle.transferTo(5, qty) end
  3509. if recipe[3] > 0 then turtle.transferTo(6, qty) end
  3510. if recipe[4] > 0 then turtle.transferTo(7, qty) end
  3511.  
  3512. if recipe[5] > 0 then turtle.transferTo(9, qty) end
  3513. if recipe[6] > 0 then turtle.transferTo(10, qty) end
  3514. if recipe[7] > 0 then turtle.transferTo(11, qty) end
  3515.  
  3516. if recipe[8] > 0 then turtle.transferTo(13, qty) end
  3517. if recipe[9] > 0 then turtle.transferTo(14, qty) end
  3518. if recipe[10] > 0 then turtle.transferTo(15, qty) end
  3519. end
  3520.  
  3521. function clearInventory()
  3522. for i=1,16 do
  3523. turtle.select(i)
  3524. turtle.dropUp()
  3525. end
  3526. turtle.select(1)
  3527. end
  3528.  
  3529. function craftRecipe(recipe)
  3530. req = requiredQty(recipe)
  3531. count = getMaterial(recipe)
  3532. occupiedSlots = occupiedSlotCount()
  3533. slotCount = turtle.getItemCount(1)
  3534.  
  3535. if occupiedSlots ~= req then
  3536. qty = slotCount / req
  3537. loadTable(recipe, qty)
  3538. slotCount = turtle.getItemCount(1)
  3539. if slotCount ~= 0 then
  3540. print("Wait. Slot 1 still has ", slotCount)
  3541. end
  3542. end
  3543.  
  3544. occupiedSlots = occupiedSlotCount()
  3545. -- print("occupied slots: ", occupiedSlots, ", req: ", req)
  3546. if occupiedSlotCount() == req then
  3547. turtle.select(16)
  3548. if not turtle.craft() then
  3549. print("Crafting failed. Wrong material?")
  3550. turtle.select(1)
  3551. return false
  3552. else
  3553. turtle.select(16)
  3554. turtle.drop()
  3555. turtle.select(1)
  3556. end
  3557. end
  3558.  
  3559. return true
  3560. end
  3561.  
  3562. -- Main program
  3563.  
  3564. args = {...}
  3565. nArgs = #args
  3566.  
  3567. if nArgs == 0 then
  3568. print(usage)
  3569. printList()
  3570. return
  3571. end
  3572.  
  3573. if nArgs ~= 1 then
  3574. print(usage)
  3575. return
  3576. end
  3577.  
  3578. itemName = args[1]
  3579. index = getIndex(itemName)
  3580. if index == 0 then
  3581. print("Can't find \"", itemName, "\"")
  3582. return
  3583. else
  3584. recipe = recipes[index]
  3585. req = requiredQty(recipe)
  3586. print("Crafting recipe: ", recipe[1])
  3587. print(req, " blocks material required for each.")
  3588. print("Run must be terminated manually.")
  3589. clearInventory()
  3590. turtle.select(1)
  3591. while true do
  3592. if not craftRecipe(recipe) then
  3593. break
  3594. end
  3595. sleep(0)
  3596. end
  3597. end
  3598.  
  3599.  
  3600.  
  3601. *** d
  3602. -- d
  3603. -- Moves the turtle the specified distance down
  3604. -- Written by HarvDad, March 2014
  3605.  
  3606. args = {...}
  3607. nArgs = #args
  3608.  
  3609. x = 0
  3610. y = 0
  3611. z = 0
  3612. face = 0
  3613. minimumFuel = 100
  3614. abort = false
  3615. local currentFuelLevel = turtle.getFuelLevel()
  3616. distance = 1;
  3617.  
  3618. if (nArgs == 1 and args[1]== "help") then
  3619. print("Moves the turtle the specified distance down")
  3620. print("Usage: f [distance]")
  3621. return
  3622. end
  3623.  
  3624. if nArgs == 1 then
  3625. distance = tonumber(args[1])
  3626. if distance == nil then
  3627. print(args[1], " is not a valid distance")
  3628. return
  3629. end
  3630. end
  3631.  
  3632. -- MAIN PROGRAM
  3633.  
  3634. turtle.select(1)
  3635.  
  3636. if currentFuelLevel ~= "unlimited" then
  3637. if currentFuelLevel < minimumFuel then
  3638. if not turtle.refuel() then
  3639. print("No fuel")
  3640. return
  3641. end
  3642. end
  3643. end
  3644.  
  3645. for i=1,distance do
  3646. turtle.down()
  3647. end
  3648. *** drainbox
  3649.  
  3650. torchSlot = 13
  3651.  
  3652. local function forward(nBlocks)
  3653. for i=1,nBlocks do
  3654. turtle.forward()
  3655. end
  3656. end
  3657.  
  3658. local function back(nBlocks)
  3659. for i=1,nBlocks do
  3660. turtle.back()
  3661. end
  3662. end
  3663.  
  3664. local function up(nBlocks)
  3665. for i=1,nBlocks do
  3666. turtle.up()
  3667. end
  3668. end
  3669.  
  3670. local function down(nBlocks)
  3671. for i=1,nBlocks do
  3672. turtle.down()
  3673. end
  3674. end
  3675.  
  3676. local function torchIt()
  3677. turtle.select(torchSlot)
  3678. up(1)
  3679.  
  3680. forward(3)
  3681. turtle.turnRight()
  3682. forward(3)
  3683. turtle.placeDown()
  3684.  
  3685. forward(5)
  3686. turtle.placeDown()
  3687.  
  3688. turtle.turnLeft()
  3689. forward(5)
  3690. turtle.placeDown()
  3691.  
  3692. turtle.turnLeft()
  3693. forward(5)
  3694. turtle.placeDown()
  3695.  
  3696. forward(3)
  3697. turtle.turnLeft()
  3698. forward(8)
  3699. turtle.turnLeft()
  3700. turtle.turnLeft()
  3701.  
  3702. down(1)
  3703. end
  3704.  
  3705. local function goToStartPoint()
  3706. turtle.turnLeft()
  3707. forward(4)
  3708. turtle.turnRight()
  3709. back(3)
  3710. end
  3711.  
  3712. local function returnHome()
  3713. forward(4)
  3714. turtle.turnRight()
  3715. forward(1)
  3716. down(elevation)
  3717. end
  3718.  
  3719.  
  3720. -- Quad Chute
  3721.  
  3722. turtle.turnLeft()
  3723. forward(2)
  3724. turtle.turnRight()
  3725. forward(2)
  3726. shell.run("quadchute up 2 false")
  3727.  
  3728. -- 12 x 12 Funnel Floor #1
  3729.  
  3730. goToStartPoint()
  3731. up(1)
  3732. shell.run("pattern funnel12")
  3733. torchIt()
  3734.  
  3735. -- First Floor walls
  3736.  
  3737. turtle.turnRight()
  3738. shell.run("walls3 12 12")
  3739.  
  3740. -- 12 x 12 Funnel Floor #2
  3741.  
  3742. up(3)
  3743. forward(1)
  3744. turtle.turnRight()
  3745. back(1)
  3746. shell.run("pattern funnel12")
  3747. torchIt()
  3748.  
  3749. -- Second Floor Walls
  3750.  
  3751. turtle.turnRight()
  3752. shell.run("walls3 12 12")
  3753.  
  3754. -- 12 x 12 Funnel Roof
  3755.  
  3756. up(3)
  3757. forward(1)
  3758. turtle.turnRight()
  3759. back(1)
  3760. shell.run("pattern funnel12")
  3761.  
  3762. -- Conveyor Belt Shingles On Roof
  3763. shell.run("convey12x12-4")
  3764.  
  3765. -- Return To Earth
  3766. turtle.turnRight()
  3767. forward(1)
  3768. down(255)
  3769.  
  3770. *** dump
  3771. -- dump
  3772. -- Dump turtle contents directly down
  3773. -- Written by HarvDad, April 2014
  3774.  
  3775. -- Rev 0.1
  3776.  
  3777. args = {...}
  3778. nArgs = #args
  3779.  
  3780. function dump()
  3781. for i=1,16 do
  3782. if (turtle.getItemCount(i) > 0) then
  3783. turtle.select(i)
  3784. turtle.dropDown()
  3785. end
  3786. end
  3787. end
  3788.  
  3789. -- MAIN PROGRAM
  3790.  
  3791. dump()
  3792.  
  3793. *** eatlava
  3794. -- eatlava
  3795. -- Refuels from lava directly below turtle
  3796. -- Must start with one lava bucket in slot 1
  3797. -- Turtle travels requested area refueling when lava is directly below, then returns
  3798. -- Written by HarvDad, March 2014
  3799.  
  3800. args = {...}
  3801. nArgs = #args
  3802.  
  3803. print("eatLava: Rev 2.1")
  3804. x = 0
  3805. y = 0
  3806. z = 0
  3807. face = 0
  3808. minimumFuel = 100
  3809. missionMessage = "Mission complete."
  3810. usage = "Usage: eatlava <length> <width>"
  3811. abort = false
  3812. local currentFuelLevel = turtle.getFuelLevel()
  3813.  
  3814. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  3815. print("Refuels from lava directly below turtle.")
  3816. print("First time: Must start with one lava bucket in slot 1")
  3817. print("Usage: eatLava <length> <width>")
  3818. return
  3819. end
  3820.  
  3821. if nArgs ~= 2 then
  3822. print("Usage: eatLava <distance>")
  3823. return
  3824. end
  3825.  
  3826. length = tonumber(args[1])
  3827. if length == nil then
  3828. print("\"", args[1], "\" is not a valid length")
  3829. return
  3830. end
  3831. if length < 1 then
  3832. print("length must be a positive number greater than zero")
  3833. return
  3834. end
  3835.  
  3836. width = tonumber(args[2])
  3837. if width == nil then
  3838. print("\"", args[1], "\" is not a valid width")
  3839. return
  3840. end
  3841. if width < 1 then
  3842. print("width must be a positive number greater than zero")
  3843. return
  3844. end
  3845.  
  3846. areaCovered = 0;
  3847.  
  3848. function eatLava()
  3849. turtle.select(1)
  3850. if turtle.placeDown() then
  3851. turtle.refuel()
  3852. end
  3853. end
  3854.  
  3855. function setFace(f)
  3856. if f == 0 then
  3857. if face == 0 then return end
  3858. if face == 1 then right() return end
  3859. if face == 2 then right() right() return end
  3860. if face == 3 then left() return end
  3861. end
  3862.  
  3863. if f == 1 then
  3864. if face == 0 then left() return end
  3865. if face == 1 then return end
  3866. if face == 2 then right() return end
  3867. if face == 3 then right() right() return end
  3868. end
  3869.  
  3870. if f == 2 then
  3871. if face == 0 then left() left() return end
  3872. if face == 1 then left() return end
  3873. if face == 2 then return end
  3874. if face == 3 then right() return end
  3875. end
  3876.  
  3877. if f == 3 then
  3878. if face == 0 then right() return end
  3879. if face == 1 then left() left() return end
  3880. if face == 2 then left() return end
  3881. if face == 3 then return end
  3882. end
  3883. end
  3884.  
  3885. function forward()
  3886. while turtle.detect() do -- This loop added in case of falling sand or whatever
  3887. turtle.dig()
  3888. end
  3889. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  3890. if turtle.forward() then
  3891. break
  3892. end
  3893. turtle.attack()
  3894. sleep(2)
  3895. end
  3896. areaCovered = areaCovered + 1
  3897.  
  3898. if face == 0 then z = z+1 return end
  3899. if face == 1 then x = x-1 return end
  3900. if face == 2 then z = z-1 return end
  3901. if face == 3 then x = x+1 return end
  3902. end
  3903.  
  3904. function left()
  3905. if face == 0 then face = 1 turtle.turnLeft() return end
  3906. if face == 1 then face = 2 turtle.turnLeft() return end
  3907. if face == 2 then face = 3 turtle.turnLeft() return end
  3908. if face == 3 then face = 0 turtle.turnLeft() return end
  3909. print("function left\(\): Bad face value: ", face)
  3910. end
  3911.  
  3912. function right()
  3913. if face == 0 then face = 3 turtle.turnRight() return end
  3914. if face == 1 then face = 0 turtle.turnRight() return end
  3915. if face == 2 then face = 1 turtle.turnRight() return end
  3916. if face == 3 then face = 2 turtle.turnRight() return end
  3917. print("function right\(\): Bad face value: ", face)
  3918. end
  3919.  
  3920. function home(targetY)
  3921. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  3922. if x < 0 then
  3923. setFace(3)
  3924. while x < 0 do
  3925. forward()
  3926. end
  3927. else
  3928. if x > 0 then
  3929. setFace(1)
  3930. while x > 0 do
  3931. forward()
  3932. end
  3933. end
  3934. end
  3935.  
  3936. if z < 0 then
  3937. setFace(0)
  3938. while z < 0 do
  3939. forward()
  3940. end
  3941. else
  3942. if z > 0 then
  3943. setFace(2)
  3944. while z > 0 do
  3945. forward()
  3946. end
  3947. end
  3948. end
  3949. setFace(0)
  3950. end
  3951.  
  3952.  
  3953. -- MAIN PROGRAM
  3954.  
  3955. turtle.select(1)
  3956.  
  3957. print("Current Fuel Level: ", currentFuelLevel)
  3958.  
  3959. if currentFuelLevel ~= "unlimited" then
  3960. if currentFuelLevel < minimumFuel then
  3961. if not turtle.refuel() then
  3962. print("No fuel")
  3963. return
  3964. end
  3965. end
  3966. end
  3967.  
  3968. nextTurn = "left"
  3969.  
  3970. forward()
  3971. targetArea = length * width
  3972. while areaCovered < targetArea do
  3973. if abort then
  3974. break
  3975. end
  3976. for w=1,width do
  3977. if abort then
  3978. break
  3979. end
  3980. for z=1,length do
  3981. if abort then
  3982. break
  3983. end
  3984. eatLava()
  3985. if z < length then
  3986. forward()
  3987. end
  3988. end
  3989. if nextTurn == "left" then
  3990. if areaCovered < targetArea then
  3991. left()
  3992. forward()
  3993. left()
  3994. nextTurn = "right"
  3995. end
  3996. else
  3997. if areaCovered < targetArea then
  3998. right()
  3999. forward()
  4000. right()
  4001. nextTurn = "left"
  4002. end
  4003. end
  4004. end
  4005. end
  4006.  
  4007. home()
  4008. print (missionMessage)
  4009. print ("Fuel level is now ", turtle.getFuelLevel())
  4010. *** f
  4011. -- f
  4012. -- Moves the turtle the specified distance forward
  4013. -- Written by HarvDad, March 2014
  4014.  
  4015. args = {...}
  4016. nArgs = #args
  4017.  
  4018. x = 0
  4019. y = 0
  4020. z = 0
  4021. face = 0
  4022. minimumFuel = 100
  4023. abort = false
  4024. local currentFuelLevel = turtle.getFuelLevel()
  4025. distance = 1;
  4026.  
  4027. if (nArgs == 1 and args[1]== "help") then
  4028. print("Moves the turtle the specified distance forward")
  4029. print("Usage: f [distance]")
  4030. return
  4031. end
  4032.  
  4033. if nArgs == 1 then
  4034. distance = tonumber(args[1])
  4035. if distance == nil then
  4036. print(args[1], " is not a valid distance")
  4037. return
  4038. end
  4039. end
  4040.  
  4041. -- MAIN PROGRAM
  4042.  
  4043. turtle.select(1)
  4044.  
  4045. if currentFuelLevel ~= "unlimited" then
  4046. if currentFuelLevel < minimumFuel then
  4047. if not turtle.refuel() then
  4048. print("No fuel")
  4049. return
  4050. end
  4051. end
  4052. end
  4053.  
  4054. for i=1,distance do
  4055. turtle.forward()
  4056. end
  4057. *** fabdrain
  4058.  
  4059.  
  4060. print("fabdrain: Rev 1.0")
  4061.  
  4062. beltSlot = 1
  4063. currentSlot = beltSlot
  4064. goForward = 0
  4065. goBackward = 1
  4066. direction = goForward
  4067. holeWidth = 3
  4068.  
  4069. -- The following 'face' directions are relative to the starting position of the turtle in this program
  4070. north = 0
  4071. west = 1
  4072. south = 2
  4073. east = 3
  4074.  
  4075. x = 0
  4076. y = 0
  4077. z = 0
  4078.  
  4079. currentFace = north
  4080.  
  4081. function setFace(f)
  4082. if f == 0 then
  4083. if face == 0 then return end
  4084. if face == 1 then right() return end
  4085. if face == 2 then right() right() return end
  4086. if face == 3 then left() return end
  4087. end
  4088.  
  4089. if f == 1 then
  4090. if face == 0 then left() return end
  4091. if face == 1 then return end
  4092. if face == 2 then right() return end
  4093. if face == 3 then right() right() return end
  4094. end
  4095.  
  4096. if f == 2 then
  4097. if face == 0 then left() left() return end
  4098. if face == 1 then left() return end
  4099. if face == 2 then return end
  4100. if face == 3 then right() return end
  4101. end
  4102.  
  4103. if f == 3 then
  4104. if face == 0 then right() return end
  4105. if face == 1 then left() left() return end
  4106. if face == 2 then left() return end
  4107. if face == 3 then return end
  4108. end
  4109. end
  4110.  
  4111. function left()
  4112. if face == 0 then face = 1 turtle.turnLeft() return end
  4113. if face == 1 then face = 2 turtle.turnLeft() return end
  4114. if face == 2 then face = 3 turtle.turnLeft() return end
  4115. if face == 3 then face = 0 turtle.turnLeft() return end
  4116. print("function left\(\): Bad face value: ", face)
  4117. end
  4118.  
  4119. function right()
  4120. if face == 0 then face = 3 turtle.turnRight() return end
  4121. if face == 1 then face = 0 turtle.turnRight() return end
  4122. if face == 2 then face = 1 turtle.turnRight() return end
  4123. if face == 3 then face = 2 turtle.turnRight() return end
  4124. print("function right\(\): Bad face value: ", face)
  4125. end
  4126.  
  4127. function aboutFace()
  4128. if face == north then setFace(south) return end
  4129. if face == south then setFace(north) return end
  4130. if face == east then setFace(west) return end
  4131. if face == west then setFace(east) return end
  4132. end
  4133.  
  4134. function reverseDirection()
  4135. if direction == goForward then
  4136. direction = goBackward
  4137. else
  4138. direction = goForward
  4139. end
  4140. end
  4141.  
  4142. function moveForward(nBlocks)
  4143. for i = 1, nBlocks do
  4144. turtle.forward()
  4145. if face == north then
  4146. z = z + 1
  4147. elseif face == south then
  4148. z = z - 1
  4149. elseif face == east then
  4150. x = x + 1
  4151. elseif face == west then
  4152. x = x - 1
  4153. end
  4154. end
  4155.  
  4156. end
  4157.  
  4158. function moveBackward(nBlocks)
  4159. for i = 1, nBlocks do
  4160. turtle.back()
  4161. if face == north then
  4162. z = z - 1
  4163. elseif face == south then
  4164. z = z + 1
  4165. elseif face == east then
  4166. x = x - 1
  4167. elseif face == west then
  4168. x = x + 1
  4169. end
  4170. end
  4171. end
  4172.  
  4173. function home()
  4174. end
  4175.  
  4176. function xzHome()
  4177. local X = gX
  4178. local Z = gZ
  4179.  
  4180. if x ~= X then
  4181. if x < X then
  4182. setFace(east)
  4183. while x < X do
  4184. turtle.forward()
  4185. x = x + 1
  4186. end
  4187. else
  4188. setFace(west)
  4189. while x > X do
  4190. turtle.forward()
  4191. x = x - 1
  4192. end
  4193. end
  4194. end
  4195.  
  4196. if z ~= Z then
  4197. if z < Z then
  4198. setFace(north)
  4199. while z < Z do
  4200. turtle.forward()
  4201. z = z + 1
  4202. end
  4203. else
  4204. setFace(south)
  4205. while z > Z do
  4206. turtle.forward()
  4207. z = z - 1
  4208. end
  4209. end
  4210. end
  4211. end
  4212.  
  4213. function layBeltRow(direction, length)
  4214. for j=1,5 do
  4215. if turtle.getItemCount(currentSlot) < 1 then
  4216. currentSlot = currentSlot + 1
  4217. if turtle.getItemCount(currentSlot) < 1 then
  4218. abort("No more belts in inventory.")
  4219. end
  4220. turtle.select(currentSlot)
  4221. end
  4222. turtle.placeDown()
  4223. if j < 5 then
  4224. if direction == goForward then
  4225. moveForward(1)
  4226. else
  4227. moveBackward(1)
  4228. end
  4229. end
  4230. end
  4231. end
  4232.  
  4233. rowHeading = west
  4234.  
  4235. function goToNextRow()
  4236. currentFace = face
  4237. if face == north or face == south then
  4238. setFace(rowHeading)
  4239. moveForward(1)
  4240. setFace(currentFace)
  4241. else
  4242. setFace(rowHeading)
  4243. moveForward(1)
  4244. setFace(currentFace)
  4245. end
  4246. end
  4247.  
  4248. function layBeltSection(length, width)
  4249. moveBackward(length - 1)
  4250. for i = 1,width do
  4251. direction = goForward
  4252. layBeltRow(direction, length)
  4253. moveForward(holeWidth+1)
  4254. aboutFace()
  4255. direction = goBackward
  4256. layBeltRow(direction, length)
  4257. goToNextRow()
  4258. end
  4259.  
  4260. setFace(east)
  4261. rowHeading = south
  4262. direction = goBackwards
  4263. segLength = length + 3 + length
  4264. for i = 1, segLength do
  4265. layBeltRow(direction, length)
  4266. if i < segLength then
  4267. goToNextRow()
  4268. reverseDirection()
  4269. end
  4270. end
  4271.  
  4272. setFace(east)
  4273. moveForward(length + holeWidth)
  4274. aboutFace()
  4275.  
  4276. rowHeading = north
  4277. direction = goBackwards
  4278. for i = 1, segLength do
  4279. layBeltRow(direction, length)
  4280. if i < segLength then
  4281. goToNextRow()
  4282. reverseDirection()
  4283. end
  4284. end
  4285. end
  4286.  
  4287. function abort(message)
  4288. print(message)
  4289. error()
  4290. end
  4291.  
  4292. -- Main Program
  4293.  
  4294. turtle.up()
  4295. y = y + 1
  4296.  
  4297. turtle.select(1)
  4298. layBeltSection(5, holeWidth)
  4299.  
  4300. xzHome()
  4301. yHome()
  4302. setFace(north)
  4303. *** floor
  4304. -- floor
  4305. -- Lays down a floor with whatever material is provided
  4306. -- Turtle returns to its starting point when mission is completed or fuel runs low
  4307. -- Written by HarvDad, March 2014
  4308.  
  4309. args = {...}
  4310. nArgs = #args
  4311.  
  4312. version = "floor: Rev 2.0"
  4313. mission = "Lay down a floor with the supplied material"
  4314. instructions = "Place stack(s) of material starting in first slot."
  4315.  
  4316. usage = "floor <length> <width> [level]"
  4317.  
  4318. x = 0
  4319. y = 0
  4320. z = 0
  4321. face = 0
  4322. minimumFuel = 100
  4323. missionMessage = "Mission complete."
  4324. abort = false
  4325. startLevel = 0
  4326. local currentFuelLevel = turtle.getFuelLevel()
  4327.  
  4328. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  4329. print(version)
  4330. print(mission)
  4331. print(instructions)
  4332. print(usage)
  4333. return
  4334. end
  4335.  
  4336. if nArgs < 2 or nArgs > 3 then
  4337. print(usage)
  4338. return
  4339. end
  4340.  
  4341. length = tonumber(args[1])
  4342. if length == nil then
  4343. print("\"", args[1], "\" is not a valid length")
  4344. return
  4345. end
  4346. if length < 1 then
  4347. print("length must be a positive number greater than zero")
  4348. end
  4349.  
  4350. width = tonumber(args[2])
  4351. if width == nil then
  4352. print("\"", args[2], "\" is not a valid width")
  4353. return
  4354. end
  4355. if width < 1 then
  4356. print("width must be a positive number greater than zero")
  4357. end
  4358.  
  4359. if nArgs == 3 then
  4360. startLevel = tonumber(args[3])
  4361. if startLevel == nil then
  4362. print("\"", args[3], "\" is not a valid start level")
  4363. return
  4364. end
  4365. end
  4366.  
  4367. targetArea = length * width
  4368. areaCovered = 1
  4369. currentSlot = 2
  4370. materialSlot = 1
  4371. maxSlot = 16
  4372.  
  4373. nextTurn = "left"
  4374.  
  4375. local clock = os.clock
  4376. function sleep(n) -- seconds
  4377. local t0 = clock()
  4378. while clock() - t0 <= n do end
  4379. end
  4380.  
  4381. function left()
  4382. if face == 0 then face = 1 turtle.turnLeft() return end
  4383. if face == 1 then face = 2 turtle.turnLeft() return end
  4384. if face == 2 then face = 3 turtle.turnLeft() return end
  4385. if face == 3 then face = 0 turtle.turnLeft() return end
  4386. print("function left\(\): Bad face value: ", face)
  4387. end
  4388.  
  4389. function right()
  4390. if face == 0 then face = 3 turtle.turnRight() return end
  4391. if face == 1 then face = 0 turtle.turnRight() return end
  4392. if face == 2 then face = 1 turtle.turnRight() return end
  4393. if face == 3 then face = 2 turtle.turnRight() return end
  4394. print("function right\(\): Bad face value: ", face)
  4395. end
  4396.  
  4397. function up()
  4398. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  4399. turtle.digUp()
  4400. end
  4401. turtle.up()
  4402. y = y+1
  4403. end
  4404.  
  4405. function rise(nBlocks)
  4406. local i
  4407. for i=1,nBlocks do
  4408. up()
  4409. end
  4410. end
  4411.  
  4412. function down()
  4413. if turtle.detectDown() then
  4414. turtle.digDown()
  4415. end
  4416. turtle.down()
  4417. y = y-1
  4418. end
  4419.  
  4420. function turn()
  4421. if nextTurn == "left" then
  4422. left()
  4423. else
  4424. right()
  4425. end
  4426. chomp()
  4427. forward()
  4428. if nextTurn == "left" then
  4429. left()
  4430. nextTurn = "right"
  4431. else
  4432. right()
  4433. nextTurn = "left"
  4434. end
  4435. areaCovered = areaCovered + 1
  4436. end
  4437.  
  4438. function forward()
  4439. while turtle.detect() do -- This loop added in case of falling sand or whatever
  4440. turtle.dig()
  4441. end
  4442. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  4443. if turtle.forward() then
  4444. break
  4445. end
  4446. turtle.attack()
  4447. sleep(2)
  4448. end
  4449. areaCovered = areaCovered + 1
  4450.  
  4451. if face == 0 then z = z+1 return end
  4452. if face == 1 then x = x-1 return end
  4453. if face == 2 then z = z-1 return end
  4454. if face == 3 then x = x+1 return end
  4455. end
  4456.  
  4457. function setFace(f)
  4458. if f == 0 then
  4459. if face == 0 then return end
  4460. if face == 1 then right() return end
  4461. if face == 2 then right() right() return end
  4462. if face == 3 then left() return end
  4463. end
  4464.  
  4465. if f == 1 then
  4466. if face == 0 then left() return end
  4467. if face == 1 then return end
  4468. if face == 2 then right() return end
  4469. if face == 3 then right() right() return end
  4470. end
  4471.  
  4472. if f == 2 then
  4473. if face == 0 then left() left() return end
  4474. if face == 1 then left() return end
  4475. if face == 2 then return end
  4476. if face == 3 then right() return end
  4477. end
  4478.  
  4479. if f == 3 then
  4480. if face == 0 then right() return end
  4481. if face == 1 then left() left() return end
  4482. if face == 2 then left() return end
  4483. if face == 3 then return end
  4484. end
  4485. end
  4486.  
  4487. function home(targetY)
  4488. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  4489. if x < 0 then
  4490. setFace(3)
  4491. while x < 0 do
  4492. forward()
  4493. end
  4494. else
  4495. if x > 0 then
  4496. setFace(1)
  4497. while x > 0 do
  4498. forward()
  4499. end
  4500. end
  4501. end
  4502.  
  4503. if z < 0 then
  4504. setFace(0)
  4505. while z < 0 do
  4506. forward()
  4507. end
  4508. else
  4509. if z > 0 then
  4510. setFace(2)
  4511. while z > 0 do
  4512. forward()
  4513. end
  4514. end
  4515. end
  4516.  
  4517. if y > 0 then
  4518. while y > 0 do
  4519. down()
  4520. end
  4521. end
  4522.  
  4523. setFace(0)
  4524. end
  4525.  
  4526. function strip(nBlocks)
  4527. local i
  4528. -- print("strip ", nBlocks)
  4529. for i=1,nBlocks do
  4530. chomp()
  4531. checkFuel()
  4532. if abort then
  4533. areaCovered = targetArea
  4534. end
  4535.  
  4536. if areaCovered < targetArea then
  4537. forward()
  4538. end
  4539. end
  4540. end
  4541.  
  4542. function ensureMaterial()
  4543. if turtle.getItemCount(materialSlot) < 3 then
  4544. organizeMaterial()
  4545. end
  4546. if turtle.getItemCount(materialSlot) < 3 then
  4547. print("No more material")
  4548. return false
  4549. end
  4550. return true
  4551. end
  4552.  
  4553. function organizeMaterial()
  4554. local i
  4555. materialCount = turtle.getItemCount(materialSlot)
  4556.  
  4557. if materialCount < 3 then
  4558. -- print("Attempting to refill slot ", materialSlot)
  4559. for i=2,16 do
  4560. turtle.select(i)
  4561. if turtle.compareTo(materialSlot) then
  4562. turtle.transferTo(materialSlot)
  4563. end
  4564. end
  4565. end
  4566. turtle.select(materialSlot)
  4567. end
  4568.  
  4569. function layBlock()
  4570. turtle.select(materialSlot)
  4571.  
  4572. if startLevel > 2 then
  4573. if turtle.detectUp() then
  4574. if turtle.compareUp() then
  4575. return
  4576. else
  4577. turtle.digUp()
  4578. end
  4579. end
  4580. if ensureMaterial() then
  4581. turtle.placeUp()
  4582. end
  4583. else
  4584. if turtle.detectDown() then
  4585. if turtle.compareDown() then
  4586. return
  4587. else
  4588. turtle.digDown()
  4589. end
  4590. end
  4591. if ensureMaterial() then
  4592. turtle.placeDown()
  4593. end
  4594. end
  4595. end
  4596.  
  4597. function checkFuel()
  4598. if currentFuelLevel == "unlimited" then
  4599. return true
  4600. end
  4601.  
  4602. if currentFuelLevel < minimumFuel then
  4603. if not turtle.refuel() then
  4604. areaCovered = targetArea
  4605. missionMessage = "Mission aborted due to low fuel."
  4606. abort = true
  4607. return false
  4608. end
  4609. end
  4610. return true
  4611. end
  4612.  
  4613. -- MAIN PROGRAM
  4614.  
  4615. turtle.select(1)
  4616.  
  4617. print("fuelLevel = ", currentFuelLevel)
  4618. print("l: ", length, ", w: ", width, ", f: ", face)
  4619.  
  4620. print("Current Fuel Level: ", currentFuelLevel)
  4621.  
  4622. if currentFuelLevel ~= "unlimited" then
  4623. if currentFuelLevel < minimumFuel then
  4624. if not turtle.refuel() then
  4625. print("No fuel")
  4626. return
  4627. end
  4628. end
  4629. end
  4630.  
  4631.  
  4632. if startLevel < 2 then
  4633. rise(startLevel)
  4634. else
  4635. rise(startLevel-2)
  4636. end
  4637.  
  4638. while areaCovered < targetArea do
  4639. if abort then
  4640. break
  4641. end
  4642. for w=1,width do
  4643. if abort then
  4644. break
  4645. end
  4646. for z=1,length do
  4647. if abort then
  4648. break
  4649. end
  4650. layBlock()
  4651. if z < length then
  4652. forward()
  4653. end
  4654. end
  4655. if nextTurn == "left" then
  4656. if areaCovered < targetArea then
  4657. left()
  4658. forward()
  4659. left()
  4660. nextTurn = "right"
  4661. end
  4662. else
  4663. if areaCovered < targetArea then
  4664. right()
  4665. forward()
  4666. right()
  4667. nextTurn = "left"
  4668. end
  4669. end
  4670. end
  4671. end
  4672. --print("Finish the main loop.")
  4673.  
  4674. --print(missionMessage)
  4675. --print(" Current fuel level is ", turtle.getFuelLevel())
  4676. home(0)
  4677. *** funneltrap
  4678.  
  4679. local function rise(nBlocks)
  4680. for i=1,nBlocks do
  4681. turtle.up()
  4682. end
  4683. end
  4684.  
  4685. local function back(nBlocks)
  4686. for i=1,nBlocks do
  4687. turtle.back()
  4688. end
  4689. end
  4690.  
  4691. local function left(nBlocks)
  4692. turtle.turnLeft()
  4693. if nBlocks == nil or nBlocks == 0 then
  4694. return
  4695. end
  4696. for i=1,nBlocks do
  4697. turtle.forward()
  4698. end
  4699. end
  4700.  
  4701. local function right(nBlocks)
  4702. turtle.turnRight()
  4703. if nBlocks == nil or nBlocks == 0 then
  4704. return
  4705. end
  4706. for i=1,nBlocks do
  4707. turtle.forward()
  4708. end
  4709. end
  4710.  
  4711. height = 42
  4712.  
  4713. shell.run("quadchute up ", height/3)
  4714. rise(height)
  4715. back(3)
  4716. left(4)
  4717. right(0)
  4718. shell.run("pattern funnel12")
  4719. right(0)
  4720. shell.run("walls 12 12 4")
  4721. *** l
  4722. -- l
  4723. -- Turns and/or move the turtle to the left
  4724. -- Written by HarvDad, March 2014
  4725.  
  4726. args = {...}
  4727. nArgs = #args
  4728.  
  4729. x = 0
  4730. y = 0
  4731. z = 0
  4732. face = 0
  4733. minimumFuel = 100
  4734. abort = false
  4735. local currentFuelLevel = turtle.getFuelLevel()
  4736. distance = nil;
  4737.  
  4738. if (nArgs == 1 and args[1]== "help") then
  4739. print("Turns and/or moves the turtle to the left")
  4740. print("Usage: l [distance]")
  4741. return
  4742. end
  4743.  
  4744. if nArgs == 1 then
  4745. distance = tonumber(args[1])
  4746. if distance == nil then
  4747. print(args[1], " is not a valid distance")
  4748. return
  4749. end
  4750. end
  4751.  
  4752. -- MAIN PROGRAM
  4753.  
  4754. turtle.turnLeft()
  4755.  
  4756. if distance ~= nil then
  4757. turtle.select(1)
  4758.  
  4759. if currentFuelLevel ~= "unlimited" then
  4760. if currentFuelLevel < minimumFuel then
  4761. if not turtle.refuel() then
  4762. print("No fuel")
  4763. return
  4764. end
  4765. end
  4766. end
  4767.  
  4768. for i=1,distance do
  4769. turtle.forward()
  4770. end
  4771. end
  4772. *** logger
  4773. -- logger
  4774. -- Grows a tree, cuts it down.
  4775. -- Stores the logs in a chest
  4776. -- Written by HarvDad, March 2014
  4777.  
  4778. args = {...}
  4779. nArgs = #args
  4780. version = "logger: Rev 2.1"
  4781.  
  4782. saplingsSlot = 1
  4783. sampleSlot = 16 -- This slot must have at least 1 sample of the correct log type
  4784. bonemealSlot = 2
  4785. y = 0
  4786.  
  4787. if nArgs == 1 and args[1] == "help" then
  4788. print(version)
  4789. print("No arguments required")
  4790. print("Place sapling supply in slot ", saplingsSlot)
  4791. print("Place log sample in slot ", sampleSlot)
  4792. print("Needs to be part of special tree farm")
  4793. end
  4794.  
  4795. function whackLeaves()
  4796. turtle.dig()
  4797. turtle.turnRight()
  4798. turtle.dig()
  4799. turtle.turnRight()
  4800. turtle.dig()
  4801. turtle.turnRight()
  4802. turtle.dig()
  4803. turtle.turnRight()
  4804. end
  4805.  
  4806. function focusSaplings()
  4807. local i
  4808. saplingCount = turtle.getItemCount(saplingsSlot)
  4809.  
  4810. if saplingCount < 64 then
  4811. -- print("Organizing saplings into slot ", saplingsSlot)
  4812. for i=2,15 do
  4813. turtle.select(i)
  4814. if turtle.compareTo(saplingsSlot) then
  4815. turtle.transferTo(saplingsSlot, 64-saplingCount)
  4816. print("Transferred ", 64 - saplingCount, " saplings to slot ", saplingsSlot)
  4817. saplingCount = turtle.getItemCount(saplingsSlot)
  4818. if saplingCount >= 64 then
  4819. turtle.select(saplingsSlot)
  4820. break
  4821. end
  4822. end
  4823. end
  4824. end
  4825.  
  4826. sampleCount = turtle.getItemCount(sampleSlot)
  4827. if sampleCount > 1 then
  4828. turtle.select(sampleSlot)
  4829. turtle.dropDown(sampleCount - 1)
  4830. end
  4831. turtle.select(saplingsSlot)
  4832. end
  4833.  
  4834. function setFace(f)
  4835. if f == 0 then
  4836. if face == 0 then return end
  4837. if face == 1 then right() return end
  4838. if face == 2 then right() right() return end
  4839. if face == 3 then left() return end
  4840. end
  4841.  
  4842. if f == 1 then
  4843. if face == 0 then left() return end
  4844. if face == 1 then return end
  4845. if face == 2 then right() return end
  4846. if face == 3 then right() right() return end
  4847. end
  4848.  
  4849. if f == 2 then
  4850. if face == 0 then left() left() return end
  4851. if face == 1 then left() return end
  4852. if face == 2 then return end
  4853. if face == 3 then right() return end
  4854. end
  4855.  
  4856. if f == 3 then
  4857. if face == 0 then right() return end
  4858. if face == 1 then left() left() return end
  4859. if face == 2 then left() return end
  4860. if face == 3 then return end
  4861. end
  4862. end
  4863.  
  4864. function suckSaplings()
  4865. for i=1,4 do
  4866. turtle.suck()
  4867. turtle.suckUp()
  4868. turtle.turnRight()
  4869. end
  4870. setFace(0)
  4871. end
  4872.  
  4873. function dump()
  4874. for i=3,15 do
  4875. if turtle.getItemCount(i) > 0 then
  4876. turtle.select(i)
  4877. turtle.dropDown()
  4878. end
  4879. end
  4880. sampleCount = turtle.getItemCount(sampleSlot)
  4881. if sampleCount > 1 then
  4882. turtle.select(sampleSlot)
  4883. turtle.dropDown(sampleCount - 1)
  4884. end
  4885. turtle.select(saplingsSlot)
  4886. end
  4887.  
  4888. function tryBonemeal()
  4889. if turtle.getItemCount(bonemealSlot) > 1 then
  4890. turtle.select(bonemealSlot)
  4891. turtle.place()
  4892. end
  4893. end
  4894.  
  4895. intervalLength = 30
  4896. interval = 0
  4897. print("Logging is enabled")
  4898.  
  4899. while true do
  4900. turtle.select(saplingsSlot)
  4901. turtle.place()
  4902. tryBonemeal()
  4903.  
  4904. turtle.select(sampleSlot)
  4905. repeat
  4906. sleep(2)
  4907. if interval > intervalLength then
  4908. focusSaplings()
  4909. interval = 0
  4910. else
  4911. interval = interval + 1
  4912. end
  4913. tryBonemeal()
  4914. turtle.select(sampleSlot)
  4915. until turtle.compare()
  4916.  
  4917. turtle.dig()
  4918. turtle.forward()
  4919.  
  4920. turtle.select(2)
  4921. while turtle.detectUp() do
  4922. turtle.digUp()
  4923. turtle.up()
  4924. end
  4925.  
  4926. while not turtle.detectDown() do
  4927. turtle.suckDown()
  4928. turtle.down()
  4929. end
  4930.  
  4931. suckSaplings()
  4932. turtle.back()
  4933. suckSaplings()
  4934. dump()
  4935. end
  4936. *** obsidian
  4937. -- obsidian
  4938. -- Generate obsidian blocks from redstone dust
  4939. -- Version: Rev 0.1
  4940.  
  4941. message1 = "Place redstone dust in slot 1"
  4942. message2 = "Place bucket of lava in slot 6"
  4943. usage = "obsidian (No arguments)"
  4944.  
  4945. args = {...}
  4946. nArgs = #args
  4947.  
  4948. function forward(nBlocks)
  4949. for i=1,nBlocks do
  4950. turtle.forward()
  4951. end
  4952. end
  4953.  
  4954. function back(nBlocks)
  4955. for i=1,nBlocks do
  4956. turtle.back()
  4957. end
  4958. end
  4959.  
  4960. function placeRedstone()
  4961. back(3)
  4962. turtle.select(1)
  4963. for i=1,7 do
  4964. turtle.placeDown()
  4965. forward(1)
  4966. end
  4967. back(3)
  4968. end
  4969.  
  4970. function mineObsidian()
  4971. back(3)
  4972. turtle.select(5)
  4973. for i=1,3 do
  4974. turtle.digDown()
  4975. forward(1)
  4976. end
  4977. forward(1)
  4978. for i=1,3 do
  4979. turtle.digDown()
  4980. forward(1)
  4981. end
  4982. back(3)
  4983. end
  4984.  
  4985. function employLava()
  4986. turtle.up()
  4987. turtle.select(16)
  4988. turtle.placeDown()
  4989. sleep(8)
  4990. turtle.placeDown()
  4991. sleep(3)
  4992. turtle.down()
  4993. end
  4994.  
  4995. function offloadObsidian()
  4996. turtle.up()
  4997. turtle.turnLeft()
  4998. if turtle.detect() then
  4999. turtle.select(5)
  5000. turtle.drop()
  5001. end
  5002. turtle.down()
  5003. turtle.turnRight()
  5004. end
  5005.  
  5006. if nArgs > 0 then
  5007. print(message1)
  5008. print(message2)
  5009. print(usage)
  5010. end
  5011.  
  5012. while true do
  5013. if turtle.getItemCount(1) < 6 then
  5014. break
  5015. end
  5016. placeRedstone()
  5017. employLava()
  5018. mineObsidian()
  5019. offloadObsidian()
  5020. end
  5021.  
  5022. print("Redstone count is below 6.")
  5023. *** ores
  5024. -- ores
  5025. -- Mines specifically for ores, every third level within specified range
  5026. -- Turtle returns to its starting point when mission is completed or fuel runs low
  5027. -- Written by HarvDad, March 2014
  5028.  
  5029. args = {...}
  5030. nArgs = #args
  5031.  
  5032. version = "ores: Rev 2.1"
  5033. mission = "Mine specifically for ores, every third level"
  5034. instructions = "The first 3 slots must contain blocks to be ignored.."
  5035.  
  5036. usage = "ores <length> <width> [level]"
  5037.  
  5038. x = 0
  5039. y = 0
  5040. z = 0
  5041. face = 0
  5042. minimumFuel = 100
  5043. missionMessage = "Mission complete."
  5044. abort = false
  5045. maxLevel = 0
  5046. local currentFuelLevel = turtle.getFuelLevel()
  5047.  
  5048. -- The following 'face' directions are relative to the starting position of the turtle in this program
  5049. north = 0
  5050. west = 1
  5051. south = 2
  5052. east = 3
  5053.  
  5054. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  5055. print(version)
  5056. print(mission)
  5057. print(instructions)
  5058. print(usage)
  5059. return
  5060. end
  5061.  
  5062. if nArgs < 2 or nArgs > 3 then
  5063. print(usage)
  5064. return
  5065. end
  5066.  
  5067. length = tonumber(args[1])
  5068. if length == nil then
  5069. print("\"", args[1], "\" is not a valid length")
  5070. return
  5071. end
  5072. if length < 1 then
  5073. print("length must be a positive number greater than zero")
  5074. end
  5075.  
  5076. width = tonumber(args[2])
  5077. if width == nil then
  5078. print("\"", args[2], "\" is not a valid width")
  5079. return
  5080. end
  5081. if width < 1 then
  5082. print("width must be a positive number greater than zero")
  5083. end
  5084.  
  5085. if nArgs == 3 then
  5086. maxLevel = ((math.floor(tonumber(args[3]) / 3)) * 3) + 1
  5087. if maxLevel == nil then
  5088. print("\"", args[3], "\" is not a valid start level")
  5089. return
  5090. end
  5091. end
  5092.  
  5093. targetArea = length * width
  5094. areaCovered = 1
  5095. currentSlot = 2
  5096. chestSlot = 16
  5097. garbageSlot = 3
  5098. maxSlot = 16
  5099.  
  5100. nextTurn = "left"
  5101.  
  5102. local clock = os.clock
  5103. function sleep(n) -- seconds
  5104. local t0 = clock()
  5105. while clock() - t0 <= n do end
  5106. end
  5107.  
  5108. function left()
  5109. if face == 0 then face = 1 turtle.turnLeft() return end
  5110. if face == 1 then face = 2 turtle.turnLeft() return end
  5111. if face == 2 then face = 3 turtle.turnLeft() return end
  5112. if face == 3 then face = 0 turtle.turnLeft() return end
  5113. print("function left\(\): Bad face value: ", face)
  5114. end
  5115.  
  5116. function right()
  5117. if face == 0 then face = 3 turtle.turnRight() return end
  5118. if face == 1 then face = 0 turtle.turnRight() return end
  5119. if face == 2 then face = 1 turtle.turnRight() return end
  5120. if face == 3 then face = 2 turtle.turnRight() return end
  5121. print("function right\(\): Bad face value: ", face)
  5122. end
  5123.  
  5124. function up()
  5125. for i=1,10 do
  5126. if not turtle.up() then
  5127. if turtle.detectUp() then
  5128. digUp()
  5129. else
  5130. turtle.attackUp()
  5131. sleep(2)
  5132. end
  5133. else
  5134. break
  5135. end
  5136. end
  5137. y = y+1
  5138. end
  5139.  
  5140. function rise(nBlocks)
  5141. local i
  5142. for i=1,nBlocks do
  5143. up()
  5144. end
  5145. end
  5146.  
  5147. function down()
  5148. for i=1,10 do
  5149. if not turtle.down() then
  5150. if turtle.detectDown() then
  5151. digDown()
  5152. else
  5153. turtle.attackDown()
  5154. sleep(2)
  5155. end
  5156. else
  5157. break
  5158. end
  5159. end
  5160. y = y-1
  5161. end
  5162.  
  5163. function turn()
  5164. if nextTurn == "left" then
  5165. left()
  5166. else
  5167. right()
  5168. end
  5169. chomp()
  5170. forward()
  5171. if nextTurn == "left" then
  5172. left()
  5173. nextTurn = "right"
  5174. else
  5175. right()
  5176. nextTurn = "left"
  5177. end
  5178. areaCovered = areaCovered + 1
  5179. end
  5180.  
  5181. function forward(keepTrackOfArea)
  5182. if keepTrackOfArea == nil then
  5183. keepTrackOfArea = true
  5184. end
  5185. while turtle.detect() do -- This loop added in case of falling sand or whatever
  5186. dig()
  5187. end
  5188. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  5189. if not turtle.forward() then
  5190. if turtle.detect() then
  5191. dig()
  5192. else
  5193. turtle.attack()
  5194. sleep(2)
  5195. end
  5196. else
  5197. break
  5198. end
  5199. end
  5200. if keepTrackOfArea then
  5201. areaCovered = areaCovered + 1
  5202. end
  5203.  
  5204. if face == 0 then z = z+1 return end
  5205. if face == 1 then x = x-1 return end
  5206. if face == 2 then z = z-1 return end
  5207. if face == 3 then x = x+1 return end
  5208. end
  5209.  
  5210. function dig()
  5211. if noMoreEmptySlots() then
  5212. jettisonGarbage()
  5213. goEmptyInventoryToChestAndReturn()
  5214. end
  5215. turtle.dig()
  5216. end
  5217.  
  5218. function digUp()
  5219. if noMoreEmptySlots() then
  5220. jettisonGarbage()
  5221. goEmptyInventoryToChestAndReturn()
  5222. end
  5223. turtle.digUp()
  5224. end
  5225.  
  5226. function digDown()
  5227. if noMoreEmptySlots() then
  5228. jettisonGarbage()
  5229. goEmptyInventoryToChestAndReturn()
  5230. end
  5231. turtle.digDown()
  5232. end
  5233.  
  5234. function setFace(f)
  5235. if f == 0 then
  5236. if face == 0 then return end
  5237. if face == 1 then right() return end
  5238. if face == 2 then right() right() return end
  5239. if face == 3 then left() return end
  5240. end
  5241.  
  5242. if f == 1 then
  5243. if face == 0 then left() return end
  5244. if face == 1 then return end
  5245. if face == 2 then right() return end
  5246. if face == 3 then right() right() return end
  5247. end
  5248.  
  5249. if f == 2 then
  5250. if face == 0 then left() left() return end
  5251. if face == 1 then left() return end
  5252. if face == 2 then return end
  5253. if face == 3 then right() return end
  5254. end
  5255.  
  5256. if f == 3 then
  5257. if face == 0 then right() return end
  5258. if face == 1 then left() left() return end
  5259. if face == 2 then left() return end
  5260. if face == 3 then return end
  5261. end
  5262. end
  5263.  
  5264. function home(homeFace)
  5265. if x < 0 then
  5266. setFace(east)
  5267. while x < 0 do
  5268. forward()
  5269. end
  5270. else
  5271. if x > 0 then
  5272. setFace(west)
  5273. while x > 0 do
  5274. forward()
  5275. end
  5276. end
  5277. end
  5278.  
  5279. if z < 0 then
  5280. setFace(north)
  5281. while z < 0 do
  5282. forward()
  5283. end
  5284. else
  5285. if z > 0 then
  5286. setFace(south)
  5287. while z > 0 do
  5288. forward()
  5289. end
  5290. end
  5291. end
  5292.  
  5293. if y > 0 then
  5294. while y > 0 do
  5295. down()
  5296. end
  5297. end
  5298.  
  5299. if homeFace ~= nil then
  5300. setFace(homeFace)
  5301. end
  5302. end
  5303.  
  5304. function returnToMark()
  5305. if markZ < 0 then
  5306. setFace(south)
  5307. while z > markZ do
  5308. forward(false)
  5309. end
  5310. else
  5311. if markZ > 0 then
  5312. setFace(north)
  5313. while z < markZ do
  5314. forward(false)
  5315. end
  5316. end
  5317. end
  5318.  
  5319. if markX < 0 then
  5320. setFace(west)
  5321. while x > markX do
  5322. forward(false)
  5323. end
  5324. else
  5325. if markX > 0 then
  5326. setFace(east)
  5327. while x < markX do
  5328. forward(false)
  5329. end
  5330. end
  5331. end
  5332.  
  5333. setFace(markFace)
  5334. end
  5335.  
  5336. function ensureMaterial()
  5337. if turtle.getItemCount(materialSlot) < 3 then
  5338. organizeMaterial()
  5339. end
  5340. if turtle.getItemCount(materialSlot) < 3 then
  5341. print("No more material")
  5342. return false
  5343. end
  5344. return true
  5345. end
  5346.  
  5347. function organizeMaterial()
  5348. local i
  5349. materialCount = turtle.getItemCount(materialSlot)
  5350.  
  5351. if materialCount < 3 then
  5352. print("Attempting to refill slot ", materialSlot)
  5353. for i=2,16 do
  5354. turtle.select(i)
  5355. if turtle.compareTo(materialSlot) then
  5356. turtle.transferTo(materialSlot)
  5357. end
  5358. end
  5359. end
  5360. turtle.select(materialSlot)
  5361. end
  5362.  
  5363. function ignoreUp()
  5364. for slot=1,3 do
  5365. turtle.select(slot)
  5366. if turtle.compareUp() then
  5367. return true
  5368. end
  5369. end
  5370. return false
  5371. end
  5372.  
  5373. function ignoreDown()
  5374. for slot=1,3 do
  5375. turtle.select(slot)
  5376. if turtle.compareDown() then
  5377. return true
  5378. end
  5379. end
  5380. return false
  5381. end
  5382.  
  5383. function mineUp()
  5384. while turtle.detectUp() do
  5385. digUp()
  5386. end
  5387. end
  5388.  
  5389. function mineDown()
  5390. if turtle.detectDown() then
  5391. digDown()
  5392. end
  5393. end
  5394.  
  5395. function mineAtLevel()
  5396. end
  5397.  
  5398. function layBlock()
  5399. turtle.select(materialSlot)
  5400.  
  5401. if maxLevel > 2 then
  5402. if turtle.detectUp() then
  5403. if turtle.compareUp() then
  5404. return
  5405. else
  5406. digUp()
  5407. end
  5408. end
  5409. if ensureMaterial() then
  5410. turtle.placeUp()
  5411. end
  5412. else
  5413. if turtle.detectDown() then
  5414. if turtle.compareDown() then
  5415. return
  5416. else
  5417. digDown()
  5418. end
  5419. end
  5420. if ensureMaterial() then
  5421. turtle.placeDown()
  5422. end
  5423. end
  5424. end
  5425.  
  5426. function checkFuel()
  5427. if currentFuelLevel == "unlimited" then
  5428. return true
  5429. end
  5430.  
  5431. if currentFuelLevel < minimumFuel then
  5432. if not turtle.refuel() then
  5433. areaCovered = targetArea
  5434. missionMessage = "Mission aborted due to low fuel."
  5435. abort = true
  5436. return false
  5437. end
  5438. end
  5439. return true
  5440. end
  5441.  
  5442. -- MAIN PROGRAM
  5443.  
  5444. turtle.select(1)
  5445.  
  5446. if currentFuelLevel ~= "unlimited" then
  5447. if currentFuelLevel < minimumFuel then
  5448. if not turtle.refuel() then
  5449. print("No fuel")
  5450. return
  5451. end
  5452. end
  5453. end
  5454.  
  5455. function mineLoop()
  5456. while areaCovered < targetArea do
  5457. if abort then
  5458. break
  5459. end
  5460. for w=1,width do
  5461. if abort then
  5462. break
  5463. end
  5464. for z=1,length do
  5465. if abort then
  5466. break
  5467. end
  5468. if not ignoreUp() then
  5469. mineUp()
  5470. end
  5471. if not ignoreDown() then
  5472. mineDown()
  5473. end
  5474. if z < length then
  5475. forward()
  5476. end
  5477. end
  5478. if nextTurn == "left" then
  5479. if areaCovered < targetArea then
  5480. left()
  5481. forward()
  5482. left()
  5483. nextTurn = "right"
  5484. end
  5485. else
  5486. if areaCovered < targetArea then
  5487. right()
  5488. forward()
  5489. right()
  5490. nextTurn = "left"
  5491. end
  5492. end
  5493. end
  5494. end
  5495. end
  5496.  
  5497. function inventoryGettingFull()
  5498. return ((turtle.getItemCount(14) > 0) or (turtle.getItemCount(15) > 0))
  5499. end
  5500.  
  5501. function noMoreEmptySlots()
  5502. return (turtle.getItemCount(15) > 0)
  5503. end
  5504.  
  5505. markX = 0
  5506. markY = 0
  5507. markZ = 0
  5508. markFace = nil
  5509.  
  5510. function goEmptyInventoryToChestAndReturn()
  5511. saveAreaCovered = areaCovered
  5512. markX = x
  5513. markY = y
  5514. markZ = z
  5515. markFace = face
  5516.  
  5517. home()
  5518. setFace(east)
  5519. while y > 0 do
  5520. down()
  5521. end
  5522. dump()
  5523. while y < markY do
  5524. up()
  5525. end
  5526. returnToMark()
  5527. areaCovered = saveAreaCovered
  5528. end
  5529.  
  5530. jettisonCount = 0
  5531. function jettisonGarbage()
  5532. jettisonCount = jettisonCount + 1
  5533. print("Jettison count ", jettisonCount)
  5534. turtle.select(garbageSlot)
  5535. for i=4,15 do
  5536. turtle.select(i)
  5537. if turtle.compareTo(garbageSlot) then
  5538. turtle.dropDown()
  5539. end
  5540. end
  5541. if turtle.getItemCount(15) > 0 then
  5542. turtle.select(15)
  5543. for i=4,13 do
  5544. if turtle.getItemCount(i) == 0 then
  5545. turtle.transferTo(i)
  5546. end
  5547. end
  5548. end
  5549. turtle.select(1)
  5550. end
  5551.  
  5552. purgeCount = 0
  5553. function purgeGarbage()
  5554. purgeCount = purgeCount + 1
  5555. print("Purge garbage ", purgeCount)
  5556. if turtle.detectDown() then
  5557. turtle.digDown()
  5558. end
  5559. turtle.select(garbageSlot)
  5560. for i=4,15 do
  5561. turtle.select(i)
  5562. if turtle.compareTo(garbageSlot) then
  5563. turtle.dropDown()
  5564. end
  5565. end
  5566.  
  5567. if turtle.getItemCount(14) > 0 then
  5568. turtle.select(14)
  5569. for i=4,13 do
  5570. if turtle.getItemCount(i) == 0 then
  5571. turtle.transferTo(i)
  5572. end
  5573. end
  5574. end
  5575. if turtle.getItemCount(15) > 0 then
  5576. turtle.select(15)
  5577. for i=4,13 do
  5578. if turtle.getItemCount(i) == 0 then
  5579. turtle.transferTo(i)
  5580. end
  5581. end
  5582. end
  5583. turtle.select(1)
  5584. end
  5585.  
  5586. function collapseInventory()
  5587. turtle.select(15)
  5588. for i=4,15 do
  5589. if turtle.getItemCount(i) == 0 then
  5590. turtle.transferTo(i)
  5591. end
  5592. end
  5593. end
  5594.  
  5595. function dump()
  5596. -- setFace(east)
  5597. --[[ turtle.select(chestSlot)
  5598. if not turtle.compare() then
  5599. plantChest()
  5600. end
  5601. --]]
  5602. for i=1,3 do
  5603. turtle.select(i)
  5604. itemCount = turtle.getItemCount(i)
  5605. if itemCount > 0 then
  5606. turtle.drop(itemCount-1)
  5607. end
  5608. end
  5609.  
  5610. for i=4,15 do
  5611. turtle.select(i)
  5612. if turtle.getItemCount(i) > 0 then
  5613. if not turtle.drop() then
  5614. print("Dump failed. Chest is full.")
  5615. return
  5616. end
  5617. end
  5618. end
  5619. turtle.select(1)
  5620. setFace(north)
  5621. end
  5622.  
  5623. function plantChest()
  5624. turtle.select(chestSlot)
  5625. setFace(east)
  5626. forward()
  5627. mineUp()
  5628. left()
  5629. forward()
  5630. mineUp()
  5631. left()
  5632. forward()
  5633. left()
  5634. left()
  5635. turtle.place()
  5636. right()
  5637. forward()
  5638. left()
  5639. turtle.place()
  5640. setFace(east)
  5641. turtle.select(1)
  5642. end
  5643.  
  5644. y = 0
  5645. --up()
  5646.  
  5647. mineLevel = 1
  5648. saveY = y
  5649.  
  5650. plantChest()
  5651. setFace(north)
  5652.  
  5653. while mineLevel <= maxLevel do
  5654. areaCovered = 1
  5655. nextTurn = "left"
  5656. mineLoop()
  5657. home()
  5658. while y > 0 do
  5659. down()
  5660. end
  5661. setFace(east)
  5662. dump()
  5663. if mineLevel < maxLevel then
  5664. mineLevel = mineLevel + 3
  5665. while y < mineLevel-1 do
  5666. up()
  5667. end
  5668. else
  5669. break
  5670. end
  5671. end
  5672.  
  5673. function sealItOff()
  5674. turtle.select(4)
  5675. turtle.up()
  5676. turtle.placeUp()
  5677. turtle.down()
  5678. turtle.placeUp()
  5679. turtle.place()
  5680. turtle.turnLeft()
  5681. turtle.place()
  5682. turtle.turnRight()
  5683. end
  5684.  
  5685. print(missionMessage)
  5686. print(" Current fuel level is ", turtle.getFuelLevel())
  5687. home(north)
  5688. sealItOff()
  5689. *** pattern
  5690.  
  5691. args = {...}
  5692. nArgs = #args
  5693.  
  5694. version = "pattern: Rev 0.1"
  5695. mission = "Lay down the specified pattern."
  5696. instructions = "Place stack(s) of material starting in first slot."
  5697.  
  5698. usage = "usage: pattern <pattern name>"
  5699.  
  5700. -- Water roof to cover a 10 x 10 structure
  5701.  
  5702. roof10x10 = {
  5703. " = ",
  5704. " === ",
  5705. " ===== ",
  5706. " ======= ",
  5707. " ========== ",
  5708. " ============ ",
  5709. " ============== ",
  5710. " ======== ======= ",
  5711. " ================= ",
  5712. " =================== ",
  5713. " ===================== ",
  5714. "======= =============== ",
  5715. " =============== =======",
  5716. " ===================== ",
  5717. " =================== ",
  5718. " ================= ",
  5719. " ======= ======== ",
  5720. " ============== ",
  5721. " ============ ",
  5722. " ========== ",
  5723. " ======= ",
  5724. " ===== ",
  5725. " === ",
  5726. " = ",
  5727. }
  5728.  
  5729. funnel12 = {
  5730. "============",
  5731. "============",
  5732. "============",
  5733. "============",
  5734. "============",
  5735. "===== =====",
  5736. "===== =====",
  5737. "============",
  5738. "============",
  5739. "============",
  5740. "============",
  5741. "============",
  5742. }
  5743.  
  5744. fullShape = {
  5745. " = ",
  5746. " === ",
  5747. " ===== ",
  5748. " ======= ",
  5749. " ========= ",
  5750. " =========== ",
  5751. " ============= ",
  5752. " =============== ",
  5753. "=================",
  5754. " =============== ",
  5755. " ============= ",
  5756. " =========== ",
  5757. " ========= ",
  5758. " ======= ",
  5759. " ===== ",
  5760. " === ",
  5761. " = ",
  5762. }
  5763.  
  5764. reducedShape = {
  5765. " ",
  5766. " = ",
  5767. " === ",
  5768. " ===== ",
  5769. " ======= ",
  5770. " ========= ",
  5771. " =========== ",
  5772. " ============= ",
  5773. " =============== ",
  5774. " ============= ",
  5775. " =========== ",
  5776. " ========= ",
  5777. " ======= ",
  5778. " ===== ",
  5779. " === ",
  5780. " = ",
  5781. " ",
  5782. }
  5783.  
  5784. walls = {
  5785. " = ",
  5786. " = = ",
  5787. " = = ",
  5788. " = = ",
  5789. " = = ",
  5790. " = = ",
  5791. " = = ",
  5792. " = = ",
  5793. "= =",
  5794. " = = ",
  5795. " = = ",
  5796. " = = ",
  5797. " = = ",
  5798. " = = ",
  5799. " = = ",
  5800. " = = ",
  5801. " = ",
  5802. }
  5803.  
  5804. x = 0
  5805. y = 0
  5806. z = 0
  5807.  
  5808. -- The following 'face' directions are relative to the starting position of the turtle in this program
  5809. north = 0
  5810. west = 1
  5811. south = 2
  5812. east = 3
  5813.  
  5814. materialSlot = 1
  5815. face = north
  5816. nextTurn = "right"
  5817.  
  5818. function ensureMaterial()
  5819. if turtle.getItemCount(materialSlot) < 3 then
  5820. organizeMaterial()
  5821. end
  5822. if turtle.getItemCount(materialSlot) < 3 then
  5823. print("No more material")
  5824. return false
  5825. end
  5826. return true
  5827. end
  5828.  
  5829. function organizeMaterial()
  5830. local i
  5831. materialCount = turtle.getItemCount(materialSlot)
  5832.  
  5833. if materialCount < 3 then
  5834. -- print("Attempting to refill slot ", materialSlot)
  5835. for i=2,16 do
  5836. turtle.select(i)
  5837. if turtle.compareTo(materialSlot) then
  5838. turtle.transferTo(materialSlot)
  5839. end
  5840. end
  5841. end
  5842. turtle.select(materialSlot)
  5843. end
  5844.  
  5845. function left()
  5846. if face == 0 then face = 1 turtle.turnLeft() return end
  5847. if face == 1 then face = 2 turtle.turnLeft() return end
  5848. if face == 2 then face = 3 turtle.turnLeft() return end
  5849. if face == 3 then face = 0 turtle.turnLeft() return end
  5850. print("function left\(\): Bad face value: ", face)
  5851. end
  5852.  
  5853. function right()
  5854. if face == 0 then face = 3 turtle.turnRight() return end
  5855. if face == 1 then face = 0 turtle.turnRight() return end
  5856. if face == 2 then face = 1 turtle.turnRight() return end
  5857. if face == 3 then face = 2 turtle.turnRight() return end
  5858. print("function right\(\): Bad face value: ", face)
  5859. end
  5860.  
  5861. function turn()
  5862. if nextTurn == "left" then
  5863. left()
  5864. else
  5865. right()
  5866. end
  5867. forward()
  5868. if nextTurn == "left" then
  5869. left()
  5870. nextTurn = "right"
  5871. else
  5872. right()
  5873. nextTurn = "left"
  5874. end
  5875. end
  5876.  
  5877. function forward()
  5878. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  5879. if turtle.forward() then
  5880. break
  5881. end
  5882. turtle.attack()
  5883. sleep(2)
  5884. end
  5885.  
  5886. if face == north then z = z+1 return end
  5887. if face == west then x = x-1 return end
  5888. if face == south then z = z-1 return end
  5889. if face == east then x = x+1 return end
  5890. end
  5891.  
  5892. function setFace(f)
  5893. if f == 0 then
  5894. if face == 0 then return end
  5895. if face == 1 then right() return end
  5896. if face == 2 then right() right() return end
  5897. if face == 3 then left() return end
  5898. end
  5899.  
  5900. if f == 1 then
  5901. if face == 0 then left() return end
  5902. if face == 1 then return end
  5903. if face == 2 then right() return end
  5904. if face == 3 then right() right() return end
  5905. end
  5906.  
  5907. if f == 2 then
  5908. if face == 0 then left() left() return end
  5909. if face == 1 then left() return end
  5910. if face == 2 then return end
  5911. if face == 3 then right() return end
  5912. end
  5913.  
  5914. if f == 3 then
  5915. if face == 0 then right() return end
  5916. if face == 1 then left() left() return end
  5917. if face == 2 then left() return end
  5918. if face == 3 then return end
  5919. end
  5920. end
  5921.  
  5922. function home(targetY)
  5923. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  5924. if x < 0 then
  5925. setFace(east)
  5926. while x < 0 do
  5927. forward()
  5928. end
  5929. else
  5930. if x > 0 then
  5931. setFace(west)
  5932. while x > 0 do
  5933. forward()
  5934. end
  5935. end
  5936. end
  5937.  
  5938. if z < 0 then
  5939. setFace(north)
  5940. while z < 0 do
  5941. forward()
  5942. end
  5943. else
  5944. if z > 0 then
  5945. setFace(south)
  5946. while z > 0 do
  5947. forward()
  5948. end
  5949. end
  5950. end
  5951.  
  5952. if y > 0 then
  5953. while y > 0 do
  5954. down()
  5955. end
  5956. end
  5957.  
  5958. setFace(0)
  5959. end
  5960.  
  5961. function layPattern(pattern)
  5962. for i=1,#pattern do
  5963. row = pattern[i]
  5964. length = string.len(row)
  5965. if face == north then
  5966. for j=1,string.len(row) do
  5967. char = string.sub(row, j, j)
  5968. if char ~= " " then
  5969. ensureMaterial()
  5970. turtle.select(materialSlot)
  5971. turtle.placeDown()
  5972. end
  5973. if j < length then
  5974. forward()
  5975. end
  5976. end
  5977. else
  5978. for j=string.len(row),1,-1 do
  5979. char = string.sub(row, j, j)
  5980. if char ~= " " then
  5981. ensureMaterial()
  5982. turtle.select(materialSlot)
  5983. turtle.placeDown()
  5984. end
  5985. if j > 1 then
  5986. forward()
  5987. end
  5988. end
  5989. end
  5990. turn()
  5991. end
  5992. end
  5993.  
  5994.  
  5995. if nArgs < 1 then
  5996. print(usage)
  5997. return
  5998. end
  5999.  
  6000. if args[1] == "roof10x10" then
  6001. layPattern(roof10x10)
  6002. elseif args[1] == "funnel12" then
  6003. layPattern(funnel12)
  6004. elseif args[1] == "full" then
  6005. layPattern(fullShape)
  6006. elseif args[1] == "reduced" then
  6007. layPattern(reducedShape)
  6008. elseif args[1] == "walls" then
  6009. layPattern(walls)
  6010. else
  6011. print("Unknown pattern: \"", args[1], "\"")
  6012. return
  6013. end
  6014.  
  6015. home()
  6016. *** pit
  6017. -- pit
  6018. -- Mines pit to specified depth or bedrock
  6019. -- Turtle returns to its starting point when mission is completed or fuel runs low
  6020. -- Written by HarvDad, June 2014
  6021.  
  6022. args = {...}
  6023. nArgs = #args
  6024.  
  6025. version = "pit: Rev 2.4"
  6026. mission = "Mines pit to specified length, width and depth or bedrock."
  6027.  
  6028. usage = "walls <length> <width> <depth>"
  6029.  
  6030. x = 0
  6031. y = 0
  6032. z = 0
  6033. orgX = 0
  6034. orgY = 0
  6035. orgZ = 0
  6036. orgLength = 0
  6037. orgWidth = 0
  6038. face = 0
  6039. minimumFuel = 100
  6040. missionMessage = "Mission complete."
  6041. abort = false
  6042. startLevel = 0
  6043. local currentFuelLevel = turtle.getFuelLevel()
  6044. targetArea = 0
  6045. areaMined = 0
  6046. bedrockReached = false
  6047. lowestLevelReached = false
  6048. lowestLevelMined = 0
  6049. finalApproach = false
  6050. liquidCaution = true
  6051.  
  6052. areaCovered = 0
  6053.  
  6054. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  6055. print(version)
  6056. print(mission)
  6057. print(usage)
  6058. return
  6059. end
  6060.  
  6061. if nArgs ~= 3 then
  6062. print(usage)
  6063. return
  6064. end
  6065.  
  6066. length = tonumber(args[1])
  6067. if length == nil then
  6068. print("\"", args[1], "\" is not a valid length")
  6069. return
  6070. end
  6071. if length < 1 then
  6072. print("length must be a positive number greater than zero")
  6073. end
  6074. orgLength = length
  6075.  
  6076. width = tonumber(args[2])
  6077. if width == nil then
  6078. print("\"", args[2], "\" is not a valid width")
  6079. return
  6080. end
  6081. if width < 1 then
  6082. print("width must be a positive number greater than zero")
  6083. end
  6084. orgWidth = width
  6085.  
  6086. targetArea = length * width
  6087.  
  6088. depth = tonumber(args[3])
  6089. if startLevel == nil then
  6090. print("\"", args[3], "\" is not a valid depth")
  6091. return
  6092. end
  6093.  
  6094. currentSlot = 2
  6095. materialSlot = 1
  6096. maxSlot = 16
  6097. fillerSlot = 2
  6098.  
  6099. nextTurn = "left"
  6100.  
  6101. local clock = os.clock
  6102. function sleep(n) -- seconds
  6103. local t0 = clock()
  6104. while clock() - t0 <= n do end
  6105. end
  6106.  
  6107. function left()
  6108. if face == 0 then face = 1 turtle.turnLeft() return end
  6109. if face == 1 then face = 2 turtle.turnLeft() return end
  6110. if face == 2 then face = 3 turtle.turnLeft() return end
  6111. if face == 3 then face = 0 turtle.turnLeft() return end
  6112. print("function left\(\): Bad face value: ", face)
  6113. end
  6114.  
  6115. function right()
  6116. if face == 0 then face = 3 turtle.turnRight() return end
  6117. if face == 1 then face = 0 turtle.turnRight() return end
  6118. if face == 2 then face = 1 turtle.turnRight() return end
  6119. if face == 3 then face = 2 turtle.turnRight() return end
  6120. print("function right\(\): Bad face value: ", face)
  6121. end
  6122.  
  6123. function up()
  6124. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  6125. turtle.digUp()
  6126. end
  6127.  
  6128. turtle.up()
  6129. y = y+1
  6130. end
  6131.  
  6132. function rise(nBlocks)
  6133. local i
  6134. for i=1,nBlocks do
  6135. up()
  6136. end
  6137. end
  6138.  
  6139. function down()
  6140. if turtle.detectDown() then
  6141. if not turtle.digDown() then
  6142. return -- must be at bedrock
  6143. end
  6144. end
  6145. turtle.down()
  6146. y = y-1
  6147. -- print("down: y is now ", y)
  6148. end
  6149.  
  6150. function turn()
  6151. if nextTurn == "left" then
  6152. left()
  6153. else
  6154. right()
  6155. end
  6156. chomp()
  6157. forward()
  6158. if nextTurn == "left" then
  6159. left()
  6160. nextTurn = "right"
  6161. else
  6162. right()
  6163. nextTurn = "left"
  6164. end
  6165. areaCovered = areaCovered + 1
  6166. end
  6167.  
  6168. function forward()
  6169. if liquidCaution and (not turtle.detect()) then
  6170. turtle.select(fillerSlot)
  6171. turtle.place()
  6172. end
  6173. while turtle.detect() do -- This loop added in case of falling sand or whatever
  6174. turtle.dig()
  6175. end
  6176. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  6177. if turtle.forward() then
  6178. break
  6179. end
  6180. turtle.attack()
  6181. sleep(2)
  6182. end
  6183. areaCovered = areaCovered + 1
  6184.  
  6185. if face == 0 then z = z+1 return end
  6186. if face == 1 then x = x-1 return end
  6187. if face == 2 then z = z-1 return end
  6188. if face == 3 then x = x+1 return end
  6189. end
  6190.  
  6191. function setFace(f)
  6192. if f == 0 then
  6193. if face == 0 then return end
  6194. if face == 1 then right() return end
  6195. if face == 2 then right() right() return end
  6196. if face == 3 then left() return end
  6197. end
  6198.  
  6199. if f == 1 then
  6200. if face == 0 then left() return end
  6201. if face == 1 then return end
  6202. if face == 2 then right() return end
  6203. if face == 3 then right() right() return end
  6204. end
  6205.  
  6206. if f == 2 then
  6207. if face == 0 then left() left() return end
  6208. if face == 1 then left() return end
  6209. if face == 2 then return end
  6210. if face == 3 then right() return end
  6211. end
  6212.  
  6213. if f == 3 then
  6214. if face == 0 then right() return end
  6215. if face == 1 then left() left() return end
  6216. if face == 2 then left() return end
  6217. if face == 3 then return end
  6218. end
  6219. end
  6220.  
  6221. function home(targetY)
  6222. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  6223. if finalApproach then print("Final approach to home...") end
  6224.  
  6225. liquidCaution = false -- No need to watch for liquid blocks
  6226. if x < 0 then
  6227. setFace(3)
  6228. while x < 0 do
  6229. forward()
  6230. end
  6231. else
  6232. if x > 0 then
  6233. setFace(1)
  6234. while x > 0 do
  6235. forward()
  6236. end
  6237. end
  6238. end
  6239.  
  6240. if z < 0 then
  6241. setFace(0)
  6242. while z < 0 do
  6243. forward()
  6244. end
  6245. else
  6246. if z > 0 then
  6247. setFace(2)
  6248. while z > 0 do
  6249. forward()
  6250. end
  6251. end
  6252. end
  6253.  
  6254. if finalApproach then print(" y = ", y, ", lowestLevel = ", lowestLevel) end
  6255. if targetY == lowestLevel then
  6256. setFace(0)
  6257. liquidCaution = true
  6258. return
  6259. end
  6260.  
  6261. if finalApproach then print(" y = ", y, ", targetY = ", targetY) end
  6262. if y < targetY then
  6263. if finalApproach then print(" Heading up..." ) end
  6264. while y < targetY do
  6265. if finalApproach then print(" up..." ) end
  6266. up()
  6267. end
  6268. end
  6269.  
  6270. setFace(0)
  6271. liquidCaution = true
  6272. end
  6273.  
  6274. function isKeeper()
  6275. for i=1,4 do
  6276. if turtle.compareTo(i) then
  6277. return true
  6278. end
  6279. end
  6280. return false
  6281. end
  6282.  
  6283. function isDisposable()
  6284. for i=1,4 do
  6285. if turtle.compareTo(i) then
  6286. return true
  6287. end
  6288. end
  6289. return false
  6290. end
  6291.  
  6292. function purge()
  6293. --[[
  6294. for i=1,4 do
  6295. turtle.select(i)
  6296. if isDisposable() then
  6297. count = turtle.getItemCount(i)
  6298. turtle.dropUp(count - 1)
  6299. end
  6300. end
  6301. --]]
  6302. for i=5,16 do
  6303. turtle.select(i)
  6304. if isDisposable() then
  6305. turtle.dropUp()
  6306. end
  6307. end
  6308. turtle.select(1)
  6309. end
  6310.  
  6311. function isFull()
  6312. for i=5,16 do
  6313. if turtle.getItemCount(i) == 0 then
  6314. return false
  6315. end
  6316. end
  6317. turtle.select(1)
  6318. return true
  6319. end
  6320.  
  6321. function emptySlots()
  6322. empties = 0
  6323.  
  6324. for i=5,16 do
  6325. if turtle.getItemCount(i) == 0 then
  6326. empties = empties + 1
  6327. end
  6328. end
  6329. return empties
  6330. end
  6331.  
  6332. function ensureMaterial()
  6333. if turtle.getItemCount(materialSlot) < 3 then
  6334. organizeMaterial()
  6335. end
  6336. if turtle.getItemCount(materialSlot) < 3 then
  6337. print("No more material")
  6338. return false
  6339. end
  6340. return true
  6341. end
  6342.  
  6343. function organizeMaterial()
  6344. local i
  6345. materialCount = turtle.getItemCount(materialSlot)
  6346.  
  6347. if materialCount < 3 then
  6348. -- print("Attempting to refill slot ", materialSlot)
  6349. for i=2,16 do
  6350. turtle.select(i)
  6351. if turtle.compareTo(materialSlot) then
  6352. turtle.transferTo(materialSlot)
  6353. end
  6354. end
  6355. end
  6356. turtle.select(materialSlot)
  6357. end
  6358.  
  6359. -- Group all materials into minimum slots
  6360.  
  6361. function consolidate()
  6362. for dst = 5,16 do
  6363. for src=(dst+1),16 do
  6364. turtle.select(src)
  6365. if turtle.getItemCount(src) > 0 then
  6366. if turtle.compareTo(dst) then
  6367. turtle.transferTo(dst)
  6368. end
  6369. end
  6370. end
  6371. end
  6372. turtle.select(1)
  6373. end
  6374.  
  6375.  
  6376. function layBlock()
  6377. turtle.select(materialSlot)
  6378.  
  6379. if startLevel > 2 then
  6380. if turtle.detectUp() then
  6381. if turtle.compareUp() then
  6382. return
  6383. else
  6384. turtle.digUp()
  6385. end
  6386. end
  6387. if ensureMaterial() then
  6388. turtle.placeUp()
  6389. end
  6390. else
  6391. if turtle.detectDown() then
  6392. if turtle.compareDown() then
  6393. return
  6394. else
  6395. turtle.digDown()
  6396. end
  6397. end
  6398. if ensureMaterial() then
  6399. turtle.placeDown()
  6400. end
  6401. end
  6402. end
  6403.  
  6404. function checkFuel()
  6405. if currentFuelLevel == "unlimited" then
  6406. return true
  6407. end
  6408.  
  6409. if currentFuelLevel < minimumFuel then
  6410. if not turtle.refuel() then
  6411. areaCovered = targetArea
  6412. missionMessage = "Mission aborted due to low fuel."
  6413. abort = true
  6414. return false
  6415. end
  6416. end
  6417. return true
  6418. end
  6419.  
  6420. currentSlot = 1
  6421.  
  6422.  
  6423. function tryToGoDown()
  6424. success = false
  6425.  
  6426. if bedrockReached then
  6427. -- print("tryToGoDown: No can do. Already at bedrock.")
  6428. return success
  6429. end
  6430. if lowestLevelReached then
  6431. -- print("tryToGoDown: Already at lowest level. Duh.")
  6432. return success
  6433. end
  6434.  
  6435. -- print("Trying to go down a level...")
  6436. if y == lowestLevel then
  6437. lowestLevelReached = true
  6438. print(" but y is ", y, " and lowestLevel is ", lowestLevel)
  6439. print("tryToGoDown: lowest level reached at ", y, "/", lowestLevel)
  6440. return success
  6441. end
  6442.  
  6443. if turtle.detectDown() then
  6444. if not turtle.digDown() then
  6445. bedrockReached = true
  6446. print("tryToGoDown: bedrock reached at y = ", y)
  6447. else
  6448. turtle.down()
  6449. success = true
  6450. y = y - 1
  6451. end
  6452. else
  6453. turtle.down()
  6454. success = true
  6455. y = y - 1
  6456. end
  6457.  
  6458. return success
  6459. end
  6460.  
  6461.  
  6462. -- Try for 3 levels down, but 2 will be considered successful
  6463.  
  6464. function goToNextLevel()
  6465. success = false
  6466.  
  6467. if tryToGoDown() == success then -- We need to go down at least 2 blocks
  6468. if tryToGoDown() == success then -- 2nd level down counts as success
  6469. success = true
  6470. tryToGoDown() -- 3rd level down is ideal, but not mandatory
  6471. end
  6472. end
  6473.  
  6474. return success
  6475. end
  6476.  
  6477. function dig()
  6478. if not turtle.detect() then
  6479. turtle.select(fillerSlot)
  6480. turtle.place()
  6481. end
  6482. turtle.dig()
  6483. turtle.select(1)
  6484. end
  6485.  
  6486. function digUp()
  6487. if not turtle.detectUp() then
  6488. turtle.select(fillerSlot)
  6489. turtle.placeUp()
  6490. end
  6491. turtle.digUp()
  6492. turtle.select(1)
  6493. end
  6494.  
  6495. function digDown()
  6496. if not turtle.detectDown() then
  6497. turtle.select(fillerSlot)
  6498. turtle.placeDown()
  6499. end
  6500. turtle.select(1)
  6501. return turtle.digDown()
  6502. end
  6503.  
  6504. function digRow(nBlocks)
  6505. -- print("digRow nBlocks: ", nBlocks)
  6506.  
  6507. for i=1,nBlocks do
  6508. digUp()
  6509. if not digDown() then
  6510. if not bedrockReached then
  6511. bedrockReached = true
  6512. -- print("digRow: bedrock reached at y = ", y)
  6513. end
  6514. end
  6515. areaMined = areaMined + 1
  6516. -- print(" areaMined = ", areaMined)
  6517. if i < nBlocks then
  6518. forward()
  6519. end
  6520. end
  6521. if isFull() then
  6522. purge()
  6523. consolidate()
  6524. end
  6525. end
  6526.  
  6527. function layRow(nBlocks)
  6528. turtle.select(materialSlot)
  6529. for i=1,nBlocks do
  6530. if ensureMaterial() then
  6531. turtle.placeDown()
  6532. turtle.forward()
  6533. else
  6534. if ensureMaterial() then
  6535. turtle.placeDown()
  6536. turtle.forward()
  6537. else
  6538. print("Can't find more material")
  6539. return
  6540. end
  6541. end
  6542. end
  6543. end
  6544.  
  6545. function mineArea()
  6546. areaMined = 0
  6547. length = orgLength
  6548. width = orgWidth
  6549. turtle.select(1)
  6550.  
  6551. -- while areaMined < targetArea do
  6552. while length >= 1 and width >= 1 do
  6553. setFace(0)
  6554. digRow(length)
  6555.  
  6556. setFace(1)
  6557. forward()
  6558. digRow(width - 1)
  6559.  
  6560. setFace(2)
  6561. forward()
  6562. digRow(length - 1)
  6563.  
  6564. setFace(3)
  6565. digRow(width - 1)
  6566.  
  6567. left()
  6568. forward()
  6569. -- print("Finished area?")
  6570. turtle.digUp()
  6571. turtle.digDown()
  6572. length = length - 2
  6573. width = width - 2
  6574. end
  6575. lowestLevelMined = y
  6576. -- print("AREA IS MINED!")
  6577. end
  6578.  
  6579. function dump()
  6580. --[[
  6581. for i = 1,4 do
  6582. turtle.select(i)
  6583. count = turtle.getItemCount(i)
  6584. if count > 1 then
  6585. turtle.drop(count - 1)
  6586. end
  6587. end
  6588. --]]
  6589.  
  6590. for i=5,16 do
  6591. turtle.select(i)
  6592. if turtle.getItemCount(i) > 0 then
  6593. turtle.drop()
  6594. end
  6595. end
  6596. end
  6597.  
  6598. function offload()
  6599. saveY = y
  6600. while y < 0 do
  6601. turtle.up()
  6602. y = y+1
  6603. end
  6604.  
  6605. turtle.turnLeft()
  6606. turtle.turnLeft()
  6607.  
  6608. if turtle.detect() then
  6609. dump()
  6610. end
  6611.  
  6612. turtle.turnLeft()
  6613. turtle.turnLeft()
  6614.  
  6615. while y > saveY do
  6616. turtle.down()
  6617. y = y-1
  6618. end
  6619. end
  6620.  
  6621. function displayTime(time)
  6622. --print("time = ", time)
  6623. rawSeconds = math.floor(time)
  6624. rawMinutes = math.floor(rawSeconds/60)
  6625. hours = math.floor(rawMinutes/60)
  6626. seconds = rawSeconds - (rawMinutes * 60)
  6627. minutes = rawMinutes - (hours * 60)
  6628.  
  6629. -- print("Raw: ", hours, "h ", rawMinutes, "m ", rawSeconds, "s")
  6630. -- print(hours, "h ", minutes, "m ", seconds, "s")
  6631.  
  6632. timeString = "Elapsed time: "
  6633.  
  6634. hStr = " hrs "
  6635. mStr = " mins "
  6636. sStr = " secs"
  6637.  
  6638. if hours == 1 then hStr = " hr " end
  6639. if minutes == 1 then mStr = " min " end
  6640. if seconds == 1 then sStr = " sec " end
  6641.  
  6642. if hours > 0 then
  6643. timeString = timeString .. hours .. hStr
  6644. end
  6645. if minutes > 0 then
  6646. timeString = timeString .. minutes .. mStr
  6647. end
  6648. if seconds > 0 then
  6649. timeString = timeString .. seconds .. sStr
  6650. end
  6651.  
  6652. print(timeString)
  6653. end
  6654.  
  6655. function thisLevelNeedsMining()
  6656. need = false
  6657.  
  6658. if lowestLevelMined == 0 then
  6659. -- print("thisLevelNeedsMining: lowestLevelMined is zero.")
  6660. return true
  6661. end
  6662.  
  6663. if lowestLevelReached or bedrockReached then
  6664. -- print("thisLevelNeedsMining: lowestLevelReach ", lowestLevelReached, " bedrockRockReached ", bedrockReached)
  6665. if y ~= lowestLevelMined and (y ~= lowestLevelMined - 1) then
  6666. -- print("thisLevelNeedsMining: y ", y, " lowestLevelMined ", lowestLevelMined)
  6667. need = true
  6668. end
  6669. else
  6670. need = true
  6671. end
  6672. -- print("thislevelneedsmining: need")
  6673. return need
  6674. end
  6675.  
  6676. -- MAIN PROGRAM
  6677.  
  6678. turtle.select(1)
  6679.  
  6680. startFuel = turtle.getFuelLevel()
  6681. --print("fuelLevel = ", startFuel)
  6682. --print("length = ", length)
  6683. --print("width = ", width)
  6684. --print("face = ", face)
  6685.  
  6686. --print("Current Fuel Level: ", currentFuelLevel)
  6687.  
  6688. if currentFuelLevel ~= "unlimited" then
  6689. if currentFuelLevel < minimumFuel then
  6690. if not turtle.refuel() then
  6691. print("No fuel")
  6692. return
  6693. end
  6694. end
  6695. end
  6696.  
  6697. if depth == 1 then end
  6698. if depth == 2 then down() end
  6699. if depth == 3 then down() down() end
  6700.  
  6701. notFinished = true
  6702. depth = -depth
  6703. lowestLevel = depth + 1 -- lowest level the turtle needs to go
  6704. startTime = os.clock()
  6705.  
  6706. down()
  6707. down()
  6708.  
  6709. while thisLevelNeedsMining() do
  6710. setFace(0)
  6711. mineArea()
  6712. -- print("Loop: lowestLevelReached: ", lowestLevelReached, " bedrockReached: ", bedrockReached, " lowestLevelMined: ", lowestLevelMined)
  6713.  
  6714. -- print("Heading home to level ", y)
  6715. home(y)
  6716. -- print(" Made it. Now at level ", y)
  6717.  
  6718. purge()
  6719. consolidate()
  6720. if emptySlots() <= 3 then
  6721. offload()
  6722. end
  6723.  
  6724. if (not bedrockReached) and (not lowestLevelReached) then
  6725. -- if y > lowestLevelMined then
  6726. goToNextLevel()
  6727. else
  6728. break
  6729. end
  6730. end
  6731.  
  6732. --print("Break out: y ", y, " lowestLevelMined ", lowestLevelMined, " bedrockReached ", bedrockReached)
  6733. --finalApproach = true
  6734.  
  6735. home(0)
  6736. setFace(0)
  6737. offload()
  6738. print(missionMessage)
  6739. --print("lowestLevelReached = ", lowestLevelReached, ", bedrockReached = ", bedrockReached)
  6740. endTime = os.clock()
  6741. elapsedTime = endTime - startTime
  6742. endFuel = turtle.getFuelLevel()
  6743. usedFuel = startFuel - endFuel
  6744. displayTime(elapsedTime)
  6745. print("Fuel used: ", usedFuel, " units")
  6746.  
  6747. print(" Current fuel level is ", turtle.getFuelLevel())
  6748. *** pop
  6749.  
  6750. version = "pop: Rev 0.1"
  6751. mission= "Protect Our Portal"
  6752. instructions = "Place stack(s) of material starting in first slot."
  6753.  
  6754. args = {...}
  6755. nArgs = #args
  6756.  
  6757. usage = "pop"
  6758.  
  6759. materialSlot = 1
  6760.  
  6761. length = 8
  6762. width = 6
  6763.  
  6764. function place()
  6765. ensureMaterial()
  6766. turtle.place()
  6767. end
  6768.  
  6769. function placeUp()
  6770. ensureMaterial()
  6771. turtle.placeUp()
  6772. end
  6773.  
  6774. function placeDown()
  6775. ensureMaterial()
  6776. turtle.placeDown()
  6777. end
  6778.  
  6779. function ensureMaterial()
  6780. if turtle.getItemCount(materialSlot) < 3 then
  6781. organizeMaterial()
  6782. end
  6783. if turtle.getItemCount(materialSlot) < 3 then
  6784. print("No more material")
  6785. return false
  6786. end
  6787. return true
  6788. end
  6789.  
  6790. function organizeMaterial()
  6791. local i
  6792. materialCount = turtle.getItemCount(materialSlot)
  6793.  
  6794. if materialCount < 6 then
  6795. -- print("Attempting to refill slot ", materialSlot)
  6796. for i=2,12 do
  6797. turtle.select(i)
  6798. if turtle.compareTo(materialSlot) then
  6799. turtle.transferTo(materialSlot)
  6800. end
  6801. end
  6802. end
  6803. turtle.select(materialSlot)
  6804. end
  6805.  
  6806. function buildWall(length)
  6807. for i=1,length do
  6808. ensureMaterial()
  6809. turtle.select(materialSlot)
  6810. placeUp()
  6811. placeDown()
  6812. if i == length then
  6813. turtle.turnLeft()
  6814. end
  6815. turtle.back()
  6816. place()
  6817. end
  6818. end
  6819.  
  6820. turtle.forward()
  6821. turtle.turnRight()
  6822. turtle.up()
  6823. buildWall(length)
  6824. buildWall(width-1)
  6825. buildWall(length-1)
  6826. turtle.down()
  6827. turtle.turnLeft()
  6828. turtle.turnLeft()
  6829. shell.run("floor 4 7 4")
  6830.  
  6831. *** quadchute
  6832. -- quadchute
  6833. -- Builds a tower up or down with 2x2 interior
  6834. -- Written by HarvDad, June 2014
  6835.  
  6836. args = {...}
  6837. nArgs = #args
  6838.  
  6839. version = "quadchute: Rev 0.1"
  6840. mission = "Builds tower with 2x2 interior to levels specified"
  6841. instructions = "Place stack(s) of material starting in first slot."
  6842.  
  6843. usage = "quadchute <up | down> <levels>"
  6844.  
  6845. x = 0
  6846. y = 0
  6847. z = 0
  6848. down = 0
  6849. up = 1
  6850. direction = 0
  6851. materialSlot = 1
  6852. ladderSlot = 16
  6853.  
  6854. -- The following 'face' directions are relative to the starting position of the turtle in this program
  6855. north = 0
  6856. west = 1
  6857. south = 2
  6858. east = 3
  6859.  
  6860. face = north
  6861. returnToEarth = true
  6862.  
  6863. function up()
  6864. if not turtle.detectUp() then
  6865. turtle.up()
  6866. y = y+1
  6867. end
  6868. end
  6869.  
  6870. function down()
  6871. if not turtle.detectDown() then
  6872. turtle.down()
  6873. y = y-1
  6874. end
  6875. end
  6876.  
  6877. function left()
  6878. if face == north then face = west turtle.turnLeft() return end
  6879. if face == west then face = south turtle.turnLeft() return end
  6880. if face == south then face = east turtle.turnLeft() return end
  6881. if face == east then face = north turtle.turnLeft() return end
  6882. print("function left\(\): Bad face value: ", face)
  6883. end
  6884.  
  6885. function right()
  6886. if face == north then face = east turtle.turnRight() return end
  6887. if face == west then face = north turtle.turnRight() return end
  6888. if face == south then face = west turtle.turnRight() return end
  6889. if face == east then face = south turtle.turnRight() return end
  6890. print("function right\(\): Bad face value: ", face)
  6891. end
  6892.  
  6893. function forward()
  6894. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  6895. if turtle.forward() then
  6896. break
  6897. end
  6898. turtle.attack()
  6899. sleep(2)
  6900. end
  6901. areaCovered = areaCovered + 1
  6902.  
  6903. if face == north then z = z+1 return end
  6904. if face == west then x = x-1 return end
  6905. if face == south then z = z-1 return end
  6906. if face == east then x = x+1 return end
  6907. end
  6908.  
  6909. function back()
  6910. turtle.back()
  6911. if face == north then z = z-1 return end
  6912. if face == west then x = x+1 return end
  6913. if face == south then z = z+1 return end
  6914. if face == east then x = x-1 return end
  6915. end
  6916.  
  6917. function wall()
  6918. ensureMaterial()
  6919. turtle.select(materialSlot)
  6920. turtle.placeDown()
  6921. ensureMaterial()
  6922. turtle.select(materialSlot)
  6923. turtle.placeUp()
  6924. back()
  6925. ensureMaterial()
  6926. turtle.select(materialSlot)
  6927. turtle.place()
  6928. ensureMaterial()
  6929. turtle.select(materialSlot)
  6930. turtle.placeDown()
  6931. ensureMaterial()
  6932. turtle.select(materialSlot)
  6933. turtle.placeUp()
  6934. back()
  6935. ensureMaterial()
  6936. turtle.select(materialSlot)
  6937. turtle.place()
  6938. end
  6939.  
  6940. function segment()
  6941. wall()
  6942. left()
  6943. back()
  6944. wall()
  6945. left()
  6946. back()
  6947. wall()
  6948. left()
  6949. back()
  6950. wall()
  6951. end
  6952.  
  6953. function nextLevel()
  6954. if direction == up then
  6955. up()
  6956. up()
  6957. up()
  6958. left()
  6959. back()
  6960. else
  6961. down()
  6962. down()
  6963. down()
  6964. left()
  6965. back()
  6966. end
  6967. end
  6968.  
  6969. function ensureMaterial()
  6970. if turtle.getItemCount(materialSlot) < 3 then
  6971. organizeMaterial()
  6972. end
  6973. if turtle.getItemCount(materialSlot) < 3 then
  6974. print("No more material")
  6975. return false
  6976. end
  6977. return true
  6978. end
  6979.  
  6980. function organizeMaterial()
  6981. local i
  6982. materialCount = turtle.getItemCount(materialSlot)
  6983.  
  6984. if materialCount < 3 then
  6985. -- print("Attempting to refill slot ", materialSlot)
  6986. for i=2,16 do
  6987. turtle.select(i)
  6988. if turtle.compareTo(materialSlot) then
  6989. turtle.transferTo(materialSlot)
  6990. end
  6991. end
  6992. end
  6993. turtle.select(materialSlot)
  6994. end
  6995.  
  6996.  
  6997. if not (nArgs > 1) then
  6998. print(usage)
  6999. return
  7000. end
  7001.  
  7002. direction = args[1]
  7003. if not (direction == "up" or direction == "down") then
  7004. print("\"", args[1], "\" is not a valid direction")
  7005. return
  7006. end
  7007. if direction == "up" then
  7008. direction = up
  7009. else
  7010. direction = down
  7011. end
  7012.  
  7013.  
  7014. levels = tonumber(args[2])
  7015. if levels == nil then
  7016. print("\"", args[2], "\" is not valid for levels")
  7017. return
  7018. end
  7019. if levels < 1 then
  7020. print("levels must be a positive number greater than zero")
  7021. return
  7022. end
  7023. levels = tonumber(args[2])
  7024.  
  7025. if nArgs == 3 then
  7026. if args[3] == "true" then
  7027. returnToEarth = true
  7028. elseif args[3] == "false" then
  7029. returnToEarth = false
  7030. else
  7031. print("3rd argument must be 'true' or 'false'")
  7032. return
  7033. end
  7034. end
  7035.  
  7036. up()
  7037. for i=1,levels do
  7038. segment()
  7039. if i < levels then
  7040. nextLevel()
  7041. end
  7042. end
  7043.  
  7044. up()
  7045. up()
  7046. left()
  7047. back()
  7048. back()
  7049. back()
  7050. back()
  7051. down()
  7052. if returnToEarth then
  7053. turtle.select(ladderSlot)
  7054. while y > 0 do
  7055. turtle.place()
  7056. if y > 0 then
  7057. down()
  7058. end
  7059. end
  7060. turtle.place()
  7061. end
  7062. *** quarry
  7063. -- quarry
  7064. -- Mines a quarry to the dimensions supplied by the user
  7065. -- Turtle drops the spoils on coveyer belts by 3 types
  7066. -- Turtle returns to its starting point when mission is completed or fuel runs low
  7067. -- Written by HarvDad, April 2014
  7068.  
  7069. args = {...}
  7070. nArgs = #args
  7071.  
  7072. print("quarry: Rev 3.0")
  7073. x = 0
  7074. y = 0
  7075. z = 0
  7076. face = 0
  7077. minimumFuel = 100
  7078. missionMessage = "Mission complete."
  7079. notDone = true
  7080. abort = false
  7081. local currentFuelLevel = turtle.getFuelLevel()
  7082. rockBottom = 0
  7083.  
  7084. -- The following 'face' directions are relative to the starting position of the turtle in this program
  7085. north = 0
  7086. west = 1
  7087. south = 2
  7088. east = 3
  7089.  
  7090. -- Status data for marking a spot to return to after going 'home'
  7091.  
  7092. markX = 0
  7093. markY = 0
  7094. markZ = 0
  7095. markFace = 0
  7096.  
  7097. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  7098. print("Quarry an area specified by the given length, width, and height")
  7099. print("Usage: Quarry <length> <width> [height]")
  7100. return
  7101. end
  7102.  
  7103. if nArgs ~= 3 then
  7104. print("Usage: Quarry <length> <width> [height]")
  7105. return
  7106. end
  7107.  
  7108. length = tonumber(args[1])
  7109. if length == nil then
  7110. print("\"", args[1], "\" is not a valid length")
  7111. return
  7112. end
  7113. if length < 1 then
  7114. print("length must be a positive number greater than zero")
  7115. end
  7116.  
  7117. width = tonumber(args[2])
  7118. if width == nil then
  7119. print("\"", args[2], "\" is not a valid width")
  7120. return
  7121. end
  7122. if width < 1 then
  7123. print("width must be a positive number greater than zero")
  7124. end
  7125.  
  7126. height = tonumber(args[3])
  7127. if height == nil then
  7128. print("\"", args[3], "\" is not a valid height")
  7129. return
  7130. end
  7131. if height < 1 then
  7132. print("height must be a positive number greater than zero")
  7133. end
  7134.  
  7135. targetArea = length * width
  7136. areaCovered = 1;
  7137.  
  7138. function chomp()
  7139. while turtle.detect() do
  7140. turtle.dig()
  7141. end
  7142. areaCovered = areaCovered+1
  7143. end
  7144.  
  7145. direction = "left"
  7146.  
  7147. local clock = os.clock
  7148. function sleep(n) -- seconds
  7149. local t0 = clock()
  7150. while clock() - t0 <= n do end
  7151. end
  7152.  
  7153. function left()
  7154. if face == 0 then face = 1 turtle.turnLeft() return end
  7155. if face == 1 then face = 2 turtle.turnLeft() return end
  7156. if face == 2 then face = 3 turtle.turnLeft() return end
  7157. if face == 3 then face = 0 turtle.turnLeft() return end
  7158. print("function left\(\): Bad face value: ", face)
  7159. end
  7160.  
  7161. function right()
  7162. if face == 0 then face = 3 turtle.turnRight() return end
  7163. if face == 1 then face = 0 turtle.turnRight() return end
  7164. if face == 2 then face = 1 turtle.turnRight() return end
  7165. if face == 3 then face = 2 turtle.turnRight() return end
  7166. print("function right\(\): Bad face value: ", face)
  7167. end
  7168.  
  7169. function up()
  7170. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  7171. turtle.digUp()
  7172. end
  7173. while not turtle.up() do
  7174. turtle.attackUp()
  7175. sleep(2)
  7176. end
  7177. y = y+1
  7178. end
  7179.  
  7180. function rise(nBlocks)
  7181. local i
  7182. for i=1,nBlocks do
  7183. up()
  7184. end
  7185. end
  7186.  
  7187. function down()
  7188. if turtle.detectDown() then
  7189. if not turtle.digDown() then
  7190. print("Unable to dig down. Assuming bedrock")
  7191. rockBottom = y
  7192. return
  7193. end
  7194. end
  7195. while not turtle.down() do
  7196. turtle.attackDown()
  7197. sleep(2)
  7198. end
  7199. y = y-1
  7200. end
  7201.  
  7202. function turn()
  7203. if direction == "left" then
  7204. left()
  7205. else
  7206. right()
  7207. end
  7208. -- chomp()
  7209. forward(true)
  7210. if direction == "left" then
  7211. left()
  7212. direction = "right"
  7213. else
  7214. right()
  7215. direction = "left"
  7216. end
  7217. end
  7218.  
  7219. function startNextRow()
  7220. if direction == "left" then
  7221. left()
  7222. else
  7223. right()
  7224. end
  7225. forward(true)
  7226. turtle.digUp()
  7227. turtle.digDown()
  7228. if direction == "left" then
  7229. left()
  7230. direction = "right"
  7231. else
  7232. right()
  7233. direction = "left"
  7234. end
  7235. end
  7236.  
  7237. function forward(keepTrackOfArea)
  7238. while turtle.detect() do -- This loop added in case of falling sand or whatever
  7239. turtle.dig()
  7240. end
  7241. for i=1,10 do
  7242. if turtle.forward() then
  7243. if keepTrackOfArea then
  7244. areaCovered = areaCovered + 1
  7245. end
  7246. break
  7247. end
  7248. turtle.attack()
  7249. sleep(2)
  7250. end
  7251. if face == 0 then z = z+1 return end
  7252. if face == 1 then x = x-1 return end
  7253. if face == 2 then z = z-1 return end
  7254. if face == 3 then x = x+1 return end
  7255. end
  7256.  
  7257. function setFace(f)
  7258. if f == 0 then
  7259. if face == 0 then return end
  7260. if face == 1 then right() return end
  7261. if face == 2 then right() right() return end
  7262. if face == 3 then left() return end
  7263. end
  7264.  
  7265. if f == 1 then
  7266. if face == 0 then left() return end
  7267. if face == 1 then return end
  7268. if face == 2 then right() return end
  7269. if face == 3 then right() right() return end
  7270. end
  7271.  
  7272. if f == 2 then
  7273. if face == 0 then left() left() return end
  7274. if face == 1 then left() return end
  7275. if face == 2 then return end
  7276. if face == 3 then right() return end
  7277. end
  7278.  
  7279. if f == 3 then
  7280. if face == 0 then right() return end
  7281. if face == 1 then left() left() return end
  7282. if face == 2 then left() return end
  7283. if face == 3 then return end
  7284. end
  7285. end
  7286.  
  7287. function home(targetY)
  7288. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  7289. if x < 0 then
  7290. setFace(3)
  7291. while x < 0 do
  7292. forward()
  7293. end
  7294. else
  7295. if x > 0 then
  7296. setFace(1)
  7297. while x > 0 do
  7298. forward()
  7299. end
  7300. end
  7301. end
  7302.  
  7303. if z < 0 then
  7304. setFace(0)
  7305. while z < 0 do
  7306. forward()
  7307. end
  7308. else
  7309. if z > 0 then
  7310. setFace(2)
  7311. while z > 0 do
  7312. forward()
  7313. end
  7314. end
  7315. end
  7316. setFace(0)
  7317.  
  7318. if (targetY == 0) then
  7319. while y < 0 do
  7320. up()
  7321. end
  7322. end
  7323. end
  7324.  
  7325. function strip(nBlocks)
  7326. local i
  7327. for i=1,nBlocks do
  7328. forward(true)
  7329. turtle.digUp()
  7330. turtle.digDown()
  7331. end
  7332. end
  7333.  
  7334.  
  7335. function checkFuel()
  7336. if currentFuelLevel == "unlimited" then
  7337. return true
  7338. end
  7339.  
  7340. if currentFuelLevel < minimumFuel then
  7341. if not turtle.refuel() then
  7342. areaCovered = targetArea
  7343. missionMessage = "Mission aborted due to low fuel."
  7344. abort = true
  7345. return false
  7346. end
  7347. end
  7348. return true
  7349. end
  7350.  
  7351. cobbleSlot = 2
  7352. dirtSlot = 1
  7353. dirtConveyor = -4
  7354. cobbleConveyor = -3
  7355. oresConveyor = -2
  7356. dumpLevel = 1
  7357.  
  7358.  
  7359. function goEmptyInventoryToChestAndReturn()
  7360. saveAreaCovered = areaCovered
  7361. markX = x
  7362. markY = y
  7363. markZ = z
  7364. markFace = face
  7365.  
  7366. home()
  7367. setFace(east)
  7368. while y > 0 do
  7369. down()
  7370. end
  7371. dump()
  7372. while y < markY do
  7373. up()
  7374. end
  7375. returnToMark()
  7376. areaCovered = saveAreaCovered
  7377. end
  7378.  
  7379. function returnToMark()
  7380. if markZ < z then
  7381. setFace(south)
  7382. while z > markZ do
  7383. forward(false)
  7384. end
  7385. else
  7386. if markZ > z then
  7387. setFace(north)
  7388. while z < markZ do
  7389. forward(false)
  7390. end
  7391. end
  7392. end
  7393.  
  7394. if markX < 0 then
  7395. setFace(west)
  7396. while x > markX do
  7397. forward(false)
  7398. end
  7399. else
  7400. if markX > 0 then
  7401. setFace(east)
  7402. while x < markX do
  7403. forward(false)
  7404. end
  7405. end
  7406. end
  7407.  
  7408. while y > markY do
  7409. down()
  7410. end
  7411.  
  7412. setFace(markFace)
  7413. end
  7414.  
  7415. function dumpItemType(typeSlot)
  7416. if typeSlot > 0 then
  7417. turtle.select(typeSlot)
  7418. dropCount = turtle.getItemCount(typeSlot)
  7419. if dropCount > 1 then
  7420. turtle.dropDown(dropCount - 1)
  7421. end
  7422. for i = 3,16 do
  7423. turtle.select(i)
  7424. if turtle.compareTo(typeSlot) then
  7425. turtle.dropDown()
  7426. end
  7427. end
  7428. else
  7429. for i = 3,16 do
  7430. if turtle.getItemCount(i) > 0 then
  7431. turtle.select(i)
  7432. turtle.dropDown()
  7433. end
  7434. end
  7435. end
  7436. end
  7437.  
  7438. function dumpAll()
  7439. saveAreaCovered = areaCovered
  7440. markX = x
  7441. markY = y
  7442. markZ = z
  7443. markFace = face
  7444.  
  7445. setFace (south)
  7446. while y < dumpLevel do
  7447. up()
  7448. end
  7449. while z > dirtConveyor do
  7450. forward(false)
  7451. end
  7452. dumpItemType(dirtSlot)
  7453.  
  7454. setFace(north)
  7455. forward(false)
  7456. dumpItemType(cobbleSlot)
  7457. forward(false)
  7458. dumpItemType(0)
  7459. turtle.select(dirtSlot)
  7460.  
  7461. returnToMark()
  7462. end
  7463.  
  7464. currentLevel = 255
  7465.  
  7466.  
  7467. -- MAIN PROGRAM
  7468.  
  7469. print("fuelLevel = ", currentFuelLevel)
  7470. print("length = ", length)
  7471. print("width = ", width)
  7472. print("height = ", height)
  7473. print("face = ", face)
  7474.  
  7475. print("Current Fuel Level: ", currentFuelLevel)
  7476.  
  7477. while notDone do
  7478.  
  7479. dumpLevel = 1
  7480. turtle.select(1)
  7481.  
  7482. if currentFuelLevel ~= "unlimited" then
  7483. if currentFuelLevel < minimumFuel then
  7484. if not turtle.refuel() then
  7485. print("No fuel")
  7486. return
  7487. end
  7488. end
  7489. end
  7490.  
  7491. if currentLevel == rockBottom then
  7492. missionMessage = "Hit rock bottom. "
  7493. break
  7494. end
  7495.  
  7496. down()
  7497. down()
  7498. turtle.digDown()
  7499.  
  7500. for w=1,width do
  7501. strip(length-1)
  7502. if z == 0 and x ~= 0 then
  7503. currentLevel = y
  7504. dumpAll()
  7505. while y > currentLevel do
  7506. down()
  7507. end
  7508. end
  7509. if areaCovered < targetArea then
  7510. startNextRow()
  7511. end
  7512. if abort then
  7513. home(0)
  7514. end
  7515. end
  7516. home(99)
  7517. down()
  7518. areaCovered = 1
  7519. direction = "left"
  7520. end
  7521.  
  7522. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
  7523. home(0)
  7524. *** r
  7525. -- r
  7526. -- Turns and/or move the turtle to the right
  7527. -- Written by HarvDad, March 2014
  7528.  
  7529. args = {...}
  7530. nArgs = #args
  7531.  
  7532. x = 0
  7533. y = 0
  7534. z = 0
  7535. face = 0
  7536. minimumFuel = 100
  7537. abort = false
  7538. local currentFuelLevel = turtle.getFuelLevel()
  7539. distance = nil;
  7540.  
  7541. if (nArgs == 1 and args[1]== "help") then
  7542. print("Turns and/or moves the turtle to the right")
  7543. print("Usage: r [distance]")
  7544. return
  7545. end
  7546.  
  7547. if nArgs == 1 then
  7548. distance = tonumber(args[1])
  7549. if distance == nil then
  7550. print(args[1], " is not a valid distance")
  7551. return
  7552. end
  7553. end
  7554.  
  7555. -- MAIN PROGRAM
  7556.  
  7557. turtle.turnRight()
  7558.  
  7559. if distance ~= nil then
  7560. turtle.select(1)
  7561.  
  7562. if currentFuelLevel ~= "unlimited" then
  7563. if currentFuelLevel < minimumFuel then
  7564. if not turtle.refuel() then
  7565. print("No fuel")
  7566. return
  7567. end
  7568. end
  7569. end
  7570.  
  7571. for i=1,distance do
  7572. turtle.forward()
  7573. end
  7574. end
  7575.  
  7576. *** rmall
  7577. -- rmall: Delete all files listed here
  7578. -- Version 0.1
  7579.  
  7580. files = {
  7581. "allfiles",
  7582. "b",
  7583. "branch",
  7584. "build",
  7585. "bwb",
  7586. "cactus",
  7587. "chute",
  7588. "clear",
  7589. "collect",
  7590. "copyall",
  7591. "d",
  7592. "dump",
  7593. "eatlava",
  7594. "f",
  7595. "fabdrain",
  7596. "floor",
  7597. "l",
  7598. "logger",
  7599. "ores",
  7600. "quarry",
  7601. "r",
  7602. "room",
  7603. "shaft",
  7604. "sifter",
  7605. "sprinkle",
  7606. "suck",
  7607. "tree",
  7608. "trees",
  7609. "tube",
  7610. "u",
  7611. "wall",
  7612. "walls",
  7613. "wt"
  7614. }
  7615.  
  7616. count = 0
  7617.  
  7618. for i=1,#files do
  7619. if (shell.run("rm " .. files[i])) ~= nil then
  7620. count = count + 1
  7621. end
  7622. end
  7623.  
  7624. print("Files deleted: ", count)
  7625. *** room
  7626. -- room
  7627. -- Creates a room with solid walls
  7628. -- Clears the interior
  7629. -- Turtle returns to its starting point when mission is completed or fuel runs low
  7630. -- Written by HarvDad, March 2014
  7631.  
  7632. args = {...}
  7633. nArgs = #args
  7634. version = "room: Rev 3.2"
  7635. usage = "Usage: room <length> <width> <height>"
  7636.  
  7637. x = 0
  7638. y = 0
  7639. z = 0
  7640. face = 0
  7641. minimumFuel = 100
  7642. missionMessage = "Mission complete."
  7643. abort = false
  7644. local currentFuelLevel = turtle.getFuelLevel()
  7645. patchSlot = 1
  7646. chestSlot = 15
  7647. torchSlot = 16
  7648. garbageSlot = 5
  7649. torchSpacing = 2
  7650. torchSpot = 5
  7651. nextTurn = "left"
  7652. addTorches = false
  7653.  
  7654. -- Status data for marking a spot to return to after going 'home'
  7655.  
  7656. markX = 0
  7657. markY = 0
  7658. markZ = 0
  7659. markFace = 0
  7660.  
  7661. -- The following 'face' directions are relative to the starting position of the turtle in this program
  7662. north = 0
  7663. west = 1
  7664. south = 2
  7665. east = 3
  7666.  
  7667. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  7668. print(version)
  7669. print("Creates a room with solid walls")
  7670. print("Clears the interior")
  7671. print("Turtle should be pre-fueled")
  7672. print("Slot 1 is for patch material")
  7673. print("Slot 5 is for garbage material")
  7674. print("Slot 15 is for storage chests")
  7675. print("Slot 16 is for torches")
  7676. print(usage)
  7677. return
  7678. end
  7679.  
  7680. if nArgs ~= 3 then
  7681. print(usage)
  7682. return
  7683. end
  7684.  
  7685. length = tonumber(args[1])
  7686. if length == nil then
  7687. print("\"", args[1], "\" is not a valid length")
  7688. return
  7689. end
  7690. if length < 1 then
  7691. print("length must be a positive number greater than zero")
  7692. end
  7693.  
  7694. width = tonumber(args[2])
  7695. if width == nil then
  7696. print("\"", args[2], "\" is not a valid width")
  7697. return
  7698. end
  7699. if width < 1 then
  7700. print("width must be a positive number greater than zero")
  7701. end
  7702.  
  7703. height = tonumber(args[3])
  7704. if height == nil then
  7705. print("\"", args[3], "\" is not a valid height")
  7706. return
  7707. end
  7708. if height < 1 then
  7709. print("height must be a positive number greater than zero")
  7710. end
  7711.  
  7712. targetArea = length * width
  7713. areaCovered = 1;
  7714.  
  7715. function patch()
  7716. if turtle.getItemCount(patchSlot) < 2 then
  7717. gatherPatchMaterial()
  7718. if turtle.getItemCount(patchSlot) < 2 then
  7719. abort = true
  7720. areaCovered = targetArea
  7721. missionMessage = "Aborted: No more wall patch"
  7722. return
  7723. end
  7724. end
  7725. turtle.select(patchSlot)
  7726. turtle.place()
  7727. end
  7728.  
  7729. function patchUp()
  7730. if turtle.getItemCount(patchSlot) < 2 then
  7731. gatherPatchMaterial()
  7732. if turtle.getItemCount(patchSlot) < 2 then
  7733. abort = true
  7734. areaCovered = targetArea
  7735. missionMessage = "Aborted: No more patch material"
  7736. return
  7737. end
  7738. end
  7739. turtle.select(patchSlot)
  7740. turtle.placeUp()
  7741. gatherPatchMaterial();
  7742. end
  7743.  
  7744. function patchDown()
  7745. if turtle.getItemCount(patchSlot) < 2 then
  7746. gatherPatchMaterial()
  7747. if turtle.getItemCount(patchSlot) < 2 then
  7748. abort = true
  7749. areaCovered = targetArea
  7750. missionMessage = "Aborted: No more patch material"
  7751. return
  7752. end
  7753. end
  7754. turtle.select(patchSlot)
  7755. turtle.placeUp()
  7756. gatherPatchMaterial();
  7757. end
  7758.  
  7759. function patchDown()
  7760. turtle.select(patchSlot)
  7761. turtle.placeDown()
  7762. gatherPatchMaterial();
  7763. end
  7764.  
  7765. function gatherPatchMaterial()
  7766. local i
  7767. patchCount = turtle.getItemCount(patchSlot)
  7768. garbageCount = turtle.getItemCount(garbageSlot)
  7769.  
  7770. if patchCount < 3 or garbageCount < 20 then
  7771. -- print("Attempting to refill slot ", patchSlot)
  7772. for i=2,14 do
  7773. turtle.select(i)
  7774. if turtle.compareTo(patchSlot) then
  7775. turtle.transferTo(patchSlot, 64-patchCount)
  7776. -- print("Transferred ", 64 - patchCount, " cobble to slot ", patchSlot)
  7777. end
  7778. if turtle.compareTo(garbageSlot) then
  7779. turtle.transferTo(garbageSlot)
  7780. end
  7781. end
  7782. end
  7783. turtle.select(patchSlot)
  7784. end
  7785.  
  7786. function left()
  7787. if face == 0 then face = 1 turtle.turnLeft() return end
  7788. if face == 1 then face = 2 turtle.turnLeft() return end
  7789. if face == 2 then face = 3 turtle.turnLeft() return end
  7790. if face == 3 then face = 0 turtle.turnLeft() return end
  7791. print("function left\(\): Bad face value: ", face)
  7792. end
  7793.  
  7794. function right()
  7795. if face == 0 then face = 3 turtle.turnRight() return end
  7796. if face == 1 then face = 0 turtle.turnRight() return end
  7797. if face == 2 then face = 1 turtle.turnRight() return end
  7798. if face == 3 then face = 2 turtle.turnRight() return end
  7799. print("function right\(\): Bad face value: ", face)
  7800. end
  7801.  
  7802. function up()
  7803. for i=1,10 do
  7804. if not turtle.up() then
  7805. if turtle.detectUp() then
  7806. digUp()
  7807. else
  7808. turtle.attackUp()
  7809. sleep(2)
  7810. end
  7811. else
  7812. break
  7813. end
  7814. end
  7815. y = y+1
  7816. end
  7817.  
  7818. function down()
  7819. for i=1,10 do
  7820. if not turtle.down() then
  7821. if turtle.detectDown() then
  7822. digDown()
  7823. else
  7824. turtle.attackDown()
  7825. sleep(2)
  7826. end
  7827. else
  7828. break
  7829. end
  7830. end
  7831. y = y-1
  7832. end
  7833.  
  7834. function goEmptyInventoryToChestAndReturn()
  7835. saveAreaCovered = areaCovered
  7836. markX = x
  7837. markY = y
  7838. markZ = z
  7839. markFace = face
  7840.  
  7841. home()
  7842. setFace(east)
  7843. while y > 0 do
  7844. down()
  7845. end
  7846. dump()
  7847. while y < markY do
  7848. up()
  7849. end
  7850. returnToMark()
  7851. areaCovered = saveAreaCovered
  7852. end
  7853.  
  7854. function returnToMark()
  7855. if markZ < z then
  7856. setFace(south)
  7857. while z > markZ do
  7858. forward(false)
  7859. end
  7860. else
  7861. if markZ > z then
  7862. setFace(north)
  7863. while z < markZ do
  7864. forward(false)
  7865. end
  7866. end
  7867. end
  7868.  
  7869. if markX < 0 then
  7870. setFace(west)
  7871. while x > markX do
  7872. forward(false)
  7873. end
  7874. else
  7875. if markX > 0 then
  7876. setFace(east)
  7877. while x < markX do
  7878. forward(false)
  7879. end
  7880. end
  7881. end
  7882.  
  7883. while y > markY do
  7884. down()
  7885. end
  7886.  
  7887. setFace(markFace)
  7888. end
  7889.  
  7890. function dig()
  7891. if noMoreEmptySlots() then
  7892. -- jettisonGarbage()
  7893. goEmptyInventoryToChestAndReturn()
  7894. end
  7895. turtle.dig()
  7896. end
  7897.  
  7898. function digUp()
  7899. if noMoreEmptySlots() then
  7900. -- jettisonGarbage()
  7901. goEmptyInventoryToChestAndReturn()
  7902. end
  7903. turtle.digUp()
  7904. end
  7905.  
  7906. function digDown()
  7907. if noMoreEmptySlots() then
  7908. -- jettisonGarbage()
  7909. goEmptyInventoryToChestAndReturn()
  7910. end
  7911. turtle.digDown()
  7912. end
  7913.  
  7914. function noMoreEmptySlots()
  7915. return (turtle.getItemCount(14) > 0)
  7916. end
  7917.  
  7918.  
  7919. function setFace(f)
  7920. if f == 0 then
  7921. if face == 0 then return end
  7922. if face == 1 then right() return end
  7923. if face == 2 then right() right() return end
  7924. if face == 3 then left() return end
  7925. end
  7926.  
  7927. if f == 1 then
  7928. if face == 0 then left() return end
  7929. if face == 1 then return end
  7930. if face == 2 then right() return end
  7931. if face == 3 then right() right() return end
  7932. end
  7933.  
  7934. if f == 2 then
  7935. if face == 0 then left() left() return end
  7936. if face == 1 then left() return end
  7937. if face == 2 then return end
  7938. if face == 3 then right() return end
  7939. end
  7940.  
  7941. if f == 3 then
  7942. if face == 0 then right() return end
  7943. if face == 1 then left() left() return end
  7944. if face == 2 then left() return end
  7945. if face == 3 then return end
  7946. end
  7947. end
  7948.  
  7949. -- digAboveForward: This function requires that the current level is already cleared
  7950.  
  7951. function DigAboveForward()
  7952. while turtle.detect() do -- This loop added in case of falling sand or whatever
  7953. turtle.dig()
  7954. end
  7955. end
  7956.  
  7957. function forward(keepTrackOfArea)
  7958. if keepTrackOfArea == nil then
  7959. keepTrackOfArea = true
  7960. end
  7961. turtle.select(chestSlot)
  7962. if not turtle.compare() then
  7963. turtle.select(garbageSlot)
  7964. turtle.place() -- in case we're facing an undectable water/lava source block, replace
  7965. end
  7966. turtle.select(patchSlot)
  7967. while turtle.detect() do -- This loop added in case of falling sand or whatever
  7968. dig()
  7969. end
  7970. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  7971. if not turtle.forward() then
  7972. if turtle.detect() then
  7973. dig()
  7974. else
  7975. turtle.attack()
  7976. sleep(2)
  7977. end
  7978. else
  7979. break
  7980. end
  7981. end
  7982. if keepTrackOfArea then
  7983. areaCovered = areaCovered + 1
  7984. end
  7985. torchCheck()
  7986.  
  7987. if face == 0 then z = z+1 return end
  7988. if face == 1 then x = x-1 return end
  7989. if face == 2 then z = z-1 return end
  7990. if face == 3 then x = x+1 return end
  7991. end
  7992.  
  7993. function sealRow(distance)
  7994. local count = 0
  7995.  
  7996. turtle.select(patchSlot)
  7997. for count=1,distance do
  7998. if y == height-1 then
  7999. patchUp()
  8000. if height > 1 then
  8001. turtle.digDown()
  8002. end
  8003. -- turtle.placeUp() -- experiment: if solid block is there it will just fail. Maybe help with lava/water?
  8004. end
  8005. if y == 0 then
  8006. patchDown()
  8007. if height > 1 then
  8008. while turtle.detectUp() do
  8009. turtle.digUp()
  8010. end
  8011. end
  8012. end
  8013. right()
  8014. patch()
  8015. left()
  8016. if count < distance then
  8017. forward()
  8018. end
  8019. end
  8020. end
  8021.  
  8022. function torchCheck()
  8023. if addTorches then
  8024. if y == 1 then
  8025. if (x % torchSpacing) == 0 then
  8026. if (z % torchSpacing) == 0 then
  8027. turtle.select(torchSlot)
  8028. turtle.placeDown()
  8029. end
  8030. end
  8031. end
  8032. end
  8033. turtle.select(patchSlot)
  8034. end
  8035.  
  8036. function clearLevel()
  8037. areaCovered = 0
  8038.  
  8039. setFace(west)
  8040. forward()
  8041. setFace(north)
  8042. forward()
  8043. if y == height-1 then
  8044. turtle.select(patchSlot)
  8045. turtle.placeUp()
  8046. end
  8047. nextTurn = "left"
  8048. areaCovered = 0
  8049.  
  8050. while areaCovered < targetArea do
  8051. if abort then
  8052. break
  8053. end
  8054. for w=1,width-2 do
  8055. if abort then
  8056. -- print("clearLevel: ABORT ABORT ABORT")
  8057. break
  8058. end
  8059. for l=1,length-2 do
  8060. if abort then
  8061. break
  8062. end
  8063. if l < length-2 then
  8064. forward()
  8065. if (y == 0) then
  8066. turtle.placeDown()
  8067. if height > 1 then
  8068. while turtle.detectUp() do
  8069. turtle.digUp()
  8070. end
  8071. end
  8072. end
  8073. if y == height-1 then
  8074. turtle.select(patchSlot) -- experiment: if solid block is there, it will just fail. Who cares?
  8075. if turtle.getItemCount(patchSlot) < 1 then
  8076. print("clearLevel: Ran out of patch material!")
  8077. end
  8078. turtle.placeUp()
  8079. if height > 1 then
  8080. turtle.digDown()
  8081. end
  8082. end
  8083. end
  8084. end
  8085.  
  8086. if w == width-2 then
  8087. -- print("There's no more to do at this level. Bailing out.")
  8088. levelsCompleted = levelsCompleted + 1
  8089. return
  8090. end
  8091. if w <= width-3 then
  8092. if nextTurn == "left" then
  8093. left()
  8094. forward()
  8095.  
  8096. if y == 0 then
  8097. if height > 1 then
  8098. while turtle.detectUp() do
  8099. turtle.digUp()
  8100. end
  8101. end
  8102. turtle.placeDown()
  8103. end
  8104.  
  8105. if y == height-1 then
  8106. turtle.select(patchSlot)
  8107. turtle.placeUp()
  8108. if height > 1 then
  8109. turtle.digDown()
  8110. end
  8111. end
  8112.  
  8113. left()
  8114. nextTurn = "right"
  8115. else
  8116. right()
  8117. forward()
  8118.  
  8119. if y == 0 then
  8120. if height > 1 then
  8121. while turtle.detectUp() do
  8122. turtle.digUp()
  8123. end
  8124. end
  8125. turtle.placeDown()
  8126. end
  8127.  
  8128. if y == height-1 then
  8129. turtle.select(patchSlot)
  8130. turtle.placeUp()
  8131. if height > 1 then
  8132. turtle.digDown()
  8133. end
  8134. end
  8135.  
  8136. right()
  8137. nextTurn = "left"
  8138. end
  8139. else
  8140. break
  8141. end
  8142. end
  8143. end
  8144. levelsCompleted = levelsCompleted + 1
  8145. end
  8146.  
  8147. function bounce()
  8148. local saveY = y
  8149. for i=1,255 do
  8150. if y > 0 then
  8151. turtle.down()
  8152. y = y - 1
  8153. else
  8154. break
  8155. end
  8156. end
  8157. dump()
  8158. while y<saveY do
  8159. turtle.up()
  8160. y = y + 1
  8161. end
  8162. end
  8163.  
  8164. function sealLevel()
  8165. sealRow(length)
  8166. left()
  8167. sealRow(width)
  8168. left()
  8169. sealRow(length)
  8170. left()
  8171. sealRow(width)
  8172. left()
  8173. end
  8174.  
  8175. function sealWalls()
  8176. local i = 0
  8177. for i=1,height do
  8178. sealLevel()
  8179. if y ~= 1 then
  8180. clearLevel()
  8181. end
  8182. if i < height then
  8183. up()
  8184. home()
  8185. end
  8186. end
  8187. end
  8188.  
  8189. function sealCeiling()
  8190. areaCovered = 0
  8191.  
  8192. while areaCovered < targetArea do
  8193. if abort then
  8194. break
  8195. end
  8196. for w=1,width do
  8197. if abort then
  8198. break
  8199. end
  8200. for z=1,length do
  8201. if abort then
  8202. break
  8203. end
  8204. if not turtle.detectUp() then
  8205. patchUp()
  8206. end
  8207. if z < length then
  8208. forward()
  8209. end
  8210. end
  8211. if w < width then
  8212. if nextTurn == "left" then
  8213. left()
  8214. forward()
  8215. left()
  8216. nextTurn = "right"
  8217. else
  8218. right()
  8219. forward()
  8220. right()
  8221. nextTurn = "left"
  8222. end
  8223. else
  8224. return
  8225. end
  8226. end
  8227. end
  8228. end
  8229.  
  8230. function sealFloor()
  8231. areaCovered = 0
  8232.  
  8233. while areaCovered < targetArea do
  8234. if abort then
  8235. break
  8236. end
  8237. for w=1,width do
  8238. if abort then
  8239. break
  8240. end
  8241. for z=1,length do
  8242. if abort then
  8243. break
  8244. end
  8245. if not turtle.detectDown() then
  8246. patchDown()
  8247. end
  8248. while turtle.detectUp() do
  8249. turtle.digUp()
  8250. end
  8251. if z < length then
  8252. forward()
  8253. end
  8254. end
  8255. if w < width then
  8256. if nextTurn == "left" then
  8257. left()
  8258. forward()
  8259. left()
  8260. nextTurn = "right"
  8261. else
  8262. right()
  8263. forward()
  8264. right()
  8265. nextTurn = "left"
  8266. end
  8267. else
  8268. return
  8269. end
  8270. end
  8271. end
  8272. end
  8273.  
  8274. function dump()
  8275. turtle.select(chestSlot)
  8276. if not turtle.compareDown() then
  8277. turtle.digDown()
  8278. turtle.placeDown()
  8279. setFace(west)
  8280. forward()
  8281. turtle.digDown()
  8282. turtle.select(chestSlot)
  8283. turtle.placeDown()
  8284. setFace(east)
  8285. forward()
  8286. setFace(north)
  8287. end
  8288.  
  8289. gatherPatchMaterial()
  8290. for i=2,4 do
  8291. turtle.select(i)
  8292. if not turtle.compareTo(patchSlot) then
  8293. if not turtle.dropDown() then
  8294. print("Dump failed. Chest is full.")
  8295. return
  8296. end
  8297. end
  8298. end
  8299. for i=6,14 do
  8300. turtle.select(i)
  8301. if turtle.getItemCount(i) > 0 then
  8302. if not turtle.dropDown() then
  8303. print("Dump failed. Chest is full.")
  8304. return
  8305. end
  8306. end
  8307. end
  8308. turtle.select(patchSlot)
  8309. setFace(north)
  8310. end
  8311.  
  8312. function home()
  8313. if x < 0 then
  8314. setFace(east)
  8315. while x < 0 do
  8316. forward()
  8317. end
  8318. else
  8319. if x > 0 then
  8320. setFace(west)
  8321. while x > 0 do
  8322. forward()
  8323. end
  8324. end
  8325. end
  8326.  
  8327. if z < 0 then
  8328. setFace(north)
  8329. while z < 0 do
  8330. forward()
  8331. end
  8332. else
  8333. if z > 0 then
  8334. setFace(south)
  8335. while z > 0 do
  8336. forward()
  8337. end
  8338. end
  8339. end
  8340. setFace(north)
  8341. nextTurn = "left"
  8342. end
  8343.  
  8344. function ceiling()
  8345. while y < height-1 do
  8346. up()
  8347. end
  8348. end
  8349.  
  8350. function floor()
  8351. while y > 0 do
  8352. y = y - 1
  8353. turtle.down()
  8354. end
  8355. end
  8356.  
  8357.  
  8358. workHeight = height
  8359. levelsCompleted = 0
  8360.  
  8361. -- Clear the top level and seal the ceiling
  8362.  
  8363. setFace(east)
  8364. turtle.select(patchSlot)
  8365. for i=1,height-1 do
  8366. up()
  8367. patch()
  8368. end
  8369. setFace(north)
  8370. sealLevel()
  8371. home()
  8372. bounce()
  8373. clearLevel()
  8374. home()
  8375. while y > 0 do
  8376. turtle.down()
  8377. y = y-1
  8378. end
  8379. dump()
  8380.  
  8381. -- Clear the first level and seal the floor
  8382.  
  8383. sealLevel()
  8384. home()
  8385. dump()
  8386. clearLevel()
  8387. home()
  8388. dump()
  8389. setFace(north)
  8390.  
  8391. -- Clear the rest of the levels
  8392.  
  8393. addTorches = true -- torchCheck only adds torches when turtle is at level 1
  8394. workHeight = 1
  8395. while levelsCompleted < height do
  8396. while y < workHeight do
  8397. up()
  8398. end
  8399. sealLevel()
  8400. home()
  8401. bounce()
  8402. clearLevel()
  8403. home()
  8404. while y > 0 do
  8405. turtle.down()
  8406. y = y-1
  8407. end
  8408. dump()
  8409. workHeight = workHeight + 1
  8410. end
  8411.  
  8412. home()
  8413. while y > 0 do
  8414. turtle.down()
  8415. y = y-1
  8416. end
  8417.  
  8418. print(missionMessage)
  8419. print("Fuel level is now ", turtle.getFuelLevel())
  8420.  
  8421. *** shaft
  8422. -- shaft
  8423. -- Digs a vertical shaft straight down to the depth specified by the user
  8424. -- If supplied, ladder is placed
  8425. -- Written by HarvDad, March 2014
  8426.  
  8427. args = {...}
  8428. nArgs = #args
  8429.  
  8430. print("shaft: Rev 2.2")
  8431. x = 0
  8432. y = 0
  8433. z = 0
  8434. face = 0
  8435. minimumFuel = 100
  8436. minLevel = 6
  8437. missionMessage = "Mission complete."
  8438. abort = false
  8439. local currentFuelLevel = turtle.getFuelLevel()
  8440. patchSlot = 1
  8441. ladderSlot = 16
  8442. goingUp = false
  8443.  
  8444. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  8445. print("Digs a vertical shaft straight down.")
  8446. print("This program assumes turtle is pre-fueled.")
  8447. print("Usage: shaft <depth>")
  8448. print("Specify the number of blocks to dig down.")
  8449. print("If desired, place ladder in slot ", ladderSlot, ".")
  8450. return
  8451. end
  8452.  
  8453. if nArgs ~= 1 then
  8454. print("Usage: shaft <depth>")
  8455. return
  8456. end
  8457.  
  8458. targetDepth = tonumber(args[1])
  8459. if targetDepth == nil then
  8460. print("\"", args[1], "\" is not a valid depth")
  8461. return
  8462. end
  8463.  
  8464. if (targetDepth < 0) then
  8465. goingUp = true
  8466. end
  8467.  
  8468. depth = 0
  8469.  
  8470.  
  8471. function left()
  8472. if face == 0 then face = 1 turtle.turnLeft() return end
  8473. if face == 1 then face = 2 turtle.turnLeft() return end
  8474. if face == 2 then face = 3 turtle.turnLeft() return end
  8475. if face == 3 then face = 0 turtle.turnLeft() return end
  8476. print("function left\(\): Bad face value: ", face)
  8477. end
  8478.  
  8479. function right()
  8480. if face == 0 then face = 3 turtle.turnRight() return end
  8481. if face == 1 then face = 0 turtle.turnRight() return end
  8482. if face == 2 then face = 1 turtle.turnRight() return end
  8483. if face == 3 then face = 2 turtle.turnRight() return end
  8484. print("function right\(\): Bad face value: ", face)
  8485. end
  8486.  
  8487. function patchWalls()
  8488. if turtle.getItemCount(patchSlot) < 4 then
  8489. gatherPatchMaterial()
  8490. end
  8491.  
  8492. turtle.select(patchSlot)
  8493.  
  8494. turtle.place()
  8495. left()
  8496.  
  8497. turtle.place()
  8498. left()
  8499.  
  8500. turtle.place()
  8501. left()
  8502.  
  8503. turtle.place()
  8504. left()
  8505. end
  8506.  
  8507. function up()
  8508. attackCount = 0
  8509. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  8510. turtle.digUp()
  8511. end
  8512. for i=1,10 do -- This loop tries to handle pests (mob) that might be in the way
  8513. if turtle.up() then
  8514. break
  8515. end
  8516. sleep(2)
  8517. end
  8518. if attackCount > 1 then
  8519. turtle.attackUp()
  8520. end
  8521.  
  8522. gatherPatchMaterial()
  8523.  
  8524. patchWalls()
  8525.  
  8526. setFace(north)
  8527. depth = depth-1
  8528. y = y+1
  8529. end
  8530.  
  8531. function down()
  8532. attackCount = 0
  8533.  
  8534. if depth >= targetDepth then
  8535. print("Hit target depth")
  8536. return
  8537. end
  8538.  
  8539. if turtle.detectDown() then
  8540. turtle.digDown()
  8541. end
  8542. for i=1,10 do -- This loop trys to handle pests (mobs) that might be in the way
  8543. if turtle.down() then
  8544. break
  8545. end
  8546. turtle.attackDown()
  8547. attackCount = attackCount + 1
  8548. sleep(2)
  8549. end
  8550.  
  8551. if attackCount > 1 then
  8552. turtle.suckDown()
  8553. turtle.suckUp()
  8554. end
  8555.  
  8556. gatherPatchMaterial()
  8557.  
  8558. turtle.select(patchSlot)
  8559. if not turtle.detect() then
  8560. turtle.place()
  8561. end
  8562.  
  8563. turtle.turnLeft()
  8564. if not turtle.detect() then
  8565. turtle.place()
  8566. end
  8567.  
  8568. turtle.turnLeft()
  8569. if not turtle.detect() then
  8570. turtle.place()
  8571. end
  8572.  
  8573. turtle.turnLeft()
  8574. if not turtle.detect() then
  8575. turtle.place()
  8576. end
  8577.  
  8578. turtle.turnLeft()
  8579. depth = depth+1
  8580. y = y-1
  8581. end
  8582.  
  8583. function rise(nBlocks)
  8584. local i
  8585. for i=1,nBlocks do
  8586. turtle.up()
  8587. y = y+1
  8588. end
  8589. end
  8590.  
  8591. function gatherPatchMaterial()
  8592. local i
  8593. patchCount = turtle.getItemCount(patchSlot)
  8594.  
  8595. if patchCount < 5 then
  8596. -- print("Attempting to refill slot ", patchSlot)
  8597. for i=2,13 do
  8598. turtle.select(i)
  8599. if turtle.compareTo(patchSlot) then
  8600. turtle.transferTo(patchSlot, 64-patchCount)
  8601. -- print("Transferred ", 64 - patchCount, " cobble to slot ", patchSlot)
  8602. end
  8603. end
  8604. end
  8605. turtle.select(patchSlot)
  8606. end
  8607.  
  8608. function setFace(f)
  8609. if f == 0 then
  8610. if face == 0 then return end
  8611. if face == 1 then right() return end
  8612. if face == 2 then right() right() return end
  8613. if face == 3 then left() return end
  8614. end
  8615.  
  8616. if f == 1 then
  8617. if face == 0 then left() return end
  8618. if face == 1 then return end
  8619. if face == 2 then right() return end
  8620. if face == 3 then right() right() return end
  8621. end
  8622.  
  8623. if f == 2 then
  8624. if face == 0 then left() left() return end
  8625. if face == 1 then left() return end
  8626. if face == 2 then return end
  8627. if face == 3 then right() return end
  8628. end
  8629.  
  8630. if f == 3 then
  8631. if face == 0 then right() return end
  8632. if face == 1 then left() left() return end
  8633. if face == 2 then left() return end
  8634. if face == 3 then return end
  8635. end
  8636. end
  8637.  
  8638. function placeLadderUp()
  8639. if turtle.getItemCount(ladderSlot) < 1 then
  8640. ladderSlot = ladderSlot - 1
  8641. if turtle.getItemCount(ladderSlot) < 1 then
  8642. ladderSlot = ladderSlot - 1
  8643. if turtle.getItemCount(ladderSlot) < 1 then
  8644. ladderSlot = ladderSlot - 1
  8645. if turtle.getItemCount(ladderSlot) < 1 then
  8646. end
  8647. end
  8648. end
  8649. end
  8650. turtle.select(ladderSlot)
  8651. turtle.placeUp()
  8652. end
  8653.  
  8654. function homeUp()
  8655. setFace(north)
  8656. turtle.select(ladderSlot)
  8657. turtle.suckUp() -- in case we have monster guts on top of us
  8658. while y < 0 do
  8659. turtle.up()
  8660. if not turtle.detectDown() then
  8661. turtle.placeDown()
  8662. end
  8663. y = y+1
  8664. end
  8665. end
  8666.  
  8667. function homeDown()
  8668. setFace(north)
  8669. turtle.select(ladderSlot)
  8670. turtle.suckDown() -- in case we have monster guts on top of us
  8671. while y > 0 do
  8672. turtle.down()
  8673. if not turtle.detectDown() then
  8674. placeLadderUp()
  8675. end
  8676. y = y-1
  8677. end
  8678. end
  8679.  
  8680. -- Main program loop
  8681.  
  8682. if goingUp then
  8683. while depth > targetDepth do
  8684. up()
  8685. end
  8686. homeDown()
  8687. else
  8688. while depth < targetDepth do
  8689. down()
  8690. end
  8691. homeUp()
  8692. end
  8693.  
  8694.  
  8695.  
  8696. setFace(north)
  8697. print(missionMessage)
  8698. *** sifter
  8699. -- Sifter: Load contents of chest into specific chests
  8700. -- Rev 1.0
  8701.  
  8702.  
  8703. x = 0
  8704. y = 0
  8705. z = 0
  8706.  
  8707. -- The following 'face' directions are relative to the starting position of the turtle in this program
  8708.  
  8709. north = 0
  8710. west = 1
  8711. south = 2
  8712. east = 3
  8713.  
  8714. face = north
  8715.  
  8716. -- Chest coordinates are relative to the drop chest
  8717. -- x, y, z, dropping direction, turtle slot number
  8718.  
  8719. boneChest = {-4, 0, 0, east, 1}
  8720. pearlChest = {-4, 0, 2, east, 2}
  8721. arrowChest = {-4, 0, 3, east, 3}
  8722.  
  8723. rottenFleshChest = {-2, 0, 6, south, 8}
  8724. heartChest = {0, 0, 6, south, 7}
  8725. junk2Chest = {1, 0, 6, south, -1}
  8726.  
  8727. gunpowderChest = {4, 0, 3, west, 6}
  8728. zombieBrainChest = {4, 0, 2, west, 5}
  8729. stringChest = {4, 0, 0, west, 4}
  8730.  
  8731. boneSlot = 1
  8732. pearlSlot = 2
  8733. arrowSlot = 3
  8734.  
  8735.  
  8736. function uploadDropChest()
  8737. for slot=1,16 do
  8738. turtle.select(slot)
  8739. turtle.suckDown()
  8740. end
  8741. end
  8742.  
  8743. function load(chest, startSlot, endSlot)
  8744. goToChest(chest)
  8745. for slot=startSlot, endSlot do
  8746. turtle.select(slot)
  8747. turtle.suckDown()
  8748. end
  8749. end
  8750.  
  8751. function dropItems(slot)
  8752. turtle.select(slot)
  8753. turtle.drop(turtle.getItemCount(slot) - 1)
  8754. for i=9,16 do
  8755. turtle.select(i)
  8756. if turtle.compareTo(slot) then
  8757. turtle.drop()
  8758. end
  8759. end
  8760. end
  8761.  
  8762. function dump(chest, startSlot, endSlot)
  8763. goToChest(chest)
  8764. for slot=startSlot, endSlot do
  8765. turtle.select(slot)
  8766. turtle.dropDown()
  8767. end
  8768. end
  8769.  
  8770. function unloadInto(chest)
  8771. saveFace = face
  8772. setFace(chest[4])
  8773. slot = chest[5]
  8774. if (slot > 0) then
  8775. dropItems(slot)
  8776. end
  8777. setFace(saveFace)
  8778. end
  8779.  
  8780. function setFace(f)
  8781. if f == 0 then
  8782. if face == 0 then return end
  8783. if face == 1 then right() return end
  8784. if face == 2 then right() right() return end
  8785. if face == 3 then left() return end
  8786. end
  8787.  
  8788. if f == 1 then
  8789. if face == 0 then left() return end
  8790. if face == 1 then return end
  8791. if face == 2 then right() return end
  8792. if face == 3 then right() right() return end
  8793. end
  8794.  
  8795. if f == 2 then
  8796. if face == 0 then left() left() return end
  8797. if face == 1 then left() return end
  8798. if face == 2 then return end
  8799. if face == 3 then right() return end
  8800. end
  8801.  
  8802. if f == 3 then
  8803. if face == 0 then right() return end
  8804. if face == 1 then left() left() return end
  8805. if face == 2 then left() return end
  8806. if face == 3 then return end
  8807. end
  8808. end
  8809.  
  8810. function left()
  8811. if face == 0 then face = 1 turtle.turnLeft() return end
  8812. if face == 1 then face = 2 turtle.turnLeft() return end
  8813. if face == 2 then face = 3 turtle.turnLeft() return end
  8814. if face == 3 then face = 0 turtle.turnLeft() return end
  8815. print("function left\(\): Bad face value: ", face)
  8816. end
  8817.  
  8818. function right()
  8819. if face == 0 then face = 3 turtle.turnRight() return end
  8820. if face == 1 then face = 0 turtle.turnRight() return end
  8821. if face == 2 then face = 1 turtle.turnRight() return end
  8822. if face == 3 then face = 2 turtle.turnRight() return end
  8823. print("function right\(\): Bad face value: ", face)
  8824. end
  8825.  
  8826. function goTo(X, Y, Z)
  8827. print("goTo(", X, ", ", Y, ", ", Z, ")")
  8828. if y == nil then print("y is nil") end
  8829. if Y == nil then print("Y is nil") end
  8830.  
  8831. if y ~= Y then
  8832. if y < Y then
  8833. while y < Y do
  8834. turtle.up()
  8835. y = y + 1
  8836. end
  8837. else
  8838. while y > Y do
  8839. turtle.down()
  8840. y = y - 1
  8841. end
  8842. end
  8843. end
  8844.  
  8845. if x ~= X then
  8846. if x < X then
  8847. setFace(east)
  8848. while x < X do
  8849. turtle.forward()
  8850. x = x + 1
  8851. end
  8852. else
  8853. setFace(west)
  8854. while x > X do
  8855. turtle.forward()
  8856. x = x - 1
  8857. end
  8858. end
  8859. end
  8860.  
  8861. if z ~= Z then
  8862. if z < Z then
  8863. setFace(north)
  8864. while z < Z do
  8865. turtle.forward()
  8866. z = z + 1
  8867. end
  8868. else
  8869. setFace(south)
  8870. while z > Z do
  8871. turtle.forward()
  8872. z = z - 1
  8873. end
  8874. end
  8875. end
  8876. end
  8877.  
  8878. function go(direction, nBlocks)
  8879. setFace(direction)
  8880. forward(nBlocks)
  8881. end
  8882.  
  8883. function back(nBlocks)
  8884. for i=1,nBlocks do
  8885. turtle.back()
  8886. end
  8887. if face == north then z = z - nBlocks end
  8888. if face == south then z = z + nBlocks end
  8889. if face == east then x = x - nBlocks end
  8890. if face == west then x = x + nBlocks end
  8891. end
  8892.  
  8893. function forward(nBlocks)
  8894. for i=1,nBlocks do
  8895. turtle.forward()
  8896. end
  8897. if face == north then z = z + nBlocks end
  8898. if face == south then z = z - nBlocks end
  8899. if face == east then x = x + nBlocks end
  8900. if face == west then x = x - nBlocks end
  8901. end
  8902.  
  8903. function goToChest(chestData)
  8904. back(2)
  8905. goTo(chestData[1], chestData[2], chestData[3])
  8906. setFace(chestData[4])
  8907. end
  8908.  
  8909. function atChest()
  8910. if (x == boneChest[1]) and (z == boneChest[3]) then return boneChest end
  8911. if (x == pearlChest[1]) and (z == pearlChest[3]) then return pearlChest end
  8912. if (x == arrowChest[1]) and (z == arrowChest[3]) then return arrowChest end
  8913.  
  8914. if (x == rottenFleshChest[1]) and (z == rottenFleshChest[3]) then return rottenFleshChest end
  8915. if (x == heartChest[1]) and (z == heartChest[3]) then return heartChest end
  8916. if (x == junk2Chest[1]) and (z == junk2Chest[3]) then return junk2Chest end
  8917.  
  8918. if (x == gunpowderChest[1]) and (z == gunpowderChest[3]) then return gunpowderChest end
  8919. if (x == zombieBrainChest[1]) and (z == zombieBrainChest[3]) then return zombieBrainChest end
  8920. if (x == stringChest[1]) and (z == stringChest[3]) then return stringChest end
  8921.  
  8922. return nil
  8923. end
  8924.  
  8925. function siftRun()
  8926. uploadDropChest()
  8927. back(2)
  8928. setFace(west)
  8929. forward(4)
  8930.  
  8931. setFace(north)
  8932. for i=1,8 do
  8933. forward(1)
  8934. chest = atChest()
  8935. if chest ~= nil then
  8936. unloadInto(chest)
  8937. end
  8938. end
  8939.  
  8940. setFace(east)
  8941. for i=1,8 do
  8942. forward(1)
  8943. chest = atChest()
  8944. if chest ~= nil then
  8945. unloadInto(chest)
  8946. end
  8947. end
  8948.  
  8949. setFace(south)
  8950. for i=1,8 do
  8951. forward(1)
  8952. chest = atChest()
  8953. if chest ~= nil then
  8954. unloadInto(chest)
  8955. end
  8956. end
  8957.  
  8958. forward(3)
  8959. for i=9,16 do
  8960. turtle.select(i)
  8961. turtle.dropDown()
  8962. end
  8963. back(3)
  8964.  
  8965. setFace(west)
  8966. forward(4)
  8967. setFace(north)
  8968. forward(2)
  8969. end
  8970.  
  8971. function home()
  8972. if (face == east) then
  8973. setFace(south)
  8974. while z > -2 do
  8975. turtle.forward()
  8976. z = z - 1
  8977. end
  8978. setFace(east)
  8979. while x < 0 do
  8980. turtle.forward()
  8981. x = x + 1
  8982. end
  8983. setFace(north)
  8984. forward(2)
  8985. else
  8986. setFace(south)
  8987. while z > -2 do
  8988. turtle.forward()
  8989. z = z - 1
  8990. end
  8991. setFace(west)
  8992. while x < 0 do
  8993. turtle.forward()
  8994. x = x + 1
  8995. end
  8996. setFace(north)
  8997. forward(2)
  8998. end
  8999. end
  9000.  
  9001. -- MAIN PROGRAM
  9002.  
  9003.  
  9004. loopCount = 0
  9005. loopInterval = 50 -- Approximately 5 minutes
  9006.  
  9007. siftRun()
  9008. while true do
  9009. if loopCount < loopInterval then
  9010. sleep(2)
  9011. loopCount = loopCount + 1
  9012. else
  9013. siftRun()
  9014. loopCount = 0
  9015. end
  9016. end
  9017.  
  9018. *** sprinkle
  9019. -- sprinkle: Place torches in rectangular pattern on horizontal surface
  9020. -- Version: 1.0
  9021.  
  9022. itemSlot = 16
  9023.  
  9024. x = 0
  9025. y = 0
  9026. z = 0
  9027.  
  9028. -- The following 'face' directions are relative to the starting position of the turtle in this program
  9029.  
  9030. north = 0
  9031. west = 1
  9032. south = 2
  9033. east = 3
  9034.  
  9035. face = north
  9036.  
  9037. length = 9
  9038. width = 9
  9039.  
  9040. interval = 4
  9041.  
  9042. args = {...}
  9043. nArgs = #args
  9044.  
  9045. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  9046. print("Lays down a pattern of items of length and width.")
  9047. print("Usage: sprinkle <length> <width>")
  9048. return
  9049. end
  9050.  
  9051. if nArgs ~= 2 then
  9052. print("Usage: sprinkle <distance>")
  9053. return
  9054. end
  9055.  
  9056. length = tonumber(args[1])
  9057. if length == nil then
  9058. print("\"", args[1], "\" is not a valid length")
  9059. return
  9060. end
  9061. if length < 1 then
  9062. print("length must be a positive number greater than zero")
  9063. return
  9064. end
  9065.  
  9066. width = tonumber(args[2])
  9067. if width == nil then
  9068. print("\"", args[1], "\" is not a valid width")
  9069. return
  9070. end
  9071. if width < 1 then
  9072. print("width must be a positive number greater than zero")
  9073. return
  9074. end
  9075.  
  9076. function left()
  9077. if face == 0 then face = 1 turtle.turnLeft() return end
  9078. if face == 1 then face = 2 turtle.turnLeft() return end
  9079. if face == 2 then face = 3 turtle.turnLeft() return end
  9080. if face == 3 then face = 0 turtle.turnLeft() return end
  9081. print("function left\(\): Bad face value: ", face)
  9082. end
  9083.  
  9084. function right()
  9085. if face == 0 then face = 3 turtle.turnRight() return end
  9086. if face == 1 then face = 0 turtle.turnRight() return end
  9087. if face == 2 then face = 1 turtle.turnRight() return end
  9088. if face == 3 then face = 2 turtle.turnRight() return end
  9089. print("function right\(\): Bad face value: ", face)
  9090. end
  9091.  
  9092. function setFace(f)
  9093. if f == 0 then
  9094. if face == 0 then return end
  9095. if face == 1 then right() return end
  9096. if face == 2 then right() right() return end
  9097. if face == 3 then left() return end
  9098. end
  9099.  
  9100. if f == 1 then
  9101. if face == 0 then left() return end
  9102. if face == 1 then return end
  9103. if face == 2 then right() return end
  9104. if face == 3 then right() right() return end
  9105. end
  9106.  
  9107. if f == 2 then
  9108. if face == 0 then left() left() return end
  9109. if face == 1 then left() return end
  9110. if face == 2 then return end
  9111. if face == 3 then right() return end
  9112. end
  9113.  
  9114. if f == 3 then
  9115. if face == 0 then right() return end
  9116. if face == 1 then left() left() return end
  9117. if face == 2 then left() return end
  9118. if face == 3 then return end
  9119. end
  9120. end
  9121.  
  9122. function forward(nBlocks)
  9123. for i=1,nBlocks do
  9124. turtle.forward()
  9125. end
  9126.  
  9127. if face == north then z = z+nBlocks return end
  9128. if face == west then x = x-nBlocks return end
  9129. if face == south then z = z-nBlocks return end
  9130. if face == east then x = x+nBlocks return end
  9131.  
  9132. end
  9133.  
  9134. function layRow(nBlocks)
  9135. turtle.select(itemSlot)
  9136.  
  9137. for i=0,nBlocks do
  9138. if (i % interval) == 0 then
  9139. turtle.placeDown()
  9140. end
  9141. if i < nBlocks then
  9142. forward(1)
  9143. end
  9144. end
  9145. end
  9146.  
  9147. function layPattern(l, w)
  9148.  
  9149. -- setFace(north)
  9150. layRow(w - 1)
  9151.  
  9152. setFace(west)
  9153. layRow(l - 1)
  9154.  
  9155. setFace(south)
  9156. layRow(w - 1)
  9157.  
  9158. setFace(east)
  9159. layRow(l - 1)
  9160.  
  9161. setFace(north)
  9162. end
  9163.  
  9164. radius = interval
  9165.  
  9166. -- Let's let the parent program get to start position
  9167.  
  9168. --[[
  9169. turtle.up()
  9170.  
  9171. turtle.select(itemSlot)
  9172. turtle.placeDown()
  9173.  
  9174. -- Move to starting position
  9175.  
  9176. setFace(north)
  9177. forward(radius)
  9178. setFace(west)
  9179. forward(radius)
  9180. --]]
  9181.  
  9182. layPattern(length, width)
  9183.  
  9184. setFace(north)
  9185. *** suck
  9186.  
  9187. while true do
  9188. turtle.suckUp()
  9189. turtle.suck()
  9190. turtle.turnRight()
  9191. turtle.suck()
  9192. turtle.turnRight()
  9193. turtle.suck()
  9194. turtle.turnRight()
  9195. turtle.suck()
  9196. turtle.turnRight()
  9197. end
  9198. *** timer
  9199. --time = os.time() print("time= ", time)
  9200.  
  9201. clockTime = os.clock()
  9202. print("clockTime: ", clockTime, ", minutes: ", clockTime / 60)
  9203.  
  9204. fakeTime = 33.4567
  9205.  
  9206.  
  9207. function displayTime(time)
  9208. --print("time = ", time)
  9209. rawSeconds = math.floor(time)
  9210. rawMinutes = math.floor(rawSeconds/60)
  9211. hours = math.floor(rawMinutes/60)
  9212. seconds = rawSeconds - (rawMinutes * 60)
  9213. minutes = rawMinutes - (hours * 60)
  9214.  
  9215. -- print("Raw: ", hours, "h ", rawMinutes, "m ", rawSeconds, "s")
  9216. -- print(hours, "h ", minutes, "m ", seconds, "s")
  9217.  
  9218. timeString = "Elapsed time: "
  9219.  
  9220. hStr = " hrs "
  9221. mStr = " mins "
  9222. sStr = " secs"
  9223.  
  9224. if hours == 1 then hStr = " hr " end
  9225. if minutes == 1 then mStr = " min " end
  9226. if seconds == 1 then sStr = " sec " end
  9227.  
  9228. if hours > 0 then
  9229. timeString = timeString .. hours .. hStr
  9230. end
  9231. if minutes > 0 then
  9232. timeString = timeString .. minutes .. mStr
  9233. end
  9234. if seconds > 0 then
  9235. timeString = timeString .. seconds .. sStr
  9236. end
  9237.  
  9238. print(timeString)
  9239. end
  9240.  
  9241. --[[
  9242. formattedTime = textutils.formatTime(timeNumber, true)
  9243. print("formattedTime: ", formattedTime)
  9244.  
  9245. elapsedTime = 12.706 - 11.637
  9246. print("elapsedTime: ", textutils.formatTime(elapsedTime, true))
  9247. --]]
  9248.  
  9249. --print("Elapsed time: ")
  9250. --displayTime(915432.4567)
  9251.  
  9252. print("Time since last reboot:")
  9253. displayTime(clockTime)
  9254. *** topgun
  9255. while true do
  9256. turtle.attackUp()
  9257. sleep(3)
  9258. end
  9259.  
  9260. *** tree
  9261. -- tree
  9262. -- Cut down a single tree directly in front of turtle
  9263. -- Trees must be 1x1 trunks with no branches
  9264. -- Program assumes turtle is pre-fueled
  9265. -- Written by HarvDad, April 2014
  9266.  
  9267. args = {...}
  9268. nArgs = #args
  9269.  
  9270. version = "tree: Rev 0.1"
  9271. mission = "Cut down a single tree"
  9272.  
  9273. usage = "tree"
  9274.  
  9275. x = 0
  9276. y = 0
  9277. z = 0
  9278. face = 0
  9279. missionMessage = "Mission complete."
  9280. abort = false
  9281. local currentFuelLevel = turtle.getFuelLevel()
  9282.  
  9283. -- The following 'face' directions are relative to the starting position of the turtle in this program
  9284. north = 0
  9285. west = 1
  9286. south = 2
  9287. east = 3
  9288.  
  9289. areaCovered = 1
  9290. currentSlot = 2
  9291. materialSlot = 1
  9292. maxSlot = 16
  9293.  
  9294. nextTurn = "left"
  9295.  
  9296. function setFace(f)
  9297. if f == 0 then
  9298. if face == 0 then return end
  9299. if face == 1 then right() return end
  9300. if face == 2 then right() right() return end
  9301. if face == 3 then left() return end
  9302. end
  9303.  
  9304. if f == 1 then
  9305. if face == 0 then left() return end
  9306. if face == 1 then return end
  9307. if face == 2 then right() return end
  9308. if face == 3 then right() right() return end
  9309. end
  9310.  
  9311. if f == 2 then
  9312. if face == 0 then left() left() return end
  9313. if face == 1 then left() return end
  9314. if face == 2 then return end
  9315. if face == 3 then right() return end
  9316. end
  9317.  
  9318. if f == 3 then
  9319. if face == 0 then right() return end
  9320. if face == 1 then left() left() return end
  9321. if face == 2 then left() return end
  9322. if face == 3 then return end
  9323. end
  9324. end
  9325.  
  9326. function forward()
  9327. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  9328. if turtle.forward() then
  9329. break
  9330. end
  9331. turtle.attack()
  9332. sleep(2)
  9333. end
  9334. areaCovered = areaCovered + 1
  9335.  
  9336. if face == 0 then z = z+1 return end
  9337. if face == 1 then x = x-1 return end
  9338. if face == 2 then z = z-1 return end
  9339. if face == 3 then x = x+1 return end
  9340. end
  9341.  
  9342. function left()
  9343. if face == 0 then face = 1 turtle.turnLeft() return end
  9344. if face == 1 then face = 2 turtle.turnLeft() return end
  9345. if face == 2 then face = 3 turtle.turnLeft() return end
  9346. if face == 3 then face = 0 turtle.turnLeft() return end
  9347. print("function left\(\): Bad face value: ", face)
  9348. end
  9349.  
  9350. function right()
  9351. if face == 0 then face = 3 turtle.turnRight() return end
  9352. if face == 1 then face = 0 turtle.turnRight() return end
  9353. if face == 2 then face = 1 turtle.turnRight() return end
  9354. if face == 3 then face = 2 turtle.turnRight() return end
  9355. print("function right\(\): Bad face value: ", face)
  9356. end
  9357.  
  9358. function up()
  9359. for i=1,10 do
  9360. if not turtle.up() then
  9361. if turtle.detectUp() then
  9362. digUp()
  9363. else
  9364. turtle.attackUp()
  9365. sleep(2)
  9366. end
  9367. else
  9368. break
  9369. end
  9370. end
  9371. y = y+1
  9372. end
  9373.  
  9374. function down()
  9375. for i=1,10 do
  9376. if not turtle.down() then
  9377. if turtle.detectDown() then
  9378. digDown()
  9379. else
  9380. turtle.attackDown()
  9381. sleep(2)
  9382. end
  9383. else
  9384. break
  9385. end
  9386. end
  9387. y = y-1
  9388. end
  9389.  
  9390. function chopTree()
  9391. turtle.dig()
  9392. forward()
  9393. while turtle.detectUp() do
  9394. turtle.digUp()
  9395. turtle.up()
  9396. end
  9397.  
  9398. while not turtle.detectDown() do
  9399. turtle.suckDown()
  9400. turtle.down()
  9401. end
  9402. end
  9403.  
  9404. function replantTree()
  9405. if turtle.getItemCount(saplingSlot) > 0 then
  9406. left()
  9407. left()
  9408. turtle.select(saplingSlot)
  9409. turtle.place()
  9410. left()
  9411. left()
  9412. end
  9413. end
  9414.  
  9415. -- Main program
  9416.  
  9417. chopTree()
  9418. replantTree()
  9419.  
  9420. if abort then
  9421. print("Mission aborted")
  9422. end
  9423. print(missionMessage)
  9424. *** trees
  9425. -- trees
  9426. -- Harvests trees laid out in rows
  9427. -- Trees must be 1x1 trunks with no branches
  9428. -- If supplied, saplings will be replanted
  9429. -- Program assumes turtle is pre-fueled
  9430. -- Turtle returns to its starting point when mission is completed or fuel runs low
  9431. -- Written by HarvDad, April 2014
  9432.  
  9433. args = {...}
  9434. nArgs = #args
  9435.  
  9436. version = "trees: Rev 1.2"
  9437. mission = "Harvest trees laid out in rows"
  9438.  
  9439. usage = "Usage: trees <rows>"
  9440.  
  9441. x = 0
  9442. y = 0
  9443. z = 0
  9444. face = 0
  9445. missionMessage = "Mission complete."
  9446. abort = false
  9447. logSlot = 1
  9448. saplingSlot = 16
  9449. markerSlot = 15
  9450. local currentFuelLevel = turtle.getFuelLevel()
  9451.  
  9452. -- The following 'face' directions are relative to the starting position of the turtle in this program
  9453. north = 0
  9454. west = 1
  9455. south = 2
  9456. east = 3
  9457.  
  9458. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  9459. print(version)
  9460. print(mission)
  9461. print("Place sample log in slot ", logSlot)
  9462. print("Place sapling supply in slot ", saplingSlot)
  9463. print("Place marker block in slot ", markerSlot)
  9464. print(usage)
  9465. return
  9466. end
  9467.  
  9468. if nArgs ~= 1 then
  9469. print(usage)
  9470. return
  9471. end
  9472.  
  9473. rows = tonumber(args[1])
  9474. if rows == nil then
  9475. print("\"", args[1], "\" is not a valid row count.")
  9476. return
  9477. end
  9478. if rows < 1 then
  9479. print("Number of rows must be positive number.")
  9480. end
  9481.  
  9482. areaCovered = 1
  9483. currentSlot = 2
  9484. materialSlot = 1
  9485. maxSlot = 16
  9486.  
  9487. nextTurn = "left"
  9488.  
  9489. function setFace(f)
  9490. if f == 0 then
  9491. if face == 0 then return end
  9492. if face == 1 then right() return end
  9493. if face == 2 then right() right() return end
  9494. if face == 3 then left() return end
  9495. end
  9496.  
  9497. if f == 1 then
  9498. if face == 0 then left() return end
  9499. if face == 1 then return end
  9500. if face == 2 then right() return end
  9501. if face == 3 then right() right() return end
  9502. end
  9503.  
  9504. if f == 2 then
  9505. if face == 0 then left() left() return end
  9506. if face == 1 then left() return end
  9507. if face == 2 then return end
  9508. if face == 3 then right() return end
  9509. end
  9510.  
  9511. if f == 3 then
  9512. if face == 0 then right() return end
  9513. if face == 1 then left() left() return end
  9514. if face == 2 then left() return end
  9515. if face == 3 then return end
  9516. end
  9517. end
  9518.  
  9519. function forward()
  9520. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  9521. if turtle.forward() then
  9522. break
  9523. end
  9524. turtle.attack()
  9525. sleep(2)
  9526. end
  9527. areaCovered = areaCovered + 1
  9528.  
  9529. if face == 0 then z = z+1 return end
  9530. if face == 1 then x = x-1 return end
  9531. if face == 2 then z = z-1 return end
  9532. if face == 3 then x = x+1 return end
  9533. end
  9534.  
  9535. function left()
  9536. if face == 0 then face = 1 turtle.turnLeft() return end
  9537. if face == 1 then face = 2 turtle.turnLeft() return end
  9538. if face == 2 then face = 3 turtle.turnLeft() return end
  9539. if face == 3 then face = 0 turtle.turnLeft() return end
  9540. print("function left\(\): Bad face value: ", face)
  9541. end
  9542.  
  9543. function right()
  9544. if face == 0 then face = 3 turtle.turnRight() return end
  9545. if face == 1 then face = 0 turtle.turnRight() return end
  9546. if face == 2 then face = 1 turtle.turnRight() return end
  9547. if face == 3 then face = 2 turtle.turnRight() return end
  9548. print("function right\(\): Bad face value: ", face)
  9549. end
  9550.  
  9551. function up()
  9552. for i=1,10 do
  9553. if not turtle.up() then
  9554. if turtle.detectUp() then
  9555. turtle.digUp()
  9556. else
  9557. turtle.attackUp()
  9558. sleep(2)
  9559. end
  9560. else
  9561. break
  9562. end
  9563. end
  9564. y = y+1
  9565. end
  9566.  
  9567. function down()
  9568. for i=1,10 do
  9569. if not turtle.down() then
  9570. if turtle.detectDown() then
  9571. turtle.digDown()
  9572. else
  9573. turtle.attackDown()
  9574. sleep(2)
  9575. end
  9576. else
  9577. break
  9578. end
  9579. end
  9580. y = y-1
  9581. end
  9582.  
  9583. function focusSaplings()
  9584. local i
  9585. saplingCount = turtle.getItemCount(saplingSlot)
  9586.  
  9587. if saplingCount < 2 then
  9588. for i=2,15 do
  9589. turtle.select(i)
  9590. if turtle.compareTo(saplingSlot) then
  9591. turtle.transferTo(saplingSlot)
  9592. end
  9593. end
  9594. end
  9595.  
  9596. turtle.select(saplingSlot)
  9597. end
  9598.  
  9599. function nextTree()
  9600. success = false
  9601.  
  9602. while not success do
  9603. if not turtle.forward() then
  9604. turtle.select(logSlot)
  9605. if turtle.compare() then
  9606. success = true
  9607. else
  9608. turtle.select(saplingSlot)
  9609. if turtle.compare() then
  9610. success = true
  9611. else
  9612. if turtle.detect() then
  9613. missionMessage = "Encountered unexpected block."
  9614. sleep(5)
  9615. abort = true
  9616. return success
  9617. else
  9618. for i=1,10 do
  9619. success = turtle.forward()
  9620. if not success then
  9621. turtle.attack()
  9622. sleep(2)
  9623. else
  9624. if z >= lastZ or x <= lastX then
  9625. return
  9626. end
  9627. updateLocation()
  9628. end
  9629. end
  9630. missionMessage = "Could not get past unknown entity"
  9631. abort = true
  9632. return success
  9633. end
  9634. end
  9635. end
  9636. else
  9637. if z >= lastZ or x <= lastX then
  9638. return success
  9639. end
  9640. updateLocation()
  9641. end
  9642. -- print("nextTree: x = ", x, ", z = ", z)
  9643. end
  9644. return success
  9645. end
  9646.  
  9647. function updateLocation()
  9648. if face == 0 then z = z+1 return end
  9649. if face == 1 then x = x-1 return end
  9650. if face == 2 then z = z-1 return end
  9651. if face == 3 then x = x+1 return end
  9652. end
  9653.  
  9654. function harvestSapling()
  9655. turtle.dig()
  9656. forward()
  9657. up()
  9658. turtle.select(saplingSlot)
  9659. turtle.placeDown()
  9660. turtle.select(logSlot)
  9661. end
  9662.  
  9663. function harvestTree()
  9664. turtle.dig()
  9665. forward()
  9666. while turtle.detectUp() do
  9667. turtle.digUp()
  9668. up()
  9669. end
  9670.  
  9671. while y > 1 do
  9672. down()
  9673. end
  9674. turtle.select(saplingSlot)
  9675. turtle.placeDown()
  9676. turtle.select(logSlot)
  9677. end
  9678.  
  9679. function chopTree()
  9680. turtle.select(logSlot)
  9681. if turtle.compare() then
  9682. turtle.dig()
  9683. forward()
  9684. while turtle.detectUp() do
  9685. turtle.digUp()
  9686. turtle.up()
  9687. end
  9688.  
  9689. while not turtle.detectDown() do
  9690. turtle.suckDown()
  9691. turtle.down()
  9692. end
  9693. else
  9694. turtle.dig()
  9695. forward()
  9696. end
  9697. forward()
  9698. totalCut = totalCut + 1
  9699. end
  9700.  
  9701. function replantTree()
  9702. focusSaplings()
  9703. if turtle.getItemCount(saplingSlot) > 0 then
  9704. left()
  9705. left()
  9706. turtle.select(saplingSlot)
  9707. turtle.place()
  9708. left()
  9709. left()
  9710. end
  9711. end
  9712.  
  9713. function _home()
  9714. setFace(east)
  9715. forward()
  9716.  
  9717. if z < 0 then
  9718. setFace(north)
  9719. while z < 0 do
  9720. forward()
  9721. end
  9722. else
  9723. if z > 0 then
  9724. setFace(south)
  9725. while z > 0 do
  9726. forward()
  9727. end
  9728. end
  9729. end
  9730.  
  9731. if x < 0 then
  9732. setFace(west)
  9733. while x < 0 do
  9734. forward()
  9735. end
  9736. else
  9737. if x > 0 then
  9738. setFace(east)
  9739. while x > 0 do
  9740. forward()
  9741. end
  9742. end
  9743. end
  9744.  
  9745. setFace(north)
  9746. nextTurn = "left"
  9747. end
  9748.  
  9749. function nextRow()
  9750. if nextTurn == "left" then
  9751. left()
  9752. for i=1,interval do
  9753. forward()
  9754. end
  9755. left()
  9756. nextTurn = "right"
  9757. else
  9758. right()
  9759. for i=1,interval do
  9760. forward()
  9761. end
  9762. right()
  9763. nextTurn = "left"
  9764. end
  9765. end
  9766.  
  9767. function facingTree()
  9768. turtle.select(logSlot)
  9769. return turtle.compare()
  9770. end
  9771.  
  9772. function facingSapling() -- WARNING!!! turtles cannot dependably compare to saplings (BUG)
  9773. turtle.select(saplingSlot)
  9774. return turtle.compare()
  9775. end
  9776.  
  9777. function facingMarker()
  9778. turtle.select(markerSlot)
  9779. return turtle.compare()
  9780. end
  9781.  
  9782. spanSet = false
  9783.  
  9784. function harvestForward()
  9785. if y > 0 then
  9786. turtle.dig()
  9787. forward()
  9788. down()
  9789. else
  9790. if facingTree() then
  9791. harvestTree()
  9792. else
  9793. if facingMarker() and x == 0 then
  9794. spanZ = z
  9795. spanSet = true
  9796. else
  9797. if turtle.detect() then -- sadly, we must assume it's a sapling
  9798. harvestSapling()
  9799. else
  9800. forward()
  9801. end
  9802. end
  9803. end
  9804. end
  9805. end
  9806.  
  9807. function home()
  9808. if z == 0 then
  9809. left()
  9810. while x < 0 do
  9811. forward()
  9812. end
  9813. else
  9814. right()
  9815. while x < 0 do
  9816. forward()
  9817. end
  9818. forward()
  9819. right()
  9820. while z > 0 do
  9821. forward()
  9822. end
  9823. right()
  9824. forward()
  9825. end
  9826. setFace(north)
  9827. end
  9828.  
  9829. -- Main program
  9830.  
  9831. totalCut = 0
  9832. rowCount = 0
  9833. columnCount = 0
  9834. firstZ = 0
  9835. lastZ = 0
  9836. lastX = 0
  9837. interval = 5
  9838.  
  9839.  
  9840. setFace(north)
  9841. nextTurn = "left"
  9842.  
  9843. --[[
  9844. for i=1,30 do
  9845. if facingTree() then
  9846. break
  9847. end
  9848. forward()
  9849. end
  9850. --]]
  9851.  
  9852. firstZ = z
  9853. lastZ = firstZ + ((rows-1) * interval)
  9854. spanZ = lastZ - firstZ
  9855.  
  9856. spanX = -12
  9857. spanZ = 100
  9858. lastJ = 0
  9859.  
  9860. for i = 1,rows do
  9861. for j = 1,spanZ do
  9862. -- forward()
  9863. harvestForward()
  9864. if x == 0 and spanSet then
  9865. break
  9866. end
  9867. end
  9868. if i < rows then
  9869. nextRow()
  9870. end
  9871. end
  9872.  
  9873. if y > 0 then
  9874. turtle.dig()
  9875. forward()
  9876. down()
  9877. end
  9878.  
  9879. print("Heading home...")
  9880.  
  9881. home()
  9882.  
  9883. if abort then
  9884. print("Mission aborted")
  9885. end
  9886. print(missionMessage)
  9887.  
  9888.  
  9889. *** tube
  9890. -- tube
  9891. -- Creates a 2x2 tunnel of the length specified by the user
  9892. -- All sides are sealed for protection
  9893. -- Torches, if supplied, will be placed on the right-hand wall at 10 block intervals
  9894. -- Written by HarvDad, March 2014
  9895.  
  9896. args = {...}
  9897. nArgs = #args
  9898.  
  9899. print("tube: Rev 3.1")
  9900. x = 0
  9901. y = 0
  9902. z = 0
  9903. face = 0
  9904. minimumFuel = 100
  9905. missionMessage = "Mission complete."
  9906. abort = false
  9907. patchSlot = 1
  9908. torchSlot = 16
  9909. local currentFuelLevel = turtle.getFuelLevel()
  9910. zipTube = false
  9911. usage = "Usage: tube <length> [zip]"
  9912.  
  9913. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  9914. print("Creates a tunnel with sealed sides, top, and bottom.")
  9915. print("If zip tube, tunnel is 1x2, else 2x2")
  9916. print("This programs assumes the turtle is pre-fueled.")
  9917. print("Place patch material (like cobblestone) in slot ", patchSlot)
  9918. print("If torches are desired, place torches in slot ", torchSlot)
  9919. print(usage)
  9920. return
  9921. end
  9922.  
  9923. if nArgs ~= 1 and nArgs ~= 2 then
  9924. print("Usage: tube <length>")
  9925. return
  9926. end
  9927.  
  9928. if nArgs == 2 then
  9929. if args[2] == "zip" then
  9930. zipTube = true
  9931. else
  9932. print("Usage: tube <length>")
  9933. end
  9934. end
  9935.  
  9936. length = tonumber(args[1])
  9937. if length == nil then
  9938. print("\"", args[1], "\" is not a valid length")
  9939. return
  9940. end
  9941. if length < 1 then
  9942. print("length must be a positive number greater than zero")
  9943. end
  9944.  
  9945. targetArea = length
  9946. areaCovered = 1;
  9947.  
  9948. -- The following 'face' directions are relative to the starting position of the turtle in this program
  9949. north = 0
  9950. west = 1
  9951. south = 2
  9952. east = 3
  9953.  
  9954.  
  9955. function left()
  9956. if face == 0 then face = 1 turtle.turnLeft() return end
  9957. if face == 1 then face = 2 turtle.turnLeft() return end
  9958. if face == 2 then face = 3 turtle.turnLeft() return end
  9959. if face == 3 then face = 0 turtle.turnLeft() return end
  9960. print("function left\(\): Bad face value: ", face)
  9961. end
  9962.  
  9963. function right()
  9964. if face == 0 then face = 3 turtle.turnRight() return end
  9965. if face == 1 then face = 0 turtle.turnRight() return end
  9966. if face == 2 then face = 1 turtle.turnRight() return end
  9967. if face == 3 then face = 2 turtle.turnRight() return end
  9968. print("function right\(\): Bad face value: ", face)
  9969. end
  9970.  
  9971. function up()
  9972. local success = false
  9973.  
  9974. repeat
  9975. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  9976. turtle.digUp()
  9977. end
  9978. success = turtle.up()
  9979. until success
  9980. y = y+1
  9981. end
  9982.  
  9983. function rise(nBlocks)
  9984. local i
  9985. for i=1,nBlocks do
  9986. up()
  9987. end
  9988. end
  9989.  
  9990. function descend(nBlocks)
  9991. local i
  9992. for i=1,nBlocks do
  9993. down()
  9994. end
  9995. end
  9996.  
  9997. function down()
  9998. if turtle.detectDown() then
  9999. turtle.digDown()
  10000. end
  10001. turtle.down()
  10002. y = y-1
  10003. end
  10004.  
  10005. function forward(keepTrackOfArea)
  10006. while turtle.detect() do -- This loop added in case of falling sand or whatever
  10007. turtle.dig()
  10008. end
  10009. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  10010. if not turtle.forward() then
  10011. if turtle.detect() then
  10012. dig()
  10013. else
  10014. turtle.attack()
  10015. sleep(2)
  10016. end
  10017. else
  10018. break
  10019. end
  10020. end
  10021. if keepTrackOfArea then
  10022. areaCovered = areaCovered + 1
  10023. end
  10024.  
  10025. if face == 0 then z = z+1 return end
  10026. if face == 1 then x = x-1 return end
  10027. if face == 2 then z = z-1 return end
  10028. if face == 3 then x = x+1 return end
  10029. end
  10030.  
  10031. function gatherPatchMaterial()
  10032. local i
  10033. patchCount = turtle.getItemCount(patchSlot)
  10034.  
  10035. if patchCount < 3 then
  10036. -- print("Attempting to refill slot ", patchSlot)
  10037. for i=2,14 do
  10038. turtle.select(i)
  10039. if turtle.compareTo(patchSlot) then
  10040. turtle.transferTo(patchSlot, 64-patchCount)
  10041. -- print("Transferred ", 64 - patchCount, " cobble to slot ", patchSlot)
  10042. end
  10043. end
  10044. end
  10045. turtle.select(patchSlot)
  10046. end
  10047.  
  10048. function patch()
  10049. gatherPatchMaterial()
  10050. turtle.select(patchSlot)
  10051. turtle.place()
  10052. end
  10053.  
  10054. function patchUp()
  10055. gatherPatchMaterial()
  10056. turtle.select(patchSlot)
  10057. turtle.placeUp()
  10058. end
  10059.  
  10060. function patchDown()
  10061. gatherPatchMaterial()
  10062. turtle.select(patchSlot)
  10063. turtle.placeDown()
  10064. end
  10065.  
  10066. function patchUpper()
  10067. patchUp()
  10068. left()
  10069. patch()
  10070. right()
  10071. right()
  10072. patch()
  10073. left()
  10074. end
  10075.  
  10076. function patchLower()
  10077. patchDown()
  10078. left()
  10079. patch()
  10080. right()
  10081. right()
  10082. patch()
  10083. left()
  10084. end
  10085.  
  10086. function patchTube()
  10087. patchUp()
  10088. patchDown()
  10089. left()
  10090. patch()
  10091. right()
  10092. right()
  10093. patch()
  10094. left()
  10095. end
  10096.  
  10097. addTorch = false
  10098. torchSpacing = 6
  10099.  
  10100. function mineForward()
  10101. forward()
  10102. if not turtle.detectDown() then
  10103. patchDown()
  10104. end
  10105. right()
  10106. if not turtle.detect() then
  10107. patch()
  10108. end
  10109. up()
  10110. if not turtle.detect() then
  10111. patch()
  10112. end
  10113. left()
  10114. if not turtle.detectUp() then
  10115. patchUp()
  10116. end
  10117.  
  10118. if addTorch then
  10119. if (torchSpot % torchSpacing) == 0 then
  10120. left()
  10121. turtle.select(torchSlot)
  10122. turtle.place()
  10123. right()
  10124. end
  10125. torchSpot = torchSpot + 1
  10126. end
  10127.  
  10128. turtle.down()
  10129. end
  10130.  
  10131. function setFace(f)
  10132. if f == 0 then
  10133. if face == 0 then return end
  10134. if face == 1 then right() return end
  10135. if face == 2 then right() right() return end
  10136. if face == 3 then left() return end
  10137. end
  10138.  
  10139. if f == 1 then
  10140. if face == 0 then left() return end
  10141. if face == 1 then return end
  10142. if face == 2 then right() return end
  10143. if face == 3 then right() right() return end
  10144. end
  10145.  
  10146. if f == 2 then
  10147. if face == 0 then left() left() return end
  10148. if face == 1 then left() return end
  10149. if face == 2 then return end
  10150. if face == 3 then right() return end
  10151. end
  10152.  
  10153. if f == 3 then
  10154. if face == 0 then right() return end
  10155. if face == 1 then left() left() return end
  10156. if face == 2 then left() return end
  10157. if face == 3 then return end
  10158. end
  10159. end
  10160.  
  10161. function checkFuel()
  10162. if currentFuelLevel == "unlimited" then
  10163. return true
  10164. end
  10165.  
  10166. if currentFuelLevel < minimumFuel then
  10167. if not turtle.refuel(200) then
  10168. areaCovered = targetArea
  10169. missionMessage = "Mission aborted due to low fuel."
  10170. abort = true
  10171. return false
  10172. end
  10173. end
  10174. return true
  10175. end
  10176.  
  10177. function home(targetY)
  10178. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  10179. if x < 0 then
  10180. setFace(east)
  10181. while x < 0 do
  10182. forward()
  10183. end
  10184. else
  10185. if x > 0 then
  10186. setFace(west)
  10187. while x > 0 do
  10188. forward()
  10189. end
  10190. end
  10191. end
  10192.  
  10193. if z < 0 then
  10194. setFace(north)
  10195. while z < 0 do
  10196. forward()
  10197. end
  10198. else
  10199. if z > 0 then
  10200. setFace(south)
  10201. while z > 0 do
  10202. forward()
  10203. end
  10204. end
  10205. end
  10206. end
  10207.  
  10208. function poopTorch()
  10209. left()
  10210. left()
  10211. turtle.select(torchSlot)
  10212. turtle.place()
  10213. right()
  10214. right()
  10215. turtle.select(patchSlot)
  10216. end
  10217.  
  10218. -- MAIN PROGRAM
  10219.  
  10220. turtle.select(patchSlot)
  10221.  
  10222. print("Current Fuel Level: ", currentFuelLevel)
  10223.  
  10224. if currentFuelLevel ~= "unlimited" then
  10225. if currentFuelLevel < minimumFuel then
  10226. if not turtle.refuel() then
  10227. print("No fuel")
  10228. return
  10229. end
  10230. end
  10231. end
  10232.  
  10233. if zipTube then
  10234. print("Starting 1x2 zip tube...")
  10235. for i=1,length do
  10236. forward()
  10237. patchLower()
  10238. end
  10239.  
  10240. patch()
  10241. up()
  10242. patch()
  10243.  
  10244. left()
  10245. left()
  10246. patchUpper()
  10247. for i=1,length-1 do
  10248. forward()
  10249. patchUpper()
  10250. if (i % torchSpacing) == 0 then
  10251. poopTorch()
  10252. end
  10253. end
  10254. down()
  10255. else
  10256. print("Starting 2x2 double-wide tube...")
  10257. for i=1,length do
  10258. mineForward()
  10259. end
  10260.  
  10261. setFace(north)
  10262. if not turtle.detect() then
  10263. patch()
  10264. end
  10265. rise(1)
  10266. if not turtle.detect() then
  10267. patch()
  10268. end
  10269. descend(1)
  10270. if not turtle.detect() then
  10271. patch()
  10272. end
  10273. setFace(west)
  10274. mineForward()
  10275. if not turtle.detect() then
  10276. patch()
  10277. end
  10278. rise(1)
  10279. if not turtle.detect() then
  10280. patch()
  10281. end
  10282. descend(1)
  10283. setFace(south)
  10284. addTorch = true
  10285. torchSpot = 7
  10286.  
  10287. for i=1,length-1 do
  10288. mineForward()
  10289. checkFuel()
  10290. if abort then
  10291. break
  10292. end
  10293. end
  10294. end
  10295.  
  10296. home(0)
  10297. setFace(north)
  10298.  
  10299. print(missionMessage, " Current fuel level is ", turtle.getFuelLevel())
  10300.  
  10301. *** u
  10302. -- u
  10303. -- Moves the turtle the specified distance up
  10304. -- Written by HarvDad, March 2014
  10305.  
  10306. args = {...}
  10307. nArgs = #args
  10308.  
  10309. x = 0
  10310. y = 0
  10311. z = 0
  10312. face = 0
  10313. minimumFuel = 100
  10314. abort = false
  10315. local currentFuelLevel = turtle.getFuelLevel()
  10316. distance = 1;
  10317.  
  10318. if (nArgs == 1 and args[1]== "help") then
  10319. print("Moves the turtle the specified distance up")
  10320. print("Usage: f [distance]")
  10321. return
  10322. end
  10323.  
  10324. if nArgs == 1 then
  10325. distance = tonumber(args[1])
  10326. if distance == nil then
  10327. print(args[1], " is not a valid distance")
  10328. return
  10329. end
  10330. if distance > 75 then
  10331. print("Maybe not a good idea")
  10332. return
  10333. end
  10334. end
  10335.  
  10336. -- MAIN PROGRAM
  10337.  
  10338. turtle.select(1)
  10339.  
  10340. if currentFuelLevel ~= "unlimited" then
  10341. if currentFuelLevel < minimumFuel then
  10342. if not turtle.refuel() then
  10343. print("No fuel")
  10344. return
  10345. end
  10346. end
  10347. end
  10348.  
  10349. for i=1,distance do
  10350. turtle.up()
  10351. end
  10352. *** valve
  10353. -- valve
  10354. -- Pours and retrieves water at specified time intervals
  10355. -- Written by HarvDad, June 2014
  10356.  
  10357. args = {...}
  10358. nArgs = #args
  10359.  
  10360. version = "valve: Rev 1.0"
  10361. mission = "Pour and retrieve water at intervals."
  10362. instructions = "Place full bucket in slot 1, empty bucket in slot 2."
  10363. usage1 = "usage: valve <direction> <t1> <t2>"
  10364. usage2 = " direction = up, down, forward"
  10365. usage3 = " t1 = seconds after pour"
  10366. usage4 = " t2 = seconds after retrieval"
  10367.  
  10368.  
  10369. secondsAfterPouring = 10
  10370. secondsAfterRetrieving = 30
  10371.  
  10372. up = 0
  10373. down = 1
  10374. forward = 2
  10375. direction = 0
  10376.  
  10377. abort = false
  10378.  
  10379. function synchWithServerTime()
  10380. print("Waiting for synch...")
  10381. while true do
  10382. time = os.time()
  10383. timeStr = tostring(time)
  10384. tailStr = string.sub(timeStr, -3)
  10385. tail = tonumber(tailStr)
  10386. if tail > 995 then
  10387. break
  10388. end
  10389. sleep(0)
  10390. end
  10391. end
  10392.  
  10393. function needWater()
  10394. turtle.select(1)
  10395. if turtle.compareTo(2) then
  10396. return true
  10397. end
  10398. return false
  10399. end
  10400.  
  10401. -- prep: Retrieve any water possibly left over from previous run
  10402.  
  10403. function prep()
  10404. turtle.select(1)
  10405.  
  10406. if turtle.compareTo(2) then
  10407. if needWater() then
  10408. turtle.placeUp()
  10409. end
  10410. if needWater() then
  10411. turtle.placeDown()
  10412. end
  10413. if needWater() then
  10414. turtle.place()
  10415. end
  10416. end
  10417. end
  10418.  
  10419. function updateWater()
  10420. turtle.select(1)
  10421.  
  10422. if direction == up then
  10423. turtle.placeUp()
  10424. elseif direction == down then
  10425. turtle.placeDown()
  10426. elseif direction == forward then
  10427. if not needWater() then
  10428. turtle.place()
  10429. if not needWater() then
  10430. print("Placing water forward failed.")
  10431. print("Apparently can only place on solid block.")
  10432. print("ComputerCraft bug? Misfeature?")
  10433. abort = true
  10434. end
  10435. end
  10436. else
  10437. print("Invalid direction: ", direction)
  10438. print("This should never happen.")
  10439. abort = true
  10440. end
  10441. end
  10442.  
  10443. function doTheRightThing()
  10444. local naptime = 0
  10445.  
  10446. turtle.select(1)
  10447. if turtle.compareTo(2) then
  10448. napTime = secondsAfterRetrieving
  10449. -- print("Bucket is empty. Retrieving water.")
  10450. else
  10451. -- print("Bucket is full. Pouring water.")
  10452. napTime = secondsAfterPouring
  10453. end
  10454. updateWater()
  10455.  
  10456. return napTime
  10457. end
  10458.  
  10459. -- Main program
  10460.  
  10461.  
  10462. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  10463. print(version)
  10464. print(instructions)
  10465. print(usage1)
  10466. print(usage2)
  10467. print(usage3)
  10468. print(usage4)
  10469. return
  10470. end
  10471.  
  10472. if nArgs < 3 or nArgs > 3 then
  10473. print(usage1)
  10474. print(usage2)
  10475. print(usage3)
  10476. print(usage4)
  10477. return
  10478. end
  10479.  
  10480. if args[1] == "up" then
  10481. direction = up
  10482. elseif args[1] == "down" then
  10483. direction = down
  10484. elseif args[1] == "forward" then
  10485. direction = forward
  10486. else
  10487. print("\"", args[1], "\" is not a valid direction.")
  10488. return
  10489. end
  10490.  
  10491. secondsAfterPouring = tonumber(args[2])
  10492. if secondsAfterPouring == nil then
  10493. print("\"", args[2], "\" is not a valid time interval")
  10494. return
  10495. end
  10496. if secondsAfterPouring < 1 then
  10497. print("t1 must be a positive integer")
  10498. return
  10499. end
  10500.  
  10501. secondsAfterRetrieving= tonumber(args[3])
  10502. if secondsAfterRetrieving == nil then
  10503. print("\"", args[3], "\" is not a valid time interval")
  10504. return
  10505. end
  10506. if secondsAfterRetrieving < 1 then
  10507. print("t2 must be a positive integer")
  10508. return
  10509. end
  10510.  
  10511. if turtle.getItemCount(1) == 0 or turtle.getItemCount(2) == 0 then
  10512. print("If no water running yet,")
  10513. print(" place full bucket in slot 1.")
  10514. print("If water is already running,")
  10515. print(" place empty bucket in slot 1.")
  10516. print("Always have empty bucket in slot 2 as comparitor.")
  10517. return
  10518. end
  10519.  
  10520. prep()
  10521. --synchWithServerTime()
  10522.  
  10523. -- Main loop
  10524.  
  10525.  
  10526. print("Beginning loop...")
  10527. while true do
  10528. if abort then
  10529. break
  10530. end
  10531. napTime = doTheRightThing()
  10532. sleep(napTime)
  10533. end
  10534.  
  10535.  
  10536.  
  10537. *** wall
  10538. -- wall
  10539. -- Build a wall of specified length and height specified
  10540. -- Turtle returns to its starting point when mission is completed or fuel runs low
  10541. -- Written by HarvDad, May 2014
  10542.  
  10543. args = {...}
  10544. nArgs = #args
  10545.  
  10546. version = "walls: Rev 1.0"
  10547. mission = "Build a wall of length and height specified"
  10548. instructions = "Place stack(s) of material starting in first slot."
  10549.  
  10550. usage = "wall <start> <end> <height>"
  10551.  
  10552. x = 0
  10553. y = 0
  10554. z = 0
  10555. face = 0
  10556. minimumFuel = 100
  10557. missionMessage = "Mission complete."
  10558. abort = false
  10559. startLevel = 0
  10560. local currentFuelLevel = turtle.getFuelLevel()
  10561.  
  10562. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  10563. print(version)
  10564. print(mission)
  10565. print(instructions)
  10566. print(usage)
  10567. return
  10568. end
  10569.  
  10570. if nArgs ~= 2 then
  10571. print(usage)
  10572. return
  10573. end
  10574.  
  10575. length = tonumber(args[1])
  10576. if length == nil then
  10577. print("\"", args[1], "\" is not a valid length")
  10578. return
  10579. end
  10580. if length < 1 then
  10581. print("length must be a positive number greater than zero")
  10582. end
  10583.  
  10584. height = tonumber(args[2])
  10585. if startLevel == nil then
  10586. print("\"", args[2], "\" is not a valid height")
  10587. return
  10588. end
  10589.  
  10590. currentSlot = 2
  10591. materialSlot = 1
  10592. maxSlot = 16
  10593.  
  10594. nextTurn = "left"
  10595.  
  10596. local clock = os.clock
  10597. function sleep(n) -- seconds
  10598. local t0 = clock()
  10599. while clock() - t0 <= n do end
  10600. end
  10601.  
  10602. function left()
  10603. if face == 0 then face = 1 turtle.turnLeft() return end
  10604. if face == 1 then face = 2 turtle.turnLeft() return end
  10605. if face == 2 then face = 3 turtle.turnLeft() return end
  10606. if face == 3 then face = 0 turtle.turnLeft() return end
  10607. print("function left\(\): Bad face value: ", face)
  10608. end
  10609.  
  10610. function right()
  10611. if face == 0 then face = 3 turtle.turnRight() return end
  10612. if face == 1 then face = 0 turtle.turnRight() return end
  10613. if face == 2 then face = 1 turtle.turnRight() return end
  10614. if face == 3 then face = 2 turtle.turnRight() return end
  10615. print("function right\(\): Bad face value: ", face)
  10616. end
  10617.  
  10618. function up()
  10619. turtle.up()
  10620. y = y+1
  10621. end
  10622.  
  10623. function rise(nBlocks)
  10624. local i
  10625. for i=1,nBlocks do
  10626. up()
  10627. end
  10628. end
  10629.  
  10630. function down()
  10631. if turtle.detectDown() then
  10632. turtle.digDown()
  10633. end
  10634. turtle.down()
  10635. y = y-1
  10636. end
  10637.  
  10638. function turn()
  10639. if nextTurn == "left" then
  10640. left()
  10641. else
  10642. right()
  10643. end
  10644. chomp()
  10645. forward()
  10646. if nextTurn == "left" then
  10647. left()
  10648. nextTurn = "right"
  10649. else
  10650. right()
  10651. nextTurn = "left"
  10652. end
  10653. areaCovered = areaCovered + 1
  10654. end
  10655.  
  10656. function forward()
  10657. while turtle.detect() do -- This loop added in case of falling sand or whatever
  10658. turtle.dig()
  10659. end
  10660. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  10661. if turtle.forward() then
  10662. break
  10663. end
  10664. turtle.attack()
  10665. sleep(2)
  10666. end
  10667.  
  10668. if face == 0 then z = z+1 return end
  10669. if face == 1 then x = x-1 return end
  10670. if face == 2 then z = z-1 return end
  10671. if face == 3 then x = x+1 return end
  10672. end
  10673.  
  10674. function back()
  10675. turtle.back()
  10676.  
  10677. if face == 0 then z = z-1 return end
  10678. if face == 1 then x = x+1 return end
  10679. if face == 2 then z = z+1 return end
  10680. if face == 3 then x = x-1 return end
  10681. end
  10682.  
  10683. function setFace(f)
  10684. if f == 0 then
  10685. if face == 0 then return end
  10686. if face == 1 then right() return end
  10687. if face == 2 then right() right() return end
  10688. if face == 3 then left() return end
  10689. end
  10690.  
  10691. if f == 1 then
  10692. if face == 0 then left() return end
  10693. if face == 1 then return end
  10694. if face == 2 then right() return end
  10695. if face == 3 then right() right() return end
  10696. end
  10697.  
  10698. if f == 2 then
  10699. if face == 0 then left() left() return end
  10700. if face == 1 then left() return end
  10701. if face == 2 then return end
  10702. if face == 3 then right() return end
  10703. end
  10704.  
  10705. if f == 3 then
  10706. if face == 0 then right() return end
  10707. if face == 1 then left() left() return end
  10708. if face == 2 then left() return end
  10709. if face == 3 then return end
  10710. end
  10711. end
  10712.  
  10713. function home(targetY)
  10714. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  10715. if x < 0 then
  10716. setFace(3)
  10717. while x < 0 do
  10718. forward()
  10719. end
  10720. else
  10721. if x > 0 then
  10722. setFace(1)
  10723. while x > 0 do
  10724. forward()
  10725. end
  10726. end
  10727. end
  10728.  
  10729. if z < 0 then
  10730. setFace(0)
  10731. while z < 0 do
  10732. forward()
  10733. end
  10734. else
  10735. if z > 0 then
  10736. setFace(2)
  10737. while z > 0 do
  10738. forward()
  10739. end
  10740. end
  10741. end
  10742.  
  10743. if y > 0 then
  10744. while y > 0 do
  10745. down()
  10746. end
  10747. end
  10748.  
  10749. setFace(0)
  10750. end
  10751.  
  10752. function ensureMaterial()
  10753. if turtle.getItemCount(materialSlot) < 3 then
  10754. organizeMaterial()
  10755. end
  10756. if turtle.getItemCount(materialSlot) < 3 then
  10757. print("No more material")
  10758. return false
  10759. end
  10760. return true
  10761. end
  10762.  
  10763. function organizeMaterial()
  10764. local i
  10765. materialCount = turtle.getItemCount(materialSlot)
  10766.  
  10767. if materialCount < 3 then
  10768. -- print("Attempting to refill slot ", materialSlot)
  10769. for i=2,16 do
  10770. turtle.select(i)
  10771. if turtle.compareTo(materialSlot) then
  10772. turtle.transferTo(materialSlot)
  10773. end
  10774. end
  10775. end
  10776. turtle.select(materialSlot)
  10777. end
  10778.  
  10779. function layBlock()
  10780. turtle.select(materialSlot)
  10781.  
  10782. if startLevel > 2 then
  10783. if turtle.detectUp() then
  10784. if turtle.compareUp() then
  10785. return
  10786. else
  10787. turtle.digUp()
  10788. end
  10789. end
  10790. if ensureMaterial() then
  10791. turtle.placeUp()
  10792. end
  10793. else
  10794. if turtle.detectDown() then
  10795. if turtle.compareDown() then
  10796. return
  10797. else
  10798. turtle.digDown()
  10799. end
  10800. end
  10801. if ensureMaterial() then
  10802. turtle.placeDown()
  10803. end
  10804. end
  10805. end
  10806.  
  10807. function checkFuel()
  10808. if currentFuelLevel == "unlimited" then
  10809. return true
  10810. end
  10811.  
  10812. if currentFuelLevel < minimumFuel then
  10813. if not turtle.refuel() then
  10814. areaCovered = targetArea
  10815. missionMessage = "Mission aborted due to low fuel."
  10816. abort = true
  10817. return false
  10818. end
  10819. end
  10820. return true
  10821. end
  10822.  
  10823. currentSlot = 1
  10824.  
  10825. directon = "forward"
  10826.  
  10827. function layRow(nBlocks)
  10828. turtle.select(currentSlot)
  10829.  
  10830. for i=1,nBlocks do
  10831. if turtle.getItemCount(currentSlot) > 0 then
  10832. turtle.placeDown()
  10833. if direction == "forward" then
  10834. if i < length then
  10835. forward()
  10836. end
  10837. else
  10838. if i < length then
  10839. back()
  10840. end
  10841. end
  10842. else
  10843. currentSlot = currentSlot + 1
  10844. if turtle.getItemCount(currentSlot) > 0 then
  10845. turtle.select(currentSlot)
  10846. turtle.placeDown()
  10847. if direction == "forward" then
  10848. if i < length then
  10849. forward()
  10850. end
  10851. else
  10852. if i < length then
  10853. back()
  10854. end
  10855. end
  10856. else
  10857. print("Can't find more material")
  10858. return
  10859. end
  10860. end
  10861. end
  10862. end
  10863.  
  10864. -- MAIN PROGRAM
  10865.  
  10866. turtle.select(1)
  10867.  
  10868. print("fuelLevel = ", currentFuelLevel)
  10869. print("length = ", length)
  10870. print("face = ", face)
  10871.  
  10872. print("Current Fuel Level: ", currentFuelLevel)
  10873.  
  10874. if currentFuelLevel ~= "unlimited" then
  10875. if currentFuelLevel < minimumFuel then
  10876. if not turtle.refuel() then
  10877. print("No fuel")
  10878. return
  10879. end
  10880. end
  10881. end
  10882.  
  10883. notFinished = true
  10884. direction = "forward"
  10885. print("wall: Setting face to local north")
  10886. setFace(0)
  10887. z = 0
  10888.  
  10889. while notFinished do
  10890. if y == height then
  10891. notFinished = false
  10892. break
  10893. end
  10894.  
  10895. up()
  10896.  
  10897. layRow(length)
  10898. if direction == "forward" then
  10899. direction = "backward"
  10900. else
  10901. direction = "forward"
  10902. end
  10903. end
  10904.  
  10905. while z > 0 do
  10906. turtle.back()
  10907. z = z - 1
  10908. end
  10909. back()
  10910. while y > 0 do
  10911. turtle.down()
  10912. y = y - 1
  10913. end
  10914. print(missionMessage)
  10915. print(" Current fuel level is ", turtle.getFuelLevel())
  10916. *** walls
  10917. -- walls
  10918. -- Puts up walls to the length, width, height specified
  10919. -- Turtle returns to its starting point when mission is completed or fuel runs low
  10920. -- Written by HarvDad, March 2014
  10921.  
  10922. args = {...}
  10923. nArgs = #args
  10924.  
  10925. version = "walls: Rev 2.0"
  10926. mission = "Put walls to the length, width, height specified"
  10927. instructions = "Place stack(s) of material starting in first slot."
  10928.  
  10929. usage = "walls <length> <width> <height>"
  10930.  
  10931. x = 0
  10932. y = 0
  10933. z = 0
  10934. face = 0
  10935. minimumFuel = 100
  10936. missionMessage = "Mission complete."
  10937. abort = false
  10938. startLevel = 0
  10939. local currentFuelLevel = turtle.getFuelLevel()
  10940. areaCovered = 0
  10941.  
  10942. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  10943. print(version)
  10944. print(mission)
  10945. print(instructions)
  10946. print(usage)
  10947. return
  10948. end
  10949.  
  10950. if nArgs ~= 3 then
  10951. print(usage)
  10952. return
  10953. end
  10954.  
  10955. length = tonumber(args[1])
  10956. if length == nil then
  10957. print("\"", args[1], "\" is not a valid length")
  10958. return
  10959. end
  10960. if length < 1 then
  10961. print("length must be a positive number greater than zero")
  10962. end
  10963.  
  10964. width = tonumber(args[2])
  10965. if width == nil then
  10966. print("\"", args[2], "\" is not a valid width")
  10967. return
  10968. end
  10969. if width < 1 then
  10970. print("width must be a positive number greater than zero")
  10971. end
  10972.  
  10973. height = tonumber(args[3])
  10974. if startLevel == nil then
  10975. print("\"", args[3], "\" is not a valid height")
  10976. return
  10977. end
  10978.  
  10979. currentSlot = 2
  10980. materialSlot = 1
  10981. maxSlot = 16
  10982.  
  10983. nextTurn = "left"
  10984.  
  10985. local clock = os.clock
  10986. function sleep(n) -- seconds
  10987. local t0 = clock()
  10988. while clock() - t0 <= n do end
  10989. end
  10990.  
  10991. function left()
  10992. if face == 0 then face = 1 turtle.turnLeft() return end
  10993. if face == 1 then face = 2 turtle.turnLeft() return end
  10994. if face == 2 then face = 3 turtle.turnLeft() return end
  10995. if face == 3 then face = 0 turtle.turnLeft() return end
  10996. print("function left\(\): Bad face value: ", face)
  10997. end
  10998.  
  10999. function right()
  11000. if face == 0 then face = 3 turtle.turnRight() return end
  11001. if face == 1 then face = 0 turtle.turnRight() return end
  11002. if face == 2 then face = 1 turtle.turnRight() return end
  11003. if face == 3 then face = 2 turtle.turnRight() return end
  11004. print("function right\(\): Bad face value: ", face)
  11005. end
  11006.  
  11007. function up()
  11008. turtle.up()
  11009. y = y+1
  11010. end
  11011.  
  11012. function rise(nBlocks)
  11013. local i
  11014. for i=1,nBlocks do
  11015. up()
  11016. end
  11017. end
  11018.  
  11019. function down()
  11020. if turtle.detectDown() then
  11021. turtle.digDown()
  11022. end
  11023. turtle.down()
  11024. y = y-1
  11025. end
  11026.  
  11027. function turn()
  11028. if nextTurn == "left" then
  11029. left()
  11030. else
  11031. right()
  11032. end
  11033. chomp()
  11034. forward()
  11035. if nextTurn == "left" then
  11036. left()
  11037. nextTurn = "right"
  11038. else
  11039. right()
  11040. nextTurn = "left"
  11041. end
  11042. areaCovered = areaCovered + 1
  11043. end
  11044.  
  11045. function forward()
  11046. while turtle.detect() do -- This loop added in case of falling sand or whatever
  11047. turtle.dig()
  11048. end
  11049. for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
  11050. if turtle.forward() then
  11051. break
  11052. end
  11053. turtle.attack()
  11054. sleep(2)
  11055. end
  11056. areaCovered = areaCovered + 1
  11057.  
  11058. if face == 0 then z = z+1 return end
  11059. if face == 1 then x = x-1 return end
  11060. if face == 2 then z = z-1 return end
  11061. if face == 3 then x = x+1 return end
  11062. end
  11063.  
  11064. function setFace(f)
  11065. if f == 0 then
  11066. if face == 0 then return end
  11067. if face == 1 then right() return end
  11068. if face == 2 then right() right() return end
  11069. if face == 3 then left() return end
  11070. end
  11071.  
  11072. if f == 1 then
  11073. if face == 0 then left() return end
  11074. if face == 1 then return end
  11075. if face == 2 then right() return end
  11076. if face == 3 then right() right() return end
  11077. end
  11078.  
  11079. if f == 2 then
  11080. if face == 0 then left() left() return end
  11081. if face == 1 then left() return end
  11082. if face == 2 then return end
  11083. if face == 3 then right() return end
  11084. end
  11085.  
  11086. if f == 3 then
  11087. if face == 0 then right() return end
  11088. if face == 1 then left() left() return end
  11089. if face == 2 then left() return end
  11090. if face == 3 then return end
  11091. end
  11092. end
  11093.  
  11094. function home(targetY)
  11095. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  11096. if x < 0 then
  11097. setFace(3)
  11098. while x < 0 do
  11099. forward()
  11100. end
  11101. else
  11102. if x > 0 then
  11103. setFace(1)
  11104. while x > 0 do
  11105. forward()
  11106. end
  11107. end
  11108. end
  11109.  
  11110. if z < 0 then
  11111. setFace(0)
  11112. while z < 0 do
  11113. forward()
  11114. end
  11115. else
  11116. if z > 0 then
  11117. setFace(2)
  11118. while z > 0 do
  11119. forward()
  11120. end
  11121. end
  11122. end
  11123.  
  11124. if y > 0 then
  11125. while y > 0 do
  11126. down()
  11127. end
  11128. end
  11129.  
  11130. setFace(0)
  11131. end
  11132.  
  11133. function ensureMaterial()
  11134. if turtle.getItemCount(materialSlot) < 3 then
  11135. organizeMaterial()
  11136. end
  11137. if turtle.getItemCount(materialSlot) < 3 then
  11138. print("No more material")
  11139. return false
  11140. end
  11141. return true
  11142. end
  11143.  
  11144. function organizeMaterial()
  11145. local i
  11146. materialCount = turtle.getItemCount(materialSlot)
  11147.  
  11148. if materialCount < 3 then
  11149. -- print("Attempting to refill slot ", materialSlot)
  11150. for i=2,16 do
  11151. turtle.select(i)
  11152. if turtle.compareTo(materialSlot) then
  11153. turtle.transferTo(materialSlot)
  11154. end
  11155. end
  11156. end
  11157. turtle.select(materialSlot)
  11158. end
  11159.  
  11160. function layBlock()
  11161. turtle.select(materialSlot)
  11162.  
  11163. if startLevel > 2 then
  11164. if turtle.detectUp() then
  11165. if turtle.compareUp() then
  11166. return
  11167. else
  11168. turtle.digUp()
  11169. end
  11170. end
  11171. if ensureMaterial() then
  11172. turtle.placeUp()
  11173. end
  11174. else
  11175. if turtle.detectDown() then
  11176. if turtle.compareDown() then
  11177. return
  11178. else
  11179. turtle.digDown()
  11180. end
  11181. end
  11182. if ensureMaterial() then
  11183. turtle.placeDown()
  11184. end
  11185. end
  11186. end
  11187.  
  11188. function checkFuel()
  11189. if currentFuelLevel == "unlimited" then
  11190. return true
  11191. end
  11192.  
  11193. if currentFuelLevel < minimumFuel then
  11194. if not turtle.refuel() then
  11195. areaCovered = targetArea
  11196. missionMessage = "Mission aborted due to low fuel."
  11197. abort = true
  11198. return false
  11199. end
  11200. end
  11201. return true
  11202. end
  11203.  
  11204. currentSlot = 1
  11205.  
  11206. --[[
  11207. function layRow(nBlocks)
  11208. turtle.select(currentSlot)
  11209.  
  11210. for i=1,nBlocks do
  11211. if turtle.getItemCount(currentSlot) > 0 then
  11212. turtle.placeDown()
  11213. turtle.forward()
  11214. else
  11215. currentSlot = currentSlot + 1
  11216. if turtle.getItemCount(currentSlot) > 0 then
  11217. turtle.select(currentSlot)
  11218. turtle.placeDown()
  11219. turtle.forward()
  11220. else
  11221. print("Can't find more material")
  11222. return
  11223. end
  11224. end
  11225. end
  11226. end
  11227. --]]
  11228.  
  11229. function layRow(nBlocks)
  11230. turtle.select(materialSlot)
  11231. for i=1,nBlocks do
  11232. if ensureMaterial() then
  11233. turtle.placeDown()
  11234. turtle.forward()
  11235. else
  11236. if ensureMaterial() then
  11237. turtle.placeDown()
  11238. turtle.forward()
  11239. else
  11240. print("Can't find more material")
  11241. return
  11242. end
  11243. end
  11244. end
  11245. end
  11246.  
  11247. -- MAIN PROGRAM
  11248.  
  11249. turtle.select(1)
  11250.  
  11251. print("fuelLevel = ", currentFuelLevel)
  11252. print("length = ", length)
  11253. print("width = ", width)
  11254. print("face = ", face)
  11255.  
  11256. print("Current Fuel Level: ", currentFuelLevel)
  11257.  
  11258. if currentFuelLevel ~= "unlimited" then
  11259. if currentFuelLevel < minimumFuel then
  11260. if not turtle.refuel() then
  11261. print("No fuel")
  11262. return
  11263. end
  11264. end
  11265. end
  11266.  
  11267. notFinished = true
  11268.  
  11269. while notFinished do
  11270. if y == height then
  11271. notFinished = false
  11272. break
  11273. end
  11274. up()
  11275.  
  11276. setFace(0)
  11277. layRow(length - 1)
  11278.  
  11279. setFace(1)
  11280. layRow(width - 1)
  11281.  
  11282. setFace(2)
  11283. layRow(length - 1)
  11284.  
  11285. setFace(3)
  11286. layRow(width - 1)
  11287. end
  11288.  
  11289. setFace(0)
  11290. turtle.back()
  11291. z = z - 1
  11292. while y > 0 do
  11293. turtle.down()
  11294. y = y - 1
  11295. end
  11296. print(missionMessage)
  11297. print(" Current fuel level is ", turtle.getFuelLevel())
  11298. *** walls3
  11299.  
  11300. version = "walls3: Rev 0.1"
  11301. mission= "Place 3-block high walls at the length and width specified."
  11302. instructions = "Place stack(s) of material starting in first slot."
  11303.  
  11304. args = {...}
  11305. nArgs = #args
  11306.  
  11307. usage = "walls3 <length> <width>"
  11308.  
  11309. materialSlot = 1
  11310.  
  11311. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  11312. print(version)
  11313. print(mission)
  11314. print(instructions)
  11315. print(usage)
  11316. return
  11317. end
  11318.  
  11319. if nArgs ~= 2 then
  11320. print(usage)
  11321. return
  11322. end
  11323.  
  11324. length = tonumber(args[1])
  11325. if length == nil then
  11326. print("\"", args[1], "\" is not a valid length")
  11327. return
  11328. end
  11329. if length < 1 then
  11330. print("length must be a positive number greater than zero")
  11331. end
  11332.  
  11333. width = tonumber(args[2])
  11334. if width == nil then
  11335. print("\"", args[2], "\" is not a valid width")
  11336. return
  11337. end
  11338. if width < 1 then
  11339. print("width must be a positive number greater than zero")
  11340. end
  11341.  
  11342. function place()
  11343. ensureMaterial()
  11344. turtle.place()
  11345. end
  11346.  
  11347. function placeUp()
  11348. ensureMaterial()
  11349. turtle.placeUp()
  11350. end
  11351.  
  11352. function placeDown()
  11353. ensureMaterial()
  11354. turtle.placeDown()
  11355. end
  11356.  
  11357. function ensureMaterial()
  11358. if turtle.getItemCount(materialSlot) < 3 then
  11359. organizeMaterial()
  11360. end
  11361. if turtle.getItemCount(materialSlot) < 3 then
  11362. print("No more material")
  11363. return false
  11364. end
  11365. return true
  11366. end
  11367.  
  11368. function organizeMaterial()
  11369. local i
  11370. materialCount = turtle.getItemCount(materialSlot)
  11371.  
  11372. if materialCount < 6 then
  11373. -- print("Attempting to refill slot ", materialSlot)
  11374. for i=2,12 do
  11375. turtle.select(i)
  11376. if turtle.compareTo(materialSlot) then
  11377. turtle.transferTo(materialSlot)
  11378. end
  11379. end
  11380. end
  11381. turtle.select(materialSlot)
  11382. end
  11383.  
  11384. function buildWall(length)
  11385. for i=1,length do
  11386. ensureMaterial()
  11387. turtle.select(materialSlot)
  11388. placeUp()
  11389. placeDown()
  11390. if i == length then
  11391. turtle.turnLeft()
  11392. end
  11393. turtle.back()
  11394. place()
  11395. end
  11396. end
  11397.  
  11398. turtle.turnLeft()
  11399. turtle.turnLeft()
  11400. turtle.up()
  11401. buildWall(length)
  11402. buildWall(length-1)
  11403. buildWall(length-1)
  11404. buildWall(length-2)
  11405.  
  11406. *** write
  11407. -- write
  11408. -- Builds the letters from the input text
  11409. -- Written by HarvDad, June 2014
  11410.  
  11411. version = "write: Rev 0.1"
  11412. instructions = "Place stack(s) of material starting in first slot."
  11413.  
  11414. usage = "write <text>"
  11415.  
  11416. args = {...}
  11417. nArgs = #args
  11418.  
  11419.  
  11420. text = ""
  11421.  
  11422. letters = {
  11423. {"A", "====== ", " = =", " = =", " = =", "====== "},
  11424. {"B", "=======", "= = =", "= = =", "= =", " == == "},
  11425. {"C", " ===== ", "= =", "= =", "= =", " = = "},
  11426. {"D", "=======", "= =", "= =", "= =", " ===== "},
  11427. {"E", "=======", "= = =", "= = =", "= = =", "= ="},
  11428. {"F", "=======", " = =", " = =", " = =", " ="},
  11429. {"G", " ===== ", "= =", "= = =", "= = =", " === ="},
  11430. {"H", "=======", " = ", " = ", " = ", "======="},
  11431. {"I", " ", "= =", "=======", "= =", " "},
  11432. {"J", " == ", "= ", "= ", "= ", " ======"},
  11433. {"K", "=======", " = ", " = = ", " = = ", "= ="},
  11434. {"L", "=======", "= ", "= ", "= ", "= "},
  11435. {"M", "=======", " = ", " = ", " = ", "======="},
  11436. {"N", "=======", " = ", " = ", " = ", "======="},
  11437. {"O", " ===== ", "= =", "= =", "= =", " ===== "},
  11438. {"P", "=======", " = =", " = =", " = =", " == "},
  11439. {"Q", " ===== ", "= =", "= = =", "== =", "====== "},
  11440. {"R", "=======", " = =", " == =", " = = =", "= == "},
  11441. {"S", "= == ", "= = =", "= = =", "= = =", " == ="},
  11442. {"T", " =", " =", "=======", " =", " ="},
  11443. {"U", " ======", "= ", "= ", "= ", " ======"},
  11444. {"V", " =====", " = ", "= ", " = ", " ====="},
  11445. {"W", "=======", " = ", " == ", " = ", "======="},
  11446. {"X", "== ==", " = = ", " = ", " = = ", "== =="},
  11447. {"Y", " ===", " = ", "=== ", " = ", " ==="},
  11448. {"Z", "== =", "= = =", "= = =", "= = =", "= =="},
  11449. {"?", " = ", " =", "= == =", " = =", " == "},
  11450. {"!", " ", " ", "= =====", " ", " "},
  11451. {" ", " ", " ", " ", " ", " "},
  11452. }
  11453.  
  11454. materialSlot = 1
  11455.  
  11456. x = 0
  11457. y = 0
  11458. z = 0
  11459. face = 0
  11460.  
  11461. -- The following 'face' directions are relative to the starting position of the turtle in this program
  11462. north = 0
  11463. west = 1
  11464. south = 2
  11465. east = 3
  11466.  
  11467. goForward = 0
  11468. goBackward = 1
  11469. direction = goForward
  11470.  
  11471. currentSlot = 1
  11472.  
  11473. function setFace(f)
  11474. if f == 0 then
  11475. if face == 0 then return end
  11476. if face == 1 then right() return end
  11477. if face == 2 then right() right() return end
  11478. if face == 3 then left() return end
  11479. end
  11480.  
  11481. if f == 1 then
  11482. if face == 0 then left() return end
  11483. if face == 1 then return end
  11484. if face == 2 then right() return end
  11485. if face == 3 then right() right() return end
  11486. end
  11487.  
  11488. if f == 2 then
  11489. if face == 0 then left() left() return end
  11490. if face == 1 then left() return end
  11491. if face == 2 then return end
  11492. if face == 3 then right() return end
  11493. end
  11494.  
  11495. if f == 3 then
  11496. if face == 0 then right() return end
  11497. if face == 1 then left() left() return end
  11498. if face == 2 then left() return end
  11499. if face == 3 then return end
  11500. end
  11501. end
  11502.  
  11503. function left()
  11504. if face == 0 then face = 1 turtle.turnLeft() return end
  11505. if face == 1 then face = 2 turtle.turnLeft() return end
  11506. if face == 2 then face = 3 turtle.turnLeft() return end
  11507. if face == 3 then face = 0 turtle.turnLeft() return end
  11508. print("function left\(\): Bad face value: ", face)
  11509. end
  11510.  
  11511. function right()
  11512. if face == 0 then face = 3 turtle.turnRight() return end
  11513. if face == 1 then face = 0 turtle.turnRight() return end
  11514. if face == 2 then face = 1 turtle.turnRight() return end
  11515. if face == 3 then face = 2 turtle.turnRight() return end
  11516. print("function right\(\): Bad face value: ", face)
  11517. end
  11518.  
  11519. function up()
  11520. while turtle.detectUp() do -- This loop added in case of falling sand or whatever
  11521. turtle.digUp()
  11522. end
  11523. turtle.up()
  11524. y = y+1
  11525. end
  11526.  
  11527. function rise(nBlocks)
  11528. local i
  11529. for i=1,nBlocks do
  11530. up()
  11531. end
  11532. end
  11533.  
  11534. function down()
  11535. if turtle.detectDown() then
  11536. turtle.digDown()
  11537. end
  11538. turtle.down()
  11539. y = y-1
  11540. end
  11541.  
  11542. function moveForward(nBlocks)
  11543. for i = 1, nBlocks do
  11544. turtle.forward()
  11545. if face == north then
  11546. z = z + 1
  11547. elseif face == south then
  11548. z = z - 1
  11549. elseif face == east then
  11550. x = x + 1
  11551. elseif face == west then
  11552. x = x - 1
  11553. end
  11554. end
  11555.  
  11556. end
  11557.  
  11558. function moveBackward(nBlocks)
  11559. for i = 1, nBlocks do
  11560. turtle.back()
  11561. if face == north then
  11562. z = z - 1
  11563. elseif face == south then
  11564. z = z + 1
  11565. elseif face == east then
  11566. x = x - 1
  11567. elseif face == west then
  11568. x = x + 1
  11569. end
  11570. end
  11571. end
  11572.  
  11573. function home(targetY)
  11574. -- print("home:face ", face, ", x = ", x, ", z = ", z)
  11575. if x < 0 then
  11576. setFace(east)
  11577. while x < 0 do
  11578. moveForward(1)
  11579. end
  11580. else
  11581. if x > 0 then
  11582. setFace(west)
  11583. while x > 0 do
  11584. moveForward(1)
  11585. end
  11586. end
  11587. end
  11588.  
  11589. if z < 0 then
  11590. setFace(north)
  11591. while z < 0 do
  11592. moveForward(1)
  11593. end
  11594. else
  11595. if z > 0 then
  11596. setFace(south)
  11597. while z > 0 do
  11598. moveForward(1)
  11599. end
  11600. end
  11601. end
  11602.  
  11603. if y > 0 then
  11604. while y > 0 do
  11605. down()
  11606. end
  11607. end
  11608.  
  11609. setFace(0)
  11610. end
  11611.  
  11612. function ensureMaterial()
  11613. if turtle.getItemCount(materialSlot) < 3 then
  11614. organizeMaterial()
  11615. end
  11616. if turtle.getItemCount(materialSlot) < 3 then
  11617. print("No more material")
  11618. return false
  11619. end
  11620. return true
  11621. end
  11622.  
  11623. function organizeMaterial()
  11624. local i
  11625. materialCount = turtle.getItemCount(materialSlot)
  11626.  
  11627. if materialCount < 3 then
  11628. -- print("Attempting to refill slot ", materialSlot)
  11629. for i=2,16 do
  11630. turtle.select(i)
  11631. if turtle.compareTo(materialSlot) then
  11632. turtle.transferTo(materialSlot)
  11633. end
  11634. end
  11635. end
  11636. turtle.select(materialSlot)
  11637. end
  11638.  
  11639. function getLetter(letter)
  11640. letter = string.upper(letter)
  11641.  
  11642. for i=1,#letters do
  11643. if letters[i][1] == letter then
  11644. return letters[i]
  11645. end
  11646. end
  11647. print("Cannot find entry for \'", letter, "\'")
  11648. return nil
  11649. end
  11650.  
  11651. function hitTheDeck()
  11652. --print("hitTheDeck: y = ", y)
  11653. while y > 0 do
  11654. down()
  11655. -- print(" Down")
  11656. end
  11657. -- print(" y ends at ", y)
  11658. goingUp = true
  11659. end
  11660.  
  11661.  
  11662. goingUp = true
  11663.  
  11664. function buildLetter(letter)
  11665. letterData = getLetter(letter)
  11666. turtle.select(1)
  11667.  
  11668. if letter == " " then
  11669. right()
  11670. moveForward(7)
  11671. left()
  11672. return
  11673. end
  11674. --[[
  11675. if letterData ~= nil then
  11676. for i=1,#letterData do
  11677. print(" ", letterData[i])
  11678. end
  11679. end
  11680. --]]
  11681.  
  11682. if letterData == nil then
  11683. print("Cannot build \'", letter, "\'")
  11684. return
  11685. end
  11686.  
  11687. for i=2,#letterData do
  11688. column = letterData[i]
  11689. height = string.len(column)
  11690. if goingUp then
  11691. for j=1,height do
  11692. char = string.sub(column, j, j)
  11693. if char ~= " " then
  11694. ensureMaterial()
  11695. turtle.select(materialSlot)
  11696. turtle.place()
  11697. end
  11698. if j < height then
  11699. up()
  11700. end
  11701. end
  11702. else
  11703. for j=height,1,-1 do
  11704. char = string.sub(column, j, j)
  11705. if char ~= " " then
  11706. ensureMaterial()
  11707. turtle.select(materialSlot)
  11708. turtle.place()
  11709. end
  11710. if j > 1 then
  11711. down()
  11712. end
  11713. end
  11714. end
  11715.  
  11716. if goingUp then
  11717. goingUp = false
  11718. else
  11719. goingUp = true
  11720. end
  11721.  
  11722. right()
  11723. moveForward(1)
  11724. left()
  11725. end
  11726. end
  11727.  
  11728.  
  11729.  
  11730. if nArgs == 0 then
  11731. print(version)
  11732. print(instructions)
  11733. print(usage)
  11734. return
  11735. end
  11736.  
  11737. text = ""
  11738. for i=1,nArgs do
  11739. text = text .. " " .. args[i]
  11740. end
  11741. text = string.sub(text, 2)
  11742.  
  11743. for i=1,string.len(text) do
  11744. buildLetter(string.sub(text,i,i))
  11745. right()
  11746. moveForward(1)
  11747. -- hitTheDeck()
  11748. moveForward(1)
  11749. left()
  11750. end
  11751.  
  11752. home(0)*** wt
  11753.  
  11754. print("Ready")
  11755.  
  11756. rednet.open("right")
  11757.  
  11758. while true do
  11759. id, message = rednet.receive()
  11760. print("received message \"", message, "\" from id ", id)
  11761. if message == "quit" then
  11762. break
  11763. end
  11764. shell.run(message)
  11765. end
  11766.  
  11767. rednet.close("right")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement