# Solved getDirection with x and z?

Comments in 'Plugin Development' started by Legoboy0215, Dec 8, 2015.

1. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
How would I know if I should add x or z from getDirection? Or other functions? I am trying to setBlock every air block in front of your face
CraftYourBukkit likes this.
2. Offline

### PocketKillerNotable Member

Joined:
Jul 20, 2015
Posts:
741
replace Player:: with the player.
do you mean
PHP:
``` Player::getLevel()->setBlock(new Vector3(Player::getX()+1, Player::getY()+1, Player::getZ())); ```
AndrewBit likes this.
3. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
Did you even read my post? x and z is different. What if his x is on his sides?
hoyinm14mc likes this.
4. Offline

### wolfdaleActive MemberPlugin Developer

Joined:
Dec 3, 2014
Posts:
276
Plugins:
1
Minecraft User:
getDirection returns int 0-3
0 = South(+x)
1 = West(+z)
2 = North(-x)
3 = East(-z)
5. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
How would I do it in a blocks perspective? I have a block (dirt) and want to set 2 blocks towards the player looking at it.
6. Offline

### wolfdaleActive MemberPlugin Developer

Joined:
Dec 3, 2014
Posts:
276
Plugins:
1
Minecraft User:
Something like this?
PHP:
```     \$x = \$player->x;    \$y = \$player->y;    \$z = \$player->z;    switch(\$player->getDirection()){        case 0: \$x += 2; break;        case 1: \$z += 2; break;        case 2: \$x -= 2; break;        case 3: \$z -= 2; break;    }    \$level->setBlock(new Vector3(\$x,\$y,\$z),Block::get(0)); ```
AndrewBit likes this.
7. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
But I want in a blocks perspective? So I want when a player is looking at a 2 block high pillar, the pillar extends (setBlock) towards the player.
8. Offline

### wolfdaleActive MemberPlugin Developer

Joined:
Dec 3, 2014
Posts:
276
Plugins:
1
Minecraft User:
Maybe you mean
PHP:
``` \$x = \$player->x;\$y = \$player->y;\$z = \$player->z;switch(\$player->getDirection()){case 0: \$x -= 1; break;case 1: \$z -= 1; break;case 2: \$x += 1; break;case 3: \$z += 1; break;}\$blocks = \$player->getLineOfSight(\$distance);foreach(\$blocks as \$b)\$level->setBlock(new Vector3(\$x,\$y,\$z),Block::get(1)); ```
9. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
What does getLineOfSight do? And \$b is useless
10. Offline

### wolfdaleActive MemberPlugin Developer

Joined:
Dec 3, 2014
Posts:
276
Plugins:
1
Minecraft User:
It gets the blocks the player is looking at. And returns array of blocks so i just foreach it
Legoboy0215 likes this.
11. Offline

### PEMapModderNotable MemberPlugin Developer

Joined:
Oct 9, 2013
Posts:
7,294
Plugins:
11
Minecraft User: