本文整理汇总了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;
}