Work only one craft

Discussion in 'Plugin Development' started by InsTCube, May 30, 2021.

  1. Offline

    InsTCube

    Code:
    package feudal.main;
    
    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.NamespacedKey;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class FeudalRPG extends JavaPlugin {
    
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(new Handler(), this);
            Bukkit.getPluginManager().registerEvents(new Items(), this);
            Bukkit.getPluginManager().registerEvents(new Blocks(), this);
            getLogger().info("Successfully enabled!");
            upgradeTableCraft();
            autoSmeltPickCraft();
       
        }
    
        public void onDisable() {
            getLogger().info("Disabled!");
       
        }
    
        private void autoSmeltPickCraft() {
            ItemStack item = new ItemStack(Material.STONE_PICKAXE);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(ChatColor.GREEN + "Better pickaxe");
            List<String> lore = new ArrayList<String>();
            lore.add(ChatColor.AQUA + "This pickaxe break smeltede blocks!");
            lore.add(" ");
            lore.add(ChatColor.translateAlternateColorCodes('&', "&f&lLevel: &e1"));
            lore.add(" ");
            lore.add(ChatColor.RED + "==============");
            lore.add(" ");
            lore.add(ChatColor.translateAlternateColorCodes('&', "&f&lRare: &aRare"));
            meta.setLore(lore);
            meta.setUnbreakable(true);
            meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
            item.setItemMeta(meta);
            NamespacedKey smeltpick = new NamespacedKey(this, "AutoMeltPick");
            ShapedRecipe s = new ShapedRecipe(smeltpick, item);
            s.shape("CFC", " N ", " S ");
            s.setIngredient('C', Material.COBBLESTONE);
            s.setIngredient('F', Material.FURNACE);
            s.setIngredient('N', Material.NETHER_STAR);
            s.setIngredient('S', Material.STICK);
            getServer().addRecipe(s);
        }
        private void upgradeTableCraft() {
            ItemStack item = new ItemStack(Material.SMITHING_TABLE);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(ChatColor.GREEN + "Upgrade center");
            List<String> lore = new ArrayList<String>();
            lore.add(ChatColor.AQUA + "You can upgrade equipment!");
            lore.add(" ");
            lore.add(ChatColor.RED + "==============");
            lore.add(" ");
            lore.add(ChatColor.translateAlternateColorCodes('&', "&f&lRare: &aRare"));
            meta.setLore(lore);
            meta.setUnbreakable(true);
            meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
            item.setItemMeta(meta);
            NamespacedKey smeltpick = new NamespacedKey(this, "AutoMeltPick");
            ShapedRecipe s = new ShapedRecipe(smeltpick, item);
            s.shape("ICI", "IGI", "FAF");
            s.setIngredient('I', Material.IRON_INGOT);
            s.setIngredient('F', Material.FURNACE);
            s.setIngredient('C', Material.FIRE_CHARGE);
            s.setIngredient('A', Material.ANVIL);
            s.setIngredient('G', Material.GUNPOWDER);
            getServer().addRecipe(s);
        }
    In onEnable i made
    upgradeTableCraft(); <--- This work
    autoSmeltPickCraft(); <--- This not
    This is crafts but only the one above works
    This is not an error in the craft code, I swapped them and each of them worked.

    I dont now what happend

    Please help
    Sorry for my English, I think I wrote it clearly. I do not know English. I wrote it from memory.

    - InsTCube
     
  2. Offline

    Shqep

    @InsTCube
    PHP:
    NamespacedKey smeltpick = new NamespacedKey(this"AutoMeltPick");
    You assigned different recipes for the same namespaced key so they overrode each other. Change the one in upgradeTableCraft() to something else?
     

Share This Page