From 0406c49ba99dd93a619bb76e09d7a29d5a9aaad2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 13 Sep 2018 17:30:02 +0100 Subject: [PATCH] Leaves: improve log search algorithm to fix vanilla inconsistencies --- src/pocketmine/block/Leaves.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index aadc9b7ab..9257ca84c 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\event\block\LeavesDecayEvent; use pocketmine\item\Item; use pocketmine\item\ItemFactory; +use pocketmine\level\Level; use pocketmine\math\Facing; use pocketmine\math\Vector3; use pocketmine\Player; @@ -68,27 +69,20 @@ class Leaves extends Transparent{ } - protected function findLog(Block $pos, array $visited = [], int $distance = 0, ?int $fromSide = null) : bool{ - $index = $pos->x . "." . $pos->y . "." . $pos->z; + protected function findLog(Block $pos, array &$visited = [], int $distance = 0) : bool{ + $index = Level::blockHash($pos->x, $pos->y, $pos->z); if(isset($visited[$index])){ return false; } + $visited[$index] = true; + if($pos->getId() === $this->woodType){ return true; - }elseif($pos->getId() === $this->id and $distance < 3){ - $visited[$index] = true; - $down = $pos->getSide(Facing::DOWN)->getId(); - if($down === $this->woodType){ - return true; - } + } - foreach([ - Facing::NORTH, - Facing::SOUTH, - Facing::WEST, - Facing::EAST - ] as $side){ - if($side !== $fromSide and $this->findLog($pos->getSide($side), $visited, $distance + 1, Facing::opposite($side))){ + if($pos->getId() === $this->id and $distance <= 4){ + foreach(Facing::ALL as $side){ + if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ return true; } }