From 128eb500ebee5163583b84640a9c4f28c0218d42 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 13 Oct 2023 17:35:15 +0100 Subject: [PATCH] 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. --- src/world/World.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/world/World.php b/src/world/World.php index 2ff2b5b2e..965214c14 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -986,8 +986,11 @@ class World implements ChunkManager{ continue; } } - foreach($this->getNearbyEntities(AxisAlignedBB::one()->offset($x, $y, $z)) as $entity){ - $entity->onNearbyBlockChange(); + $cellAABB = AxisAlignedBB::one()->offset($x, $y, $z); + foreach($this->getChunkEntities($x >> Chunk::COORD_BIT_SIZE, $z >> Chunk::COORD_BIT_SIZE) as $entity){ + if($entity->getBoundingBox()->intersectsWith($cellAABB)){ + $entity->onNearbyBlockChange(); + } } $block->onNearbyBlockChange(); }