Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- xDest, yDest, zDest = tArgs[1], tArgs[2], tArgs[3]
- function correctUsage()
- if #tArgs ~= 3 then
- print("Correct usage: goTo <X> <Y> <Z>")
- print("NOTE: Requires GPS API")
- end
- end
- function direction()
- xPos, yPos, zPos = gps.locate()
- 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
- print(fDir)
- 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
- function left()
- turtle.turnLeft()
- fDir = fDir - 1
- if fDir < 0 then fDir = 3 end
- end
- function right()
- turtle.turnRight()
- fDir = fDir + 1
- if fDir > 3 then fDir = 0 end
- end
- function goToX()
- if xDest < xPos then
- while fDir ~= 1 do
- left()
- end
- elseif xDest > xPos then
- while fDir ~= 3 do
- left()
- end
- end
- while xPos ~= xDest do
- turtle.dig()
- forward()
- end
- end
- function goToZ()
- if zDest < zPos then
- while fDir ~= 2 do
- left()
- end
- elseif zDest > zPos then
- while fDir ~= 0 do
- left()
- end
- end
- while zPos ~= zDest do
- turtle.dig()
- forward()
- end
- end
- function goToY()
- if yDest < yPos then
- while yDest ~= yPos do
- turtle.digDown()
- turtle.down()
- yPos = yPos - 1
- end
- elseif yDest > yPos then
- while yDest ~= yPos do
- turtle.digUp()
- turtle.Up()
- yPos = yPos + 1
- end
- end
- end
- correctUsage()
- direction()
- goToX()
- goToZ()
- goToY()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement