PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
Position.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 
22 namespace pocketmine\level;
23 
26 
27 class Position extends Vector3{
28 
30  public $level = null;
31 
38  public function __construct($x = 0, $y = 0, $z = 0, Level $level = null){
39  $this->x = $x;
40  $this->y = $y;
41  $this->z = $z;
42  $this->level = $level;
43  }
44 
45  public static function fromObject(Vector3 $pos, Level $level = null){
46  return new Position($pos->x, $pos->y, $pos->z, $level);
47  }
48 
52  public function getLevel(){
53  return $this->level;
54  }
55 
56  public function setLevel(Level $level){
57  $this->level = $level;
58  return $this;
59  }
60 
66  public function isValid(){
67  return $this->level !== null;
68  }
69 
78  public function setStrong(){
79  return false;
80  }
81 
90  public function setWeak(){
91  return false;
92  }
93 
104  public function getSide($side, $step = 1){
105  if(!$this->isValid()){
106  throw new LevelException("Undefined Level reference");
107  }
108 
109  return Position::fromObject(parent::getSide($side, $step), $this->level);
110  }
111 
112  public function __toString(){
113  return "Position(level=" . ($this->isValid() ? $this->getLevel()->getName() : "null") . ",x=" . $this->x . ",y=" . $this->y . ",z=" . $this->z . ")";
114  }
115 
123  public function setComponents($x, $y, $z){
124  $this->x = $x;
125  $this->y = $y;
126  $this->z = $z;
127  return $this;
128  }
129 
130 }
getSide($side, $step=1)
Definition: Position.php:104
__construct($x=0, $y=0, $z=0, Level $level=null)
Definition: Position.php:38
setComponents($x, $y, $z)
Definition: Position.php:123