Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- getOrientation()
- -- Gets the turtle's orientation.
- function getOrientation()
- if turtle.getFuelLevel() < 2 then
- print("Not enough fuel for determining the orientation. Needs at least two.")
- return
- end
- local tries = 1
- while turtle.detect() do
- if tries =< 4 then
- print("Obstructed, turning.")
- tries = tries + 1
- turtle.turnRight()
- else
- print("Turtle obstructed, orientation cannot be determined.")
- return;
- end
- end
- local pos1 = vector.new(gps.locate(5))
- turtle.forward()
- local pos2 = vector.new(gps.locate(5))
- turtle.back()
- local deltaZ = pos2.z - pos1.z
- local deltaX = pos2.x - pos1.x
- local orientation = nil
- if deltaZ == 0 then
- if deltaX == 1 then
- orientation = "east"
- else
- orientation = "west"
- end
- else
- if deltaZ == 1 then
- orientation = "south"
- else
- orientation = "north"
- end
- end
- print("Looking " .. orientation)
- end
- -- Moves turtle forwards until the path is obstructed.
- function moveForward()
- while not turtle.detect() do
- if turtle.getFuelLevel() > 0 then
- turtle.forward()
- else
- print("Not enough fuel to continue, aborting...")
- break
- end
- end
- end
- -- Moves turtle one block forwards
- function moveOneForward()
- if turtle.getFuelLevel() > 0 then
- -- turtle.forward() returns true or false depending on whether the turtle did actually move or not
- if not turtle.forward() then
- print("Path is obstructed!")
- end
- else
- print("Not enough fuel for moving forward!")
- end
- end
- function moveLeft()
- turtle.turnLeft()
- moveForward()
- end
- function moveOneLeft()
- turtle.turnLeft()
- moveOneForward()
- end
- function moveRight()
- turtle.turnRight()
- moveForward()
- end
- function moveOneRight()
- turtle.turnRight()
- moveOneForward()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement