本文整理匯總了PHP中pocketmine\item\Item::getEnchantments方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::getEnchantments方法的具體用法?PHP Item::getEnchantments怎麽用?PHP Item::getEnchantments使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::getEnchantments方法的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;
}
}
}
}
}