Remove Position->setWorld()

This commit is contained in:
Dylan K. Taylor 2020-05-19 18:33:16 +01:00
parent 148228e360
commit 8a8b1b0b97
5 changed files with 26 additions and 24 deletions

View File

@ -345,10 +345,7 @@ class Block{
* @internal
*/
final public function position(World $world, int $x, int $y, int $z) : void{
$this->pos->x = $x;
$this->pos->y = $y;
$this->pos->z = $z;
$this->pos->world = $world;
$this->pos = new Position($x, $y, $z, $world);
}
/**

View File

@ -131,8 +131,8 @@ abstract class Tile{
if($this->pos->isValid()){
$this->pos->getWorldNonNull()->removeTile($this);
$this->pos->setWorld(null);
}
$this->pos = null;
}
}
}

View File

@ -1486,7 +1486,14 @@ abstract class Entity{
$this->despawnFromAll();
}
$this->location->setWorld($targetWorld);
$this->location = new Location(
$this->location->x,
$this->location->y,
$this->location->z,
$this->location->yaw,
$this->location->pitch,
$targetWorld
);
$this->getWorld()->addEntity($this);
$this->chunk = null;
@ -1634,7 +1641,7 @@ abstract class Entity{
*/
protected function destroyCycles() : void{
$this->chunk = null;
$this->location->setWorld(null);
$this->location = null;
$this->lastDamageCause = null;
}

View File

@ -39,7 +39,11 @@ class Position extends Vector3{
*/
public function __construct($x = 0, $y = 0, $z = 0, ?World $world = null){
parent::__construct($x, $y, $z);
$this->setWorld($world);
if($world !== null and $world->isClosed()){
throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used");
}
$this->world = $world;
}
/**
@ -85,22 +89,6 @@ class Position extends Vector3{
return $world;
}
/**
* Sets the target world of the position.
*
* @return $this
*
* @throws \InvalidArgumentException if the specified World has been closed
*/
public function setWorld(?World $world){
if($world !== null and $world->isClosed()){
throw new \InvalidArgumentException("Specified world has been unloaded and cannot be used");
}
$this->world = $world;
return $this;
}
/**
* Checks if this object has a valid reference to a loaded world
*/

View File

@ -20,6 +20,16 @@ parameters:
count: 1
path: ../../../src/block/tile/Hopper.php
-
message: "#^Property pocketmine\\\\block\\\\tile\\\\Tile\\:\\:\\$pos \\(pocketmine\\\\world\\\\Position\\) does not accept null\\.$#"
count: 1
path: ../../../src/block/tile/Tile.php
-
message: "#^Property pocketmine\\\\entity\\\\Entity\\:\\:\\$location \\(pocketmine\\\\entity\\\\Location\\) does not accept null\\.$#"
count: 1
path: ../../../src/entity/Entity.php
-
message: "#^Property pocketmine\\\\entity\\\\Human\\:\\:\\$inventory \\(pocketmine\\\\inventory\\\\PlayerInventory\\) does not accept null\\.$#"
count: 1