World: avoid code duplication between getCollidingEntities() and getNearbyEntities()

these two methods are very misleadingly named, but they do almost exactly the same thing - the only difference is that getCollidingEntities() does a couple of additional checks.
This commit is contained in:
Dylan K. Taylor 2021-09-05 15:13:22 +01:00
parent d4d00a9b80
commit 19513c65f0
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -1882,22 +1882,9 @@ class World implements ChunkManager{
$nearby = [];
if($entity === null or $entity->canCollide){
$minX = ((int) floor($bb->minX - 2)) >> 4;
$maxX = ((int) floor($bb->maxX + 2)) >> 4;
$minZ = ((int) floor($bb->minZ - 2)) >> 4;
$maxZ = ((int) floor($bb->maxZ + 2)) >> 4;
for($x = $minX; $x <= $maxX; ++$x){
for($z = $minZ; $z <= $maxZ; ++$z){
if(!$this->isChunkLoaded($x, $z)){
continue;
}
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;
}
}
foreach($this->getNearbyEntities($bb, $entity) as $ent){
if($ent->canBeCollidedWith() and ($entity === null or $entity->canCollideWith($ent))){
$nearby[] = $ent;
}
}
}