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

Add enchantment

Discussion in 'Development' started by Denzel Code, Dec 24, 2017.

  1. Denzel Code

    Denzel Code Spider

    Messages:
    10
    GitHub:
    denzelcode
    How can i add enchantment?
     
  2. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    OnTheVerge likes this.
  3. Denzel Code

    Denzel Code Spider

    Messages:
    10
    GitHub:
    denzelcode
    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);
    }
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    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.
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    With the latest API modifications,
    PHP:
    /** @var Item $item */
    $enchantment Enchantment::getEnchantment(enchantmentId);
    $enchInstance = new EnchantmentInstance($enchantmentenchantmentLevel);
    $item->addEnchantment($enchInstance);
     
  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.