本文整理汇总了PHP中pocketmine\item\Item::hasEnchantments方法的典型用法代码示例。如果您正苦于以下问题:PHP Item::hasEnchantments方法的具体用法?PHP Item::hasEnchantments怎么用?PHP Item::hasEnchantments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::hasEnchantments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onEnchant
public function onEnchant(Player $who, Item $before, Item $after)
{
$result = $before->getId() == Item::BOOK ? new EnchantedBook() : $before;
if (!$before->hasEnchantments() and $after->hasEnchantments() and $after->getId() == $result->getId() and $this->levels != null and $this->entries != null) {
$enchantments = $after->getEnchantments();
for ($i = 0; $i < 3; $i++) {
if ($enchantments == $this->entries[$i]->getEnchantments()) {
$lapis = $this->getItem(1);
$level = $who->getExpLevel();
$exp = $who->getExperience();
$cost = $this->entries[$i]->getCost();
if ($lapis->getId() == Item::DYE and $lapis->getDamage() == Dye::BLUE and $lapis->getCount() > $i and $level >= $cost) {
foreach ($enchantments as $enchantment) {
$result->addEnchantment($enchantment);
}
$this->setItem(0, $result);
$lapis->setCount($lapis->getCount() - $i - 1);
$this->setItem(1, $lapis);
$who->setExperienceAndLevel($exp, $level - $cost);
break;
}
}
}
}
}