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,15 +92,13 @@ 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));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($this, $ev->getNewState(), true, true); $this->getLevel()->setBlock($this, $ev->getNewState(), true, true);
}
} }
} }
} }