我想创建新项目。我称它为生命水晶。我还为此新项目创建了新食谱。我的问题是当我尝试制作该物品时,我制作的是普通物品而没有新的显示名称和结界。我的代码如下所示。
// Life Crystal
ItemStack lifecrystal = new ItemStack(Material.DIAMOND);
NamespacedKey lifecrystalKey = new NamespacedKey((Plugin) this, "lifecrystal");
ShapedRecipe lifecrystalRecipe = new ShapedRecipe(lifecrystalKey, lifecrystal);
ItemMeta lifecrystalLabel = lifecrystal.getItemMeta();
lifecrystalLabel.setDisplayName(ChatColor.GOLD + "Life Crystal");
lifecrystalLabel.addEnchant(Enchantment.BINDING_CURSE, 1, false);
lifecrystal.setItemMeta(lifecrystalLabel);
lifecrystalRecipe.shape(" E ", "LAL", "DRD");
lifecrystalRecipe.setIngredient('E', Material.EMERALD);
lifecrystalRecipe.setIngredient('L', Material.LAPIS_LAZULI);
lifecrystalRecipe.setIngredient('A', Material.GOLDEN_APPLE);
lifecrystalRecipe.setIngredient('R', Material.GOLD_INGOT);
lifecrystalRecipe.setIngredient('D', Material.DIAMOND);
Bukkit.addRecipe(lifecrystalRecipe);
编辑:我的方法.setDisplayName显示错误:(方法调用集显示名称可能会产生null)
您应该首先使用所有自定义元数据制作ItemStack
,然后制作配方。
ItemStack lifecrystal = new ItemStack(Material.DIAMOND);
ItemMeta lifecrystalLabel = lifecrystal.getItemMeta();
lifecrystalLabel.setDisplayName(ChatColor.GOLD + "Life Crystal");
lifecrystalLabel.addEnchant(Enchantment.BINDING_CURSE, 1, false);
lifecrystal.setItemMeta(lifecrystalLabel);
NamespacedKey lifecrystalKey = new NamespacedKey((Plugin) this, "lifecrystal");
ShapedRecipe lifecrystalRecipe = new ShapedRecipe(lifecrystalKey, lifecrystal);
lifecrystalRecipe.shape(" E ", "LAL", "DRD");
lifecrystalRecipe.setIngredient('E', Material.EMERALD);
lifecrystalRecipe.setIngredient('L', Material.LAPIS_LAZULI);
lifecrystalRecipe.setIngredient('A', Material.GOLDEN_APPLE);
lifecrystalRecipe.setIngredient('R', Material.GOLD_INGOT);
lifecrystalRecipe.setIngredient('D', Material.DIAMOND);
Bukkit.addRecipe(lifecrystalRecipe);