# Solved Block left Player's Head

Comments in 'Plugin Development' started by MineBuilderFR, Jun 1, 2016.

1. Offline

### MineBuilderFRActive Member

Joined:
Mar 14, 2015
Posts:
56
Minecraft User:
Hii !
How to place a block to the left of the player's head ?

File size:
576.2 KB
Views:
33
2. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
This needs calculation. 4 directions, 4 different codes.
3. Offline

### BlubberBoy333Active Member

Joined:
Aug 31, 2014
Posts:
177
Minecraft User:
PHP:
``` \$player = \$this->getServer()->getPlayer("Player");\$player->getLevel()->setBlock(new Vector3(\$player->x + 1, \$player->y + 1, \$player->z), new BlockName()); ```
For BlockName, you can choose the block that you want to set by changing it from BlockName to an actual block. Also, make sure you're using the block...
PHP:
``` use pocketmine\block\BlockName; ```
4. Offline

### BlubberBoy333Active Member

Joined:
Aug 31, 2014
Posts:
177
Minecraft User:
Oh wait, this won't place it to their left , just by their head
5. Offline

### Legoboy0215Notable Member

Joined:
Nov 1, 2014
Posts:
1,724
Minecraft User:
Primus likes this.
6. Offline

### MineBuilderFRActive Member

Joined:
Mar 14, 2015
Posts:
56
Minecraft User:
Thank you but I think I found the solution. Your code works but it does not always put the block in the left of the player. So I calculate the coordinates (North, East , West, South ) depending on the orientation of the player's head with the function \$player->getLocation()->getYaw() and I have set This to 360° ^^
7. Offline

### SOFeBanned

Joined:
May 28, 2016
Posts:
386
Minecraft User:
https://github.com/PocketMine/Pocketmine-mp/blob/master/src/pocketmine/entity/Entity.php#L969

Modify this code a bit to change north to west, west to south, etc.

PHP:
``` function getLeft(Player \$player) : int{        \$rotation = (\$yaw - 90) % 360;        if(\$rotation < 0){            \$rotation += 360.0;        }        if((0 <= \$rotation and \$rotation < 45) or (315 <= \$rotation and \$rotation < 360)){            return Vector3::SIDE_WEST;        }elseif(45 <= \$rotation and \$rotation < 135){            return Vector3::SIDE_NORTH;        }elseif(135 <= \$rotation and \$rotation < 225){            return Vector3::SIDE_EAST;        }elseif(225 <= \$rotation and \$rotation < 315){            return Vector3::SIDE_SOUTH;        }else{            throw new RuntimeException();        }}\$player->getLevel()->setBlock(\$player->getSide(getLeft(\$player), 2), \$block); ```