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

Solved texture of enchantment

Discussion in 'Development' started by armagadon159753, Oct 9, 2017.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    hi coders I stroll on YouTube and by suprise I saw this video. I am curious to know how can I add the enchantment texture on a random item

    Vidéo :
     
  2. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
    Do you mean this?
    PHP:
    $item->addEnchantment(new Enchantment(-1"unknown"000));
     
    Levi and armagadon159753 like this.
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    I thank you but the -1 designates the ID of the enchantment?
     
  4. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
    Yes
     
    armagadon159753 likes this.
  5. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Wich class name i do use in code?
     
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    \pocketmine\item\enchantment\Enchantment
     
  7. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    PHP:
    [19:38:52] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'LobbyItems v1'Argument 2 passed to pocketmine\inventory\BaseInventory::setItem() must be an instance of pocketmine\item\Itemnull givencalled in /home/arma/plugins/LobbyItems/src/ArmaGadon/lobbyitems.php on line 40 on ArmaGadon\lobbyitems                                           [19:38:52] [Server thread/CRITICAL]: TypeError"Argument 2 passed to pocketmine\inventory\BaseInventory::setItem() must be an instance of pocketmine\item\Item, null given, called in /home/arma/plugins/LobbyItems/src/ArmaGadon/lobbyitems.php on line 40" (EXCEPTIONin "src/pocketmine/inventory/BaseInventory" at line 135    [19:38:52] [Server thread/DEBUG]: #0 LobbyItems/src/ArmaGadon/lobbyitems(40): pocketmine\inventory\BaseInventory->setItem(integer 1, NULL )
    PHP:
    $player->getInventory()->setItem(1Item::get(347)->addEnchantment(new Enchantment(-1"unknown"000)));
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Cool, but what if want I to use setCustomName() on item.. Then text will be higher than normal and "\n" don't fix :D
     
    armagadon159753 likes this.
  9. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    Can you vive an exemple with
    PHP:
    $player->getInventory()->setItem(4Item::get(347)->setCustomName("§ashop"));
    And addEnchantment plz i dont realy understand
     
  10. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Item::addEnchantment() doesn't return the Item instance
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L374
     
  11. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    PHP:
    $item Item::get(347);
    $item->addEnchantment(new Enchantment(-1"unknown"000));
    $item->setCustomName("§ashop");
    $player->getIventory()->setItem(4$item);
     
    armagadon159753 and jasonwynn10 like this.
  12. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    The code is correct. something else you did is incorrect. We cannot help with that unless it is shown
     
  13. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    This happens when you copy - paste code .. Write it to your plugin without copying
     
    armagadon159753 and jasonwynn10 like this.
  14. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
     
  15. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Much better, just add the "ench" (Tag_List) onto the item, the game will render it as if it were enchanted.
    PHP:
    $tag = new ListTag("ench");

    //API 3.0.0-ALPHA9
    $item->setNamedTagEntry($tag);

    //Older API versions
    $nbt $item->getNamedTag() ?? new CompoundTag();
    $nbt->ench $tag;
    $item->setNamedTag($nbt);
     
    robske_110 (Tim) and jasonwynn10 like this.
  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.