I'm making a kits plugin using InvMenu and I wanted to make it so the player grabs the item in the chest. I tried adding an enchantment to an item in the chest. $menu->getInventory()->setContents([ Item::get(Item::IRON_HELMET)->addEnchantment(EEnchantment::getEnchantment(1), 1); ]); I tried other methods too. This is the latest code. It this possible?
$i = Item::get(Item::IRON_HELMET); $i->addEnchantment(EEnchantment::getEnchantment(1); $menu->getInventory()->setItem($slot, $i);
public function Starter(Player $player) { $menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST)->setName(TextFormat::GREEN . "Kit Shop"); $inventory = $menu->getInventory(); $helmet = Item::IRON_HELMET; $enchInstance = new EnchantmentInstance(Enchantment::getEnchantment(17), 1); $i = Item::get(Item::IRON_HELMET); $i->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(17), 1)); $menu->getInventory()->addItem(Item::get($i)); /** @var Player $player */ $menu->send($player); }
No need for $helmet, also why not just do $i->addEnchantment($enchInstance)? Seems cleaner to me. Your error is likely in your InvMenu class. Is it Musqit's InvMenu virion?
it should be PHP: $i = Item::get(Item::IRON_HELMET);$i->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::UNBREAKING), 1));$menu->getInventory()->addItem($i);
Now it doesn't display errors or anything. public function Starter(Player $player) { $menu = InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST)->setName(TextFormat::GREEN . "Kit Shop"); $inv = $menu->getInventory(); $i = Item::get(Item::IRON_HELMET); $i->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::UNBREAKING), 1)); $inv->addItem($i); /** @var Player $player */ $menu->send($player); }