本文整理汇总了PHP中pocketmine\nbt\NBT::write方法的典型用法代码示例。如果您正苦于以下问题:PHP NBT::write方法的具体用法?PHP NBT::write怎么用?PHP NBT::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\nbt\NBT
的用法示例。
在下文中一共展示了NBT::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeCompoundTag
private static function writeCompoundTag(CompoundTag $tag) : string
{
if (self::$cachedParser === null) {
self::$cachedParser = new NBT(NBT::LITTLE_ENDIAN);
}
self::$cachedParser->setData($tag);
return self::$cachedParser->write();
}
示例2: saveMacro
public function saveMacro($name, Macro $macro)
{
$tag = new tag\Compound();
$tag["author"] = new tag\String("author", $macro->getAuthor());
$tag["description"] = new tag\String("description", $macro->getDescription());
$tag["ops"] = new tag\Enum("ops");
foreach ($macro->getOperations() as $i => $log) {
$tag["ops"][$i] = $log->toTag();
}
$nbt = new NBT();
$nbt->setData($tag);
$file = $this->getFile($name);
$stream = fopen($file, "wb");
if (!is_resource($stream)) {
throw new \RuntimeException("Unable to open stream. Maybe the macro name is not a valid filename?");
}
$compression = $this->getMain()->getConfig()->getAll()["data providers"]["macro"]["mcr"]["compression"];
if ($compression === 0) {
$data = $nbt->write();
} else {
$data = $nbt->writeCompressed($compression);
}
fwrite($stream, chr($compression) . $data);
fclose($stream);
}
示例3: requestChunkTask
public function requestChunkTask($x, $z)
{
$chunk = $this->getChunk($x, $z, false);
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk sent");
}
$tiles = "";
if (count($chunk->getTiles()) > 0) {
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$list = [];
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$list[] = $tile->getSpawnCompound();
}
}
$nbt->setData($list);
$tiles = $nbt->write(true);
}
$extraData = new BinaryStream();
$extraData->putLInt(count($chunk->getBlockExtraDataArray()));
foreach ($chunk->getBlockExtraDataArray() as $key => $value) {
$extraData->putLInt($key);
$extraData->putLShort($value);
}
$ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . pack("C*", ...$chunk->getHeightMapArray()) . pack("N*", ...$chunk->getBiomeColorArray()) . $extraData->getBuffer() . $tiles;
$this->getLevel()->chunkRequestCallback($x, $z, $ordered, FullChunkDataPacket::ORDER_LAYERED);
return null;
}
示例4: spawnTo
public function spawnTo(Player $player)
{
if ($this->closed) {
return \false;
}
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($this->getSpawnCompound());
$pk = new TileEntityDataPacket();
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->namedtag = $nbt->write();
$player->dataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
return \true;
}
示例5: spawnTo
public function spawnTo(Player $player)
{
if ($this->closed) {
return false;
}
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($this->getSpawnCompound());
$pk = new TileEntityDataPacket();
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->namedtag = $nbt->write();
$player->dataPacket($pk);
return true;
}
示例6: __construct
public function __construct(Level $level, Chunk $chunk)
{
$this->levelId = $level->getId();
$this->chunk = $chunk->toFastBinary();
$this->chunkX = $chunk->getX();
$this->chunkZ = $chunk->getZ();
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write();
}
}
$this->tiles = $tiles;
}
示例7: __construct
public function __construct(Anvil $level, $levelId, $chunkX, $chunkZ)
{
$this->levelId = $levelId;
$this->chunkX = $chunkX;
$this->chunkZ = $chunkZ;
$chunk = $level->getChunk($chunkX, $chunkZ, false);
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk sent");
}
$this->biomeIds = $chunk->getBiomeIdArray();
$this->biomeColors = $chunk->getBiomeColorArray();
$this->sections = $chunk->getSections();
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write();
}
}
$this->tiles = $tiles;
$this->compressionLevel = Level::$COMPRESSION_LEVEL;
}
示例8: onRun
public function onRun($currentTicks)
{
$this->getOwner()->updateVars();
foreach ($this->getOwner()->getServer()->getLevels() as $lv) {
if (count($lv->getPlayers()) == 0) {
continue;
}
foreach ($lv->getTiles() as $tile) {
if (!$tile instanceof Sign) {
continue;
}
$sign = $tile->getText();
$text = $this->getOwner()->getLiveSign($sign);
if ($text == null) {
continue;
}
$pk = new TileEntityDataPacket();
$data = $tile->getSpawnCompound();
$data->Text1 = new String("Text1", $text[0]);
$data->Text2 = new String("Text2", $text[1]);
$data->Text3 = new String("Text3", $text[2]);
$data->Text4 = new String("Text4", $text[3]);
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($data);
$pk->x = $tile->getX();
$pk->y = $tile->getY();
$pk->z = $tile->getZ();
$pk->namedtag = $nbt->write();
foreach ($lv->getPlayers() as $pl) {
$pl->dataPacket($pk);
}
//foreach Players
}
//foreach Tiles
}
// foreach Levels
}
示例9: requestChunkTask
public function requestChunkTask($x, $z)
{
$chunk = $this->getChunk($x, $z, \false);
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk sent");
}
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write();
}
}
$biomeColors = \pack("N*", ...$chunk->getBiomeColorArray());
$ordered = \zlib_encode(\pack("V", $x) . \pack("V", $z) . $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . $chunk->getBiomeIdArray() . $biomeColors . $tiles, ZLIB_ENCODING_DEFLATE, Level::$COMPRESSION_LEVEL);
$this->getLevel()->chunkRequestCallback($x, $z, $ordered);
return \null;
}
示例10: toBinary
public function toBinary($saveExtra = false)
{
$chunkIndex = LevelDB::chunkIndex($this->getX(), $this->getZ());
$provider = $this->getProvider();
if ($saveExtra and $provider instanceof LevelDB) {
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$entities = [];
foreach ($this->getEntities() as $entity) {
if (!$entity instanceof Player and !$entity->closed) {
$entity->saveNBT();
$nbt->setData($entity->namedtag);
$entities[] = $nbt->write();
}
}
if (count($entities) > 0) {
$provider->getDatabase()->put($chunkIndex . "2", implode($entities));
} else {
$provider->getDatabase()->delete($chunkIndex . "2");
}
$tiles = [];
foreach ($this->getTiles() as $tile) {
if (!$tile->closed) {
$tile->saveNBT();
$nbt->setData($tile->namedtag);
$tiles[] = $nbt->write();
}
}
if (count($tiles) > 0) {
$provider->getDatabase()->put($chunkIndex . "1", implode($tiles));
} else {
$provider->getDatabase()->delete($chunkIndex . "1");
}
}
$biomeColors = pack("N*", ...$this->getBiomeColorArray());
return $chunkIndex . $this->getBlockIdArray() . $this->getBlockDataArray() . $this->getBlockSkyLightArray() . $this->getBlockLightArray() . $this->getBiomeIdArray() . $biomeColors . chr(($this->isPopulated() ? 0x2 : 0) | ($this->isGenerated() ? 0x1 : 0));
}
示例11: updateSign
private function updateSign($pl, $tile, $text)
{
$pk = new TileEntityDataPacket();
$data = $tile->getSpawnCompound();
$data->Text1 = new String("Text1", $text[0]);
$data->Text2 = new String("Text2", $text[1]);
$data->Text3 = new String("Text3", $text[2]);
$data->Text4 = new String("Text4", $text[3]);
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($data);
$pk->x = $tile->getX();
$pk->y = $tile->getY();
$pk->z = $tile->getZ();
$pk->namedtag = $nbt->write();
$pl->dataPacket($pk);
}
示例12: toBinary
public function toBinary($saveExtra = \false)
{
$chunkIndex = LevelDB::chunkIndex($this->getX(), $this->getZ());
$provider = $this->getProvider();
if ($saveExtra and $provider instanceof LevelDB) {
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$entities = [];
foreach ($this->getEntities() as $entity) {
if (!$entity instanceof Player and !$entity->closed) {
$entity->saveNBT();
$entities[] = $entity->namedtag;
}
}
if (\count($entities) > 0) {
$nbt->setData($entities);
$provider->getDatabase()->put($chunkIndex . LevelDB::ENTRY_ENTITIES, $nbt->write());
} else {
$provider->getDatabase()->delete($chunkIndex . LevelDB::ENTRY_ENTITIES);
}
$tiles = [];
foreach ($this->getTiles() as $tile) {
if (!$tile->closed) {
$tile->saveNBT();
$tiles[] = $tile->namedtag;
}
}
if (\count($tiles) > 0) {
$nbt->setData($tiles);
$provider->getDatabase()->put($chunkIndex . LevelDB::ENTRY_TILES, $nbt->write());
} else {
$provider->getDatabase()->delete($chunkIndex . LevelDB::ENTRY_TILES);
}
if (\count($this->getBlockExtraDataArray()) > 0) {
$extraData = new BinaryStream();
$extraData->putInt(\count($this->getBlockExtraDataArray()));
foreach ($this->getBlockExtraDataArray() as $key => $value) {
$extraData->putInt($key);
$extraData->putShort($value);
}
$provider->getDatabase()->put($chunkIndex . LevelDB::ENTRY_EXTRA_DATA, $extraData->getBuffer());
} else {
$provider->getDatabase()->delete($chunkIndex . LevelDB::ENTRY_EXTRA_DATA);
}
}
$heightmap = \pack("C*", ...$this->getHeightMapArray());
$biomeColors = \pack("N*", ...$this->getBiomeColorArray());
return $chunkIndex . $this->getBlockIdArray() . $this->getBlockDataArray() . $this->getBlockSkyLightArray() . $this->getBlockLightArray() . $heightmap . $biomeColors . \chr(($this->isLightPopulated() ? 0x4 : 0) | ($this->isPopulated() ? 0x2 : 0) | ($this->isGenerated() ? 0x1 : 0));
}
示例13: requestChunkTask
public function requestChunkTask($x, $z)
{
$chunk = $this->getChunk($x, $z, \false);
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk sent");
}
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write();
}
}
$heightmap = \pack("C*", ...$chunk->getHeightMapArray());
$biomeColors = \pack("N*", ...$chunk->getBiomeColorArray());
$extraData = new BinaryStream();
$extraData->putLInt(\count($chunk->getBlockExtraDataArray()));
foreach ($chunk->getBlockExtraDataArray() as $key => $value) {
$extraData->putLInt($key);
$extraData->putLShort($value);
}
$ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . $heightmap . $biomeColors . $extraData->getBuffer() . $tiles;
$this->getLevel()->chunkRequestCallback($x, $z, $ordered);
return \null;
}
示例14: requestChunkTask
public function requestChunkTask($x, $z)
{
$chunk = $this->getChunk($x, $z, false);
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk sent");
}
$tiles = "";
$nbt = new NBT(NBT::LITTLE_ENDIAN);
foreach ($chunk->getTiles() as $tile) {
if ($tile instanceof Spawnable) {
$nbt->setData($tile->getSpawnCompound());
$tiles .= $nbt->write();
}
}
$biomeColors = pack("N*", ...$chunk->getBiomeColorArray());
$ordered = $chunk->getBlockIdArray() . $chunk->getBlockDataArray() . $chunk->getBlockSkyLightArray() . $chunk->getBlockLightArray() . $chunk->getBiomeIdArray() . $biomeColors . $tiles;
$this->getLevel()->chunkRequestCallback($x, $z, $ordered);
return null;
}
示例15: upgrade_From1_To2
private function upgrade_From1_To2()
{
MainLogger::getLogger()->notice("Old PMF Level format version #1 detected, upgrading to version #2");
$nbt = new Compound("", [new Enum("Entities", []), new Enum("TileEntities", [])]);
$nbt->Entities->setTagType(NBT::TAG_Compound);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$nbtCodec = new NBT(NBT::BIG_ENDIAN);
$nbtCodec->setData($nbt);
$namedtag = $nbtCodec->write();
$namedtag = Binary::writeInt(strlen($namedtag)) . $namedtag;
foreach (glob(dirname($this->file) . "/chunks/*/*.*.pmc") as $chunkFile) {
$oldChunk = zlib_decode(file_get_contents($chunkFile));
$newChunk = substr($oldChunk, 0, 5);
$newChunk .= $namedtag;
$newChunk .= str_repeat("", 256);
//Biome indexes (all Plains)
$newChunk .= substr($oldChunk, 5);
file_put_contents($chunkFile, zlib_encode($newChunk, self::ZLIB_ENCODING, self::ZLIB_LEVEL));
}
$this->levelData["version"] = 2;
}