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

Enchants on chest?

Discussion in 'Help' started by A354-PH, Nov 1, 2018.

  1. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    How to add custom enchants/vanilla enchants to items in a chest?
     
  2. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    Still dont have a reply....
     
  3. Kkora

    Kkora Baby Zombie

    Messages:
    189
    GitHub:
    shisui203
    Not even possible. I've tried but not work
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    1) Create enchantment instance
    2) Add it to item
    3) Put item into the chest

    PHP:
    $item Item::get(Item::STONE_SWORD);
    $id Enchantment::SHARPNESS;
    $level 2;
    $instance = new EnchantmentInstance(Enchantment::getEnchantment($id), $level);
    $item->addEnchantment($instance);

    $pos = new Vector3(451); //chest position
    /** @var \pocketmine\level\Level $level */
    $tile $level->getTile($pos);
    if (
    $tile instanceof Chest) {
        
    $tile->getInventory()->addItem($item);
    }
     
  5. A354-PH

    A354-PH Baby Zombie

    Messages:
    186
    GitHub:
    Kizu
    How to use it on Multiple items?
     
  6. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
  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.