mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 04:17:48 +00:00
Avoid unnecessary Entity::getWorld() calls in loops
This commit is contained in:
parent
0f620fad94
commit
fbcf4649eb
@ -173,8 +173,9 @@ abstract class Projectile extends Entity{
|
|||||||
$entityHit = null;
|
$entityHit = null;
|
||||||
$hitResult = null;
|
$hitResult = null;
|
||||||
|
|
||||||
|
$world = $this->getWorld();
|
||||||
foreach(VoxelRayTrace::betweenPoints($start, $end) as $vector3){
|
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);
|
$blockHitResult = $this->calculateInterceptWithBlock($block, $start, $end);
|
||||||
if($blockHitResult !== null){
|
if($blockHitResult !== null){
|
||||||
@ -188,7 +189,7 @@ abstract class Projectile extends Entity{
|
|||||||
$entityDistance = PHP_INT_MAX;
|
$entityDistance = PHP_INT_MAX;
|
||||||
|
|
||||||
$newDiff = $end->subtractVector($start);
|
$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){
|
if($entity->getId() === $this->getOwningEntityId() && $this->ticksLived < 5){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -256,7 +257,7 @@ abstract class Projectile extends Entity{
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getWorld()->onEntityMoved($this);
|
$world->onEntityMoved($this);
|
||||||
$this->checkBlockIntersections();
|
$this->checkBlockIntersections();
|
||||||
|
|
||||||
Timings::$projectileMove->stopTiming();
|
Timings::$projectileMove->stopTiming();
|
||||||
|
@ -31,8 +31,9 @@ class Snowball extends Throwable{
|
|||||||
public static function getNetworkTypeId() : string{ return EntityIds::SNOWBALL; }
|
public static function getNetworkTypeId() : string{ return EntityIds::SNOWBALL; }
|
||||||
|
|
||||||
protected function onHit(ProjectileHitEvent $event) : void{
|
protected function onHit(ProjectileHitEvent $event) : void{
|
||||||
|
$world = $this->getWorld();
|
||||||
for($i = 0; $i < 6; ++$i){
|
for($i = 0; $i < 6; ++$i){
|
||||||
$this->getWorld()->addParticle($this->location, new SnowballPoofParticle());
|
$world->addParticle($this->location, new SnowballPoofParticle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -813,13 +813,13 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
|
|||||||
$this->usedChunks[$index] = UsedChunkStatus::REQUESTED_GENERATION;
|
$this->usedChunks[$index] = UsedChunkStatus::REQUESTED_GENERATION;
|
||||||
$this->activeChunkGenerationRequests[$index] = true;
|
$this->activeChunkGenerationRequests[$index] = true;
|
||||||
unset($this->loadQueue[$index]);
|
unset($this->loadQueue[$index]);
|
||||||
$this->getWorld()->registerChunkLoader($this->chunkLoader, $X, $Z, true);
|
$world->registerChunkLoader($this->chunkLoader, $X, $Z, true);
|
||||||
$this->getWorld()->registerChunkListener($this, $X, $Z);
|
$world->registerChunkListener($this, $X, $Z);
|
||||||
if(isset($this->tickingChunks[$index])){
|
if(isset($this->tickingChunks[$index])){
|
||||||
$this->getWorld()->registerTickingChunk($this->chunkTicker, $X, $Z);
|
$world->registerTickingChunk($this->chunkTicker, $X, $Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->getWorld()->requestChunkPopulation($X, $Z, $this->chunkLoader)->onCompletion(
|
$world->requestChunkPopulation($X, $Z, $this->chunkLoader)->onCompletion(
|
||||||
function() use ($X, $Z, $index, $world) : void{
|
function() use ($X, $Z, $index, $world) : void{
|
||||||
if(!$this->isConnected() || !isset($this->usedChunks[$index]) || $world !== $this->getWorld()){
|
if(!$this->isConnected() || !isset($this->usedChunks[$index]) || $world !== $this->getWorld()){
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user