英文:
how do i use itemStack in recipe
问题
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 a 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?
英文:
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?
答案1
得分: 0
你可以使用这个链接:https://gist.github.com/MrMaurice211/6b2f8d0909900efe3f4383030ea781e6
而且这应该会起作用:
ShapedRegister recipe = new ShapedRegister(ItemStack);
recipe.shape(" E ", " E ", " S ");
recipe.setIngredient("E", RecipeChoice.ExactChoice(enchantedEmerald));
recipe.setIngredient("S", Material.STICK);
recipe.register();
来源:https://www.spigotmc.org/threads/spigot-recipe-with-itemstack.284800/
英文:
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/
答案2
得分: 0
所以... 你的第一个代码对我有效 zaze。我正在使用1.18的spigot API。
英文:
So... your first code works for me zaze. I'm using 1.18 spigot API.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论