本文整理汇总了PHP中pocketmine\nbt\NBT::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP NBT::setData方法的具体用法?PHP NBT::setData怎么用?PHP NBT::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\nbt\NBT
的用法示例。
在下文中一共展示了NBT::setData方法的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: generateChunk
public function generateChunk($x, $z)
{
$nbt = new Compound("Level", []);
$nbt->xPos = new Int("xPos", $this->getX() * 32 + $x);
$nbt->zPos = new Int("zPos", $this->getZ() * 32 + $z);
$nbt->LastUpdate = new Long("LastUpdate", 0);
$nbt->LightPopulated = new Byte("LightPopulated", 0);
$nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
$nbt->V = new Byte("V", self::VERSION);
$nbt->InhabitedTime = new Long("InhabitedTime", 0);
$biomes = str_repeat(Binary::writeByte(-1), 256);
$nbt->Biomes = new ByteArray("Biomes", $biomes);
$nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("…²J")));
$nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 127));
$nbt->Sections = new Enum("Sections", []);
$nbt->Sections->setTagType(NBT::TAG_Compound);
$nbt->Entities = new Enum("Entities", []);
$nbt->Entities->setTagType(NBT::TAG_Compound);
$nbt->TileEntities = new Enum("TileEntities", []);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$nbt->TileTicks = new Enum("TileTicks", []);
$nbt->TileTicks->setTagType(NBT::TAG_Compound);
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
$chunkData = $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
$this->saveChunk($x, $z, $chunkData);
}
示例3: 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);
}
示例4: 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;
}
示例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->setChannel(Network::CHANNEL_WORLD_EVENTS));
return \true;
}
示例6: 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;
}
示例7: __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;
}
示例8: __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;
}
示例9: 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
}
示例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: updateTile
private function updateTile($tile)
{
$sign = $tile->getText();
$sn = $this->texts[$sign[0]];
$upd = [$sign[0], $sign[1], $sign[2], $sign[3]];
switch ($sn) {
case "stats":
$lv = $tile->getLevel();
foreach ($lv->getPlayers() as $pl) {
$score = $this->dbm->getScore($pl->getName());
if ($score == null) {
continue;
}
$money = $this->getMoney($pl->getName());
$data = $tile->getSpawnCompound();
$data->Text1 = new String("Text1", $sign[0]);
$data->Text2 = new String("Text2", "Level: " . $score["level"]);
$data->Text3 = new String("Text3", "Kills: " . $score["kills"]);
$data->Text4 = new String("Text4", "Points: " . $money);
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$nbt->setData($data);
$pk = new EntityDataPacket();
$pk->x = $tile->getX();
$pk->y = $tile->getY();
$pk->z = $tile->getZ();
$pk->namedtag = $nbt->write();
$pl->dataPacket($pk);
}
break;
case "rankings":
case "onlineranks":
$res = $this->getRankings(3, $sn == "onlineranks");
if ($res == null) {
$upd[1] = "Not Available";
$upd[2] = "insufficient";
$upd[3] = "players on-line";
break;
}
$upd[1] = "";
$upd[2] = "";
$upd[3] = "";
$i = 1;
foreach ($res as $r) {
$upd[$i] = implode(" ", [$r["player"], $r["kills"]]);
++$i;
}
break;
default:
return;
}
if ($upd[0] == $sign[0] && $upd[2] == $sign[2] && $upd[1] == $sign[1] && $upd[3] == $sign[3]) {
return;
}
$tile->setText($upd[0], $upd[1], $upd[2], $upd[3]);
}
示例12: saveLevelData
public function saveLevelData()
{
$nbt = new NBT(NBT::BIG_ENDIAN);
$nbt->setData(new Compound("", ["Data" => $this->levelData]));
$buffer = $nbt->writeCompressed();
file_put_contents($this->getPath() . "level.dat", $buffer);
}
示例13: 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);
}
示例14: generateChunk
public function generateChunk($x, $z)
{
$nbt = new Compound("Level", []);
$nbt->xPos = new Int("xPos", $this->getX() * 32 + $x);
$nbt->zPos = new Int("zPos", $this->getZ() * 32 + $z);
$nbt->LastUpdate = new Long("LastUpdate", 0);
$nbt->LightPopulated = new Byte("LightPopulated", 0);
$nbt->TerrainPopulated = new Byte("TerrainPopulated", 0);
$nbt->V = new Byte("V", self::VERSION);
$nbt->InhabitedTime = new Long("InhabitedTime", 0);
$nbt->Biomes = new ByteArray("Biomes", \str_repeat(\chr(-1), 256));
$nbt->HeightMap = new IntArray("HeightMap", \array_fill(0, 256, 127));
$nbt->BiomeColors = new IntArray("BiomeColors", \array_fill(0, 256, \PHP_INT_SIZE === 8 ? \unpack("N", "…²J")[1] << 32 >> 32 : \unpack("N", "…²J")[1]));
$nbt->Blocks = new ByteArray("Blocks", \str_repeat("", 32768));
$nbt->Data = new ByteArray("Data", $half = \str_repeat("", 16384));
$nbt->SkyLight = new ByteArray("SkyLight", $half);
$nbt->BlockLight = new ByteArray("BlockLight", $half);
$nbt->Entities = new Enum("Entities", []);
$nbt->Entities->setTagType(NBT::TAG_Compound);
$nbt->TileEntities = new Enum("TileEntities", []);
$nbt->TileEntities->setTagType(NBT::TAG_Compound);
$nbt->TileTicks = new Enum("TileTicks", []);
$nbt->TileTicks->setTagType(NBT::TAG_Compound);
$writer = new NBT(NBT::BIG_ENDIAN);
$nbt->setName("Level");
$writer->setData(new Compound("", ["Level" => $nbt]));
$chunkData = $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, self::$COMPRESSION_LEVEL);
if ($chunkData !== \false) {
$this->saveChunk($x, $z, $chunkData);
}
}
示例15: onQuit
/**
* Called when the user logs out
*
* @param PlayerQuitEvent $event
*/
public function onQuit(PlayerQuitEvent $event)
{
if (isset($this->standbyAuth[strtolower($event->getPlayer()->getName())])) {
unset($this->standbyAuth[strtolower($event->getPlayer()->getName())]);
return;
}
if (isset($this->needAuth[strtolower($event->getPlayer()->getName())])) {
unset($this->needAuth[strtolower($event->getPlayer()->getName())]);
return;
}
if ($this->plugin->getConfig()->get("servermode", null) != "slave") {
return;
}
$nbt = new NBT(NBT::BIG_ENDIAN);
try {
$nbt->setData($event->getPlayer()->namedtag);
$nbtFile = mb_convert_encoding($nbt->writeCompressed(), "UTF-8", "ISO-8859-1");
// itemSyncro
// slave->master = [passcode, itemSyncro, username, itemData]
$data = [$this->plugin->getConfig()->get("passcode"), "itemSyncro", $event->getPlayer()->getName(), $nbtFile];
CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data)));
} catch (\Exception $e) {
$this->plugin->getLogger()->critical($this->plugin->getServer()->getLanguage()->translateString("pocketmine.data.saveError", [$event->getPlayer()->getName(), $e->getMessage()]));
if (\pocketmine\DEBUG > 1 and $this->plugin->getServer()->getLogger() instanceof MainLogger) {
$this->plugin->getServer()->getLogger()->logException($e);
}
}
// logoutRequest
// slave->master = [passcode, logoutRequest, username, IP, isUserGenerate]
$data = [$this->plugin->getConfig()->get("passcode"), "logoutRequest", $event->getPlayer()->getName(), $event->getPlayer()->getAddress(), false];
CPAPI::sendPacket(new DataPacket($this->plugin->getConfig()->get("masterip"), $this->plugin->getConfig()->get("masterport"), json_encode($data)));
}