Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- The coordinate system has center to the turtle
- and is rotated relatively to the turtle
- ]]--
- --Local variables
- local x, y, z, dir, waitTime;
- --Global variables
- L=0;
- U=1;
- R=2;
- D=3;
- dir=1;
- x=0;
- y=0;
- z=0;
- waitTime=30;
- --Functions
- local function updateCoords(incrementValue)
- if (dir==0)
- then
- x=x+incrementValue;
- elseif (dir==1)
- then
- y=y+incrementValue;
- elseif (dir==2)
- then
- x=x-incrementValue;
- elseif (dir==3)
- then
- y=y-incrementValue;
- end
- end
- function f(gravelSensor) --Go forward
- local i;
- i=0;
- while (true)
- do
- if (turtle.forward())
- then
- updateCoords(1);
- break;
- end
- if (gravelSensor)
- then
- if (i>waitTime)--Maybe there is gravel or a mob!
- then
- turtle.dig();
- turtle.attack();
- end
- i=i+1;
- end
- end
- end
- function b() --Go back
- while (true)
- do
- if (turtle.back())
- then
- updateCoords(-1);
- break;
- end
- end
- end
- function u(gravelSensor) --Go up
- local i=0;
- while (true)
- do
- if (turtle.up())
- then
- z=z+1;
- break;
- end
- if (gravelSensor)
- then
- if (i>waitTime) --Maybe there is gravel or a mob!
- then
- turtle.digUp();
- turtle.attackUp();
- end
- i=i+1;
- end
- end
- end
- function d(gravelSensor) --Go down
- local i=0;
- while (true)
- do
- if (turtle.down())
- then
- z=z-1;
- break;
- end
- if (gravelSensor)
- then
- if (i>waitTime) --Maybe there is gravel or a mob!
- then
- turtle.digDown();
- turtle.attackDown();
- end
- i=i+1;
- end
- end
- end
- function r() --Turn right
- turtle.turnRight();
- if (dir==0)
- then
- dir=3;
- else
- dir=dir-1;
- end
- end
- function l() --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 pointTo(_dir)
- while(getDir()>_dir)
- do
- r();
- end
- while(getDir()<_dir)
- do
- l();
- end
- end
- function getDir() --Get the direction of the turtle (0=left, 1=up, 2=right, 3=down)
- return dir;
- end
- function setDir(_dir) --Set the direction of the turtle
- dir=_dir;
- end
- function setPos(_x, _y, _z) --Set the coordinates
- x=_x;
- y=_y;
- z=_z;
- end
- function pos()
- return {x, y, z};
- end
- function getX()
- return x;
- end
- function getY()
- return y;
- end
- function getZ()
- return z;
- end
- function setWaitTime(_waitTime)
- waitTime=_waitTime;
- end
- function getWaitTime()
- return waitTime;
- end
- --Aliasses
- forward=f;
- back=b;
- turnLeft=l;
- turnL=l;
- turnRight=r;
- turnR=r;
- up=u;
- down=d;
- getPos=pos;
- LEFT=L;
- UP=U;
- RIGHT=R;
- DOWN=D;
- --Original script by SolidSnake96AS.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement