Skip to content

Commit

Permalink
Try applying fix for array_rand & remove obsolete count()===0 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
inxomnyaa committed Jan 26, 2020
1 parent eb6416e commit f102ddd
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 13 deletions.
5 changes: 1 addition & 4 deletions src/xenialdan/MagicWE2/task/AsyncFillTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ private function execute(Selection $selection, AsyncChunkManager $manager, array
}
}
/** @var Block $new */
if (count($newBlocks) === 1)
$new = clone $newBlocks[0];
else
$new = clone $newBlocks[(int)array_rand($newBlocks, 1)];
$new = clone $newBlocks[array_rand($newBlocks)];
if ($new->getId() === $block->getId() && $new->getDamage() === $block->getDamage()) continue;//skip same blocks
yield $manager->getBlockAt($block->getFloorX(), $block->getFloorY(), $block->getFloorZ())->setComponents($block->x, $block->y, $block->z);
$manager->setBlockAt($block->getFloorX(), $block->getFloorY(), $block->getFloorZ(), $new);
Expand Down
5 changes: 1 addition & 4 deletions src/xenialdan/MagicWE2/task/AsyncReplaceTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ private function execute(Selection $selection, AsyncChunkManager $manager, array
}
}
/** @var Block $new */
if (count($newBlocks) === 1)
$new = clone $newBlocks[0];
else
$new = clone $newBlocks[(int)array_rand($newBlocks, 1)];
$new = clone $newBlocks[array_rand($newBlocks)];
if ($new->getId() === $block->getId() && $new->getDamage() === $block->getDamage()) continue;//skip same blocks
yield $manager->getBlockAt($block->getFloorX(), $block->getFloorY(), $block->getFloorZ())->setComponents($block->x, $block->y, $block->z);
$manager->setBlockAt($block->getFloorX(), $block->getFloorY(), $block->getFloorZ(), $new);
Expand Down
5 changes: 1 addition & 4 deletions src/xenialdan/MagicWE2/task/action/SetBlockAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public function execute(string $sessionUUID, Selection $selection, AsyncChunkMan
$lastProgress = new Progress(0, "");
foreach ($selection->getShape()->getBlocks($manager, $blockFilter) as $block) {
/** @var Block $new */
if (count($newBlocks) === 1)
$new = clone $newBlocks[0];
else
$new = clone $newBlocks[(int)array_rand($newBlocks, 1)];
$new = clone $newBlocks[array_rand($newBlocks)];
if ($new->getId() === $block->getId() && $new->getDamage() === $block->getDamage()) continue;//skip same blocks
$oldBlocks[] = $manager->getBlockAt($block->getFloorX(), $block->getFloorY(), $block->getFloorZ())->setComponents($block->x, $block->y, $block->z);
$manager->setBlockAt($block->getFloorX(), $block->getFloorY(), $block->getFloorZ(), $new);
Expand Down
2 changes: 1 addition & 1 deletion src/xenialdan/MagicWE2/tool/Flood.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function getHorizontalSides($manager, Vector3 $vector3): Generator
foreach ([Vector3::SIDE_NORTH, Vector3::SIDE_SOUTH, Vector3::SIDE_WEST, Vector3::SIDE_EAST] as $vSide) {
$side = $vector3->getSide($vSide);
if ($manager->getChunk($side->x >> 4, $side->z >> 4) === null) continue;
$block = $manager->getBlockAt($side->x, $side->y, $side->z);
$block = $manager->getBlockAt($side->getFloorX(), $side->getFloorY(), $side->getFloorZ());
$block->setComponents($side->x, $side->y, $side->z);
yield $block;
}
Expand Down

0 comments on commit f102ddd

Please sign in to comment.