Use new Location objects instead of mutating Entity->location directly

I'm actually not a big fan of needing to recreate the whole thing just to modify the coordinates. This seems kind of stupid.
This commit is contained in:
Dylan K. Taylor 2020-09-25 18:43:49 +01:00
parent db7fb25196
commit 626680c6c1
2 changed files with 20 additions and 9 deletions

View File

@ -1192,9 +1192,14 @@ abstract class Entity{
$this->boundingBox = $moveBB; $this->boundingBox = $moveBB;
} }
$this->location->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2; $this->location = new Location(
$this->location->y = $this->boundingBox->minY - $this->ySize; ($this->boundingBox->minX + $this->boundingBox->maxX) / 2,
$this->location->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2; $this->boundingBox->minY - $this->ySize,
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2,
$this->location->yaw,
$this->location->pitch,
$this->location->world
);
$this->checkChunks(); $this->checkChunks();
$this->checkBlockCollision(); $this->checkBlockCollision();
@ -1301,9 +1306,12 @@ abstract class Entity{
} }
} }
$this->location->x = $pos->x; $this->location = Location::fromObject(
$this->location->y = $pos->y; $pos,
$this->location->z = $pos->z; $this->location->world,
$this->location->yaw,
$this->location->pitch
);
$this->recalculateBoundingBox(); $this->recalculateBoundingBox();

View File

@ -219,9 +219,12 @@ abstract class Projectile extends Entity{
} }
} }
$this->location->x = $end->x; $this->location = Location::fromObject(
$this->location->y = $end->y; $end,
$this->location->z = $end->z; $this->location->world,
$this->location->yaw,
$this->location->pitch
);
$this->recalculateBoundingBox(); $this->recalculateBoundingBox();
if($hitResult !== null){ if($hitResult !== null){