Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Block left Player's Head

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

  1. MineBuilderFR
    Offline

    MineBuilderFR Active Member

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

    Thanks For your Help :)

    Attached Files:

  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

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

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    PHP:
    $player $this->getServer()->getPlayer("Player");
    $player->getLevel()->setBlock(new Vector3($player->1$player->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. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

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

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Bad practice. Use Block::get(Block::BLOCK_NAME)
    Primus likes this.
  6. MineBuilderFR
    Offline

    MineBuilderFR Active Member

    Joined:
    Mar 14, 2015
    Posts:
    56
    Minecraft User:
    MineBuilderFR
    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. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    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((
    <= $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);

Share This Page

Advertisement