-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5c43d6
commit 6b2a928
Showing
8 changed files
with
250 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Aternos\Thanos\Task; | ||
|
||
use Aternos\Taskmaster\Task\OnChild; | ||
use Aternos\Taskmaster\Task\Task; | ||
use Aternos\Thanos\Region\AnvilRegion; | ||
use Exception; | ||
|
||
class RegionTask extends Task | ||
{ | ||
public function __construct( | ||
#[OnChild] protected string $inputFile, | ||
#[OnChild] protected string $outputFile, | ||
#[OnChild] protected int $inhabitedTimeThreshold, | ||
#[OnChild] protected bool $removeUnknownChunks, | ||
|
||
/** | ||
* @var int[][] | ||
*/ | ||
#[OnChild] protected array $forceLoadedChunks, | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* @throws Exception | ||
*/ | ||
#[OnChild] public function run() | ||
{ | ||
$removedChunks = 0; | ||
$region = new AnvilRegion($this->inputFile, $this->outputFile); | ||
foreach ($region->getChunks() as $chunk) { | ||
if (in_array([$chunk->getGlobalXPos(), $chunk->getGlobalYPos()], $this->forceLoadedChunks, true)) { | ||
$chunk->save(); | ||
continue; | ||
} | ||
$time = $chunk->getInhabitedTime(); | ||
if ($time > $this->inhabitedTimeThreshold || ($time === -1 && !$this->removeUnknownChunks)) { | ||
$chunk->save(); | ||
} else { | ||
$removedChunks++; | ||
} | ||
} | ||
$region->save(); | ||
return $removedChunks; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Aternos\Thanos\Task; | ||
|
||
use Aternos\Taskmaster\Task\TaskFactory; | ||
use Aternos\Taskmaster\Task\TaskInterface; | ||
use Aternos\Thanos\World\AnvilWorld; | ||
use Generator; | ||
|
||
class RegionTaskFactory extends TaskFactory | ||
{ | ||
protected Generator $taskGenerator; | ||
|
||
public function __construct( | ||
protected AnvilWorld $world, | ||
protected int $inhabitedTimeThreshold, | ||
protected bool $removeUnknownChunks | ||
) | ||
{ | ||
$this->taskGenerator = $this->generateTasks(); | ||
} | ||
|
||
/** | ||
* @return Generator<RegionTask> | ||
*/ | ||
protected function generateTasks(): Generator | ||
{ | ||
foreach ($this->world->getRegionDirectories() as $regionDirectory) { | ||
$forcedChunks = $regionDirectory->getForceLoadedChunks(); | ||
|
||
foreach ($regionDirectory->getRegionFiles() as $file) { | ||
yield new RegionTask( | ||
$regionDirectory->getPath() . DIRECTORY_SEPARATOR . $file, | ||
$regionDirectory->getDestination() . DIRECTORY_SEPARATOR . $file, | ||
$this->inhabitedTimeThreshold, | ||
$this->removeUnknownChunks, | ||
$forcedChunks | ||
); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function createNextTask(?string $group): ?TaskInterface | ||
{ | ||
if (!$this->taskGenerator->valid()) { | ||
return null; | ||
} | ||
$task = $this->taskGenerator->current(); | ||
$this->taskGenerator->next(); | ||
return $task; | ||
} | ||
} |
Oops, something went wrong.