Specified enchantment cannot be applied to this itemstack

Discussion in 'Plugin Development' started by UltraMC, Dec 22, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    UltraMC

    Why do I get this error on attempt to set item's enchantment (error line is one of 'itemToAdd.addEnchantment'):

    Code:
    ItemStack itemToAdd = new ItemStack(itemID, itemQTY, itemSUB);
    itemToAdd.setDurability(itemDUR);
     
    if (isItABook == true) {
        EnchantmentStorageMeta bookmeta = (EnchantmentStorageMeta) itemToAdd.getItemMeta();
        bookmeta.addStoredEnchant(enchantTYPE, enchantLVL, true);
        itemToAdd.setItemMeta(bookmeta);
    } else {
        itemToAdd.addEnchantment(enchantTYPE, enchantLVL);
    }
     
    player.getInventory().addItem(itemToAdd);
    Self solved:

    I was trying to add ARROW_DAMAGE to a DIAMOND_SWORD ;-)

    But I've craeted that thing in creative so there is a way to it without error. But how?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  2. Offline

    hellboyPS

    Instead of .addEnchantment() use .addUnsafeEnchantment()
     
    UltraMC likes this.
Thread Status:
Not open for further replies.

Share This Page