World: specialize nearby entity updating for block updates

this slashes the cost of checking this with no entities by 50%, which should be the common case for farms and such.
once factoring in other things, this translates into a real-world performance gain of about 15% for block updates.
This commit is contained in:
Dylan K. Taylor 2023-10-13 17:35:15 +01:00
parent 8b52a5cd9e
commit 128eb500eb
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -986,8 +986,11 @@ class World implements ChunkManager{
continue; continue;
} }
} }
foreach($this->getNearbyEntities(AxisAlignedBB::one()->offset($x, $y, $z)) as $entity){ $cellAABB = AxisAlignedBB::one()->offset($x, $y, $z);
$entity->onNearbyBlockChange(); foreach($this->getChunkEntities($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE) as $entity){
if($entity->getBoundingBox()->intersectsWith($cellAABB)){
$entity->onNearbyBlockChange();
}
} }
$block->onNearbyBlockChange(); $block->onNearbyBlockChange();
} }