如何在配方中使用 itemStack。

huangapple go评论122阅读模式
英文:

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, &quot;emerald_sword&quot;);
ShapedRecipe recipe = new ShapedRecipe(key, sword);
recipe.shape(&quot; E &quot;, &quot; E &quot;, &quot; S &quot;);
recipe.setIngredient(&#39;E&#39;, RecipeChoice.ExactChoice(enchantedEmerald));// part not working
recipe.setIngredient(&#39;S&#39;, Material.STICK);
Bukkit.addRecipe(recipe);

Emerald sword

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

Enchanted emerald

ItemStack enchantedEmerald = new ItemStack( Material.EMERALD );
ItemMeta EEM = enchantedEmerald.getItemMeta();
EEM.setDisplayName(&quot;enchanted Emerald&quot;);
ArrayList&lt;String&gt; lore = new ArrayList&lt;String&gt;();
lore.add(&quot;enchanted Emeralds is an rare material&quot;);
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(&quot; E &quot;, &quot; E &quot;, &quot; S &quot;);
recipe.setIngredient(&quot;E&quot;, RecipeChoice.ExactChoice(enchantedEmerald));
recipe.setIngredient(&quot;S&quot;, 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.

huangapple
  • 本文由 发表于 2020年9月12日 22:50:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/63861566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定