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


PHP Block::onUpdate方法代码示例

本文整理汇总了PHP中pocketmine\block\Block::onUpdate方法的典型用法代码示例。如果您正苦于以下问题:PHP Block::onUpdate方法的具体用法?PHP Block::onUpdate怎么用?PHP Block::onUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\block\Block的用法示例。


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

示例1: setBlock

 /**
  * Sets on Vector3 the data from a Block object,
  * does block updates and puts the changes to the send queue.
  *
  * If $direct is true, it'll send changes directly to players. if false, it'll be queued
  * and the best way to send queued changes will be done in the next tick.
  * This way big changes can be sent on a single chunk update packet instead of thousands of packets.
  *
  * If $update is true, it'll get the neighbour blocks (6 sides) and update them.
  * If you are doing big changes, you might want to set this to false, then update manually.
  *
  * @param Vector3 $pos
  * @param Block   $block
  * @param bool    $direct
  * @param bool    $update
  *
  * @return bool
  */
 public function setBlock(Vector3 $pos, Block $block, $direct = false, $update = true)
 {
     if ($pos->y < 0 or $pos->y >= 128 or !$block instanceof Block) {
         return false;
     }
     if ($this->getChunkAt($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf, $block->getID(), $block->getDamage())) {
         if (!$pos instanceof Position) {
             $pos = new Position($pos->x, $pos->y, $pos->z, $this);
         }
         $block->position($pos);
         $index = Level::chunkHash($pos->x >> 4, $pos->z >> 4);
         if (ADVANCED_CACHE == true) {
             Cache::remove("world:" . $this->getID() . ":" . $index);
         }
         if ($direct === true) {
             $pk = new UpdateBlockPacket();
             $pk->x = $pos->x;
             $pk->y = $pos->y;
             $pk->z = $pos->z;
             $pk->block = $block->getID();
             $pk->meta = $block->getDamage();
             foreach ($this->getUsingChunk($pos->x >> 4, $pos->z >> 4) as $player) {
                 /** @var Player $player */
                 $player->directDataPacket($pk);
             }
         } else {
             if (!$pos instanceof Position) {
                 $pos = new Position($pos->x, $pos->y, $pos->z, $this);
             }
             $block->position($pos);
             if (!isset($this->changedBlocks[$index])) {
                 $this->changedBlocks[$index] = [];
                 $this->changedCount[$index] = 0;
             }
             $Y = $pos->y >> 4;
             if (!isset($this->changedBlocks[$index][$Y])) {
                 $this->changedBlocks[$index][$Y] = [];
                 $this->changedCount[$index] |= 1 << $Y;
             }
             $this->changedBlocks[$index][$Y][] = clone $block;
         }
         if ($update === true) {
             $this->updateAround($pos, self::BLOCK_UPDATE_NORMAL);
             $block->onUpdate(self::BLOCK_UPDATE_NORMAL);
         }
     }
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:65,代码来源:Level.php

示例2: doNormalBlockUpdate

 /**
  * @param Block $block
  * @param Vector3/Position/Block $fromBlock
  */
 public function doNormalBlockUpdate($block, $fromBlock)
 {
     if ($block->getId() == Block::OBSERVER) {
         #ToDo:AddAInterfaceForThis
         $block->onUpdate(self::BLOCK_UPDATE_NORMAL, $fromBlock);
     } else {
         $block->onUpdate(self::BLOCK_UPDATE_NORMAL);
     }
 }
开发者ID:ClearSkyTeam,项目名称:ClearSky,代码行数:13,代码来源:Level.php


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