mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
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:
parent
a195e940db
commit
9651b3f470
@ -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);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user