Enchantments on Custom Recipes

Discussion in 'Plugin Development' started by Nedinator, Apr 19, 2015.

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

    Nedinator

    So I have a plugin that got "abandoned" and I would like to pick it up. Problem is I never actually got it working. For some reason, whenever I added enchantments to custom weapons/tools it didn't work.

    Heres the code I've been trying :

    Code:
    private void dSword() {
            ItemStack dsw = new ItemStack(Material.DIAMOND_SWORD, 1);
            ItemMeta meta = dsw.getItemMeta();
            meta.setDisplayName(ChatColor.GOLD + "Super Diamond Sword");
            meta.setLore(Arrays.asList(ChatColor.BLUE + "Reinforced diamond sword."));
            dsw.addEnchantment(Enchantment.DAMAGE_ALL, 3);
            dsw.addEnchantment(Enchantment.DURABILITY, 3);
            dsw.addEnchantment(Enchantment.FIRE_ASPECT, 2);
            dsw.setItemMeta(meta);
            ShapedRecipe dSword = new ShapedRecipe(dsw);
            dSword.shape(" @ ", " @ ", " # ");
            dSword.setIngredient('@', Material.IRON_BLOCK);
            dSword.setIngredient('#', Material.STICK);
            Bukkit.getServer().addRecipe(dSword);
        }
    I had an old thread about this same problem back in december but it was never solved, just closed after I bumped it.

    Any help is appreciated.

    -Nedinator
     
  2. Offline

    sgavster

    try dsw.addUnsafeEnchantment (or you might use the meta, no IDE atm)
    Also, I think the recipe should be in onEnable, not there.
     
  3. Offline

    Nedinator

    I'll try the unsafe enchantment later. And I have it added into the onEnable.
     
  4. Offline

    sgavster

  5. Offline

    Nedinator

    The recipe works fine. But the enchantment does not.
     
  6. Offline

    sgavster

    Try using this:
    meta.addEnchant(Enchantment, level, false);
    This works fine for me.
    This is my code(for an example.)
    Code:
        public ItemStack heatPick() {
            ItemStack hp = new ItemStack(Material.DIAMOND_PICKAXE);
            ItemMeta hpm = hp.getItemMeta();
            hpm.setDisplayName("§4Heat Pickaxe");
            hpm.addEnchant(Enchantment.DIG_SPEED, 2, false);
            hpm.addEnchant(Enchantment.DURABILITY, 2, false);
            List<String> hpl = new ArrayList<String>();
            hpl.add("§7Heat I");
            hpm.setLore(hpl);
            hp.setItemMeta(hpm);
            return hp;
        }
     
  7. Offline

    TehHypnoz

    What happens when you add the enchantment after you set the item meta?
     
Thread Status:
Not open for further replies.

Share This Page