PocketMine-MP 5.15.1 git-be6754494fdbbb9dd57c058ba0e33a4a78c4581f
Location.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\entity;
25
29
30class Location extends Position{
31
32 public float $yaw;
33 public float $pitch;
34
35 public function __construct(float $x, float $y, float $z, ?World $world, float $yaw, float $pitch){
36 $this->yaw = $yaw;
37 $this->pitch = $pitch;
38 parent::__construct($x, $y, $z, $world);
39 }
40
44 public static function fromObject(Vector3 $pos, ?World $world, float $yaw = 0.0, float $pitch = 0.0){
45 return new Location($pos->x, $pos->y, $pos->z, $world ?? (($pos instanceof Position) ? $pos->world : null), $yaw, $pitch);
46 }
47
51 public function asLocation() : Location{
52 return new Location($this->x, $this->y, $this->z, $this->world, $this->yaw, $this->pitch);
53 }
54
55 public function getYaw() : float{
56 return $this->yaw;
57 }
58
59 public function getPitch() : float{
60 return $this->pitch;
61 }
62
63 public function __toString(){
64 return "Location (world=" . ($this->isValid() ? $this->getWorld()->getDisplayName() : "null") . ", x=$this->x, y=$this->y, z=$this->z, yaw=$this->yaw, pitch=$this->pitch)";
65 }
66
67 public function equals(Vector3 $v) : bool{
68 if($v instanceof Location){
69 return parent::equals($v) && $v->yaw == $this->yaw && $v->pitch == $this->pitch;
70 }
71 return parent::equals($v);
72 }
73}
static fromObject(Vector3 $pos, ?World $world, float $yaw=0.0, float $pitch=0.0)
Definition: Location.php:44
equals(self $other)
Definition: EnumTrait.php:106