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.
This commit is contained in:
Dylan K. Taylor 2019-07-29 18:20:33 +01:00
parent a4042e5d18
commit 452cfe2f59
2 changed files with 5 additions and 17 deletions

View File

@ -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);
}

View File

@ -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
*