Пример #1
0
 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
0
 /**
  * @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;
 }
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong($this->eid);
     $meta = Binary::writeMetadata($this->metadata);
     $this->buffer .= $meta;
 }
Пример #4
0
 /**
  * @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;
 }
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong($this->from);
     $this->buffer .= Binary::writeLong($this->to);
     $this->buffer .= \chr($this->type);
 }
 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
0
 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;
     }
 }
 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));
 }
 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
0
 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
0
 public function encode()
 {
     $this->buffer = \chr(self::NETWORK_ID);
     $this->offset = 0;
     $this->buffer .= Binary::writeLong($this->eid);
     $this->putUUID($this->clientId);
 }
Пример #12
0
 public function encode()
 {
     $this->reset();
     $this->putLong($this->eid);
     $meta = Binary::writeMetadata($this->metadata);
     $this->put($meta);
 }
Пример #13
0
 public function onPkt(DataPacketReceiveEvent $e)
 {
     if ($e->getPacket()->pid() !== 0x0) {
         return;
     }
     $this->lastPing[strtolower($e->getPlayer()->getName())] = Binary::readLong($e->getPacket()->buffer) / 1000.0;
 }
 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();
 }
 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);
 }
 public function encode()
 {
     $this->buffer = \chr(self::NETWORK_ID);
     $this->offset = 0;
     $this->buffer .= \pack("NN", $this->eid >> 32, $this->eid & 0xffffffff);
     $meta = Binary::writeMetadata($this->metadata);
     $this->buffer .= $meta;
 }
 public function encode()
 {
     $this->buffer = \chr(self::NETWORK_ID);
     $this->offset = 0;
     $this->buffer .= Binary::writeLong($this->eid);
     $meta = Binary::writeMetadata($this->metadata);
     $this->buffer .= $meta;
 }
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong($this->eid);
     $this->buffer .= \chr($this->slots[0]);
     $this->buffer .= \chr($this->slots[1]);
     $this->buffer .= \chr($this->slots[2]);
     $this->buffer .= \chr($this->slots[3]);
 }
 public function encode()
 {
     $this->buffer = \chr(self::NETWORK_ID);
     $this->offset = 0;
     $this->buffer .= Binary::writeLong($this->eid);
     $this->putSlot($this->item);
     $this->buffer .= \chr($this->slot);
     $this->buffer .= \chr($this->selectedSlot);
 }
 public function decode()
 {
     $this->eid = Binary::readLong($this->get(8));
     $this->action = \unpack("N", $this->get(4))[1] << 32 >> 32;
     $this->x = \unpack("N", $this->get(4))[1] << 32 >> 32;
     $this->y = \unpack("N", $this->get(4))[1] << 32 >> 32;
     $this->z = \unpack("N", $this->get(4))[1] << 32 >> 32;
     $this->face = \unpack("N", $this->get(4))[1] << 32 >> 32;
 }
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong($this->eid);
     $this->buffer .= \pack("n", $this->item);
     $this->buffer .= \pack("n", $this->meta);
     $this->buffer .= \chr($this->slot);
     $this->buffer .= \chr($this->selectedSlot);
 }
Пример #22
0
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong(0);
     //TODO: remove
     $this->buffer .= \ENDIANNESS === 0 ? \pack("f", $this->x) : \strrev(\pack("f", $this->x));
     $this->buffer .= \ENDIANNESS === 0 ? \pack("f", $this->y) : \strrev(\pack("f", $this->y));
     $this->buffer .= \ENDIANNESS === 0 ? \pack("f", $this->z) : \strrev(\pack("f", $this->z));
 }
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong($this->eid);
     $this->buffer .= \pack("N", $this->action);
     $this->buffer .= \pack("N", $this->x);
     $this->buffer .= \pack("N", $this->y);
     $this->buffer .= \pack("N", $this->z);
     $this->buffer .= \pack("N", $this->face);
 }
Пример #24
0
 public function encode()
 {
     $this->buffer = \chr(self::NETWORK_ID);
     $this->offset = 0;
     $this->buffer .= Binary::writeLong($this->eid);
     $this->putSlot($this->slots[0]);
     $this->putSlot($this->slots[1]);
     $this->putSlot($this->slots[2]);
     $this->putSlot($this->slots[3]);
 }
Пример #25
0
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong($this->eid);
     $this->buffer .= \chr($this->eventId);
     $this->buffer .= \chr($this->effectId);
     $this->buffer .= \chr($this->amplifier);
     $this->buffer .= \chr($this->particles ? 1 : 0);
     $this->buffer .= \pack("N", $this->duration);
 }
Пример #26
0
 public function encode()
 {
     $this->reset();
     $this->buffer .= Binary::writeLong($this->eid);
     $this->buffer .= \pack("N", $this->x);
     $this->buffer .= \pack("N", $this->y);
     $this->buffer .= \pack("N", $this->z);
     $this->buffer .= \pack("N", $this->direction);
     $this->putString($this->title);
 }
Пример #27
0
 public function encode()
 {
     $this->buffer = \chr(self::NETWORK_ID);
     $this->offset = 0;
     $this->buffer .= Binary::writeLong($this->eid);
     $this->buffer .= \chr($this->eventId);
     $this->buffer .= \chr($this->effectId);
     $this->buffer .= \chr($this->amplifier);
     $this->buffer .= \chr($this->particles ? 1 : 0);
     $this->buffer .= \pack("N", $this->duration);
 }
 public function encode()
 {
     $this->buffer = \chr(self::NETWORK_ID);
     $this->offset = 0;
     $this->buffer .= Binary::writeLong($this->eid);
     $this->buffer .= \pack("N", $this->action);
     $this->buffer .= \pack("N", $this->x);
     $this->buffer .= \pack("N", $this->y);
     $this->buffer .= \pack("N", $this->z);
     $this->buffer .= \pack("N", $this->face);
 }
 public function decode()
 {
     $this->eid = Binary::readLong($this->get(8));
     $this->x = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1];
     $this->y = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1];
     $this->z = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1];
     $this->yaw = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1];
     $this->bodyYaw = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1];
     $this->pitch = \ENDIANNESS === 0 ? \unpack("f", $this->get(4))[1] : \unpack("f", \strrev($this->get(4)))[1];
     $this->mode = \ord($this->get(1));
     $this->onGround = \ord($this->get(1)) > 0;
 }
Пример #30
0
 public function encode()
 {
     $this->reset();
     $this->putInt($this->eid);
     $this->putInt($this->type);
     $this->putInt($this->x);
     $this->putInt($this->y);
     $this->putInt($this->z);
     $this->putByte(floor($this->yaw * (256 / 360)));
     $this->putByte(floor($this->pitch * (256 / 360)));
     $this->put(Binary::writeMetadata($this->metadata));
 }