From 390cc3060a9183ceac9cea07a3c7801c8b9d68eb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 29 Sep 2023 12:45:37 +0100 Subject: [PATCH] Disable random ticking for some blocks depending on their states we don't need to waste CPU time attempting to tick fully grown crops. --- src/block/CocoaBlock.php | 2 +- src/block/Crops.php | 2 +- src/block/DoublePitcherCrop.php | 2 +- src/block/Leaves.php | 2 +- src/block/NetherVines.php | 8 ++++---- src/block/NetherWartPlant.php | 2 +- src/block/RedstoneOre.php | 2 +- src/block/SweetBerryBush.php | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/block/CocoaBlock.php b/src/block/CocoaBlock.php index a76514249..25c53b23a 100644 --- a/src/block/CocoaBlock.php +++ b/src/block/CocoaBlock.php @@ -99,7 +99,7 @@ class CocoaBlock extends Transparent{ } public function ticksRandomly() : bool{ - return true; + return $this->age < self::MAX_AGE; } public function onRandomTick() : void{ diff --git a/src/block/Crops.php b/src/block/Crops.php index e47e63be8..350268863 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -62,7 +62,7 @@ abstract class Crops extends Flowable{ } public function ticksRandomly() : bool{ - return true; + return $this->age < self::MAX_AGE; } public function onRandomTick() : void{ diff --git a/src/block/DoublePitcherCrop.php b/src/block/DoublePitcherCrop.php index 06bcf5fb0..db700a625 100644 --- a/src/block/DoublePitcherCrop.php +++ b/src/block/DoublePitcherCrop.php @@ -97,7 +97,7 @@ final class DoublePitcherCrop extends DoublePlant{ } public function ticksRandomly() : bool{ - return true; + return $this->age < self::MAX_AGE && !$this->top; } public function onRandomTick() : void{ diff --git a/src/block/Leaves.php b/src/block/Leaves.php index b28a3832e..0aa3557a4 100644 --- a/src/block/Leaves.php +++ b/src/block/Leaves.php @@ -110,7 +110,7 @@ class Leaves extends Transparent{ } public function ticksRandomly() : bool{ - return true; + return !$this->noDecay && $this->checkDecay; } public function onRandomTick() : void{ diff --git a/src/block/NetherVines.php b/src/block/NetherVines.php index dba86d259..3a0369740 100644 --- a/src/block/NetherVines.php +++ b/src/block/NetherVines.php @@ -59,10 +59,6 @@ class NetherVines extends Flowable{ return true; } - public function ticksRandomly() : bool{ - return true; - } - public function canClimb() : bool{ return true; } @@ -98,6 +94,10 @@ class NetherVines extends Flowable{ return false; } + public function ticksRandomly() : bool{ + return $this->age < self::MAX_AGE; + } + public function onRandomTick() : void{ if(mt_rand(1, 10) === 1 && $this->age < self::MAX_AGE){ if($this->getSide($this->growthFace)->canBeReplaced()){ diff --git a/src/block/NetherWartPlant.php b/src/block/NetherWartPlant.php index 17aa9c4f8..34e6fd57e 100644 --- a/src/block/NetherWartPlant.php +++ b/src/block/NetherWartPlant.php @@ -42,7 +42,7 @@ class NetherWartPlant extends Flowable{ } public function ticksRandomly() : bool{ - return true; + return $this->age < self::MAX_AGE; } public function onRandomTick() : void{ diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index 75f5063ee..9e537bd27 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -70,7 +70,7 @@ class RedstoneOre extends Opaque{ } public function ticksRandomly() : bool{ - return true; + return $this->lit; } public function onRandomTick() : void{ diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index c34df3de5..a0a26ef6e 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -102,7 +102,7 @@ class SweetBerryBush extends Flowable{ } public function ticksRandomly() : bool{ - return true; + return $this->age < self::STAGE_MATURE; } public function onRandomTick() : void{