aternos/hawk

用于从Minecraft区域文件中获取、替换和删除区块/实体的PHP库

v1.6.3 2024-07-24 14:57 UTC

This package is auto-updated.

Last update: 2024-09-08 14:53:33 UTC


README

关于

Hawk是一个PHP库,用于从Minecraft区域文件中获取和/或替换方块,并获取和/或删除实体。这允许用户替换方块或删除在加载时会导致服务器崩溃的实体。

目前支持以下版本

1.12+ for entities
1.16+ for blocks

安装

composer require aternos/hawk

使用方法

类文件

如何从磁盘获取文件

$file = new File("your/region/file");

如何使用setContent()设置文件流,并使用getContent()从流中获取内容

$file = new File();
$file->setContent(file_get_contents("your/region/file"));
$file->setFileName("your/file/name");
"...do stuff here..."
$contentToBeWritten = $file->getContent();

类Hawk

设置

任何支持版本中区块和区块实体的设置

// New block coordinates
$blockPos = new McCoordinates3D(1, 2, 3);

// Path to your region file and calculating the filename from the coordinates
$inputPath = "/your/world/region/directory";
$blockFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock($blockPos));

// Instantiating Hawk only with blockFiles
$hawk = new Hawk(blockFiles: $blockFiles);

1.17之前的实体设置

// New entity coordinates
$entityPos = new McCoordinatesFloat(1.2, 2.3, 3.4);

// Path to your region file and calculating the filename from the coordinates
$inputPath = "/your/world/region/directory";
$entitiesFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos)));

// Instantiating Hawk only with blockFiles because entities used to be in the same file
$hawk = new Hawk(blockFiles: $entitiesFiles);

从1.17开始的实体设置

// Path to your entities directory and calculating the filename from the coordinates
$inputPath = "/your/world/entities/directory";
$entitiesFiles[] = new File($inputPath . "/" . Region::getRegionFileNameFromBlock(McCoordinatesFloat::get3DCoordinates($entityPos)));

$hawk = new Hawk(entitiesFiles: $entitiesFiles);

如何读取一个区块

$block = $hawk->getBlock($blockPos);

如何将x = 1,y = 2,z = 3处的方块替换为羊毛(默认为minecraft:stone)

$hawk->replaceBlock($blockPos, "minecraft:wool");
$hawk->save();

获取特定区块中的所有实体

$entities = $hawk->getAllEntitiesFromChunk(McCoordinatesFloat::get3DCoordinates($entityPos));

如何获取紧邻浮点坐标的所有实体(可能不止一个)

$entities = $hawk->getEntities($entityName,$entityPos);

如何删除一个实体

$entities = $hawk->getEntities($entityName,$entityPos);
$hawk->deleteEntity($entities[0]);
$hawk->save();

获取特定区块中的所有区块实体

$entities = $hawk->getAllBlockEntitiesFromChunk(McCoordinatesFloat::get3DCoordinates($entityPos));

如何获取紧邻浮点坐标的所有区块实体(可能不止一个)

$entities = $hawk->getBlockEntities($entityName,$entityPos);

如何删除一个区块实体

$entities = $hawk->getBlockEntities($entityName,$entityPos);
$hawk->deleteBlockEntity($entities[0]);
$hawk->save();

更多信息请参阅以下示例: getBlock.phpreplaceBlock.phpgetEntity.phpgetAllEntitiesInChunk.phpdeleteEntity.php

方法

类Region

Region对象表示Minecraft区域文件。Region对象的主要任务是读取/解压缩和写入/压缩区域文件中的区块。此外,它还提供静态函数来计算区域坐标和其文件名。

方法

类Chunk

Chunk对象表示Mojang的区块格式中的Minecraft区块。Chunk对象的主要任务是替换NBT结构的sections标签,压缩新的区块数据并将其提供给其区域。此外,它还提供静态函数来计算区块坐标。

方法

类Section

Section对象表示单个section标签。

方法