Наследование: extends DataPacket
 public function removeWaterField(Player $player)
 {
     $level = $player->getLevel();
     $pk = new UpdateBlockPacket();
     if (isset($this->waterField[$player->getName()]["pos"])) {
         $pos = explode(":", $this->waterField[$player->getName()]["pos"]);
         $sides = [[1, 1], [1, 0], [1, 1], [0, -1], [0, 0], [0, 1], [-1, -1], [-1, 0], [-1, 0]];
         foreach ($sides as $side) {
             $downId = $level->getBlockIdAt($pos[0] + $side[0], $pos[2], $pos[1] + $side[1]);
             $downDmg = $level->getBlockDataAt($pos[0] + $side[0], $pos[2], $pos[1] + $side[1]);
             $pk->records[] = [$pos[0] + $side[0], $pos[1] + $side[1], $pos[2], $downId, $downDmg, UpdateBlockPacket::FLAG_NONE];
         }
         $player->directDataPacket($pk->setChannel(Network::CHANNEL_BLOCKS));
         unset($this->waterField[$player->getName()]["pos"]);
     }
 }
Пример #2
0
 /**
  * @param Player[] $target
  * @param Block[]  $blocks
  * @param int      $flags
  */
 public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE)
 {
     $pk = new UpdateBlockPacket();
     foreach ($blocks as $b) {
         if ($b === null) {
             continue;
         }
         if ($b instanceof Block) {
             $pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $flags];
         } else {
             $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
             $pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $flags];
         }
     }
     Server::broadcastPacket($target, $pk->setChannel(Network::CHANNEL_BLOCKS));
 }
Пример #3
0
 /**
  * @param Player[] $target
  * @param Block[]  $blocks
  * @param int      $flags
  * @param bool     $optimizeRebuilds
  */
 public function sendBlocks(array $target, array $blocks, $flags = UpdateBlockPacket::FLAG_NONE, $optimizeRebuilds = false)
 {
     $pk = new UpdateBlockPacket();
     if ($optimizeRebuilds) {
         $chunks = [];
         foreach ($blocks as $b) {
             if ($b === null) {
                 continue;
             }
             $first = false;
             if (!isset($chunks[$index = Level::chunkHash($b->x >> 4, $b->z >> 4)])) {
                 $chunks[$index] = true;
                 $first = true;
             }
             if ($b instanceof Block) {
                 $pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $first ? $flags : UpdateBlockPacket::FLAG_NONE];
             } else {
                 $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
                 $pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $first ? $flags : UpdateBlockPacket::FLAG_NONE];
             }
         }
     } else {
         foreach ($blocks as $b) {
             if ($b === null) {
                 continue;
             }
             if ($b instanceof Block) {
                 $pk->records[] = [$b->x, $b->z, $b->y, $b->getId(), $b->getDamage(), $flags];
             } else {
                 $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z);
                 $pk->records[] = [$b->x, $b->z, $b->y, $fullBlock >> 4, $fullBlock & 0xf, $flags];
             }
         }
     }
     Server::broadcastPacket($target, $pk->setChannel(Network::CHANNEL_BLOCKS));
 }