Skip to content

Commit

Permalink
Fix //undo with //cut2
Browse files Browse the repository at this point in the history
  • Loading branch information
inxomnyaa committed Oct 5, 2022
1 parent 2f98a82 commit 8e08010
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/xenialdan/MagicWE2/task/AsyncActionTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ public function onCompletion(): void
$changed = $result["changed"];
/** @var Selection $selection */
$selection = igbinary_unserialize($this->selection/*, ['allowed_classes' => [Selection::class]]*/);//TODO test pm4
$undoChunks = $selection->getIterator()->getManager()->getChunks();
$undoChunks = [];
$totalCount = $selection->getShape()->getTotalCount();
$world = $selection->getWorld();
foreach ($resultChunks as $hash => $chunk) {
World::getXZ($hash, $x, $z);
$undoChunks[$hash] = $world->getChunk($x, $z);
$world->setChunk($x, $z, $chunk);
}
if (!is_null($session)) {
Expand Down
4 changes: 4 additions & 0 deletions src/xenialdan/MagicWE2/task/AsyncRevertTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public function __construct(UuidInterface $sessionUUID, RevertClipboard $clipboa
$this->clipboard = igbinary_serialize($clipboard);
$this->type = $type;
$this->manager = AsyncWorld::fromRevertClipboard($clipboard);
foreach($clipboard->chunks as $hash => $chunk){
World::getXZ($hash, $x, $z);
var_dump("Chunk $hash at $x, $z");
}
}

/**
Expand Down
10 changes: 6 additions & 4 deletions src/xenialdan/MagicWE2/task/action/CutAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,20 @@ public function execute(string $sessionUUID, Selection $selection, AsyncWorld &$
foreach($selection->getShape()->getBlocks($manager, $blockFilter) as $block){//TODO Merged iterator
/** @var Block $new */
$new = $newBlocks->blocks()->current();//TODO Merged iterator
if ($new->getId() === $block->getId() && $new->getMeta() === $block->getMeta()) continue;//skip same blocks
/** @noinspection PhpInternalEntityUsedInspection */
if($new->getFullId() === $block->getFullId()) continue;//skip same blocks
#$oldBlocks[] = API::setComponents($manager->getBlockAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ()),$block->x, $block->y, $block->z);
$newv3 = $block->getPosition()->subtractVector($min)->floor();//TODO check if only used for clipboard
#$newv3 = $block->getPosition()->subtractVector($min)->floor();//TODO check if only used for clipboard
$newv3 = $block->getPosition()->asVector3();
$oldBlocksSingleClipboard->addEntry($newv3->getFloorX(), $newv3->getFloorY(), $newv3->getFloorZ(), BlockEntry::fromBlock($block));
$manager->setBlockAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ(), $new);
/** @noinspection PhpInternalEntityUsedInspection */
if ($manager->getBlockFullIdAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ()) !== $block->getFullId()) {
if($manager->getBlockFullIdAt($block->getPosition()->getFloorX(), $block->getPosition()->getFloorY(), $block->getPosition()->getFloorZ()) !== $block->getFullId()){
$changed++;
}
$i++;
$progress = new Progress($i / $count, "Changed $changed blocks out of $count");
if (floor($progress->progress * 100) > floor($lastProgress->progress * 100)) {
if(floor($progress->progress * 100) > floor($lastProgress->progress * 100)){
yield $progress;
$lastProgress = $progress;
}
Expand Down

0 comments on commit 8e08010

Please sign in to comment.