Advertisement
Blackhome

Tunnel 9 Turtles

Dec 16th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.70 KB | None | 0 0
  1. -- What to do?:
  2. -- Droping Items in Chest
  3. -- Communication of Fuel and Cobblestone
  4. -- Communication of Commands
  5. -- Communication Turtle look on each other
  6.  
  7. local turtlePosition
  8. local controleId
  9.  
  10. local notWishedItems = {}
  11. notWishedItems[0] = "minecraft:dirt"
  12. notWishedItems[1] = "minecraft:cobblestone"
  13. notWishedItems[2] = "minecraft:stone"
  14. notWishedItems[3] = "minecraft:obsidian"
  15. notWishedItems[4] = "minecraft:sand"
  16. notWishedItems[5] = "minecraft:gravel"
  17. notWishedItems[6] = "minecraft:rail"
  18. notWishedItems[7] = "minecraft:planks"
  19. notWishedItems[8] = "minecraft:fence"
  20. notWishedItems[9] = "bluepower:marble"
  21. notWishedItems[10] = "minecraft:torch"
  22. notWishedItems[11] = "minecraft:trapped_chest"
  23. notWishedItems[12] = "minecraft:flowing_water"
  24. notWishedItems[13] = "minecraft:flowing_lava"
  25. notWishedItems[14] = "minecraft:chest"
  26. notWishedItems[15] = "computercraft:CC-TurtleExpanded"
  27.  
  28.  
  29. --get the position of the turtles building the tunnel. TopLeft is position one, BottomRight is position 9
  30. function getPositionOfTurtle()
  31. local number = 10
  32. local bNum = (number > 9 or number < 1)
  33. local bShow = true
  34. while (bNum) do
  35. if(bShow) then
  36. io.write("Geben Sie an, um welche Turtel es sich handelt")
  37. io.write("Folgende Turtel git es:")
  38. io.write("Linksoben: 1\nMitteoben: 2\nRechtsoben: 3\n")
  39. io.write("Linksmitte: 4\nMitte: 5\nRechtsmitte: 6\n")
  40. io.write("Linksunten: 7\nMitteunten: 8\nRechtsunten: 9\n")
  41. bShow = false
  42. end
  43. number = tonumber(io.read())
  44. bNum = (number > 9 or number < 1)
  45. if (bNum) then
  46. io.write("Falsche Nummer, bitte erneut angeben")
  47. io.write("Wollen Sie die Nummern der Turteln nochmal eingeblendet haben?\n")
  48. io.write("Dann geben Sie die 1 ein. Ansonsten eine andere Zahl\n ")
  49. bShow = (tonumber(io.read()) == 1)
  50. end
  51. end
  52. return number
  53. end
  54.  
  55. --register the turtles to interact with
  56. function registerAllTurtles(turtleArr)
  57. if(not(rednet.isOpen("left"))) then
  58. rednet.open("left")
  59. end
  60. while(true) do
  61. rednet.broadcast("Give Position", "registerTurtles")
  62. local tId, tPos, prot = rednet.receive("register", 0.5)
  63. if(tId and (tonumber(tPos)) > 0 and tonumber(tPos) < 10 and tonumber(tPos) ~= 5)then
  64. printMsgGotBy(tId, tPos)
  65. if(tPos < 5)then
  66. turtleArr[tPos-1] = tId
  67. else
  68. turtleArr[tPos-2] = tId
  69. end
  70. local msg = "RegisterSuccessfull"
  71. rednet.send(tId, msg)
  72. printMsgSendTo(tId, msg)
  73. end
  74. if(getArrLength(turtleArr) == 8)then
  75. while (true)do
  76. local tId, tPos, prot = rednet.receive("register", 1)
  77. if(tId == nil)then
  78. return 0
  79. else
  80. local msg = "RegisterSuccessfull"
  81. rednet.send(tId, msg)
  82. printMsgSendTo(tId, msg)
  83. end
  84. end
  85. end
  86. end
  87. end
  88. function registerAndGetSenderId(tPosition)
  89. if(not(rednet.isOpen("left"))) then
  90. rednet.open("left")
  91. end
  92. local senderId, message, protocoll = rednet.receive("registerTurtles")
  93. printMsgGotBy(senderId, message)
  94. while(true) do
  95. rednet.send(senderId, tPosition, "register")
  96. printMsgSendTo(senderId, tPosition)
  97. local s1Id
  98. s1Id, message, protocoll = rednet.receive(0.25)
  99. if (s1Id) then
  100. printMsgGotBy(s1Id, message)
  101. end
  102.  
  103. if((s1Id == senderId) and (message == "RegisterSuccessfull")) then
  104. return senderId;
  105. end
  106. end
  107. end
  108.  
  109. function getArrLength(arr)
  110. local num1 = 0
  111. local length = 0;
  112. while (num1 <= table.getn(arr))do
  113. if (arr[num1] ~= nil)then
  114. length = length + 1
  115. end
  116. num1 = num1 + 1
  117. end
  118. return length
  119. end
  120.  
  121. --shoud be used after sending a onetime message, to make a message protocoll
  122. function printMsgSendTo(rId, msg )
  123. print("Message send to ", rId, ": ", msg, "\n")
  124. end
  125. function printMsgGotBy(sId, msg)
  126. print("Message received from ", sId, ": ", msg, "\n")
  127. end
  128.  
  129.  
  130. --if there is no block in the used direction, the turtle places one
  131. function setBlockOnTop()
  132. local success, data = turtle.inspectUp()
  133. if (success and data.name == "minecraft:gravel")then
  134. while(turtle.detectUp())do
  135. turtle.digUp()
  136. os.sleep(0.25)
  137. end
  138. end
  139. if(turtle.detectUp() == false or detectWaterOrLavaOnTop())then
  140. placeOutsideCobblestone("top")
  141. return true
  142. end
  143. return false
  144. end
  145. function setBlockOnBottom()
  146. if(turtle.detectDown() == false or detectWaterOrLavaOnBottom())then
  147. placeOutsideCobblestone("bottom")
  148. return true
  149. end
  150. return false
  151. end
  152. function setBlockInFront()
  153. local success, data = turtle.inspect()
  154. if (success and data.name == "minecraft:gravel")then
  155. while(turtle.detect())do
  156. turtle.dig()
  157. os.sleep(0.25)
  158. end
  159. end
  160. if(turtle.detect() == false or detectWaterOrLavaInFront())then
  161. placeOutsideCobblestone("front")
  162. return true
  163. end
  164. return false
  165. end
  166.  
  167. --starting mining on the top side of the turtle
  168. function miningOnTop(locData)
  169. local success, data = turtle.inspectUp()
  170. if(success and isAWishedBlock(data.name))then
  171. turtleUp()
  172. locData.highDis = locData.highDis + 1
  173. mining(locData.rightDis, locData.highDis, locData.lookDir)
  174. turtleDown()
  175. locData.highDis = locData.highDis - 1
  176. placeOutsideCobblestone("top")
  177. end
  178. end
  179. function miningOnBottom(locData)
  180. local success, data = turtle.inspectDown()
  181. if(success and isAWishedBlock(data.name))then
  182. turtleDown()
  183. locData.highDis = locData.highDis - 1
  184. mining(locData.rightDis, locData.highDis, locData.lookDir)
  185. turtleUp()
  186. locData.highDis = locData.highDis + 1
  187. placeOutsideCobblestone("bottom")
  188. end
  189. end
  190. function miningInFront(locData)
  191. local success, data = turtle.inspect()
  192. if(success and isAWishedBlock(data.name))then
  193. turtleForward()
  194. if (locData.lookDir % 4 == 1)then
  195. locData.rightDis = locData.rightDis + 1
  196. elseif (locData.lookDir % 4 == 3)then
  197. locData.rightDis = locData.rightDis - 1
  198. end
  199. mining(locData.rightDis, locData.highDis, locData.lookDir)
  200. turtle.turnLeft()
  201. turtle.turnLeft()
  202. turtleForward()
  203. turtle.turnLeft()
  204. turtle.turnLeft()
  205. if (locData.lookDir % 4 == 1)then
  206. locData.rightDis = locData.rightDis - 1
  207. elseif (locData.lookDir % 4 == 3)then
  208. locData.rightDis = locData.rightDis + 1
  209. end
  210. placeOutsideCobblestone("front")
  211. end
  212. end
  213.  
  214. --complete moving actions of any turtle
  215. function moveTurtleLeftTop(miningActive, locData)
  216. turtleForward()
  217. turtle.turnLeft()
  218. local sBoT = setBlockOnTop()
  219. local sBiF = setBlockInFront()
  220. local goMiningTop = miningActive and (not sBoT)
  221. local goMiningFront = miningActive and (not sBiF)
  222. if(goMiningTop)then
  223. miningOnTop(locData)
  224. end
  225. if(goMiningFront)then
  226. miningInFront(locData)
  227. end
  228. turtle.turnRight()
  229. return true
  230. end
  231. function moveTurtleLeftTop(miningActive, locData)
  232. turtleForward()
  233. turtle.turnLeft()
  234. local sBoT = setBlockOnTop()
  235. local sBiF = setBlockInFront()
  236. local goMiningTop = miningActive and (not sBoT)
  237. local goMiningFront = miningActive and (not sBiF)
  238. if(goMiningTop)then
  239. miningOnTop(locData)
  240. end
  241. if(goMiningFront)then
  242. miningInFront(locData)
  243. end
  244. turtle.turnRight()
  245. return true
  246. end
  247. function moveTurtleMiddleTop(miningActive, locData)
  248. turtleForward()
  249. local sBoT = setBlockOnTop()
  250. local goMiningTop = miningActive and (not sBoT)
  251. if (goMiningTop)then
  252. miningOnTop(locData)
  253. end
  254. return true
  255. end
  256. function moveTurtleRightTop(miningActive, locData)
  257. turtleForward()
  258. turtle.turnRight()
  259. local sBoT = setBlockOnTop()
  260. local sBiF = setBlockInFront()
  261. local goMiningTop = miningActive and (not sBoT)
  262. local goMiningFront = miningActive and (not sBiF)
  263. if(goMiningTop)then
  264. miningOnTop(locData)
  265. end
  266. if(goMiningFront)then
  267. miningInFront(locData)
  268. end
  269. turtle.turnLeft()
  270. return true
  271. end
  272. function moveTurtleLeftMiddle(miningActive, locData)
  273. turtleForward()
  274. turtle.turnLeft()
  275. local sBiF = setBlockInFront()
  276. local goMiningFront = miningActive and (not sBiF)
  277. if(goMiningFront)then
  278. miningInFront(locData)
  279. end
  280. turtle.turnRight()
  281. return true
  282. end
  283. function moveTurtleMiddleMiddle(miningActive, locData)
  284. turtleForward()
  285. return true
  286. end
  287. function moveTurtleRightMiddle(miningActive, locData)
  288. turtleForward()
  289. turtle.turnRight()
  290. local sBiF = setBlockInFront()
  291. local goMiningFront = miningActive and (not sBiF)
  292. if(goMiningFront)then
  293. miningInFront(locData)
  294. end
  295. turtle.turnLeft()
  296. return true
  297. end
  298. function moveTurtleLeftBottom(miningActive, locData)
  299. turtleForward()
  300. turtle.turnLeft()
  301. local sBoB = setBlockOnBottom()
  302. local sBiF = setBlockInFront()
  303. local goMiningBottom = miningActive and (not sBoB)
  304. local goMiningFront = miningActive and (not sBiF)
  305. if(goMiningBottom)then
  306. miningOnBottom(locData)
  307. end
  308. if(goMiningFront)then
  309. miningInFront(locData)
  310. end
  311. turtle.turnRight()
  312. return true
  313. end
  314. function moveTurtleMiddleBottom(miningActive, locData)
  315. turtleForward()
  316. local sBoB = setBlockOnBottom()
  317. local goMiningBottom = miningActive and (not sBoB)
  318. if (goMiningBottom)then
  319. miningOnBottom(locData)
  320. end
  321. return true
  322. end
  323. function moveTurtleRightBottom(miningActive, locData)
  324. turtleForward()
  325. turtle.turnRight()
  326. local sBoB = setBlockOnBottom()
  327. local sBiF = setBlockInFront()
  328. local goMiningBottom = miningActive and (not sBoB)
  329. local goMiningFront = miningActive and (not sBiF)
  330. if(goMiningBottom)then
  331. miningOnBottom(locData)
  332. end
  333. if(goMiningFront)then
  334. miningInFront(locData)
  335. end
  336. turtle.turnLeft()
  337. return true
  338. end
  339.  
  340. --moving Turtle. If there is no Fuel calling for fuel.
  341. function turtleForward()
  342. haveEnoughFuel()
  343. local numOfWait = 0
  344. while(turtle.forward() == false)do
  345. local success, data = turtle.inspect()
  346. if (success and data.name == "computercraft:CC-TurtleExpanded")then
  347. os.sleep(0.5)
  348. if (numOfWait%10 == 0)then
  349. print("Turtle is waiting in front of me")
  350. end
  351. numOfWait = numOfWait + 1
  352. else
  353. turtle.dig()
  354. end
  355. end
  356. end
  357. function turtleUp()
  358. haveEnoughFuel()
  359. local numOfWait = 0
  360. while(turtle.up() == false)do
  361. local success, data = turtle.inspectUp()
  362. if (success and data.name == "computercraft:CC-TurtleExpanded")then
  363. os.sleep(0.5)
  364. if (numOfWait%10 == 0)then
  365. print("Turtle is waiting on top of me")
  366. end
  367. numOfWait = numOfWait + 1
  368. else
  369. turtle.digUp()
  370. end
  371. end
  372. end
  373. function turtleDown()
  374. haveEnoughFuel()
  375. local numOfWait = 0
  376. while(turtle.down() == false)do
  377. local success, data = turtle.inspectDown()
  378. if (success and data.name == "computercraft:CC-TurtleExpanded")then
  379. os.sleep(0.5)
  380. if (numOfWait%10 == 0)then
  381. print("Turtle is waiting on bottom of me")
  382. end
  383. numOfWait = numOfWait + 1
  384. else
  385. turtle.digDown()
  386. end
  387. end
  388. end
  389.  
  390. --get all special blocks the turtle crosses
  391. function mining()
  392. local cnt = 0
  393. while (cnt < 6)do
  394. if (cnt == 0)then
  395. local success, data = turtle.inspectUp()
  396. if (success and isAWishedBlock(data.name))then
  397. turtleUp()
  398. mining()
  399. turtleDown()
  400. end
  401. elseif (cnt == 1)then
  402. local success, data = turtle.inspectDown()
  403. if (success and isAWishedBlock(data.name))then
  404. turtleDown()
  405. mining()
  406. turtleUp()
  407. end
  408. else
  409. local success, data = turtle.inspect()
  410. if (success and isAWishedBlock(data.name))then
  411. turtleForward()
  412. mining()
  413. turtle.turnRight()
  414. turtle.turnRight()
  415. turtleForward()
  416. turtle.turnRight()
  417. turtle.turnRight()
  418. end
  419. turtle.turnRight()
  420. end
  421. cnt = cnt + 1
  422. end
  423. end
  424. function mining(rightDis, highDis, lookDir)
  425. -- point (0|0) is the point of the right-top-turtle
  426. -- looking right is lookDir 1, looking back is lookDir 2, looking left is lookDir 3, looking forwards is lookDir 0
  427. local cnt = 0
  428. while (cnt < 6)do
  429. if (cnt == 0)then
  430. local success, data = turtle.inspectUp()
  431. if (success and isAWishedBlock(data.name) and ((highDis > -1 or highDis < -3) or (rightDis > 0 or rightDis < -2)))then
  432. turtleUp()
  433. highDis = highDis + 1
  434. mining(rightDis, highDis, lookDir)
  435. turtleDown()
  436. highDis = highDis - 1
  437. end
  438. elseif (cnt == 1)then
  439. local success, data = turtle.inspectDown()
  440. if (success and isAWishedBlock(data.name) and ((highDis > 1 or highDis < -1) or (rightDis > 0 or rightDis < -2)))then
  441. turtleDown()
  442. highDis = highDis - 1
  443. mining(rightDis, highDis, lookDir)
  444. turtleUp()
  445. highDis = highDis + 1
  446. end
  447. else
  448. local success, data = turtle.inspect()
  449. local bRightSide = (lookDir % 4 == 3 and rightDis < 2 and rightDis > -2 and highDis < 1 and highDis > -3)
  450. local bLeftSide = (lookDir % 4 == 1 and rightDis > -4 and rightDis < 0 and highDis < 1 and highDis > -3)
  451. if (success and isAWishedBlock(data.name) and (not bRightSide) and (not bLeftSide))then
  452. turtleForward()
  453. if (lookDir % 4 == 1)then
  454. rightDis = rightDis + 1
  455. elseif (lookDir % 4 == 3)then
  456. rightDis = rightDis - 1
  457. end
  458. mining(rightDis, highDis, lookDir)
  459. turtle.turnRight()
  460. turtle.turnRight()
  461. turtleForward()
  462. turtle.turnRight()
  463. turtle.turnRight()
  464. if (lookDir % 4 == 1)then
  465. rightDis = rightDis - 1
  466. elseif (lookDir % 4 == 3)then
  467. rightDis = rightDis + 1
  468. end
  469. end
  470. turtle.turnRight()
  471. lookDir = lookDir + 1
  472. end
  473. cnt = cnt + 1
  474. end
  475. end
  476.  
  477.  
  478. --returns whether there is water or lava in the used direction
  479. function detectWaterOrLavaOnTop()
  480. local success, data = turtle.inspectUp()
  481. if(data.name == "minecraft:flowing_water" or data.name == "minecraft:flowing_lava")then
  482. return true
  483. end
  484. return false
  485. end
  486. function detectWaterOrLavaOnBottom()
  487. local success, data = turtle.inspectDown()
  488. if(data.name == "minecraft:flowing_water" or data.name == "minecraft:flowing_lava")then
  489. return true
  490. end
  491. return false
  492. end
  493. function detectWaterOrLavaInFront()
  494. local success, data = turtle.inspect()
  495. if(data.name == "minecraft:flowing_water" or data.name == "minecraft:flowing_lava")then
  496. return true
  497. end
  498. return false
  499. end
  500.  
  501. --returns true, if user wants to get the item from the object
  502. function isAWishedBlock(objectName)
  503. local i = 0
  504. while (i <= #notWishedItems)do
  505. if(objectName == notWishedItems[i])then
  506. return false
  507. end
  508. i = i + 1
  509. end
  510. return true
  511. end
  512.  
  513. --place a cobblestone on the entered side of the turtle. sides are only "top", "bottom", "front"
  514. function placeOutsideCobblestone(side)
  515. local slotsLeft = 16
  516. while (slotsLeft > 0)do
  517. turtle.select(slotsLeft)
  518. local data = turtle.getItemDetail()
  519. if (data)then
  520. if (data.name == "minecraft:cobblestone")then
  521. break
  522. elseif(slotsLeft == 1 and turtlePosition ~= 5)then
  523. getCobbleWithMsg()
  524. elseif(slotsLeft == 1 and turtlePosition == 5)then
  525. print("Please give some Cobblestone to this turtle! After that press enter!")
  526. io.read()
  527. slotsLeft = 17
  528. end
  529. elseif (slotsLeft == 1 and turtlePosition == 5)then
  530. print("Please give some Cobblestone to this turtle! After that press enter!")
  531. io.read()
  532. slotsLeft = 17
  533. elseif (slotsLeft == 1 and turtlePosition ~= 5)then
  534. getCobbleWithMsg()
  535. end
  536. slotsLeft = slotsLeft - 1
  537. end
  538.  
  539. if(side == "top")then
  540. turtle.placeUp()
  541. elseif(side == "bottom")then
  542. turtle.placeDown()
  543. elseif(side == "front")then
  544. turtle.place()
  545. end
  546. end
  547. function getCobbleWithMsg()
  548. callConTurtle("needCobble", "msgCobReceived")
  549. local slotsLeft = 16
  550. while (slotsLeft > 0)do
  551. turtle.select(slotsLeft)
  552. local data = turtle.getItemDetail()
  553. if (data and data.name == "minecraft:cobblestone")then
  554. break
  555. elseif (slotsLeft == 1)then
  556. print("Please give some Cobblestone to this turtle! After that press enter!")
  557. io.read()
  558. slotsLeft = 17
  559. end
  560. slotsLeft = slotsLeft - 1
  561. end
  562. end
  563.  
  564. --makes enough fuel by filling up with own fuel or calling for new one
  565. function haveEnoughFuel()
  566. if (turtle.getFuelLevel() == 0 and turtlePosition ~= 5)then
  567. refuelWithMsg()
  568. elseif(turtle.getFuelLevel() == 0 and turtlePosition == 5)then
  569. while(fuelWithOwnRessources() == false)do
  570. print("Please give some fuel to this turtle! After that press enter!")
  571. io.read()
  572. end
  573. end
  574. return true
  575. end
  576. function fuelWithOwnRessources()
  577. local slotsLeft = 16
  578. while (slotsLeft > 0)do
  579. turtle.select(slotsLeft)
  580. if(turtle.refuel())then
  581. return true
  582. end
  583. slotsLeft = slotsLeft - 1
  584. end
  585. return false
  586. end
  587. function refuelWithMsg()
  588. callConTurtle("refuel", "msgFuelReceived")
  589. while(fuelWithOwnRessources() == false)do
  590. print("Please give some fuel to this turtle! After that press enter!")
  591. io.read()
  592. end
  593. end
  594.  
  595. function getMsgByConsoleTurtle()
  596. local sId, msg, protocoll
  597. while(true)do
  598. sId, msg, protocoll = rednet.receive()
  599. printMsgGotBy(sId, msg)
  600. if(sId == controleId)then
  601. break
  602. end
  603. end
  604.  
  605. return msg
  606. end
  607.  
  608. function callConTurtle(msg, msgB)
  609. local answer = false
  610. local num = 0
  611. while(not answer)do
  612. rednet.send(controleId, msg)
  613. if(num % 20 == 0)then
  614. printMsgSendTo(controleId, msg)
  615. end
  616. local sId, msgA, protocoll = rednet.receive(0.25)
  617. printMsgGotBy(sId, msgA)
  618. if (sId == controleId and msgA == msgB)then
  619. answer = true
  620. end
  621. num = num + 1
  622. end
  623. end
  624.  
  625. function callAllTurtles(msg, turtleList)
  626. local num = 0
  627. while (num <= #turtleList)do
  628. print(turtleList[num])
  629. rednet.send(turtleList[num], msg)
  630. printMsgSendTo(turtleList[num], msg)
  631. num = num + 1
  632. end
  633. end
  634. function giveTurtlesPosNames(turtList, posNames)
  635. local turtleList = {}
  636. local num = 0
  637. while (num < 8)do
  638. turtleList[posNames[num]] = turtList[num]
  639. num = num + 1
  640. end
  641. return turtleList
  642. end
  643. function getNumInList(id, list)
  644. local cnt = 0
  645. while (cnt < 8)do
  646. if (list[cnt] == id)then
  647. return cnt
  648. end
  649. cnt = cnt + 1
  650. end
  651. return false
  652. end
  653. function isEveryEntryLookedWord(list, lWord)
  654. local num = 1
  655. while (num <= #list)do
  656. if (list[num] ~= lWord)then
  657. return false
  658. end
  659. num = num + 1
  660. end
  661. return true
  662. end
  663. --every action of the middle turtle, being also the controlling turtle
  664. function middleControl(bMining, disForwards)
  665. local sideTurtleArray = {nil, nil, nil, nil, nil, nil, nil, nil}
  666. registerAllTurtles(sideTurtleArray)
  667. local posNames = {"topLeft", "topMiddle", "topRight", "middleLeft", "middleRight", "bottomLeft", "bottomMiddle", "bottomRight"}
  668. --local turtleList = giveTurtlesPosNames(sideTurtleArray, posNames)
  669. while(true)do
  670. local textMining
  671. if (bMining)then
  672. textMining = "mining"
  673. else
  674. textMining = "notMininig"
  675. end
  676. callAllTurtles(textMining, sideTurtleArray)
  677. break
  678. end
  679. local blocksMoved = 0
  680. while(disForwards > 0)do
  681. turtleForward()
  682. callAllTurtles("moveForward", sideTurtleArray)
  683. local bSuccess = false
  684. local successList = {false, false, false, false, false, false, false, false}
  685. local loopNum = 1
  686. while(not bSuccess)do
  687. local sId, message, protocoll = rednet.receive()
  688. printMsgGotBy(sId, message)
  689. local pos = getNumInList(sId, sideTurtleArray)
  690. if (pos ~= false)then
  691. if (message == "refuel")then
  692. rednet.send(sId, "msgFuelReceived")
  693. printMsgSendTo(sId, "msgFuelReceived")
  694. print("Turtle at ", posNames[pos], "needs more Fuel. Please refuel there")
  695. print("Press enter to continue!")
  696. io.read()
  697. elseif (message == "needCobble")then
  698. rednet.send(sId, "msgCobReceived")
  699. printMsgSendTo(sId, "msgCobReceived")
  700. print("Turtle at ", posNames[pos], "needs more Cobblestone. Please fill it up there")
  701. print("Press enter to continue!")
  702. elseif (message == "movedForwardCleared")then
  703. rednet.send(sId, "fullMovementReceived")
  704. printMsgSendTo(sId, "fullMovementReceived")
  705. successList[pos + 1] = true
  706. end
  707. end
  708. bSuccess = isEveryEntryLookedWord(successList, true)
  709. loopNum = loopNum + 1
  710. end
  711. disForwards = disForwards - 1
  712. blocksMoved = blocksMoved + 1
  713. if (blocksMoved % 50 == 0)then
  714. print(blocksMoved, " blocks moved, to continue press enter")
  715. io.read()
  716. end
  717. if (disForwards == 0)then
  718. print("Reached given distance. If you want to tunnel further on, please enter a new distance, otherwise the 0")
  719. disForwards = tonumber(io.read())
  720. end
  721. if(disForwards == 0)then
  722. callAllTurtles("finish", sideTurtleArray)
  723. break
  724. end
  725. end
  726. print("IDs: ", sideTurtleArray[0], sideTurtleArray[1], sideTurtleArray[2], sideTurtleArray[3], sideTurtleArray[4], sideTurtleArray[5], sideTurtleArray[6], sideTurtleArray[7])
  727. -- moveTurtleMiddleMiddle(false)
  728. end
  729.  
  730. --every action of all turtles except the middle one
  731. function sideTurtle()
  732. controleId = registerAndGetSenderId(turtlePosition)
  733. local bMining = ""
  734. while(true)do
  735. bMining = getMsgByConsoleTurtle()
  736. if (bMining == "mining")then
  737. bMining = true
  738. break
  739. elseif (bMining == "notMininig")then
  740. bMining = false
  741. break
  742. end
  743. end
  744. while(true)do
  745. local msg = getMsgByConsoleTurtle()
  746. if(msg == "moveForward") then
  747. local locData ={}
  748. if(turtlePosition == 1)then
  749. locData["rightDis"] = -2
  750. locData["highDis"] = 0
  751. locData["lookDir"] = 3
  752. moveTurtleLeftTop(bMining, locData)
  753. elseif(turtlePosition == 2)then
  754. locData["rightDis"] = -1
  755. locData["highDis"] = 0
  756. locData["lookDir"] = 0
  757. moveTurtleMiddleTop(bMining, locData)
  758. elseif(turtlePosition == 3)then
  759. locData["rightDis"] = 0
  760. locData["highDis"] = 0
  761. locData["lookDir"] = 1
  762. moveTurtleRightTop(bMining, locData)
  763. elseif(turtlePosition == 4)then
  764. locData["rightDis"] = -2
  765. locData["highDis"] = -1
  766. locData["lookDir"] = 3
  767. moveTurtleLeftMiddle(bMining, locData)
  768. elseif(turtlePosition == 6)then
  769. locData["rightDis"] = 0
  770. locData["highDis"] = -1
  771. locData["lookDir"] = 1
  772. moveTurtleRightMiddle(bMining, locData)
  773. elseif(turtlePosition == 7)then
  774. locData["rightDis"] = -2
  775. locData["highDis"] = -2
  776. locData["lookDir"] = 3
  777. moveTurtleLeftBottom(bMining, locData)
  778. elseif(turtlePosition == 8)then
  779. locData["rightDis"] = -1
  780. locData["highDis"] = -2
  781. locData["lookDir"] = 0
  782. moveTurtleMiddleBottom(bMining, locData)
  783. elseif(turtlePosition == 9)then
  784. locData["rightDis"] = 0
  785. locData["highDis"] = -2
  786. locData["lookDir"] = 1
  787. moveTurtleRightBottom(bMining, locData)
  788. end
  789. callConTurtle("movedForwardCleared", "fullMovementReceived")
  790. elseif(msg == "finish")then
  791. print("Programm closed successfull!")
  792. break
  793. end
  794. end
  795. -- local locData ={}
  796. -- if(turtlePosition == 1)then
  797. -- locData["rightDis"] = -2
  798. -- locData["highDis"] = 0
  799. -- locData["lookDir"] = 3
  800. -- moveTurtleLeftTop(bMining, locData)
  801. -- elseif(turtlePosition == 2)then
  802. -- locData["rightDis"] = -1
  803. -- locData["highDis"] = 0
  804. -- locData["lookDir"] = 0
  805. -- moveTurtleMiddleTop(bMining, locData)
  806. -- elseif(turtlePosition == 3)then
  807. -- locData["rightDis"] = 0
  808. -- locData["highDis"] = 0
  809. -- locData["lookDir"] = 1
  810. -- moveTurtleRightTop(bMining, locData)
  811. -- elseif(turtlePosition == 4)then
  812. -- locData["rightDis"] = -2
  813. -- locData["highDis"] = -1
  814. -- locData["lookDir"] = 3
  815. -- moveTurtleLeftMiddle(bMining, locData)
  816. -- elseif(turtlePosition == 6)then
  817. -- locData["rightDis"] = 0
  818. -- locData["highDis"] = -1
  819. -- locData["lookDir"] = 1
  820. -- moveTurtleRightMiddle(bMining, locData)
  821. -- elseif(turtlePosition == 7)then
  822. -- locData["rightDis"] = -2
  823. -- locData["highDis"] = -2
  824. -- locData["lookDir"] = 3
  825. -- moveTurtleLeftBottom(bMining, locData)
  826. -- elseif(turtlePosition == 8)then
  827. -- locData["rightDis"] = -1
  828. -- locData["highDis"] = -2
  829. -- locData["lookDir"] = 0
  830. -- moveTurtleMiddleBottom(bMining, locData)
  831. -- elseif(turtlePosition == 9)then
  832. -- locData["rightDis"] = 0
  833. -- locData["highDis"] = -2
  834. -- locData["lookDir"] = 1
  835. -- moveTurtleRightBottom(bMining, locData)
  836. -- end
  837. end
  838.  
  839. function main()
  840. turtlePosition = getPositionOfTurtle()
  841.  
  842. if(turtlePosition == 5) then
  843. print("Do you want to mine? Then enter a 1")
  844. local mineActivate = tonumber(io.read())
  845. print("How many blocks do you want to move?")
  846. local disForwards = tonumber(io.read())
  847. if (mineActivate == 1)then
  848. mineActivate = true
  849. else
  850. mineActivate = false
  851. end
  852. middleControl(mineActivate, disForwards)
  853. else
  854. sideTurtle()
  855. end
  856. end
  857.  
  858.  
  859. main()
  860. -- pastebin get U47JQVUG Tunnel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement