Entity: assume that position has a valid World during setPosition()

This commit is contained in:
Dylan K. Taylor 2020-12-27 19:20:37 +00:00
parent f215207a27
commit 793081d803
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -1306,8 +1306,7 @@ abstract class Entity{
} }
$oldWorld = $this->getWorld(); $oldWorld = $this->getWorld();
//TODO: staying in the same world when the target is invalid is probably not expected behaviour... this should bail instead $newWorld = $pos instanceof Position ? $pos->getWorld() : $oldWorld;
$newWorld = $pos instanceof Position && $pos->isValid() ? $pos->getWorld() : $oldWorld;
if($oldWorld !== $newWorld){ if($oldWorld !== $newWorld){
$this->despawnFromAll(); $this->despawnFromAll();
$oldWorld->removeEntity($this); $oldWorld->removeEntity($this);