mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 07:39:57 +00:00
Server: remove premature optimization of findEntity()
This commit is contained in:
parent
fe6d546190
commit
032b20f659
@ -1138,17 +1138,12 @@ class Server{
|
|||||||
* Useful for tracking entities across multiple worlds without needing strong references.
|
* Useful for tracking entities across multiple worlds without needing strong references.
|
||||||
*
|
*
|
||||||
* @param int $entityId
|
* @param int $entityId
|
||||||
* @param Level|null $expectedLevel Level to look in first for the target
|
* @param Level|null $expectedLevel @deprecated Level to look in first for the target
|
||||||
*
|
*
|
||||||
* @return Entity|null
|
* @return Entity|null
|
||||||
*/
|
*/
|
||||||
public function findEntity(int $entityId, Level $expectedLevel = null){
|
public function findEntity(int $entityId, Level $expectedLevel = null){
|
||||||
$levels = $this->levels;
|
foreach($this->levels as $level){
|
||||||
if($expectedLevel !== null){
|
|
||||||
array_unshift($levels, $expectedLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($levels as $level){
|
|
||||||
assert(!$level->isClosed());
|
assert(!$level->isClosed());
|
||||||
if(($entity = $level->getEntity($entityId)) instanceof Entity){
|
if(($entity = $level->getEntity($entityId)) instanceof Entity){
|
||||||
return $entity;
|
return $entity;
|
||||||
|
@ -749,7 +749,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
public function getOwningEntity() : ?Entity{
|
public function getOwningEntity() : ?Entity{
|
||||||
$eid = $this->getOwningEntityId();
|
$eid = $this->getOwningEntityId();
|
||||||
if($eid !== null){
|
if($eid !== null){
|
||||||
return $this->server->findEntity($eid, $this->level);
|
return $this->server->findEntity($eid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -789,7 +789,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
|||||||
public function getTargetEntity() : ?Entity{
|
public function getTargetEntity() : ?Entity{
|
||||||
$eid = $this->getTargetEntityId();
|
$eid = $this->getTargetEntityId();
|
||||||
if($eid !== null){
|
if($eid !== null){
|
||||||
return $this->server->findEntity($eid, $this->level);
|
return $this->server->findEntity($eid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -144,7 +144,7 @@ class ExperienceOrb extends Entity{
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity = $this->server->findEntity($this->targetPlayerRuntimeId, $this->level);
|
$entity = $this->server->findEntity($this->targetPlayerRuntimeId);
|
||||||
if($entity instanceof Human){
|
if($entity instanceof Human){
|
||||||
return $entity;
|
return $entity;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,6 @@ class EntityDamageByChildEntityEvent extends EntityDamageByEntityEvent{
|
|||||||
* @return Entity|null
|
* @return Entity|null
|
||||||
*/
|
*/
|
||||||
public function getChild() : ?Entity{
|
public function getChild() : ?Entity{
|
||||||
return $this->getEntity()->getLevel()->getServer()->findEntity($this->childEntityEid, $this->getEntity()->getLevel());
|
return $this->getEntity()->getLevel()->getServer()->findEntity($this->childEntityEid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ class EntityDamageByEntityEvent extends EntityDamageEvent{
|
|||||||
* @return Entity|null
|
* @return Entity|null
|
||||||
*/
|
*/
|
||||||
public function getDamager() : ?Entity{
|
public function getDamager() : ?Entity{
|
||||||
return $this->getEntity()->getLevel()->getServer()->findEntity($this->damagerEntityId, $this->getEntity()->getLevel());
|
return $this->getEntity()->getLevel()->getServer()->findEntity($this->damagerEntityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user