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


PHP BlockBreakEvent::getInstaBreak方法代码示例

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


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

示例1: useBreakOn

 /**
  * Tries to break a block using a item, including Player time checks if available
  *
  * @param Vector3 $vector
  * @param Item    &$item (if null, can break anything)
  * @param Player  $player
  *
  * @return boolean
  */
 public function useBreakOn(Vector3 $vector, Item &$item = null, Player $player = null)
 {
     $target = $this->getBlock($vector);
     //TODO: Adventure mode checks
     if ($item === null) {
         $item = Item::get(Item::AIR, 0, 0);
     }
     if ($player instanceof Player) {
         $ev = new BlockBreakEvent($player, $target, $item, ($player->getGamemode() & 0x1) === 1 ? true : false);
         $lastTime = $player->lastBreak - 0.1;
         //TODO: replace with true lag
         if (($player->getGamemode() & 0x1) > 0) {
             $ev->setInstaBreak(true);
         } elseif ($lastTime + $target->getBreakTime($item) >= microtime(true)) {
             $ev->setCancelled();
         }
         if ($item instanceof Item and !$target->isBreakable($item) and $ev->getInstaBreak() === false) {
             $ev->setCancelled();
         }
         if (!$player->isOp() and ($distance = $this->server->getConfigInt("spawn-protection", 16)) > -1) {
             $t = new Vector2($target->x, $target->z);
             $s = new Vector2($this->getSpawn()->x, $this->getSpawn()->z);
             if ($t->distance($s) <= $distance) {
                 //set it to cancelled so plugins can bypass this
                 $ev->setCancelled();
             }
         }
         $this->server->getPluginManager()->callEvent($ev);
         if ($ev->isCancelled()) {
             return false;
         }
         $player->lastBreak = microtime(true);
     } elseif ($item instanceof Item and !$target->isBreakable($item)) {
         return false;
     }
     $level = $target->getLevel();
     if ($level instanceof Level) {
         $above = $level->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
         if ($above instanceof Block) {
             if ($above->getID() === Item::FIRE) {
                 $level->setBlock($above, new Air(), true);
             }
         }
     }
     $drops = $target->getDrops($item);
     //Fixes tile entities being deleted before getting drops
     $target->onBreak($item);
     $tile = $this->getTile($target);
     if ($tile instanceof Tile) {
         if ($tile instanceof InventoryHolder) {
             if ($tile instanceof Chest) {
                 $tile->unpair();
             }
             foreach ($tile->getInventory()->getContents() as $item) {
                 $this->dropItem($target, $item);
             }
         }
         $tile->close();
     }
     if ($item instanceof Item) {
         $item->useOn($target);
         if ($item->isTool() and $item->getDamage() >= $item->getMaxDurability()) {
             $item = Item::get(Item::AIR, 0, 0);
         }
     }
     if (!$player instanceof Player or ($player->getGamemode() & 0x1) === 0) {
         foreach ($drops as $drop) {
             if ($drop[2] > 0) {
                 $this->dropItem($vector->add(0.5, 0.5, 0.5), Item::get($drop[0], $drop[1], $drop[2]));
             }
         }
     }
     return true;
 }
开发者ID:boybook,项目名称:PocketMine-MP,代码行数:83,代码来源:Level.php


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