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

API4 entity create issue

Discussion in 'Development' started by Kabluinc, Mar 15, 2017.

  1. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Since the API4 changes, I'm aware that some things must be changed in plugins that create entities. However with this piece of code I'm not really sure what will make it work.

    PHP:
    public function spawn(Player $player$name)
        {
            
    $entity Entity::createEntity($name$player->getLevel()->getChunk($player->>> 4$player->>> 4), $this->createNbt($player->x$player->y$player->z$player->yaw$player->pitch));
            
    $entity->spawnToAll();
            
    $this->eid[$player->getName()] = $entity->getId();
            
    $entity->setNameTag($player->getName());
            
    $entity->setNameTagAlwaysVisible(true);
            
    $entity->setNameTagVisible(true);
            foreach (
    $this->getServer()->getOnlinePlayers() as $pl) {
                
    $pl->hidePlayer($player);
            }
            
    $player->addEffect(Effect::getEffect(14)->setDuration(9999999999)->setVisible(false));
        }
    iv tried changing it to.

    Code:
    public function spawn(Player $player, $name)
        {
            $entity = Entity::createEntity($name, $player->getLevel(), $this->createNbt($player->x, $player->y, $player->z, $player->yaw, $player->pitch));
            $entity->spawnToAll();
            $this->eid[$player->getName()] = $entity->getId();
            $entity->setNameTag($player->getName());
            $entity->setNameTagAlwaysVisible(true);
            $entity->setNameTagVisible(true);
            foreach ($this->getServer()->getOnlinePlayers() as $pl) {
                $pl->hidePlayer($player);
            }
            $player->addEffect(Effect::getEffect(14)->setDuration(9999999999)->setVisible(false));
        }
    but then it says something about spawnToAll

    Please help
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    "says something" doesn't give us anything to help with. Give the error output
     
  3. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Code:
    2017-03-15 [17:58:24] [Server thread/CRITICAL]: Unhandled exception executing command 'morph cat' in morph: Call to a member function spawnToAll() on null
    2017-03-15 [17:58:24] [Server thread/CRITICAL]: Error: "Call to a member function spawnToAll() on null" (EXCEPTION) in "/plugins/morph_v0.1beta/src/morph/main" at line 99
    
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    It appears that Entity::CreateEntity() is returning a null. You didn't do something right. Probably because of
    PHP:
    $this->createNbt($player->x$player->y$player->z$player->yaw$player->pitch)
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Muqsit likes this.
  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.