Advertisement
NeoLegends

Lua Tekkit Turtle

Jul 30th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. local tArgs = {...}
  2. getOrientation()
  3.  
  4. -- Gets the turtle's orientation.
  5. function getOrientation()
  6.     if turtle.getFuelLevel() < 2 then
  7.         print("Not enough fuel for determining the orientation. Needs at least two.")
  8.         return
  9.     end
  10.    
  11.     local tries = 1
  12.     while turtle.detect() do
  13.         if tries =< 4 then
  14.             print("Obstructed, turning.")
  15.             tries = tries + 1
  16.             turtle.turnRight()
  17.         else
  18.             print("Turtle obstructed, orientation cannot be determined.")
  19.             return;
  20.         end
  21.     end
  22.    
  23.     local pos1 = vector.new(gps.locate(5))
  24.     turtle.forward()
  25.     local pos2 = vector.new(gps.locate(5))
  26.     turtle.back()
  27.    
  28.     local deltaZ = pos2.z - pos1.z
  29.     local deltaX = pos2.x - pos1.x
  30.    
  31.     local orientation = nil
  32.     if deltaZ == 0 then
  33.         if deltaX == 1 then
  34.             orientation = "east"
  35.         else
  36.             orientation = "west"
  37.         end
  38.     else
  39.         if deltaZ == 1 then
  40.             orientation = "south"
  41.         else
  42.             orientation = "north"
  43.         end
  44.     end
  45.  
  46.     print("Looking " .. orientation)
  47. end
  48.  
  49. -- Moves turtle forwards until the path is obstructed.
  50. function moveForward()
  51.     while not turtle.detect() do
  52.         if turtle.getFuelLevel() > 0 then
  53.             turtle.forward()
  54.         else
  55.             print("Not enough fuel to continue, aborting...")
  56.             break
  57.         end
  58.     end
  59. end
  60.  
  61. -- Moves turtle one block forwards
  62. function moveOneForward()
  63.     if turtle.getFuelLevel() > 0 then
  64.         -- turtle.forward() returns true or false depending on whether the turtle did actually move or not
  65.         if not turtle.forward() then
  66.             print("Path is obstructed!")
  67.         end
  68.     else
  69.         print("Not enough fuel for moving forward!")
  70.     end
  71. end
  72.  
  73. function moveLeft()
  74.     turtle.turnLeft()
  75.     moveForward()
  76. end
  77.  
  78. function moveOneLeft()
  79.     turtle.turnLeft()
  80.     moveOneForward()
  81. end
  82.    
  83. function moveRight()
  84.     turtle.turnRight()
  85.     moveForward()
  86. end
  87.  
  88. function moveOneRight()
  89.     turtle.turnRight()
  90.     moveOneForward()
  91. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement