mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Leaves: improve log search algorithm to fix vanilla inconsistencies
This commit is contained in:
parent
3b772f54e9
commit
0406c49ba9
@ -26,6 +26,7 @@ namespace pocketmine\block;
|
|||||||
use pocketmine\event\block\LeavesDecayEvent;
|
use pocketmine\event\block\LeavesDecayEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemFactory;
|
use pocketmine\item\ItemFactory;
|
||||||
|
use pocketmine\level\Level;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\Player;
|
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{
|
protected function findLog(Block $pos, array &$visited = [], int $distance = 0) : bool{
|
||||||
$index = $pos->x . "." . $pos->y . "." . $pos->z;
|
$index = Level::blockHash($pos->x, $pos->y, $pos->z);
|
||||||
if(isset($visited[$index])){
|
if(isset($visited[$index])){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$visited[$index] = true;
|
||||||
|
|
||||||
if($pos->getId() === $this->woodType){
|
if($pos->getId() === $this->woodType){
|
||||||
return true;
|
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([
|
if($pos->getId() === $this->id and $distance <= 4){
|
||||||
Facing::NORTH,
|
foreach(Facing::ALL as $side){
|
||||||
Facing::SOUTH,
|
if($this->findLog($pos->getSide($side), $visited, $distance + 1)){
|
||||||
Facing::WEST,
|
|
||||||
Facing::EAST
|
|
||||||
] as $side){
|
|
||||||
if($side !== $fromSide and $this->findLog($pos->getSide($side), $visited, $distance + 1, Facing::opposite($side))){
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user