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 :
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\Item, null given, called 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" (EXCEPTION) in "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(1, Item::get(347)->addEnchantment(new Enchantment(-1, "unknown", 0, 0, 0)));
Cool, but what if want I to use setCustomName() on item.. Then text will be higher than normal and "\n" don't fix
Can you vive an exemple with PHP: $player->getInventory()->setItem(4, Item::get(347)->setCustomName("§ashop")); And addEnchantment plz i dont realy understand
Item::addEnchantment() doesn't return the Item instance https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L374
PHP: $item = Item::get(347);$item->addEnchantment(new Enchantment(-1, "unknown", 0, 0, 0));$item->setCustomName("§ashop");$player->getIventory()->setItem(4, $item);
The code is correct. something else you did is incorrect. We cannot help with that unless it is shown
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);