From 452cfe2f5999df2206746f8d0fae683feab32d8b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 29 Jul 2019 18:20:33 +0100 Subject: [PATCH] World: drop getChunkEntities(), use getChunk()->getEntities() everywhere this function is used, it should be assumed/expected that the chunk in question is already present and loaded. --- src/pocketmine/player/Player.php | 4 ++-- src/pocketmine/world/World.php | 18 +++--------------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/pocketmine/player/Player.php b/src/pocketmine/player/Player.php index e364d11be..8d231406c 100644 --- a/src/pocketmine/player/Player.php +++ b/src/pocketmine/player/Player.php @@ -827,7 +827,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $world = $world ?? $this->world; $index = World::chunkHash($x, $z); if(isset($this->usedChunks[$index])){ - foreach($world->getChunkEntities($x, $z) as $entity){ + foreach($world->getChunk($x, $z)->getEntities() as $entity){ if($entity !== $this){ $entity->despawnFrom($this); } @@ -841,7 +841,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, } protected function spawnEntitiesOnChunk(int $chunkX, int $chunkZ) : void{ - foreach($this->world->getChunkEntities($chunkX, $chunkZ) as $entity){ + foreach($this->world->getChunk($chunkX, $chunkZ)->getEntities() as $entity){ if($entity !== $this and !$entity->isFlaggedForDespawn()){ $entity->spawnTo($this); } diff --git a/src/pocketmine/world/World.php b/src/pocketmine/world/World.php index 97aa5132b..c40b55a0a 100644 --- a/src/pocketmine/world/World.php +++ b/src/pocketmine/world/World.php @@ -1829,7 +1829,7 @@ class World implements ChunkManager{ if(!$this->isChunkLoaded($x, $z)){ continue; } - foreach($this->getChunkEntities($x, $z) as $ent){ + foreach($this->getChunk($x, $z)->getEntities() as $ent){ /** @var Entity|null $entity */ if($ent->canBeCollidedWith() and ($entity === null or ($ent !== $entity and $entity->canCollideWith($ent))) and $ent->boundingBox->intersectsWith($bb)){ $nearby[] = $ent; @@ -1863,7 +1863,7 @@ class World implements ChunkManager{ if(!$this->isChunkLoaded($x, $z)){ continue; } - foreach($this->getChunkEntities($x, $z) as $ent){ + foreach($this->getChunk($x, $z)->getEntities() as $ent){ if($ent !== $entity and $ent->boundingBox->intersectsWith($bb)){ $nearby[] = $ent; } @@ -1902,7 +1902,7 @@ class World implements ChunkManager{ if(!$this->isChunkLoaded($x, $z)){ continue; } - foreach($this->getChunkEntities($x, $z) as $entity){ + foreach($this->getChunk($x, $z)->getEntities() as $entity){ if(!($entity instanceof $entityType) or $entity->isFlaggedForDespawn() or (!$includeDead and !$entity->isAlive())){ continue; } @@ -1961,18 +1961,6 @@ class World implements ChunkManager{ return ($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null ? $chunk->getTile($x & 0x0f, $y, $z & 0x0f) : null; } - /** - * Returns a list of the entities on a given chunk - * - * @param int $X - * @param int $Z - * - * @return Entity[] - */ - public function getChunkEntities(int $X, int $Z) : array{ - return ($chunk = $this->getChunk($X, $Z)) !== null ? $chunk->getEntities() : []; - } - /** * Gets the raw block skylight level *