From eb9f60f41cdb2362076dff0426d7ec8ec11e8ab5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 24 Mar 2018 11:52:23 +0000 Subject: [PATCH] Entity: some minor cleanup to constructor --- src/pocketmine/entity/Entity.php | 35 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 9755ca146..5a37b2c8a 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -374,11 +374,11 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ public $lastZ = null; /** @var float */ - public $motionX; + public $motionX = 0.0; /** @var float */ - public $motionY; + public $motionY = 0.0; /** @var float */ - public $motionZ; + public $motionZ = 0.0; /** @var Vector3 */ public $temporalVector; /** @var float */ @@ -492,37 +492,32 @@ abstract class Entity extends Location implements Metadatable, EntityIds{ $this->id = Entity::$entityCount++; $this->namedtag = $nbt; + $this->server = $level->getServer(); /** @var float[] $pos */ $pos = $this->namedtag->getListTag("Pos")->getAllValues(); + /** @var float[] $rotation */ + $rotation = $this->namedtag->getListTag("Rotation")->getAllValues(); - $this->chunk = $level->getChunk(((int) floor($pos[0])) >> 4, ((int) floor($pos[2])) >> 4, true); + parent::__construct($pos[0], $pos[1], $pos[2], $rotation[0], $rotation[1], $level); + assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z)); + + $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); + $this->recalculateBoundingBox(); + + $this->chunk = $this->level->getChunk($this->getFloorX() >> 4, $this->getFloorZ() >> 4, false); if($this->chunk === null){ throw new \InvalidStateException("Cannot create entities in unloaded chunks"); } - $this->setLevel($level); - $this->server = $level->getServer(); - - $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0); - - /** @var float[] $rotation */ - $rotation = $this->namedtag->getListTag("Rotation")->getAllValues(); - - $this->setPositionAndRotation($this->temporalVector->setComponents(...$pos), ...$rotation); - - /** @var float[] $motion */ - $motion = [0, 0, 0]; if($this->namedtag->hasTag("Motion", ListTag::class)){ + /** @var float[] $motion */ $motion = $this->namedtag->getListTag("Motion")->getAllValues(); + $this->setMotion($this->temporalVector->setComponents(...$motion)); } - $this->setMotion($this->temporalVector->setComponents(...$motion)); - $this->resetLastMovements(); - assert(!is_nan($this->x) and !is_infinite($this->x) and !is_nan($this->y) and !is_infinite($this->y) and !is_nan($this->z) and !is_infinite($this->z)); - $this->fallDistance = $this->namedtag->getFloat("FallDistance", 0.0); $this->propertyManager = new DataPropertyManager();