Custom Inventory with enchantments

Discussion in 'Plugin Development' started by Legocowchaser, Nov 30, 2013.

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

    Legocowchaser

    How do I make an item in my custom inventory have an enchantment?

    Code:
                    myInventory.setItem(1, new ItemStack(Material.DIAMOND_SWORD, 2));
     
  2. Offline

    sgavster

    Code:java
    1. ItemStack dsword = new ItemStack(Material.DIAMOND_SWROD, 2);
    2. dsword.addEnchantment(Enchantment.DAMAGE_ALL, 1);
    3. myInventory.setItem(1, dsword);
     
    Legocowchaser likes this.
  3. Offline

    Legocowchaser

    sgavster Thanks that looks like what I wanted. [diamond] It is kind of funny because I had looked at your profile ealier today from a different thread. :D

    What about colors?
    Code:
            ItemStack hat = new ItemStack(Material.LEATHER_HELMET, 1);
            hat.setColor(DyeColor.RED);
            myInventory.setItem(0, hat);
    sgavster

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

    sgavster

    Legocowchaser
    Code:java
    1. ItemStack hat = new ItemStack(Material.LEATHER_HELMET);
    2. LeatherArmorMeta hm = (LeatherArmorMeta) hat.getItemMeta();
    3. hm.setColor(Color.RED);
    4. hat.setItemMeta(hm);
    5. myInventory.setItem(0, hat);
     
    Legocowchaser likes this.
  5. Offline

    Legocowchaser

Thread Status:
Not open for further replies.

Share This Page