1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Enchantment error

Discussion in 'Development' started by MSG100PM, Aug 11, 2018.

  1. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It's because Item::addEnchantment() doesn't return the item instance (unlike setCustomName(), setLore(), etc..).
    You need to use:
    PHP:
    $item Item::get(Item::STICK);
    $item->addEnchantment(...);
    $player->getInventory()->addItem($item);
    Also, small tip: You can specify multiple 'Item' parameters to Inventory::addItem().
    PHP:
    $inventory->addItem(
        
    Item::get(Item::STICK),
        
    Item::get(Item::STONE),
        
    Item::get(Item::BONE)
    );
     
  2. MSG100PM

    MSG100PM Slime

    Messages:
    95
    GitHub:
    MSG100TC
    Thanks!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.