pocketmine\level\Location::add PHP Method

add() public method

public add ( $x, $y, $z, $yaw, $pitch )
    public function add($x, $y = 0, $z = 0, $yaw = 0, $pitch = 0)
    {
        if ($x instanceof Location) {
            return new Location($this->x + $x->x, $this->y + $x->y, $this->z + $x->z, $this->yaw + $x->yaw, $this->pitch + $x->pitch, $this->level);
        } else {
            return new Location($this->x + $x, $this->y + $y, $this->z + $z, $this->yaw + $yaw, $this->pitch + $pitch, $this->level);
        }
    }

Usage Example

Example #1
0
 public function createTouchEffect(Location $position, $entityHeight, Location $damagerPosition, $damagerHeight)
 {
     if (isset($this->config["NU_EFFECT"]) && !$this->config["NU_EFFECT"]) {
         $position->getLevel()->addSound(new DoorSound($position));
         for ($i = 0; $i < 50; $i++) {
             $position->getLevel()->addParticle(new HeartParticle($position->add(mt_rand(-1, 1), mt_rand(-1, 1) + $entityHeight, mt_rand(-1, 1))));
         }
         for ($i = 0; $i < 50; $i++) {
             $damagerPosition->getLevel()->addParticle(new HeartParticle($damagerPosition->add(mt_rand(-1, 1), mt_rand(-1, 1) + $damagerHeight, mt_rand(-1, 1))));
         }
     } else {
         $position->getLevel()->addSound(new DoorSound($position));
         for ($i = 0; $i < 50; $i++) {
             $position->getLevel()->addParticle(new DustParticle($position->add(mt_rand(-1, 1) / 2, mt_rand(-1, 1) / 2 + $entityHeight, mt_rand(-1, 1) / 2), 153, 51, 255));
         }
         for ($i = 0; $i < 50; $i++) {
             $damagerPosition->getLevel()->addParticle(new DustParticle($damagerPosition->add(mt_rand(-1, 1) / 2, mt_rand(-1, 1) / 2 + $damagerHeight, mt_rand(-1, 1) / 2), 153, 51, 255));
         }
     }
 }