mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Entity: fix chunk tracking consistency issues, fixed attempted chunk loading in origin world when teleporting to a different position in a different world
This commit is contained in:
@ -96,8 +96,8 @@ abstract class Entity{
|
||||
/** @var EntityMetadataCollection */
|
||||
private $networkProperties;
|
||||
|
||||
/** @var Location */
|
||||
private $worldLastKnownLocation;
|
||||
/** @var Vector3 */
|
||||
public $worldLastKnownLocation;
|
||||
|
||||
/** @var EntityDamageEvent|null */
|
||||
protected $lastDamageCause = null;
|
||||
@ -1210,7 +1210,7 @@ abstract class Entity{
|
||||
$this->location->world
|
||||
);
|
||||
|
||||
$this->checkChunks();
|
||||
$this->getWorld()->onEntityMoved($this);
|
||||
$this->checkBlockCollision();
|
||||
$this->checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz);
|
||||
$this->updateFallState($dy, $this->onGround);
|
||||
@ -1309,15 +1309,17 @@ abstract class Entity{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($pos instanceof Position and $pos->isValid() and $pos->getWorld() !== $this->getWorld()){
|
||||
if(!$this->switchWorld($pos->getWorld())){
|
||||
return false;
|
||||
}
|
||||
$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->isValid() ? $pos->getWorld() : $oldWorld;
|
||||
if($oldWorld !== $newWorld){
|
||||
$this->despawnFromAll();
|
||||
$oldWorld->removeEntity($this);
|
||||
}
|
||||
|
||||
$this->location = Location::fromObject(
|
||||
$pos,
|
||||
$this->location->world,
|
||||
$newWorld,
|
||||
$this->location->yaw,
|
||||
$this->location->pitch
|
||||
);
|
||||
@ -1326,7 +1328,11 @@ abstract class Entity{
|
||||
|
||||
$this->blocksAround = null;
|
||||
|
||||
$this->checkChunks();
|
||||
if($oldWorld !== $newWorld){
|
||||
$newWorld->addEntity($this);
|
||||
}else{
|
||||
$newWorld->onEntityMoved($this);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1347,11 +1353,6 @@ abstract class Entity{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function checkChunks() : void{
|
||||
$this->getWorld()->onEntityMoved($this, $this->worldLastKnownLocation);
|
||||
$this->worldLastKnownLocation = $this->location->asLocation();
|
||||
}
|
||||
|
||||
protected function resetLastMovements() : void{
|
||||
$this->lastLocation = $this->location->asLocation();
|
||||
$this->lastMotion = clone $this->motion;
|
||||
@ -1421,29 +1422,6 @@ abstract class Entity{
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function switchWorld(World $targetWorld) : bool{
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->location->isValid()){
|
||||
$this->getWorld()->removeEntity($this);
|
||||
$this->despawnFromAll();
|
||||
}
|
||||
|
||||
$this->location = new Location(
|
||||
$this->location->x,
|
||||
$this->location->y,
|
||||
$this->location->z,
|
||||
$this->location->yaw,
|
||||
$this->location->pitch,
|
||||
$targetWorld
|
||||
);
|
||||
$this->getWorld()->addEntity($this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getId() : int{
|
||||
return $this->id;
|
||||
}
|
||||
|
Reference in New Issue
Block a user