Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Could help me a spell of adding an article on this with this code?

Comments in 'Plugin Development' started by xPixel2, Oct 7, 2016.

  1. xPixel2
    Offline

    xPixel2 New Member

    Joined:
    Oct 7, 2016
    Posts:
    4
    Minecraft User:
    xPixel2
    How do I add enchantment to a plugin that I am modifying previously had no enchantments but I want them to? This is the code:

    $player->getInventory()->addItem(Item::get(ITEM: DIAMOND_SWORD));

    Help me please v:

    Thanks You :D Screenshot_2016-10-07-16-25-36.png Screenshot_2016-10-07-16-25-46.png
  2. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
    I have two ideas for you.

    The first one is a link.
    http://minecraft.gamepedia.com/Pocket_Edition_data_values
    Enjoyyy

    The Second idea is
    PHP:
    $player->getInventory()->addItem(Item::get(id),damage,count);
    // replace 'damage' and 'count' with your own value. (or leave it out)
    //'id' also meaning enter a value. for example, 19 - for Sponge
    $player->getInventory()->sendContents($player);
    //this can be found on https://forums.pocketmine.net/threads/new-api-additem-function.4070/
  3. xPixel2
    Offline

    xPixel2 New Member

    Joined:
    Oct 7, 2016
    Posts:
    4
    Minecraft User:
    xPixel2
    Ok
    that already so I understand but, how would add you so say so sharpness to this sword? (It is a 1vs1 plugin)
  4. xPixel2
    Offline

    xPixel2 New Member

    Joined:
    Oct 7, 2016
    Posts:
    4
    Minecraft User:
    xPixel2
    I mean that I want to put charms to that sword would be the code?
  5. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
  6. Thunder33345
    Offline

    Thunder33345 Notable Member

    Joined:
    Apr 3, 2014
    Posts:
    755
    Minecraft User:
    Thunder33345
    TheDeibo likes this.
  7. TheDeibo
    Offline

    TheDeibo Notable Member Plugin Developer

    Joined:
    Sep 8, 2014
    Posts:
    692
    Plugins:
    1
    Minecraft User:
    TheDeibo
    indeed. there are many ways. I was just so tired staying up till 2AM trying to use my brain for everything related to TheDeibo life, and my college life... ao thats why I posted links.
  8. archie426
    Offline

    archie426 Active Member

    Joined:
    Apr 26, 2015
    Posts:
    193
    Minecraft User:
    archie426
    Make sure ur device doesn't run out! and btw what app r u using (off-topic, i know, but, REBEL)
  9. xPixel2
    Offline

    xPixel2 New Member

    Joined:
    Oct 7, 2016
    Posts:
    4
    Minecraft User:
    xPixel2
    I use the application of DroidEdit in my opinion is good now that I'll be a good time without pc :)
  10. corytortoise
    Offline

    corytortoise New Member

    Joined:
    Aug 23, 2015
    Posts:
    10
    Minecraft User:
    corytortoise
    To add an enchantment, use

    PHP:
    $item->addEnchantment(Enchantment::getEnchantment(ID)->setLevel(LVL));

    /* Define $item as the Item::get object beforehand. then you can do: */

    $player->getInventory()->addItem($item);

    I am sure there are better ways, but using this you can understand the code a bit better.
  11. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael

    PHP:
    $item Item::get(27601);
    $player $event->getPlayer();
    // Or other methods your using

    $enchant Enchantment::getEffectByName("WEAPON_SHARPNESS");
    // OR
    $enchant Enchantment::getEnchantment(0);

    $enchant->setLevel($level 3);
    // Put desired level
    $item->addEnchantment($enchant);
    $player->getInventory()->addItem($item);
    TheDeibo likes this.

Share This Page

Advertisement