public function getPowerSources(RedstoneWire $wire, array $powers = [], array $hasUpdated = [], $isStart = false)
{
if (!$isStart) {
$wire->meta = 0;
$wire->getLevel()->setBlock($wire, $wire, true, false);
$wire->deactivate();
}
$hasChecked = [Vector3::SIDE_WEST => false, Vector3::SIDE_EAST => false, Vector3::SIDE_NORTH => false, Vector3::SIDE_SOUTH => false];
$hash = Level::blockHash($wire->x, $wire->y, $wire->z);
if (!isset($hasUpdated[$hash])) {
$hasUpdated[$hash] = true;
} else {
return [$powers, $hasUpdated];
}
//check blocks around
foreach ($hasChecked as $side => $bool) {
/** @var RedstoneWire $block */
$block = $wire->getSide($side);
if ($block instanceof RedstoneSource) {
if ($block->isActivated($wire)) {
if ($block->getId() != $this->id) {
$powers[] = $block;
} else {
$result = $this->getPowerSources($block, $powers, $hasUpdated);
$powers = $result[0];
$hasUpdated = $result[1];
}
$hasChecked[$side] = true;
}
}
}
//check blocks above
$baseBlock = $wire->add(0, 1, 0);
foreach ($hasChecked as $side => $bool) {
if (!$bool) {
$block = $this->getLevel()->getBlock($baseBlock->getSide($side));
if ($block instanceof RedstoneSource) {
if ($block->isActivated($wire)) {
if ($block->getId() == $this->id) {
$result = $this->getPowerSources($block, $powers, $hasUpdated);
$powers = $result[0];
$hasUpdated = $result[1];
$hasChecked[$side] = true;
}
}
}
}
}
//check blocks below
$baseBlock = $wire->add(0, -1, 0);
foreach ($hasChecked as $side => $bool) {
if (!$bool) {
$block = $this->getLevel()->getBlock($baseBlock->getSide($side));
if ($block instanceof RedstoneSource) {
if ($block->isActivated($wire)) {
if ($block->getId() == $this->id) {
$result = $this->getPowerSources($block, $powers, $hasUpdated);
$powers = $result[0];
$hasUpdated = $result[1];
$hasChecked[$side] = true;
}
}
}
}
}
return [$powers, $hasUpdated];
}