Solved Enchanting an ItemStack (Infinity 1 to arrow problem)

Discussion in 'Plugin Development' started by Peavalu, Dec 14, 2014.

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

    Peavalu

    Hello fellow developers,

    I just got into developing plugins and I've ran into my first cornerstone.

    I'm attempting to create an arrow, add infinity I to it, then add the arrow to the players taskbar.
    This is the current code, and when ran in-game I get an internal error, and the log says that this kind of enchantment cannot be applied to this kind of itemstack. What am I doing wrong?
    The problem shouldn't be in anything else than this, I'm correctly registering my command and events etc.
    It's just this method that gives me an error in-game.

    Apology for the text formatting as I didn't see any code "tag"'s when creating this thread.

    arrow id = 262
    Infinity enchantment id = 51
    enchantment level = 1

    public void infinityarrow(PlayerInventory inv){

    short id = 1;
    int effectId = 51;
    int enchantmentLevel = 1;

    @SuppressWarnings("deprecation")
    ItemStack infinityarrow = new ItemStack(Material.getMaterial(262), 1, id);
    Enchantment infinityEnch = new EnchantmentWrapper(effectId);
    infinityarrow.addEnchantment(infinityEnch, enchantmentLevel);

    inv.addItem(infinityarrow);


    }


    I've also tried a method like this

    public void infinityarrow(PlayerInventory inv){


    int effectId = 51;
    int enchantmentLevel = 1;


    ItemStack infinityarrow = new ItemStack(Material.ARROW, 1);
    Enchantment infinityEnch = new EnchantmentWrapper(effectId);
    infinityarrow.addEnchantment(infinityEnch, enchantmentLevel);

    inv.addItem(infinityarrow);


    }


    Any help is appreciated!

    Regards,
    Peavalu
     
  2. @Peavalu
    Use addUnsafeEnchantment() instead.
     
    Peavalu and Darkpicasa like this.
  3. Offline

    Peavalu

    Thank you for your answer. It did work, sort of.
    Altho I was the fool who was trying hard to put infinity I onto an arrow and hoping it to work afterwards. Infinity I is a bow enchant afterall.
    :p

    Best regards,
    Peavalu
     
    Last edited: Dec 14, 2014
  4. Offline

    mine-care

    @Peavalu Please mark the thread solved. =)
     
Thread Status:
Not open for further replies.

Share This Page