Don't know how add NBT tag

Discussion in 'Plugin Development' started by uapvp, Jul 11, 2023.

Thread Status:
Not open for further replies.
  1. Offline

    uapvp

    So, I am very bad at coding Java. And I tried to make plugin that makes a custom recipe for smithing table at 1.20.1, it works, but result item doesn't have unbreakable NBT.

    Code:
    package uapvp.newnetherite;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.NamespacedKey;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.RecipeChoice;
    import org.bukkit.inventory.SmithingRecipe;
    import org.bukkit.inventory.SmithingTransformRecipe;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    import net.md_5.bungee.api.ChatColor;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class NewNetherite extends JavaPlugin {
    
        @Override
        public void onEnable() {
            // Регистрация рецепта
            registerSmithingRecipe();
        }
    
        private void registerSmithingRecipe() {
            ItemStack template = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);
            ItemStack base = new ItemStack(Material.SHEARS);
            ItemStack addition = new ItemStack(Material.NETHERITE_INGOT);
            ItemStack result = new ItemStack(Material.SHEARS);
    
            // Установка NBT-тега Unbreakable
            ItemMeta resultMeta = result.getItemMeta();
            resultMeta.setUnbreakable(true);
            result.setItemMeta(resultMeta);
    
            RecipeChoice.ExactChoice templateChoice = new RecipeChoice.ExactChoice(template);
            RecipeChoice.ExactChoice baseChoice = new RecipeChoice.ExactChoice(base);
            RecipeChoice.ExactChoice additionChoice = new RecipeChoice.ExactChoice(addition);
    
            SmithingRecipe smithingRecipe = new SmithingTransformRecipe(
                    new NamespacedKey(this, "custom_smithing_recipe"),
                    result,
                    templateChoice,
                    baseChoice,
                    additionChoice
            );
    
            Bukkit.addRecipe(smithingRecipe);
        }
    }
    I will be glad for any help
     
Thread Status:
Not open for further replies.

Share This Page