aternos / thanos
一个简单的库,用于检测并从Minecraft世界中移除未使用的块。
Requires
- php: >=8.1
- ext-zlib: *
- aternos/nbt: ^v1.9.0
- aternos/taskmaster: ^1.1.3
Suggests
- ext-lz4: Support for LZ4 compressed chunks (Minecraft 1.20.5+)
README
关于
Thanos是一个PHP库,用于自动检测并从Minecraft世界中移除未使用的块。这可以将世界的文件大小减少超过50%。
除了现有工具外,此库不使用区块列表。相反,使用居住时间值来确定区块是否被使用。这可以防止意外删除已使用的区块,并使此库与大多数模组和插件兼容。
目前,仅支持Minecraft Anvil世界格式(Minecraft Java版)。
安装
composer require aternos/thanos
为了处理LZ4压缩的块(Minecraft 1.20.5+),您还应该安装PHP LZ4扩展。
使用
CLI工具
此库包含一个简单的CLI工具。
./thanos.php /path/to/world/directory [/path/to/output/directory]
Thanos使用Taskmaster进行异步任务,可以使用环境变量进行配置。
Windows支持
虽然Thanos通常可以在Windows上运行,但由于不支持异步任务,它将非常慢。因此,建议使用Windows子系统Linux在Windows上运行Thanos。
已知问题
如果包含该功能一半的区块被移除而另一半未被移除,则有时会看到世界功能(如树木)被截断。有关详细信息,请参阅此问题:#20
世界
世界对象代表一个具有所有文件的Minecraft世界。它允许遍历所有区块并提供一个将所有非区域文件复制到输出目录的功能。
$world = new Aternos\Thanos\World\AnvilWorld("/path/to/world/directory", "/path/to/output/directory"); $world->copyOtherFiles(); //copy non-region files foreach ($world as $chunk){ echo $chunk->getInhabitedTime() . "\n"; //output inhabited time for each chunk }
遍历完区域文件的所有区块后,它将自动保存到输出目录。
方法
getPath() : string
获取世界目录路径
getDestination() : string
获取世界输出目录
getOtherFiles() : string[]
获取所有非区域目录的文件
copyOtherFiles() : void
将所有非区域目录的文件复制到输出目录
static isWorld(string $path) : bool
检查$path
是否为世界目录
区块
区块对象代表一个Minecraft世界区块。由于性能原因,区块数据不会被完全解析,而只是用于查找帮助确定区块是否被使用的元数据。
if($chunk->getInhabitedTime() > 0){ $chunk->save(); }
如果区块未被标记为已保存,则不会写入输出目录。
方法
getOffset() : int
获取区块数据在区域文件中的偏移量
getLength() : int
获取原始区块数据的长度
getData() : string
获取原始区块数据
getInhabitedTime() : int
从区块数据中获取居住时间值。如果无法读取居住时间,则返回-1。
getLastUpdate() : int
从区块数据中获取最后更新值。如果无法读取最后更新,则返回-1。
setTimestamp(int $timestamp) : void
设置最后修改时间
getTimestamp() : int
获取最后修改时间
save() : void
将区块标记为已保存
isSaved() : bool
检查这个区块是否被标记为已保存
Thanos
Thanos 会自动在世界上找到未使用的区块,并将它们还原为原子。
$thanos = new Aternos\Thanos\Thanos(); $thanos->setMaxInhabitedTime(0); $world = new Aternos\Thanos\World\AnvilWorld("/path/to/world/directory", "/path/to/output/directory"); $removedChunks = $thanos->snap($world); echo "Removed $removedChunks chunks\n";
方法
setMinInhabitedTime(int $minInhabitedTime) : void
设置区块的最小居住时间,防止其被删除
getMinInhabitedTime() : int
获取最小居住时间
snap(WorldInterface $world) : int
删除未使用的区块,返回删除的区块数量