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

Spawn entity in front of player

Comments in 'Plugin Development' started by PalkiaDudeYT, Oct 3, 2016.

  1. PalkiaDudeYT
    Offline

    PalkiaDudeYT New Member

    Joined:
    Aug 30, 2015
    Posts:
    33
    Minecraft User:
    PalkiaDude
    How do I spawn an entity right in front of a player?
  2. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Get the directions of player and if direction is 1 spawn it player.getX() +1, player.getY(), player.getZ() (Only example the values arent correct)
  3. Ragnok1234
    Offline

    Ragnok1234 Active Member

    Joined:
    Jul 18, 2016
    Posts:
    53
    Minecraft User:
    Ragnok123
    I dont remember, but you must somethink do with NBT tag. When I will be at home, I send you.
    Khaled098 likes this.
  4. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Easy
    PHP:

    use pocketmine\entity\Entity;
    use 
    pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\nbt\tag\ByteTag;
    use 
    pocketmine\nbt\tag\StringTag;
    use 
    pocketmine\nbt\tag\DoubleTag;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\ListTag;
    use 
    pocketmine\nbt\tag\FloatTag;

    public function 
    onInteract(PlayerInteractEvent $event){
    $player $event->getPlayer();
    $block $player;
    $block->cos($player->yaw M_PI 180);
    $block->sin($player->yaw M_PI 180);
    $npc = new Human($player->chunk,
    new 
    CompoundTag("", [
    "Pos" => new ListTag("Pos", [
    new 
    DoubleTag(""$block->getX()),
    new 
    DoubleTag(""$block->getY()),
    new 
    DoubleTag(""$block->getZ())
    ]),
    "Motion" => new ListTag("Motion", [
    new 
    DoubleTag(""0),
    new 
    DoubleTag(""0),
    new 
    DoubleTag(""0)
    ]),
    "Rotation" => new ListTag("Rotation", [
    new 
    FloatTag(""90),
    new 
    FloatTag(""0)
    ]),
    "Skin" => new CompoundTag("Skin", [
    "Data" => new StringTag("Data"$player->getSkinData())
    ])
    ]
    ));



    $npc->spawnToAll();
    $npc->setDataProperty(Entity::DATA_NAMETAGEntity::DATA_TYPE_STRING"YOUR ENTITY NAME");
    $npc->setDataProperty(Entity::DATA_SHOW_NAMETAGEntity::DATA_TYPE_BYTE1);

    }
    Skullex and XShockinFireX like this.

Share This Page

Advertisement