Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("right")
- function left()
- turtle.turnLeft()
- fDir = fDir - 1
- if fDir < 0 then fDir = 3 end
- end
- function up()
- turtle.up()
- yPos = yPos + 1
- end
- function down()
- turtle.down()
- yPos = yPos - 1
- end
- function forward()
- turtle.forward()
- if fDir == 0 then zPos = zPos + 1 end
- if fDir == 2 then zPos = zPos - 1 end
- if fDir == 1 then xPos = xPos - 1 end
- if fDir == 3 then xPos = xPos + 1 end
- end
- fDir = nil
- xPos = nil
- yPos = nil
- zPos = nil
- function initDir()
- xPos, yPos, zPos = gps.locate()
- if not xPos or not yPos or not zPos then
- print("ERROR: GPS API REQUIRED")
- os.exit(goTo)
- end
- turtle.forward()
- xPos2, yPos2, zPos2 = gps.locate()
- turtle.back()
- if xPos ~= xPos2 then
- if xPos > xPos2 then
- fDir = 1
- else
- fDir = 3
- end
- else
- if zPos > zPos2 then
- fDir = 2
- else
- fDir = 0
- end
- end
- end
- initDir()
- while true do
- id = nil
- id, location = rednet.receive(.01)
- if id then
- xDest = location[1]
- yDest = location[2]
- zDest = location[3]
- end
- if xDest < xPos then
- while fDir ~= 1 do
- left()
- end
- turtle.dig()
- forward()
- elseif xDest > xPos then
- while fDir ~= 3 do
- left()
- end
- turtle.dig()
- forward()
- elseif zDest < zPos then
- while fDir ~= 2 do
- left()
- end
- turtle.dig()
- forward()
- elseif zDest > zPos then
- while fDir ~= 0 do
- left()
- end
- turtle.dig()
- forward()
- elseif yDest < yPos then
- turtle.digDown()
- down()
- elseif yDest > yPos then
- turtle.digUp()
- up()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement