Crops: micro optimization - check age before generating random number (faster)

I don't have any idea how much benefit this will provide in real terms, but it may be significant.
This commit is contained in:
Dylan K. Taylor 2018-09-24 16:48:19 +01:00
parent a195e940db
commit 9651b3f470

View File

@ -92,8 +92,7 @@ abstract class Crops extends Flowable{
} }
public function onRandomTick() : void{ public function onRandomTick() : void{
if(mt_rand(0, 2) === 1){ if($this->age < 7 and mt_rand(0, 2) === 1){
if($this->age < 7){
$block = clone $this; $block = clone $this;
++$block->age; ++$block->age;
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block)); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($this, $block));
@ -103,7 +102,6 @@ abstract class Crops extends Flowable{
} }
} }
} }
}
public function isAffectedBySilkTouch() : bool{ public function isAffectedBySilkTouch() : bool{
return false; return false;