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

Vanilla Enchants To Items

Discussion in 'Development' started by Vincent, Dec 27, 2017.

  1. Vincent

    Vincent Silverfish

    Messages:
    16
    GitHub:
    vincent
    Im making a plugin that needs for me to give an item an enchant... Such as feather falling. Thx
     
  2. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    Lmfao
    What is the point of this post? XD
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    He's asking how to give enchant to item
     
    OnTheVerge likes this.
  4. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    Oh thought he was making..
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Yes, but he does not said it's finished
     
  6. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    PHP:
    $item Item::get(313,0,1); //diamond boots
    $item->addEnchantment(Enchantment::getEnchantment(2)->setLevel(1); //this adds FeatherFalling to the boot and sets the enchantment level to 1
     
  7. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    This is wrong! The new addEnchantment() param is the class EnchantmentInstance!
    Heres what it should look like
    PHP:
    $enchantment Enchantment::getEnchantment(0);
    $ench = new EnchantmentInstance($enchantment$lvl);
    /** @var Item */
    $item;
    $item->addEnchantment($ench);
    getEnchantment() function: https://github.com/pmmp/PocketMine-...ketmine/item/enchantment/Enchantment.php#L109

    EnchantmentInstance class: https://github.com/pmmp/PocketMine-...mine/item/enchantment/EnchantmentInstance.php

    addEnchantment() function: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L363

    Btw there are only 3 enchants currently registered in PMMP! ;P
     
  8. OnTheVerge

    OnTheVerge Spider Jockey

    Messages:
    46
    I use it that way and It works perfectly fine xD and also you're my teacher bish -.- XD you so evil -.- lml
     
  9. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    PHP:
    use pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\inventory\Inventory;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\item\enchantment\EnchantmentInstance;

    $e Enchantment::getEnchantment((int) 0); //0 is Enchant
    $item Item::get(1,0,1//stone

    $item->addEnchantment(new EnchantmentInstance($e, (int) 2));  //2 is level
    $sender->getInventory()->addItem($item); //I use $sender it just for Player, CommandSender , etc...

     
  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.