当前位置: 首页>>代码示例>>PHP>>正文


PHP nbt\NBT类代码示例

本文整理汇总了PHP中pocketmine\nbt\NBT的典型用法代码示例。如果您正苦于以下问题:PHP NBT类的具体用法?PHP NBT怎么用?PHP NBT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NBT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
 }
开发者ID:barnseyminesuk,项目名称:Small-ZC-Plugins,代码行数:25,代码来源:LocalNBTMacroDataProvider.php

示例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);
 }
开发者ID:TylerGames,项目名称:PocketMine-MP,代码行数:28,代码来源:RegionLoader.php

示例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;
 }
开发者ID:robske110,项目名称:ClearSky,代码行数:28,代码来源:Anvil.php

示例4: write

 public function write(NBT $nbt, bool $network = false)
 {
     foreach ($this as $tag) {
         if ($tag instanceof Tag and !$tag instanceof EndTag) {
             $nbt->writeTag($tag, $network);
         }
     }
     $nbt->writeTag(new EndTag(), $network);
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:9,代码来源:CompoundTag.php

示例5: write

 public function write(NBT $nbt)
 {
     foreach ($this as $tag) {
         if ($tag instanceof Tag and !$tag instanceof End) {
             $nbt->writeTag($tag);
         }
     }
     $nbt->writeTag(new End());
 }
开发者ID:Edwardthedog2,项目名称:Steadfast2,代码行数:9,代码来源:Compound.php

示例6: getOfflinePlayerData

 /**
  *
  * @param string $name        	
  *
  * @return CompoundTag
  */
 public function getOfflinePlayerData($name)
 {
     $name = strtolower($name);
     $path = $this->datapath . "players/";
     if (file_exists($path . "{$name}.dat")) {
         try {
             $nbt = new NBT(NBT::BIG_ENDIAN);
             $nbt->readCompressed(file_get_contents($path . "{$name}.dat"));
             return $nbt->getData();
         } catch (\Throwable $e) {
             // zlib decode error / corrupt data
             rename($path . "{$name}.dat", $path . "{$name}.dat.bak");
         }
     }
     $spawn = explode(':', $this->spawn);
     $nbt = new CompoundTag("", [new LongTag("firstPlayed", floor(microtime(true) * 1000)), new LongTag("lastPlayed", floor(microtime(true) * 1000)), new ListTag("Pos", [new DoubleTag(0, $spawn[0]), new DoubleTag(1, $spawn[1]), new DoubleTag(2, $spawn[2])]), new StringTag("Level", $spawn[3]), new ListTag("Inventory", []), new CompoundTag("Achievements", []), new IntTag("playerGameType", $this->gamemode), new ListTag("Motion", [new DoubleTag(0, 0.0), new DoubleTag(1, 0.0), new DoubleTag(2, 0.0)]), new ListTag("Rotation", [new FloatTag(0, 0.0), new FloatTag(1, 0.0)]), new FloatTag("FallDistance", 0.0), new ShortTag("Fire", 0), new ShortTag("Air", 300), new ByteTag("OnGround", 1), new ByteTag("Invulnerable", 0), new StringTag("NameTag", $name)]);
     $nbt->Pos->setTagType(NBT::TAG_Double);
     $nbt->Inventory->setTagType(NBT::TAG_Compound);
     $nbt->Motion->setTagType(NBT::TAG_Double);
     $nbt->Rotation->setTagType(NBT::TAG_Float);
     if (file_exists($path . "{$name}.yml")) {
         // Importing old PocketMine-MP files
         $data = new Config($path . "{$name}.yml", Config::YAML, []);
         $nbt["playerGameType"] = (int) $data->get("gamemode");
         $nbt["Level"] = $data->get("position")["level"];
         $nbt["Pos"][0] = $data->get("position")["x"];
         $nbt["Pos"][1] = $data->get("position")["y"];
         $nbt["Pos"][2] = $data->get("position")["z"];
         $nbt["SpawnLevel"] = $data->get("spawn")["level"];
         $nbt["SpawnX"] = (int) $data->get("spawn")["x"];
         $nbt["SpawnY"] = (int) $data->get("spawn")["y"];
         $nbt["SpawnZ"] = (int) $data->get("spawn")["z"];
         foreach ($data->get("inventory") as $slot => $item) {
             if (count($item) === 3) {
                 $nbt->Inventory[$slot + 9] = new CompoundTag("", [new ShortTag("id", $item[0]), new ShortTag("Damage", $item[1]), new ByteTag("Count", $item[2]), new ByteTag("Slot", $slot + 9), new ByteTag("TrueSlot", $slot + 9)]);
             }
         }
         foreach ($data->get("hotbar") as $slot => $itemSlot) {
             if (isset($nbt->Inventory[$itemSlot + 9])) {
                 $item = $nbt->Inventory[$itemSlot + 9];
                 $nbt->Inventory[$slot] = new CompoundTag("", [new ShortTag("id", $item["id"]), new ShortTag("Damage", $item["Damage"]), new ByteTag("Count", $item["Count"]), new ByteTag("Slot", $slot), new ByteTag("TrueSlot", $item["TrueSlot"])]);
             }
         }
         foreach ($data->get("armor") as $slot => $item) {
             if (count($item) === 2) {
                 $nbt->Inventory[$slot + 100] = new CompoundTag("", [new ShortTag("id", $item[0]), new ShortTag("Damage", $item[1]), new ByteTag("Count", 1), new ByteTag("Slot", $slot + 100)]);
             }
         }
         foreach ($data->get("achievements") as $achievement => $status) {
             $nbt->Achievements[$achievement] = new ByteTag($achievement, $status == true ? 1 : 0);
         }
         unlink($path . "{$name}.yml");
     }
     return $nbt;
 }
开发者ID:organization,项目名称:SpawningPool,代码行数:61,代码来源:GetOfflinePlayerDataTask.php

示例7: 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;
 }
开发者ID:Edwardthedog2,项目名称:Steadfast2,代码行数:15,代码来源:Spawnable.php

示例8: 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;
 }
开发者ID:TylerAndrew,项目名称:Steadfast2,代码行数:15,代码来源:Spawnable.php

示例9: __construct

 public function __construct(Human $player, $contents = null)
 {
     $this->hotbar = range(0, $this->getHotbarSize() - 1, 1);
     parent::__construct($player, InventoryType::get(InventoryType::PLAYER));
     if ($contents !== null) {
         if ($contents instanceof ListTag) {
             //Saved data to be loaded into the inventory
             foreach ($contents as $item) {
                 if ($item["Slot"] >= 0 and $item["Slot"] < $this->getHotbarSize()) {
                     //Hotbar
                     if (isset($item["TrueSlot"])) {
                         //Valid slot was found, change the linkage to this slot
                         if (0 <= $item["TrueSlot"] and $item["TrueSlot"] < $this->getSize()) {
                             $this->hotbar[$item["Slot"]] = $item["TrueSlot"];
                         } elseif ($item["TrueSlot"] < 0) {
                             //Link to an empty slot (empty hand)
                             $this->hotbar[$item["Slot"]] = -1;
                         }
                     }
                     /* If TrueSlot is not set, leave the slot index as its default which was filled in above
                      * This only overwrites slot indexes for valid links */
                 } elseif ($item["Slot"] >= 100 and $item["Slot"] < 104) {
                     //Armor
                     $this->setItem($this->getSize() + $item["Slot"] - 100, NBT::getItemHelper($item), false);
                 } else {
                     $this->setItem($item["Slot"] - $this->getHotbarSize(), NBT::getItemHelper($item), false);
                 }
             }
         } else {
             throw new \InvalidArgumentException("Expecting ListTag, received " . gettype($contents));
         }
     }
 }
开发者ID:robske110,项目名称:ClearSky,代码行数:33,代码来源:PlayerInventory.php

示例10: __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;
 }
开发者ID:iTXTech,项目名称:Genisys,代码行数:16,代码来源:ChunkRequestTask.php

示例11: setItem

 public function setItem(Item $item, bool $setChanged = true)
 {
     $nbtItem = NBT::putItemHelper($item);
     $nbtItem->setName("Item");
     $this->namedtag->Item = $nbtItem;
     if ($setChanged) {
         $this->setChanged();
     }
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:9,代码来源:ItemFrame.php

示例12: writeToNBT

 /**
  * Return the defined game rules as NBT.
  */
 public function writeToNBT()
 {
     $compoundarray = [];
     foreach ($this->theGameRules as $key => $value) {
         $compoundarray[] = NBT::fromArrayGuesser($key, $value);
     }
     $nbttagcompound = new CompoundTag("GameRules", $compoundarray);
     return $nbttagcompound;
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:12,代码来源:GameRules.php

示例13: setItem

 public function setItem(Item $item)
 {
     $tag = NBT::putItemHelper($item);
     $tag->setName("Item");
     $this->namedtag->Item = $tag;
     $this->spawnToAll();
     if ($this->chunk) {
         $this->chunk->setChanged();
         $this->level->clearChunkCache($this->chunk->getX(), $this->chunk->getZ());
     }
 }
开发者ID:beito123,项目名称:PocketMine-MP-Plugins,代码行数:11,代码来源:ItemFrame.php

示例14: __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;
 }
开发者ID:rryy,项目名称:PocketMine-MP,代码行数:23,代码来源:ChunkRequestTask.php

示例15: 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
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:37,代码来源:TileUpdTask.php


注:本文中的pocketmine\nbt\NBT类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。