1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved AddPlayerPacket to spawn npc

Discussion in 'Plugin Help' started by Herox, Apr 14, 2021.

  1. Herox

    Herox Creeper

    Messages:
    4
    Error: "Call to undefined method pocketmine\item\ItemBlock::write()" (EXCEPTION) in "pmsrc/src/pocketmine/network/mcpe/protocol/AddPlayerPacket" at line 132

    /**
    * @param VortexPlayer $player
    */
    public function spawnTo(VortexPlayer $player): void {
    $pk = new PlayerListPacket();
    $pk->type = PlayerListPacket::TYPE_ADD;
    $pk->entries = [PlayerListEntry::createAdditionEntry($this->uuid, $this->entityId, $this->getNameTag(), SkinAdapterSingleton::get()->toSkinData($this->skin))];
    $player->dataPacket($pk);
    $xdiff = $player->x - $this->position->x;
    $zdiff = $player->z - $this->position->z;
    $angle = atan2($zdiff, $xdiff);
    $yaw = (($angle * 180) / M_PI) - 90;
    $ydiff = $player->y - $this->position->y;
    $v = new Vector2($this->position->x, $this->position->z);
    $dist = $v->distance($player->x, $player->z);
    $angle = atan2($dist, $ydiff);
    $pitch = (($angle * 180) / M_PI) - 90;
    $pk = new AddPlayerPacket();
    $pk->uuid = $this->getUniqueId();
    $pk->username = $this->nameTag;
    $pk->entityRuntimeId = $this->entityId;
    $pk->position = $this->position->asVector3();
    $pk->yaw = $yaw;
    $pk->pitch = $pitch;
    $pk->item = Item::get(Item::AIR);
    $pk->metadata = [
    Entity::DATA_FLAGS => [
    Entity::DATA_TYPE_LONG, 1 << Entity::DATA_FLAG_ALWAYS_SHOW_NAMETAG
    ^ 1 << Entity::DATA_FLAG_CAN_SHOW_NAMETAG
    ],
    Entity::DATA_NAMETAG => [
    Entity::DATA_TYPE_STRING, $this->nameTag
    ],
    Entity::DATA_LEAD_HOLDER_EID => [
    Entity::DATA_TYPE_LONG, -1
    ]
    ];
    $player->dataPacket($pk);
    $this->setNameTag($player);
    $pk = new PlayerListPacket();
    $pk->type = PlayerListPacket::TYPE_REMOVE;
    $pk->entries = [PlayerListEntry::createRemovalEntry($this->uuid)];
    $player->dataPacket($pk);
    }



    and

    /**
    * @priority NORMAL
    *
    * @param PlayerJoinEvent $event
    */
    public function onPlayerJoin(PlayerJoinEvent $event) {
    $player = $event->getPlayer();
    if(!$player instanceof VortexPlayer) {
    return;
    }
    foreach($this->core->getEntityManager()->getNPCs() as $npc) {
    $npc->spawnTo($player);
    }
    }
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Whats with the text color :facepalm:
    $pk->item is no longer Item and is now ItemStackWrapper
     
    Herox likes this.
  3. DavyCraft648

    DavyCraft648 Spider Jockey

    Messages:
    40
    GitHub:
    DavyCraft648
    PHP:
    $pk->item = \pocketmine\network\mcpe\protocol\types\inventory\ItemStackWrapper::legacy(\pocketmine\item\ItemFactory::get(\pocketmine\item\ItemIds::AIR));
     
    Last edited: Apr 14, 2021
    wolfdale and Herox like this.
  4. Herox

    Herox Creeper

    Messages:
    4
    Thx
     
  5. Herox

    Herox Creeper

    Messages:
    4
    thx
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.