How would I go about adding enchantments via nbt? Heres my code(P.S. ITS WRONG!): PHP: if($args[0] === "cetest") { $tag = $item->getNamedTag(); $count = 0; foreach($tag->ench as $key => $value){ if(is_numeric($key)){ $count++; } } if(isset($tag->ench)){ $tag = $tag->ench; if($tag instanceof ListTag){ foreach($item->getEnchantments() as $en) { $player->sendMessage("lit"); $item->setCustomName("sick"); $tag = new CompoundTag('', []); $tag->ench->{$count + 1} = new CompoundTag("", [ "id" => new ShortTag("id", $en->getId()), "lvl" => new ShortTag("lvl", $en->getLevel()) ]); $item->setNamedTag($tag); $inv->setItemInHand($item); return true; } } } }
Why don't you want to use Item::addEnchantment() ? https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L483
1. trying to test out different methods whether its performance. 2.Its buggy when setting custom names
RTFS(Read The Fine Source) https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L483 either way using self made NBT of PMMP's method it all will still use NBT and will be the same
That's a problem with MCPE itself. For some weird reason, an item with 3+ NBT tags just drop it off the inventory.