Advertisement
SolidSnake96AS

Advance Movement API

Sep 14th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local x,y,z,dir;
  2.  
  3. --The coordinate system has center to the turtle
  4. --and is rotated relatively to the turtle
  5.  
  6. dir=1;
  7. x=0;
  8. y=0;
  9. z=0;
  10.  
  11. function forward(gravelSensor)--Go forward
  12.     local i;
  13.    
  14.     i=0;
  15.    
  16.     while (true)
  17.     do
  18.         if (turtle.forward())
  19.         then
  20.             if (dir==0)
  21.             then
  22.                 x=x+1;
  23.             elseif (dir==1)
  24.             then
  25.                 y=y+1;
  26.             elseif (dir==2)
  27.             then
  28.                 x=x-1;
  29.             elseif (dir==3)
  30.             then
  31.                 y=y-1;
  32.             end
  33.            
  34.             break;
  35.         end
  36.        
  37.         if (gravelSensor)
  38.         then
  39.             if (i>30)--Maybe there is gravel or a mob!
  40.             then
  41.                 turtle.dig();
  42.                 turtle.attack();
  43.             end
  44.            
  45.             i=i+1;
  46.         end
  47.     end
  48. end
  49.  
  50. function back()--Go back
  51.     while (true)
  52.     do
  53.         if (turtle.back())
  54.         then
  55.             if (dir==0)
  56.             then
  57.                 x=x-1;
  58.             elseif (dir==1)
  59.             then
  60.                 y=y-1;
  61.             elseif (dir==2)
  62.             then
  63.                 x=x+1;
  64.             elseif (dir==3)
  65.             then
  66.                 y=y+1;
  67.             end
  68.            
  69.             break;
  70.         end
  71.     end
  72. end
  73.  
  74. function up()--Go up
  75.     while (true)
  76.     do
  77.         if (turtle.up())
  78.         then
  79.             z=z+1;
  80.             break;
  81.         end
  82.     end
  83. end
  84.  
  85. function down()--Go down
  86.     while (true)
  87.     do
  88.         if (turtle.down())
  89.         then
  90.             z=z-1;
  91.             break;
  92.         end
  93.     end
  94. end
  95.  
  96. function turnR()--Turn right
  97.     turtle.turnRight();
  98.    
  99.     if (dir==0)
  100.     then
  101.         dir=3;
  102.     else
  103.         dir=dir-1;
  104.     end
  105. end
  106.  
  107. function turnL()--Turn left
  108.     turtle.turnLeft();
  109.    
  110.     if (dir==3)
  111.     then
  112.         dir=0;
  113.     else
  114.         dir=dir+1;
  115.     end
  116. end
  117.  
  118. function digL()--Dig to the left
  119.     turtle.turnLeft();
  120.     turtle.dig();
  121.     turtle.turnRight();
  122. end
  123.  
  124. function digR()--Dig to the right
  125.     turtle.turnRight();
  126.     turtle.dig();
  127.     turtle.turnLeft();
  128. end
  129.  
  130. function getDir()--Get the direction of the turtle (0=left, 1=up, 2=right, 3=down)
  131.     return dir;
  132. end
  133.  
  134. function setDir(_dir)
  135.     dir=_dir;
  136. end
  137.  
  138. function setCoords(_x, _y, _z)--Set the coordinates
  139.     x=_x;
  140.     y=_y;
  141.     z=_z;
  142. end
  143.  
  144. function getX()
  145.     return x;
  146. end
  147.  
  148. function getY()
  149.     return y;
  150. end
  151.  
  152. function getZ()
  153.     return z;
  154. end
  155.  
  156. --Original script by SolidSnake96AS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement