Avoid unnecessary Entity::getWorld() calls in loops

This commit is contained in:
Dylan K. Taylor
2023-11-17 13:58:41 +00:00
parent 0f620fad94
commit fbcf4649eb
3 changed files with 10 additions and 8 deletions

View File

@ -173,8 +173,9 @@ abstract class Projectile extends Entity{
$entityHit = null;
$hitResult = null;
$world = $this->getWorld();
foreach(VoxelRayTrace::betweenPoints($start, $end) as $vector3){
$block = $this->getWorld()->getBlockAt($vector3->x, $vector3->y, $vector3->z);
$block = $world->getBlockAt($vector3->x, $vector3->y, $vector3->z);
$blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end);
if($blockHitResult !== null){
@ -188,7 +189,7 @@ abstract class Projectile extends Entity{
$entityDistance = PHP_INT_MAX;
$newDiff = $end->subtractVector($start);
foreach($this->getWorld()->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){
foreach($world->getCollidingEntities($this->boundingBox->addCoord($newDiff->x, $newDiff->y, $newDiff->z)->expand(1, 1, 1), $this) as $entity){
if($entity->getId() === $this->getOwningEntityId() && $this->ticksLived < 5){
continue;
}
@ -256,7 +257,7 @@ abstract class Projectile extends Entity{
);
}
$this->getWorld()->onEntityMoved($this);
$world->onEntityMoved($this);
$this->checkBlockIntersections();
Timings::$projectileMove->stopTiming();