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

How to ecnchant

Discussion in 'Development' started by 7awariGamer, Sep 16, 2018.

  1. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    Any one can help??
    How I can add enchantment for any item?
     
  2. azk_

    azk_ Spider Jockey

    Messages:
    49
    Code:
    $item = $player->getInventory()->getItemInHand();
    $id = 0; //protection
    $level = 1; //level 1
    
    $enchantment = new EnchantmentInstance(Enchantment::getEnchantment($id), $level);
    $item->addEnchantment($enchantment);
    $player->getInventory()->setItemInHand($item);
     
  3. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    Lol I want to enchant this:
    PHP:
                 case "getinfo";
                      
    $item Item::get(369,0,1);
                      
    $inv $sender->getInventory();
                      
    $item->setCustomName("§l§bInfo");
                      
    $inv->addItem($item);
                      return 
    true;
                      break;
                }[
    PHP]




    [
    QUOTE="azk_, post: 57577, member: 1439"][CODE]$item $player->getInventory()->getItemInHand();
    $id 0//protection
    $level 1//level 1

    $enchantment = new EnchantmentInstance(Enchantment::getEnchantment($id), $level);
    $item->addEnchantment($enchantment);
    $player->getInventory()->setItemInHand($item);[/CODE][/QUOTE]
     
    Last edited: Sep 16, 2018
  4. azk_

    azk_ Spider Jockey

    Messages:
    49
    Like this?
    PHP:
    case "getinfo";
                      
    $item Item::get(369,0,1);
                      
    $id 0//protection
                      
    $level 1//level 1
                      
    $enchantment = new EnchantmentInstance(Enchantment::getEnchantment($id), $level);
                      
    $inv $sender->getInventory();
                      
    $item->setCustomName("§l§bInfo");
                      
    $item->addEnchantment($enchantment);
                      
    $inv->addItem($item);
                      return 
    true;
                      break;
                }
    Edit: Do not forget to add;

    PHP:
    use pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\item\enchantment\EnchantmentInstance;
     
    dbcooper likes this.
  5. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    Thx
     
  6. 7awariGamer

    7awariGamer Baby Zombie

    Messages:
    120
    GitHub:
    7awariGamer
    I
    Why I didn't get the enchantment with the item?
    It's doesn't work
     
  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.