/** * Returns a Position pointing to the spawn * * @return Position */ public function getSpawnLocation() { return Position::fromObject($this->provider->getSpawn(), $this); }
/** * Returns a side Vector * * @param int $side * @param int $step * * @return Position * * @throws LevelException */ public function getSide($side, $step = 1) { if (!$this->isValid()) { throw new LevelException("Undefined Level reference"); } return Position::fromObject(parent::getSide($side, $step), $this->level); }
/** * Returns the Block on the side $side, works like Vector3::side() * * @param int $side * @param int $step * * @return Block */ public function getSide($side, $step = 1) { if ($this->isValid()) { return $this->getLevel()->getBlock(Vector3::getSide($side, $step)); } return Block::get(Item::AIR, 0, Position::fromObject(Vector3::getSide($side, $step))); }
/** * @param Vector3|Position|Location $pos * @param float $yaw * @param float $pitch * * @return bool */ public function teleport(Vector3 $pos, $yaw = null, $pitch = null) { if ($pos instanceof Location) { $yaw = $yaw === null ? $pos->yaw : $yaw; $pitch = $pitch === null ? $pos->pitch : $pitch; } $from = Position::fromObject($this, $this->level); $to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level); $this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to)); if ($ev->isCancelled()) { return false; } $this->ySize = 0; $pos = $ev->getTo(); $this->setMotion($this->temporalVector->setComponents(0, 0, 0)); if ($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch) !== false) { $this->resetFallDistance(); $this->onGround = true; $this->lastX = $this->x; $this->lastY = $this->y; $this->lastZ = $this->z; $this->lastYaw = $this->yaw; $this->lastPitch = $this->pitch; $this->updateMovement(); return true; } return false; }