-1

I'm making a plugin using 1.16 spigot API and I'm stuck trying to get an itemStack in the recipe. I was using 1.8 spigot API but when I'm realized that I was either in need of a third party API or making my own crafting system I chose to change from 1.8 to 1.16

Recipe

NamespacedKey key = new NamespacedKey(this, "emerald_sword");
ShapedRecipe recipe = new ShapedRecipe(key, sword);
recipe.shape(" E ", " E ", " S ");
recipe.setIngredient('E', RecipeChoice.ExactChoice(enchantedEmerald));// part not working
recipe.setIngredient('S', Material.STICK);
Bukkit.addRecipe(recipe);

Emerald sword

ItemStack sword = new ItemStack( Material.DIAMOND_SWORD );
ItemMeta IM = sword.getItemMeta();
IM.setDisplayName(ChatColor.GREEN + "Emerald Sword" );
sword.setItemMeta( IM );
sword.addEnchantment( Enchantment.DAMAGE_ALL, 5 );

Enchanted emerald

ItemStack enchantedEmerald = new ItemStack( Material.EMERALD );
ItemMeta EEM = enchantedEmerald.getItemMeta();
EEM.setDisplayName("enchanted Emerald");
ArrayList<String> lore = new ArrayList<String>();
lore.add("enchanted Emeralds is an rare material");
EEM.setLore(lore);
enchantedEmerald.setItemMeta(EEM);

the order is the emerald sword, enchanted emerald, and recipe

how can I use itemStack in a recipe?

zaze
  • 37
  • 1
  • 1
  • 6

2 Answers2

0

You can use this : https://gist.github.com/MrMaurice211/6b2f8d0909900efe3f4383030ea781e6 and this should work:

ShapedRegister recipe = new ShapedRegister(ItemStack);
recipe.shape(" E ", " E ", " S ");
recipe.setIngredient("E", RecipeChoice.ExactChoice(enchantedEmerald));
recipe.setIngredient("S", Material.STICK);
recipe.register();

Source : https://www.spigotmc.org/threads/spigot-recipe-with-itemstack.284800/

BigPouley
  • 91
  • 2
0

So... your first code works for me zaze. I'm using 1.18 spigot API.

  • 1
    well, then they have changed it. Well, it's for an old project and I have now left the development of plugins for Minecraft, hardly even doing mods today but hope you can get things to work in ways I whasent. – zaze Feb 15 '22 at 21:08