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

How to add KnockBack to an Stick?

Discussion in 'Development' started by SkyZone, Oct 8, 2017.

  1. SkyZone

    SkyZone Slime

    Messages:
    95
    I tried this
    PHP:
    $item Item::get(2800
     
    $item->addEnchantment(Enchantment::getEnchantment(Enchantment::KNOCKBACK)->setLevel(1));
     
    $item->setCustomName(TextFormat::GOLD.TextFormat::ITALIC.'KNOCKBACK');
     
    $player->getInventory()->setItem(0$itemTRUE);
    But it return:
    Code:
    [06:30:35] [Server thread/CRITICAL]: Could not execute task SkyZoneMC\OneLine\OLTask: Call to a member function setLevel() on null
    [06:30:35] [Server thread/CRITICAL]: Error: "Call to a member function setLevel() on null" (EXCEPTION) in "OneLine - SkyZoneMC/src/SkyZoneMC/OneLine/OneLine" at line 829
    
    I dont know how to fix this ._.
     
  2. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
  3. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
    if you do not understand, then they did not add the enchantment
     
  4. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You can create new enchant and try add it to stick

    PHP:
    $item Item::get(Item::STICK01);
    $enchantment = new Enchantment(Enchantment::KNOCKBACK"Knockback"1Enchantment::ACTIVATION_HELD0);
    $enchantment->setLevel(1);
    $item->addEnchantment($enchantment);
    $p->getInventory()->addItem($item);
    $p->getInventory()->addItem(Item::get(Item::ARROW01));
     
  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.