Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function moveForward(times)
- if times then
- for i = 1, times do
- while not turtle.forward() do
- turtle.dig()
- end
- end
- else
- while not turtle.forward() do
- turtle.dig()
- end
- end
- end
- function moveUp(times)
- if times then
- for i = 1, times do
- while not turtle.up() do
- turtle.digUp()
- end
- end
- else
- while not turtle.up() do
- turtle.digUp()
- end
- end
- end
- function moveDown(times)
- if times then
- for i = 1, times do
- while not turtle.down() do
- turtle.digDown()
- end
- end
- else
- while not turtle.down() do
- turtle.digDown()
- end
- end
- end
- -- Location needs to be a vector.
- function moveToLocation(location)
- local startingPosition = 0
- local currentPosition = 0
- if gps.locate(2 , false) then
- startingPosition = vector.new(gps.locate(2 , false))
- currentPosition = startingPosition
- -- Y Movement
- if currentPosition.y > location.y then
- -- We need to move down.
- while currentPosition.y ~= location.y do
- moveDown()
- currentPosition = vector.new(gps.locate(2 , false))
- end
- else
- -- We need to move up.
- while currentPosition.y ~= location.y do
- moveUp()
- currentPosition = vector.new(gps.locate(2 , false))
- end
- end
- turtle.forward()
- currentPosition = vector.new(gps.locate(2 , false))
- local difference = startingPosition - currentPosition
- local moving = ""
- if difference.x == -1 then
- -- East
- moving = "east"
- elseif difference.x == 1 then
- -- West
- moving = "west"
- end
- if difference.z == -1 then
- -- South
- moving = "south"
- elseif difference.z == 1 then
- -- North
- moving = "north"
- end
- -- X Movement
- if currentPosition.x > location.x then
- -- We need to move West, to let's face that direction relative to the current facting direciton.
- if moving == "south" then
- turtle.turnRight()
- elseif moving == "north" then
- turtle.turnLeft()
- elseif moving == "east" then
- turtle.turnRight()
- turtle.turnRight()
- end
- moving = "west"
- while currentPosition.x ~= location.x do
- moveForward()
- currentPosition = vector.new(gps.locate(2 , false))
- print(moving)
- end
- else
- -- We need to move East, to let's face that direction relative to the current facting direciton.
- if moving == "south" then
- turtle.turnLeft()
- elseif moving == "north" then
- turtle.turnRight()
- elseif moving == "west" then
- turtle.turnRight()
- turtle.turnRight()
- end
- moving = "east"
- while currentPosition.x ~= location.x do
- moveForward()
- currentPosition = vector.new(gps.locate(2 , false))
- print(moving)
- end
- end
- -- Z Movement
- if currentPosition.z > location.z then
- -- We need to move North, to let's face that direction relative to the current facting direciton.
- if moving == "south" then
- turtle.turnRight()
- turtle.turnRight()
- elseif moving == "west" then
- turtle.turnRight()
- elseif moving == "east" then
- turtle.turnLeft()
- end
- moving = "north"
- while currentPosition.z ~= location.z do
- moveForward()
- currentPosition = vector.new(gps.locate(2 , false))
- print(moving)
- end
- else
- -- We need to move South, to let's face that direction relative to the current facting direciton.
- if moving == "north" then
- turtle.turnRight()
- turtle.turnRight()
- elseif moving == "west" then
- turtle.turnLeft()
- elseif moving == "east" then
- turtle.turnRight()
- end
- moving = "south"
- while currentPosition.z ~= location.z do
- moveForward()
- currentPosition = vector.new(gps.locate(2 , false))
- print(moving)
- end
- end
- else
- print("Could not get turtle's location.")
- return
- end
- end
- -- rednet.open("right")
- -- moveToLocation(vector.new(536, 64, -1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement