pocketmine\entity\Entity::setPosition PHP Method

setPosition() public method

public setPosition ( Vector3 $pos )
$pos pocketmine\math\Vector3
    public function setPosition(Vector3 $pos)
    {
        if ($this->closed) {
            return false;
        }
        if ($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level) {
            if ($this->switchLevel($pos->getLevel()) === false) {
                return false;
            }
        }
        $this->x = $pos->x;
        $this->y = $pos->y;
        $this->z = $pos->z;
        $radius = $this->width / 2;
        $this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius);
        $this->checkChunks();
        return true;
    }

Usage Example

Example #1
0
 public function knockBackover(Entity $entity, Vector3 $v3)
 {
     if ($entity instanceof Entity) {
         if (isset($this->zombie[$entity->getId()])) {
             $entity->setPosition($v3);
             $this->zombie[$entity->getId()]['knockBack'] = false;
         }
         if (isset($this->Cow[$entity->getId()])) {
             $entity->setPosition($v3);
             $this->Cow[$entity->getId()]['knockBack'] = false;
         }
         if (isset($this->Pig[$entity->getId()])) {
             $entity->setPosition($v3);
             $this->Pig[$entity->getId()]['knockBack'] = false;
         }
         if (isset($this->Sheep[$entity->getId()])) {
             $entity->setPosition($v3);
             $this->Sheep[$entity->getId()]['knockBack'] = false;
         }
         if (isset($this->Chicken[$entity->getId()])) {
             $entity->setPosition($v3);
             $this->Chicken[$entity->getId()]['knockBack'] = false;
         }
         if (isset($this->Skeleton[$entity->getId()])) {
             $entity->setPosition($v3);
             $this->Skeleton[$entity->getId()]['knockBack'] = false;
         }
         if (isset($this->Creeper[$entity->getId()])) {
             $entity->setPosition($v3);
             $this->Creeper[$entity->getId()]['knockBack'] = false;
         }
     }
 }