本文整理汇总了PHP中pocketmine\utils\Binary类的典型用法代码示例。如果您正苦于以下问题:PHP Binary类的具体用法?PHP Binary怎么用?PHP Binary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Binary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: __construct
/**
* @param LevelProvider $provider
* @param int $x
* @param int $z
* @param string $blocks
* @param string $data
* @param string $skyLight
* @param string $blockLight
* @param string $biomeIds
* @param int[] $biomeColors
* @param int[] $heightMap
* @param Compound[] $entities
* @param Compound[] $tiles
*/
protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, $biomeIds = null, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = [])
{
$this->provider = $provider;
$this->x = (int) $x;
$this->z = (int) $z;
$this->blocks = $blocks;
$this->data = $data;
$this->skyLight = $skyLight;
$this->blockLight = $blockLight;
if (strlen($biomeIds) === 256) {
$this->biomeIds = $biomeIds;
} else {
$this->biomeIds = str_repeat("", 256);
}
if (count($biomeColors) === 256) {
$this->biomeColors = $biomeColors;
} else {
$this->biomeColors = array_fill(0, 256, Binary::readInt("…²J"));
}
if (count($heightMap) === 256) {
$this->heightMap = $heightMap;
} else {
$this->heightMap = array_fill(0, 256, 127);
}
$this->NBTtiles = $tiles;
$this->NBTentities = $entities;
}
示例3: encode
public function encode()
{
$this->reset();
$this->buffer .= Binary::writeLong($this->eid);
$meta = Binary::writeMetadata($this->metadata);
$this->buffer .= $meta;
}
示例4: __construct
/**
* @param LevelProvider $provider
* @param int $x
* @param int $z
* @param ChunkSection[] $sections
* @param string $biomeIds
* @param int[] $biomeColors
* @param int[] $heightMap
* @param Compound[] $entities
* @param Compound[] $tiles
*
* @throws ChunkException
*/
protected function __construct($provider, $x, $z, array $sections, $biomeIds = null, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = [])
{
$this->provider = $provider;
$this->x = (int) $x;
$this->z = (int) $z;
foreach ($sections as $Y => $section) {
if ($section instanceof ChunkSection) {
$this->sections[$Y] = $section;
} else {
throw new ChunkException("Received invalid ChunkSection instance");
}
if ($Y >= self::SECTION_COUNT) {
throw new ChunkException("Invalid amount of chunks");
}
}
if (strlen($biomeIds) === 256) {
$this->biomeIds = $biomeIds;
} else {
$this->biomeIds = str_repeat("", 256);
}
if (count($biomeColors) === 256) {
$this->biomeColors = $biomeColors;
} else {
$this->biomeColors = array_fill(0, 256, Binary::readInt("…²J"));
}
if (count($heightMap) === 256) {
$this->heightMap = $heightMap;
} else {
$this->heightMap = array_fill(0, 256, 127);
}
$this->NBTtiles = $tiles;
$this->NBTentities = $entities;
}
示例5: encode
public function encode()
{
$this->reset();
$this->buffer .= Binary::writeLong($this->from);
$this->buffer .= Binary::writeLong($this->to);
$this->buffer .= \chr($this->type);
}
示例6: decode
public function decode()
{
$this->eid = Binary::readLong($this->get(8));
$this->x = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1];
$this->z = \PHP_INT_SIZE === 8 ? \unpack("N", $this->get(4))[1] << 32 >> 32 : \unpack("N", $this->get(4))[1];
$this->y = \ord($this->get(1));
}
示例7: handle
public function handle($address, $port, $packet)
{
$offset = 2;
$packetType = ord($packet[$offset++]);
$sessionID = Binary::readInt(substr($packet, $offset, 4));
$offset += 4;
$payload = substr($packet, $offset);
switch ($packetType) {
case self::HANDSHAKE:
//Handshake
$reply = chr(self::HANDSHAKE);
$reply .= Binary::writeInt($sessionID);
$reply .= self::getTokenString($this->token, $address) . "";
$this->server->getNetwork()->sendPacket($address, $port, $reply);
break;
case self::STATISTICS:
//Stat
$token = Binary::readInt(substr($payload, 0, 4));
if ($token !== self::getTokenString($this->token, $address) and $token !== self::getTokenString($this->lastToken, $address)) {
break;
}
$reply = chr(self::STATISTICS);
$reply .= Binary::writeInt($sessionID);
if ($this->timeout < microtime(true)) {
$this->regenerateInfo();
}
if (strlen($payload) === 8) {
$reply .= $this->longData;
} else {
$reply .= $this->shortData;
}
$this->server->getNetwork()->sendPacket($address, $port, $reply);
break;
}
}
示例8: decode
public function decode()
{
$this->eid = Binary::readLong($this->get(8));
$this->x = \unpack("N", $this->get(4))[1];
$this->z = \unpack("N", $this->get(4))[1];
$this->y = \ord($this->get(1));
}
示例9: decode
public function decode()
{
$this->eid = Binary::readLong($this->get(8));
$this->item = $this->getSlot();
$this->slot = \ord($this->get(1));
$this->selectedSlot = \ord($this->get(1));
}
示例10: encode
public function encode()
{
$this->buffer = \chr(self::NETWORK_ID);
$this->offset = 0;
$this->buffer .= Binary::writeLong($this->target);
$this->buffer .= Binary::writeLong($this->eid);
}
示例11: encode
public function encode()
{
$this->buffer = \chr(self::NETWORK_ID);
$this->offset = 0;
$this->buffer .= Binary::writeLong($this->eid);
$this->putUUID($this->clientId);
}
示例12: encode
public function encode()
{
$this->reset();
$this->putLong($this->eid);
$meta = Binary::writeMetadata($this->metadata);
$this->put($meta);
}
示例13: onPkt
public function onPkt(DataPacketReceiveEvent $e)
{
if ($e->getPacket()->pid() !== 0x0) {
return;
}
$this->lastPing[strtolower($e->getPlayer()->getName())] = Binary::readLong($e->getPacket()->buffer) / 1000.0;
}
示例14: decode
public function decode()
{
$this->eid = Binary::readLong($this->get(8));
$this->slots[0] = $this->getSlot();
$this->slots[1] = $this->getSlot();
$this->slots[2] = $this->getSlot();
$this->slots[3] = $this->getSlot();
}
示例15: encode
public function encode()
{
$this->buffer = \chr(self::NETWORK_ID);
$this->offset = 0;
$this->buffer .= Binary::writeLong($this->from);
$this->buffer .= Binary::writeLong($this->to);
$this->buffer .= \chr($this->type);
}