PHP: $enchantment = Enchantment::getEnchantment(id);$enchantment->setLevel(lvl);/** @var Item */$item->addEnchantment($enchantment); getEnchantment() https://github.com/pmmp/PocketMine-...ketmine/item/enchantment/Enchantment.php#L109 addEnchantment() https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L363
Now the code id this: if (is_int($value['id'])) { $enchantment = Enchantment::getEnchantment($value['id']); } else { $enchantment = Enchantment::getEnchantmentByName($value['id']); } if ($enchantment instanceof Enchantment) { $enchantment = new EnchantmentInstance($enchantment); if (isset($value['level'])) $enchantment->setLevel($value['level']); $item->addEnchantment($enchantment); }
am aware that is the code but am not in the mood in giving the entire code when the OP can just go to the source and read one line i missed.
With the latest API modifications, PHP: /** @var Item $item */$enchantment = Enchantment::getEnchantment(enchantmentId);$enchInstance = new EnchantmentInstance($enchantment, enchantmentLevel);$item->addEnchantment($enchInstance);