Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y,z,dir;
- --The coordinate system has center to the turtle
- --and is rotated relatively to the turtle
- dir=1;
- x=0;
- y=0;
- z=0;
- function forward(gravelSensor)--Go forward
- local i;
- i=0;
- while (true)
- do
- if (turtle.forward())
- then
- if (dir==0)
- then
- x=x+1;
- elseif (dir==1)
- then
- y=y+1;
- elseif (dir==2)
- then
- x=x-1;
- elseif (dir==3)
- then
- y=y-1;
- end
- break;
- end
- if (gravelSensor)
- then
- if (i>30)--Maybe there is gravel or a mob!
- then
- turtle.dig();
- turtle.attack();
- end
- i=i+1;
- end
- end
- end
- function back()--Go back
- while (true)
- do
- if (turtle.back())
- then
- if (dir==0)
- then
- x=x-1;
- elseif (dir==1)
- then
- y=y-1;
- elseif (dir==2)
- then
- x=x+1;
- elseif (dir==3)
- then
- y=y+1;
- end
- break;
- end
- end
- end
- function up()--Go up
- while (true)
- do
- if (turtle.up())
- then
- z=z+1;
- break;
- end
- end
- end
- function down()--Go down
- while (true)
- do
- if (turtle.down())
- then
- z=z-1;
- break;
- end
- end
- end
- function turnR()--Turn right
- turtle.turnRight();
- if (dir==0)
- then
- dir=3;
- else
- dir=dir-1;
- end
- end
- function turnL()--Turn left
- turtle.turnLeft();
- if (dir==3)
- then
- dir=0;
- else
- dir=dir+1;
- end
- end
- function digL()--Dig to the left
- turtle.turnLeft();
- turtle.dig();
- turtle.turnRight();
- end
- function digR()--Dig to the right
- turtle.turnRight();
- turtle.dig();
- turtle.turnLeft();
- end
- function getDir()--Get the direction of the turtle (0=left, 1=up, 2=right, 3=down)
- return dir;
- end
- function setDir(_dir)
- dir=_dir;
- end
- function setCoords(_x, _y, _z)--Set the coordinates
- x=_x;
- y=_y;
- z=_z;
- end
- function getX()
- return x;
- end
- function getY()
- return y;
- end
- function getZ()
- return z;
- end
- --Original script by SolidSnake96AS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement