Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local north
- local west
- local PCID = os.getComputerID ()
- local k
- local p
- local turnLeft = false
- rednet.open ("right")
- function fuelUp ()
- turtle.turnLeft ()
- turtle.suck (16)
- turtle.refuel ()
- turtle.turnRight ()
- end
- -----TURTLE IS SUPPOSED TO FACE POSITIVE X (EAST)
- function goToPlr ()
- local forwardXAmount
- local forwardYAmount
- local forwardZAmount
- local curPosX, curPosY, curPosZ = gps.locate ()
- local curPos = { curPosX, curPosY, curPosZ }
- local curZPos = math.abs (curPos[3])
- local plrZPos = math.abs (plrPos[3])
- print (curPos[1])
- print (plrPos[1])
- print (curPos[2])
- print (plrPos[2])
- print (curPos[3])
- print (plrPos[3])
- for i, v in pairs (curPos) do
- print (i .. ":" .. v)
- end
- if curPos[1] > plrPos[1] then
- turtle.turnRight ()
- turtle.turnRight ()
- end
- if curPos[1] > plrPos[1] then
- forwardXAmount = math.abs(curPos[1]) - math.abs(plrPos[1])
- west = true
- else
- forwardXAmount = math.abs(plrPos[1]) - math.abs(curPos[1])
- west = false
- end
- forwardXAmount = math.abs(forwardXAmount)
- print ("goToPlr Forward Amount Debug: " .. forwardXAmount)
- for i=1, forwardXAmount do
- forwardAndCheck ()
- end
- if curPos[3] > plrPos[3] then
- if west == true then
- turtle.turnRight ()
- north = true
- else
- turtle.turnLeft ()
- north = true
- end
- forwardZAmount = plrZPos - curZPos
- else
- if west == true then
- turtle.turnLeft ()
- north = false
- else
- turtle.turnRight ()
- north = false
- end
- forwardZAmount = curZPos - plrZPos
- end
- forwardZAmount = math.abs(forwardZAmount)
- print("goToPlr ForwardZAmount Debug: "..forwardZAmount)
- west = false
- for i=1, forwardZAmount do
- forwardAndCheck ()
- end
- forwardYAmount = curPos[2] - plrPos[2]
- for i=1, forwardYAmount-1 do
- turtle.down ()
- end
- print(north)
- if north == true then
- turtle.turnRight ()
- else
- turtle.turnLeft ()
- end
- end
- function forwardAndCheck ()
- if turtle.forward () == false then
- repeat
- turtle.up ()
- until turtle.forward () == true
- end
- end
- function downAndCheck ()
- if turtle.down () == false then
- repeat
- sleep (1)
- until turtle.down () == true
- end
- end
- function goToSectors (turtleID, deploymentCoords, plrPos)
- local j = 1
- newPlrPos = {}
- print ("goToSectors turtleID Debug: " .. turtleID)
- local deploymentYPos = turtleID*2
- local deploymentXPos = deploymentYPos - 1
- local xPos = deploymentCoords[deploymentXPos]
- local yPos = deploymentCoords[deploymentYPos]
- local xPos = math.abs (xPos)
- local yPos = math.abs (yPos)
- for i,v in pairs(plrPos) do
- v = math.abs(v)
- table.insert(newPlrPos, v)
- end
- print("goToSectors xPos Debug: "..xPos)
- print ("goToSectors yPos Debug: " .. yPos)
- print ("goToSectors plrYPos Debug: " .. newPlrPos[3])
- local forwardXAmount = xPos - newPlrPos[1]
- local forwardYAmount = newPlrPos[3] - yPos
- local forwardXAmount = math.abs(forwardXAmount)
- local forwardYAmount = math.abs(forwardYAmount)
- print ("goToSectors forwardXAmount Debug: " .. forwardXAmount)
- print ("goToSectors forwardYAmount Debug: " .. forwardYAmount)
- for i=1, forwardYAmount do
- forwardAndCheck()
- end
- turtle.turnRight()
- for i=1,forwardXAmount do
- forwardAndCheck()
- end
- turtle.turnLeft()
- turtle.down()
- end
- function mineColumn(miningDimensions, length)
- print("nextRow yRemainder Debug: "..yRemainder)
- xPos = 1
- reverseXPos = false
- if yRemainder == 1 then
- for i=1, length-1 do
- turtle.dig()
- turtle.forward()
- if reverseXPos == true then
- xPos = xPos-1
- else
- xPos = xPos+1
- end
- end
- elseif yRemainder == 2 then
- for i=1, length-1 do
- turtle.dig()
- turtle.digDown()
- turtle.forward()
- if reverseXPos == true then
- xPos = xPos-1
- else
- xPos = xPos+1
- end
- end
- else
- for i=1, length-1 do
- turtle.digDown()
- turtle.digUp()
- turtle.dig()
- turtle.forward()
- if reverseXPos == true then
- xPos = xPos-1
- else
- xPos = xPos+1
- end
- end
- end
- end
- function nextRow()
- print("nextRow yRemainder Debug: "..yRemainder)
- zPos = 1
- if turnLeft == false then
- turtle.turnRight()
- if yRemainder == 1 then
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- zPos = zPos+1
- elseif yRemainder == 2 then
- turtle.dig()
- turtle.digDown()
- turtle.forward()
- turtle.digDown()
- turtle.turnRight()
- zPos = zPos + 1
- else
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- zPos = zPos + 1
- end
- turnLeft = true
- else
- turtle.turnLeft()
- if yRemainder == 1 then
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- zPos = zPos + 1
- elseif yRemainder == 2 then
- turtle.dig()
- turtle.digDown()
- turtle.forward()
- turtle.digDown()
- turtle.turnLeft()
- zPos = zPos + 1
- else
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- turtle.turnLeft()
- zPos = zPos + 1
- end
- turnLeft = false
- end
- end
- function goToY (miningDimensions)
- local curXPos, curYPos, curZPos = gps.locate()
- local curPos = {curXPos, curYPos, curZPos}
- local forwardYAmount = curPos[2] - miningDimensions[4]
- if tonumber(miningDimensions[2]) >= 3 then
- for i=1, forwardYAmount+1 do
- turtle.digDown()
- turtle.down()
- end
- else
- for i=1, forwardYAmount do
- turtle.digDown ()
- turtle.down ()
- end
- end
- end
- k, packet, p = rednet.receive ()
- turtleID = packet[1]
- turtleCountNeeded = packet[2]
- plrPos = packet[3]
- miningDimensions = packet[4]
- rowsPerTurtle = packet[5]
- deploymentCoords = packet[6]
- yRemainder = miningDimensions[2]
- length = packet[7]
- width = packet[8]
- print("yRemainder Debug: "..yRemainder)
- fuelUp ()
- turtle.forward ()
- turtle.forward ()
- turtle.forward ()
- turtle.forward ()
- turtle.down ()
- turtle.down ()
- goToPlr ()
- goToSectors (turtleID, deploymentCoords, plrPos)
- goToY(miningDimensions)
- for i=1,width do
- mineColumn(miningDimensions, length)
- nextRow(yRemainder)
- end
Add Comment
Please, Sign In to add comment