Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modemSide = "left"
- -- What to do?:
- -- Droping Items in Chest
- -- Communication of Fuel and Cobblestone
- -- Communication of Commands
- -- Communication Turtle look on each other
- local turtlePosition
- local controleId
- local notWishedItems = {}
- notWishedItems[0] = "minecraft:dirt"
- notWishedItems[1] = "minecraft:cobblestone"
- notWishedItems[2] = "minecraft:stone"
- notWishedItems[3] = "minecraft:obsidian"
- notWishedItems[4] = "minecraft:sand"
- notWishedItems[5] = "minecraft:gravel"
- notWishedItems[6] = "minecraft:rail"
- notWishedItems[7] = "minecraft:planks"
- notWishedItems[8] = "minecraft:fence"
- notWishedItems[9] = "bluepower:marble"
- notWishedItems[10] = "minecraft:torch"
- notWishedItems[11] = "minecraft:trapped_chest"
- notWishedItems[12] = "minecraft:flowing_water"
- notWishedItems[13] = "minecraft:flowing_lava"
- notWishedItems[14] = "minecraft:chest"
- notWishedItems[15] = "computercraft:CC-TurtleExpanded"
- --get the position of the turtles building the tunnel. TopLeft is position one, BottomRight is position 9
- function getPositionOfTurtle()
- local number = 10
- local bNum = (number > 9 or number < 1)
- local bShow = true
- while (bNum) do
- if(bShow) then
- io.write("Geben Sie an, um welche Turtel es sich handelt")
- io.write("Folgende Turtel git es:")
- io.write("Linksoben: 1\nMitteoben: 2\nRechtsoben: 3\n")
- io.write("Linksmitte: 4\nMitte: 5\nRechtsmitte: 6\n")
- io.write("Linksunten: 7\nMitteunten: 8\nRechtsunten: 9\n")
- bShow = false
- end
- number = tonumber(io.read())
- bNum = (number > 9 or number < 1)
- if (bNum) then
- io.write("Falsche Nummer, bitte erneut angeben")
- io.write("Wollen Sie die Nummern der Turteln nochmal eingeblendet haben?\n")
- io.write("Dann geben Sie die 1 ein. Ansonsten eine andere Zahl\n ")
- bShow = (tonumber(io.read()) == 1)
- end
- end
- return number
- end
- --register the turtles to interact with
- function registerAllTurtles(turtleArr)
- if(not(rednet.isOpen(modemSide))) then
- rednet.open(modemSide)
- end
- while(true) do
- rednet.broadcast("Give Position", "registerTurtles")
- local tId, tPos, prot = rednet.receive("register", 0.5)
- if(tId and (tonumber(tPos)) > 0 and tonumber(tPos) < 10 and tonumber(tPos) ~= 5)then
- printMsgGotBy(tId, tPos)
- if(tPos < 5)then
- turtleArr[tPos-1] = tId
- else
- turtleArr[tPos-2] = tId
- end
- local msg = "RegisterSuccessfull"
- rednet.send(tId, msg)
- printMsgSendTo(tId, msg)
- end
- if(getArrLength(turtleArr) == 8)then
- while (true)do
- local tId, tPos, prot = rednet.receive("register", 1)
- if(tId == nil)then
- return 0
- else
- local msg = "RegisterSuccessfull"
- rednet.send(tId, msg)
- printMsgSendTo(tId, msg)
- end
- end
- end
- end
- end
- function registerAndGetSenderId(tPosition)
- if(not(rednet.isOpen(modemSide))) then
- rednet.open(modemSide)
- end
- local senderId, message, protocoll = rednet.receive("registerTurtles")
- printMsgGotBy(senderId, message)
- while(true) do
- rednet.send(senderId, tPosition, "register")
- printMsgSendTo(senderId, tPosition)
- local s1Id
- s1Id, message, protocoll = rednet.receive(0.25)
- if (s1Id) then
- printMsgGotBy(s1Id, message)
- end
- if((s1Id == senderId) and (message == "RegisterSuccessfull")) then
- return senderId;
- end
- end
- end
- function getArrLength(arr)
- local num1 = 0
- local length = 0;
- while (num1 <= table.getn(arr))do
- if (arr[num1] ~= nil)then
- length = length + 1
- end
- num1 = num1 + 1
- end
- return length
- end
- --shoud be used after sending a onetime message, to make a message protocoll
- function printMsgSendTo(rId, msg )
- print("Message send to ", rId, ": ", msg, "\n")
- end
- function printMsgGotBy(sId, msg)
- print("Message received from ", sId, ": ", msg, "\n")
- end
- function printArr(arr)
- local cnt
- if (arr[0] ~= nil)then
- cnt = 0
- else
- cnt = 1
- end
- while(cnt <= #arr)do
- io.write(arr[cnt], " ")
- cnt = cnt + 1
- if(cnt < #arr)then
- print(arr[cnt])
- cnt = cnt + 1
- end
- end
- end
- --if there is no block in the used direction, the turtle places one
- function setBlockOnTop()
- local success, data = turtle.inspectUp()
- if (success and data.name == "minecraft:gravel")then
- while(turtle.detectUp())do
- turtle.digUp()
- os.sleep(0.25)
- end
- end
- if(turtle.detectUp() == false or detectWaterOrLavaOnTop())then
- placeOutsideCobblestone("top")
- return true
- end
- return false
- end
- function setBlockOnBottom()
- if(turtle.detectDown() == false or detectWaterOrLavaOnBottom())then
- placeOutsideCobblestone("bottom")
- return true
- end
- return false
- end
- function setBlockInFront()
- local success, data = turtle.inspect()
- if (success and data.name == "minecraft:gravel")then
- while(turtle.detect())do
- turtle.dig()
- os.sleep(0.25)
- end
- end
- if(turtle.detect() == false or detectWaterOrLavaInFront())then
- placeOutsideCobblestone("front")
- return true
- end
- return false
- end
- --starting mining on the top side of the turtle
- function miningOnTop(locData)
- local success, data = turtle.inspectUp()
- if(success and isAWishedBlock(data.name))then
- turtleUp()
- locData.highDis = locData.highDis + 1
- mining(locData.rightDis, locData.highDis, locData.lookDir)
- turtleDown()
- locData.highDis = locData.highDis - 1
- placeOutsideCobblestone("top")
- end
- end
- function miningOnBottom(locData)
- local success, data = turtle.inspectDown()
- if(success and isAWishedBlock(data.name))then
- turtleDown()
- locData.highDis = locData.highDis - 1
- mining(locData.rightDis, locData.highDis, locData.lookDir)
- turtleUp()
- locData.highDis = locData.highDis + 1
- placeOutsideCobblestone("bottom")
- end
- end
- function miningInFront(locData)
- local success, data = turtle.inspect()
- if(success and isAWishedBlock(data.name))then
- turtleForward()
- if (locData.lookDir % 4 == 1)then
- locData.rightDis = locData.rightDis + 1
- elseif (locData.lookDir % 4 == 3)then
- locData.rightDis = locData.rightDis - 1
- end
- mining(locData.rightDis, locData.highDis, locData.lookDir)
- turtle.turnLeft()
- turtle.turnLeft()
- turtleForward()
- turtle.turnLeft()
- turtle.turnLeft()
- if (locData.lookDir % 4 == 1)then
- locData.rightDis = locData.rightDis - 1
- elseif (locData.lookDir % 4 == 3)then
- locData.rightDis = locData.rightDis + 1
- end
- placeOutsideCobblestone("front")
- end
- end
- --complete moving actions of any turtle
- function moveTurtleLeftTop(miningActive, locData)
- turtleForward()
- turtle.turnLeft()
- local sBoT = setBlockOnTop()
- local sBiF = setBlockInFront()
- local goMiningTop = miningActive and (not sBoT)
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningTop)then
- miningOnTop(locData)
- end
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnRight()
- return true
- end
- function moveTurtleMiddleTop(miningActive, locData)
- turtleForward()
- local sBoT = setBlockOnTop()
- local goMiningTop = miningActive and (not sBoT)
- if (goMiningTop)then
- miningOnTop(locData)
- end
- return true
- end
- function moveTurtleRightTop(miningActive, locData)
- turtleForward()
- turtle.turnRight()
- local sBoT = setBlockOnTop()
- local sBiF = setBlockInFront()
- local goMiningTop = miningActive and (not sBoT)
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningTop)then
- miningOnTop(locData)
- end
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnLeft()
- return true
- end
- function moveTurtleLeftMiddle(miningActive, locData)
- turtleForward()
- turtle.turnLeft()
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnRight()
- return true
- end
- function moveTurtleMiddleMiddle(miningActive, locData)
- turtleForward()
- return true
- end
- function moveTurtleRightMiddle(miningActive, locData)
- turtleForward()
- turtle.turnRight()
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnLeft()
- return true
- end
- function moveTurtleLeftBottom(miningActive, locData)
- turtleForward()
- turtle.turnLeft()
- local sBoB = setBlockOnBottom()
- local sBiF = setBlockInFront()
- local goMiningBottom = miningActive and (not sBoB)
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningBottom)then
- miningOnBottom(locData)
- end
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnRight()
- return true
- end
- function moveTurtleMiddleBottom(miningActive, locData)
- turtleForward()
- local sBoB = setBlockOnBottom()
- local goMiningBottom = miningActive and (not sBoB)
- if (goMiningBottom)then
- miningOnBottom(locData)
- end
- return true
- end
- function moveTurtleRightBottom(miningActive, locData)
- turtleForward()
- turtle.turnRight()
- local sBoB = setBlockOnBottom()
- local sBiF = setBlockInFront()
- local goMiningBottom = miningActive and (not sBoB)
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningBottom)then
- miningOnBottom(locData)
- end
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnLeft()
- return true
- end
- function moveLeftTurtleTurningLeft()
- turtle.turnLeft()
- turtle.turnLeft()
- turtleForward()
- turtle.turnRight()
- end
- function moveRightTurtleTurningRight()
- turtle.turnRight()
- turtle.turnRight()
- turtleForward()
- turtle.turnLeft()
- end
- function moveLeftTurtleTurningRight(miningActive)
- local locData ={}
- if(turtlePosition == 1)then
- locData["rightDis"] = -2
- locData["highDis"] = 0
- locData["lookDir"] = 3
- moveTurtleLeftTop(bMining, locData)
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnRight()
- moveTurtleLeftTop(bMining, locData)
- moveTurtleLeftTop(bMining, locData)
- elseif(turtlePosition == 4)then
- locData["rightDis"] = -2
- locData["highDis"] = -1
- locData["lookDir"] = 3
- moveTurtleLeftMiddle(bMining, locData)
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnRight()
- moveTurtleLeftMiddle(bMining, locData)
- moveTurtleLeftMiddle(bMining, locData)
- elseif(turtlePosition == 7)then
- locData["rightDis"] = -2
- locData["highDis"] = -2
- locData["lookDir"] = 3
- moveTurtleLeftBottom(bMining, locData)
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnRight()
- moveTurtleLeftBottom(bMining, locData)
- moveTurtleLeftBottom(bMining, locData)
- end
- end
- function moveRightTurtleTurningLeft(miningActive)
- local locData = {}
- if(turtlePosition == 3)then
- locData["rightDis"] = 0
- locData["highDis"] = 0
- locData["lookDir"] = 1
- moveTurtleRightTop(bMining, locData)
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnLeft()
- moveTurtleRightTop(bMining, locData)
- moveTurtleRightTop(bMining, locData)
- elseif(turtlePosition == 6)then
- locData["rightDis"] = 0
- locData["highDis"] = -1
- locData["lookDir"] = 1
- moveTurtleRightMiddle(bMining, locData)
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnLeft()
- moveTurtleRightMiddle(bMining, locData)
- moveTurtleRightMiddle(bMining, locData)
- elseif(turtlePosition == 9)then
- locData["rightDis"] = 0
- locData["highDis"] = -2
- locData["lookDir"] = 1
- moveTurtleRightBottom(bMining, locData)
- local sBiF = setBlockInFront()
- local goMiningFront = miningActive and (not sBiF)
- if(goMiningFront)then
- miningInFront(locData)
- end
- turtle.turnLeft()
- moveTurtleRightBottom(bMining, locData)
- moveTurtleRightBottom(bMining, locData)
- end
- end
- --moving Turtle. If there is no Fuel calling for fuel.
- function turtleForward()
- haveEnoughFuel()
- local numOfWait = 0
- while(turtle.forward() == false)do
- local success, data = turtle.inspect()
- if (success and data.name == "computercraft:CC-TurtleExpanded")then
- os.sleep(0.5)
- if (numOfWait%10 == 0)then
- print("Turtle is waiting in front of me")
- end
- numOfWait = numOfWait + 1
- else
- turtle.dig()
- end
- end
- end
- function turtleUp()
- haveEnoughFuel()
- local numOfWait = 0
- while(turtle.up() == false)do
- local success, data = turtle.inspectUp()
- if (success and data.name == "computercraft:CC-TurtleExpanded")then
- os.sleep(0.5)
- if (numOfWait%10 == 0)then
- print("Turtle is waiting on top of me")
- end
- numOfWait = numOfWait + 1
- else
- turtle.digUp()
- end
- end
- end
- function turtleDown()
- haveEnoughFuel()
- local numOfWait = 0
- while(turtle.down() == false)do
- local success, data = turtle.inspectDown()
- if (success and data.name == "computercraft:CC-TurtleExpanded")then
- os.sleep(0.5)
- if (numOfWait%10 == 0)then
- print("Turtle is waiting on bottom of me")
- end
- numOfWait = numOfWait + 1
- else
- turtle.digDown()
- end
- end
- end
- --get all special blocks the turtle crosses
- function mining()
- local cnt = 0
- while (cnt < 6)do
- if (cnt == 0)then
- local success, data = turtle.inspectUp()
- if (success and isAWishedBlock(data.name))then
- turtleUp()
- mining()
- turtleDown()
- end
- elseif (cnt == 1)then
- local success, data = turtle.inspectDown()
- if (success and isAWishedBlock(data.name))then
- turtleDown()
- mining()
- turtleUp()
- end
- else
- local success, data = turtle.inspect()
- if (success and isAWishedBlock(data.name))then
- turtleForward()
- mining()
- turtle.turnRight()
- turtle.turnRight()
- turtleForward()
- turtle.turnRight()
- turtle.turnRight()
- end
- turtle.turnRight()
- end
- cnt = cnt + 1
- end
- end
- function mining(rightDis, highDis, lookDir)
- -- point (0|0) is the point of the right-top-turtle
- -- looking right is lookDir 1, looking back is lookDir 2, looking left is lookDir 3, looking forwards is lookDir 0
- local cnt = 0
- while (cnt < 6)do
- if (cnt == 0)then
- local success, data = turtle.inspectUp()
- if (success and isAWishedBlock(data.name) and ((highDis > -1 or highDis < -3) or (rightDis > 0 or rightDis < -2)))then
- turtleUp()
- highDis = highDis + 1
- mining(rightDis, highDis, lookDir)
- turtleDown()
- highDis = highDis - 1
- end
- elseif (cnt == 1)then
- local success, data = turtle.inspectDown()
- if (success and isAWishedBlock(data.name) and ((highDis > 1 or highDis < -1) or (rightDis > 0 or rightDis < -2)))then
- turtleDown()
- highDis = highDis - 1
- mining(rightDis, highDis, lookDir)
- turtleUp()
- highDis = highDis + 1
- end
- else
- local success, data = turtle.inspect()
- local bRightSide = (lookDir % 4 == 3 and rightDis < 2 and rightDis > -2 and highDis < 1 and highDis > -3)
- local bLeftSide = (lookDir % 4 == 1 and rightDis > -4 and rightDis < 0 and highDis < 1 and highDis > -3)
- if (success and isAWishedBlock(data.name) and (not bRightSide) and (not bLeftSide))then
- turtleForward()
- if (lookDir % 4 == 1)then
- rightDis = rightDis + 1
- elseif (lookDir % 4 == 3)then
- rightDis = rightDis - 1
- end
- mining(rightDis, highDis, lookDir)
- turtle.turnRight()
- turtle.turnRight()
- turtleForward()
- turtle.turnRight()
- turtle.turnRight()
- if (lookDir % 4 == 1)then
- rightDis = rightDis - 1
- elseif (lookDir % 4 == 3)then
- rightDis = rightDis + 1
- end
- end
- turtle.turnRight()
- lookDir = lookDir + 1
- end
- cnt = cnt + 1
- end
- end
- --returns whether there is water or lava in the used direction
- function detectWaterOrLavaOnTop()
- local success, data = turtle.inspectUp()
- if(data.name == "minecraft:flowing_water" or data.name == "minecraft:flowing_lava")then
- return true
- end
- return false
- end
- function detectWaterOrLavaOnBottom()
- local success, data = turtle.inspectDown()
- if(data.name == "minecraft:flowing_water" or data.name == "minecraft:flowing_lava")then
- return true
- end
- return false
- end
- function detectWaterOrLavaInFront()
- local success, data = turtle.inspect()
- if(data.name == "minecraft:flowing_water" or data.name == "minecraft:flowing_lava")then
- return true
- end
- return false
- end
- --returns true, if user wants to get the item from the object
- function isAWishedBlock(objectName)
- local i = 0
- while (i <= #notWishedItems)do
- if(objectName == notWishedItems[i])then
- return false
- end
- i = i + 1
- end
- return true
- end
- --place a cobblestone on the entered side of the turtle. sides are only "top", "bottom", "front"
- function placeOutsideCobblestone(side)
- local slotsLeft = 16
- while (slotsLeft > 0)do
- turtle.select(slotsLeft)
- local data = turtle.getItemDetail()
- if (data)then
- if (data.name == "minecraft:cobblestone")then
- break
- elseif(slotsLeft == 1 and turtlePosition ~= 5)then
- getCobbleWithMsg()
- elseif(slotsLeft == 1 and turtlePosition == 5)then
- print("Please give some Cobblestone to this turtle! After that press enter!")
- io.read()
- slotsLeft = 17
- end
- elseif (slotsLeft == 1 and turtlePosition == 5)then
- print("Please give some Cobblestone to this turtle! After that press enter!")
- io.read()
- slotsLeft = 17
- elseif (slotsLeft == 1 and turtlePosition ~= 5)then
- getCobbleWithMsg()
- end
- slotsLeft = slotsLeft - 1
- end
- if(side == "top")then
- turtle.placeUp()
- elseif(side == "bottom")then
- turtle.placeDown()
- elseif(side == "front")then
- turtle.place()
- end
- end
- function getCobbleWithMsg()
- callConTurtle("needCobble", "msgCobReceived")
- local slotsLeft = 16
- while (slotsLeft > 0)do
- turtle.select(slotsLeft)
- local data = turtle.getItemDetail()
- if (data and data.name == "minecraft:cobblestone")then
- break
- elseif (slotsLeft == 1)then
- print("Please give some Cobblestone to this turtle! After that press enter!")
- io.read()
- slotsLeft = 17
- end
- slotsLeft = slotsLeft - 1
- end
- end
- --makes enough fuel by filling up with own fuel or calling for new one
- function haveEnoughFuel()
- if (turtle.getFuelLevel() == 0 and turtlePosition ~= 5)then
- refuelWithMsg()
- elseif(turtle.getFuelLevel() == 0 and turtlePosition == 5)then
- while(fuelWithOwnRessources() == false)do
- print("Please give some fuel to this turtle! After that press enter!")
- io.read()
- end
- end
- return true
- end
- function fuelWithOwnRessources()
- local slotsLeft = 16
- while (slotsLeft > 0)do
- turtle.select(slotsLeft)
- if(turtle.refuel())then
- return true
- end
- slotsLeft = slotsLeft - 1
- end
- return false
- end
- function refuelWithMsg()
- callConTurtle("refuel", "msgFuelReceived")
- while(fuelWithOwnRessources() == false)do
- print("Please give some fuel to this turtle! After that press enter!")
- io.read()
- end
- end
- function getMsgByConsoleTurtle()
- local sId, msg, protocoll
- while(true)do
- sId, msg, protocoll = rednet.receive()
- printMsgGotBy(sId, msg)
- if(sId == controleId)then
- break
- end
- end
- return msg
- end
- function callConTurtle(msg, msgB)
- local answer = false
- local num = 0
- while(not answer)do
- rednet.send(controleId, msg)
- if(num % 20 == 0)then
- printMsgSendTo(controleId, msg)
- end
- local sId, msgA, protocoll = rednet.receive(0.25)
- printMsgGotBy(sId, msgA)
- if (sId == controleId and msgA == msgB)then
- answer = true
- end
- num = num + 1
- end
- end
- function callAllTurtles(msg, turtleList)
- local num = 0
- while (num <= #turtleList)do
- print(turtleList[num])
- rednet.send(turtleList[num], msg)
- printMsgSendTo(turtleList[num], msg)
- num = num + 1
- end
- end
- function giveTurtlesPosNames(turtList, posNames)
- local turtleList = {}
- local num = 0
- while (num < 8)do
- turtleList[posNames[num]] = turtList[num]
- num = num + 1
- end
- return turtleList
- end
- function getNumInList(id, list)
- local cnt = 0
- while (cnt < 8)do
- if (list[cnt] == id)then
- return cnt
- end
- cnt = cnt + 1
- end
- return false
- end
- function isEveryEntryLookedWord(list, lWord)
- local num = 1
- while (num <= #list)do
- if (list[num] ~= lWord)then
- return false
- end
- num = num + 1
- end
- return true
- end
- function getAllMessages(posNames, sideTurtleArray)
- local bSuccess = false
- local successList = {false, false, false, false, false, false, false, false}
- local loopNum = 1
- while(not bSuccess)do
- local sId, message, protocoll = rednet.receive()
- printMsgGotBy(sId, message)
- local pos = getNumInList(sId, sideTurtleArray)
- if (pos ~= false)then
- if (message == "refuel")then
- rednet.send(sId, "msgFuelReceived")
- printMsgSendTo(sId, "msgFuelReceived")
- print("Turtle at ", posNames[pos], "needs more Fuel. Please refuel there")
- print("Press enter to continue!")
- io.read()
- elseif (message == "needCobble")then
- rednet.send(sId, "msgCobReceived")
- printMsgSendTo(sId, "msgCobReceived")
- print("Turtle at ", posNames[pos], "needs more Cobblestone. Please fill it up there")
- print("Press enter to continue!")
- elseif (message == "movedForwardCleared")then
- rednet.send(sId, "fullMovementReceived")
- printMsgSendTo(sId, "fullMovementReceived")
- successList[pos + 1] = true
- end
- end
- bSuccess = isEveryEntryLookedWord(successList, true)
- loopNum = loopNum + 1
- end
- end
- function changeSettings(settings)
- print("Do you want to mine? Then enter an one")
- if (tonumber(io.read()) == 1)then
- settings.bMining = true
- end
- print("Do you want to go to an point or an choosen distance forward?")
- print("Enter an one for special coordinates")
- if (tonumber(io.read()) == 1)then
- print("Please enter the X-coordinate of the middle turtle!")
- settings.ownCoordX = tonumber(io.read())
- print("Please enter the Y-coordinate of the middle turtle!")
- settings.ownCoordY = tonumber(io.read())
- print("Please enter the Z-coordinate of the middle turtle!")
- settings.ownCoordZ = tonumber(io.read())
- print("Please enter the X-coordinate of the target!")
- settings.targetCoordX = tonumber(io.read())
- print("Please enter the Y-coordinate of the target!")
- settings.targetCoordY = tonumber(io.read())
- print("Please enter the Z-coordinate of the target!")
- settings.targetCoordZ = tonumber(io.read())
- print("Please enter the direction the turtle is looking at:")
- print("For higher X enter 0")
- print("For higher Z enter 1")
- print("For lower X enter 2")
- print("For lower Z enter 3")
- settings.lookingIn = tonumber(io.read()) -- 2
- local distanceX = settings.targetCoordX - settings.ownCoordX -- -21
- local distanceY = settings.targetCoordY - settings.ownCoordY -- 0
- local distanceZ = settings.targetCoordZ - settings.ownCoordZ -- 47
- if (settings.lookingIn == 0)then
- settings.disForwards = distanceX
- elseif(settings.lookingIn == 1)then
- settings.disForwards = distanceZ --
- elseif(settings.lookingIn == 2)then
- settings.disForwards = -distanceX
- else
- settings.disForwards = -distanceZ
- end
- settings.disUp = distanceY
- if (settings.lookingIn == 0)then
- if(settings.disForwards > 0)then
- settings.disLeft = -distanceZ
- else
- settings.disLeft = distanceZ
- end
- elseif (settings.lookingIn == 1)then
- if(settings.disForwards > 0)then
- settings.disLeft = distanceX
- else
- settings.disLeft = -distanceX
- end
- elseif (settings.lookingIn == 2)then
- if(settings.disForwards < 0)then
- settings.disLeft = -distanceZ
- else
- settings.disLeft = distanceZ
- end
- else
- if(settings.disForwards < 0)then
- settings.disLeft = distanceX
- else
- settings.disLeft = -distanceX
- end
- end
- print("Forwards: ", settings.disForwards)
- print("Upwards: ", settings.disUp)
- print("Leftwards: ", settings.disLeft)
- else
- print("Please give the distance for the tunnel")
- settings.disForwards = tonumber(io.read())
- end
- end
- function changePositionsInList(sideTurtleArray)
- local b = sideTurtleArray[0]
- sideTurtleArray[0] = sideTurtleArray[2]
- sideTurtleArray[2] = b
- b = sideTurtleArray[3]
- sideTurtleArray[3] = sideTurtleArray[4]
- sideTurtleArray[4] = b
- b = sideTurtleArray[5]
- sideTurtleArray[5] = sideTurtleArray[7]
- sideTurtleArray[7] = b
- end
- --every action of the middle turtle, being also the controlling turtle
- function middleControl()
- local settings = {}
- settings["bMining"] = false
- settings["disForwards"] = 10
- settings["disLeft"] = -10
- settings["disUp"] = 0
- settings["ownCoordX"] = 0
- settings["ownCoordY"] = 0
- settings["ownCoordZ"] = 0
- settings["targetCoordX"] = 0
- settings["targetCoordY"] = 0
- settings["targetCoordZ"] = 0
- settings["lookingIn"] = 0
- -- bMining = settings.bMining
- print("To change the settings please enter 1")
- if(tonumber(io.read()) == 1)then
- changeSettings(settings)
- end
- local disForwards = settings.disForwards
- local disLeft = settings.disLeft
- local sideTurtleArray = {nil, nil, nil, nil, nil, nil, nil, nil}
- registerAllTurtles(sideTurtleArray)
- local posNames = {"topLeft", "topMiddle", "topRight", "middleLeft", "middleRight", "bottomLeft", "bottomMiddle", "bottomRight"}
- --local turtleList = giveTurtlesPosNames(sideTurtleArray, posNames)
- while(true)do
- local textMining
- if (bMining)then
- textMining = "mining"
- else
- textMining = "notMininig"
- end
- callAllTurtles(textMining, sideTurtleArray)
- break
- end
- local blocksMoved = 0
- while(disForwards ~= 0)do
- if (disForwards < 0)then
- turtle.turnLeft()
- turtle.turnLeft()
- callAllTurtles("turnAround", sideTurtleArray)
- getAllMessages(posNames, sideTurtleArray)
- changePositionsInList(sideTurtleArray)
- disForwards = -disForwards
- end
- turtleForward()
- callAllTurtles("moveForward", sideTurtleArray)
- getAllMessages(posNames, sideTurtleArray)
- disForwards = disForwards - 1
- blocksMoved = blocksMoved + 1
- if (blocksMoved % 50 == 0)then
- print(blocksMoved, " blocks moved, to continue press enter")
- io.read()
- end
- if (disForwards == 0)then
- if (settings.disLeft > 0)then
- disForwards = settings.disLeft - 1
- settings.disLeft = 0
- turtle.turnLeft()
- callAllTurtles("turnLeft", sideTurtleArray)
- turtleForward()
- getAllMessages(posNames, sideTurtleArray)
- elseif(settings.disLeft < 0)then
- disForwards = -settings.disLeft - 1
- settings.disLeft = 0
- turtle.turnRight()
- callAllTurtles("turnRight", sideTurtleArray)
- turtleForward()
- getAllMessages(posNames, sideTurtleArray)
- end
- end
- if(disForwards == 0)then
- callAllTurtles("finish", sideTurtleArray)
- break
- end
- end
- print("IDs: ", sideTurtleArray[0], sideTurtleArray[1], sideTurtleArray[2], sideTurtleArray[3], sideTurtleArray[4], sideTurtleArray[5], sideTurtleArray[6], sideTurtleArray[7])
- -- moveTurtleMiddleMiddle(false)
- end
- --every action of all turtles except the middle one
- function sideTurtle()
- controleId = registerAndGetSenderId(turtlePosition)
- local bMining = ""
- while(true)do
- bMining = getMsgByConsoleTurtle()
- if (bMining == "mining")then
- bMining = true
- break
- elseif (bMining == "notMininig")then
- bMining = false
- break
- end
- end
- while(true)do
- local msg = getMsgByConsoleTurtle()
- if(msg == "moveForward") then
- local locData ={}
- if(turtlePosition == 1)then
- locData["rightDis"] = -2
- locData["highDis"] = 0
- locData["lookDir"] = 3
- moveTurtleLeftTop(bMining, locData)
- elseif(turtlePosition == 2)then
- locData["rightDis"] = -1
- locData["highDis"] = 0
- locData["lookDir"] = 0
- moveTurtleMiddleTop(bMining, locData)
- elseif(turtlePosition == 3)then
- locData["rightDis"] = 0
- locData["highDis"] = 0
- locData["lookDir"] = 1
- moveTurtleRightTop(bMining, locData)
- elseif(turtlePosition == 4)then
- locData["rightDis"] = -2
- locData["highDis"] = -1
- locData["lookDir"] = 3
- moveTurtleLeftMiddle(bMining, locData)
- elseif(turtlePosition == 6)then
- locData["rightDis"] = 0
- locData["highDis"] = -1
- locData["lookDir"] = 1
- moveTurtleRightMiddle(bMining, locData)
- elseif(turtlePosition == 7)then
- locData["rightDis"] = -2
- locData["highDis"] = -2
- locData["lookDir"] = 3
- moveTurtleLeftBottom(bMining, locData)
- elseif(turtlePosition == 8)then
- locData["rightDis"] = -1
- locData["highDis"] = -2
- locData["lookDir"] = 0
- moveTurtleMiddleBottom(bMining, locData)
- elseif(turtlePosition == 9)then
- locData["rightDis"] = 0
- locData["highDis"] = -2
- locData["lookDir"] = 1
- moveTurtleRightBottom(bMining, locData)
- end
- callConTurtle("movedForwardCleared", "fullMovementReceived")
- elseif(msg == "finish")then
- print("Programm closed successfull!")
- break
- elseif(msg == "turnAround")then
- turtle.turnLeft()
- turtle.turnLeft()
- if (turtlePosition % 3 == 1)then
- turtlePosition = turtlePosition + 2
- elseif (turtlePosition % 3 == 0)then
- turtlePosition = turtlePosition - 2
- end
- callConTurtle("movedForwardCleared", "fullMovementReceived")
- elseif(msg == "turnLeft")then
- if(turtlePosition % 3 == 2)then
- turtle.turnLeft()
- turtleForward()
- elseif(turtlePosition % 3 == 1)then
- moveLeftTurtleTurningLeft()
- else
- moveRightTurtleTurningLeft(bMining)
- end
- callConTurtle("movedForwardCleared", "fullMovementReceived")
- elseif(msg == "turnRight")then
- if(turtlePosition % 3 == 2)then
- turtle.turnRight()
- turtleForward()
- elseif(turtlePosition % 3 == 1)then
- moveLeftTurtleTurningRight(bMining)
- else
- moveRightTurtleTurningRight()
- end
- callConTurtle("movedForwardCleared", "fullMovementReceived")
- end
- end
- end
- function main()
- turtlePosition = getPositionOfTurtle()
- if(turtlePosition == 5) then
- middleControl()
- else
- sideTurtle()
- end
- end
- main()
- -- pastebin get WNLvCqqp sTunnel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement