ItemStack heldItem = player.getHeldItemMainhand();
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
if (heldItem.getTagCompound().hasKey("ench", 9)) {
enchantedBook.setTagCompound(heldItem.getTagCompound().getCompoundTag("ench"));
player.inventory.addItemStackToInventory(enchantedBook);
}
heldItem.getTagCompound().getCompoundTag("ench").copy()
if (heldItem.isItemEnchanted()) {
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
enchantedBook.setTagCompound(heldItem.getTagCompound().getCompoundTag("ench").copy());
player.inventory.addItemStackToInventory(enchantedBook);
}
enchantedBook.getTagCompound().getCompoundTag("StoredEnchantments").merge(heldItem.getTagCompound().getCompoundTag("ench").copy());
enchantedBook.getTagCompound().setTag("StoredEnchantments", new NBTTagEnd());
чтобы был пустой, но существующий тег. Всё равно нулл.enchantedBook.setTagCompound(new NBTTagCompound());
if (heldItem.isItemEnchanted()) {
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
assert heldItem.getTagCompound() != null;
enchantedBook.setTagCompound(new NBTTagCompound());
assert enchantedBook.getTagCompound() != null;
enchantedBook.getTagCompound().getCompoundTag("StoredEnchantments").merge(heldItem.getTagCompound().getCompoundTag("ench").copy());
player.inventory.addItemStackToInventory(enchantedBook);
}
if (heldItem.isItemEnchanted()) {
ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
EnchantmentHelper.setEnchantments(EnchantmentHelper.getEnchantments(heldItem), enchantedBook);
player.inventory.addItemStackToInventory(enchantedBook);
}
Слушай, если не получается, сделай по-простому: достань из стака все зачарования и с помощью метода addEnchantment в книге добавь их.