gpt4 book ai didi

java - Bukkit - 使用自定义配方添加自定义项目

转载 作者:行者123 更新时间:2023-12-01 19:36:26 26 4
gpt4 key购买 nike

我想创建新项目。我称之为生命 Crystal 。我还为这个新项目创建了新配方。我的问题是,当我尝试制作该元素时,我制作了普通元素,没有新的显示名称和结界。我的代码如下所示。

 // 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);

关于java - Bukkit - 使用自定义配方添加自定义项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59214993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com