Block: make getAllSides() and getHorizontalSides() return generators

This commit is contained in:
Dylan K. Taylor 2020-06-29 20:54:51 +01:00
parent e61a08a56b
commit 43ae1a5cb4

View File

@ -43,7 +43,6 @@ use pocketmine\player\Player;
use pocketmine\world\BlockTransaction; use pocketmine\world\BlockTransaction;
use pocketmine\world\Position; use pocketmine\world\Position;
use pocketmine\world\World; use pocketmine\world\World;
use function array_merge;
use function assert; use function assert;
use function count; use function count;
use function dechex; use function dechex;
@ -489,30 +488,26 @@ class Block{
/** /**
* Returns the 4 blocks on the horizontal axes around the block (north, south, east, west) * Returns the 4 blocks on the horizontal axes around the block (north, south, east, west)
* *
* @return Block[] * @return Block[]|\Generator
* @phpstan-return \Generator<int, Block, void, void>
*/ */
public function getHorizontalSides() : array{ public function getHorizontalSides() : \Generator{
return [ yield $this->getSide(Facing::NORTH);
$this->getSide(Facing::NORTH), yield $this->getSide(Facing::SOUTH);
$this->getSide(Facing::SOUTH), yield $this->getSide(Facing::WEST);
$this->getSide(Facing::WEST), yield $this->getSide(Facing::EAST);
$this->getSide(Facing::EAST)
];
} }
/** /**
* Returns the six blocks around this block. * Returns the six blocks around this block.
* *
* @return Block[] * @return Block[]|\Generator
* @phpstan-return \Generator<int, Block, void, void>
*/ */
public function getAllSides() : array{ public function getAllSides() : \Generator{
return array_merge( yield $this->getSide(Facing::DOWN);
[ yield $this->getSide(Facing::UP);
$this->getSide(Facing::DOWN), yield from $this->getHorizontalSides();
$this->getSide(Facing::UP)
],
$this->getHorizontalSides()
);
} }
/** /**