Solved Ingredient Name

Discussion in 'Plugin Development' started by mehboss, Feb 24, 2017.

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

    mehboss

    What is the easiest way to make it so an ingredient on a crafting recipe has a display name. I tried this

    I have tried
    Code:
                    Material mi = Material.matchMaterial(lin2);
                 
                    ItemStack mms = new ItemStack(mi);
                    ItemMeta mm = mms.getItemMeta();
                 
                    mm.setDisplayName(ChatColor.translateAlternateColorCodes('&', b[2]));
                    mms.setItemMeta(mm);
                 
                    R.setIngredient(lin1, mms.getData());
    The closest thing I have found is PrepareItemCraft event
     
  2. Offline

    MrGeneralQ

    I'm not sure but are you talking about existing recipes or new ones?

    UPDATE:

    Okay so I tought about a solution. Not sure if it will work at all, but can't you add a custom recipe that is actually the same and overwrite that recipe and change the item you get from there

    Here is how you do that
    https://www.spigotmc.org/wiki/recipe-example/

    I hope it helps
     
    Last edited: Feb 24, 2017
  3. Offline

    mehboss

    It shouldn't matter. New ones. I want to set the ingredient to have not just a material but a display name so the item can only be crafted if the ingredient had the display name.


    Sent from my iPhone using Tapatalk
     
  4. Offline

    MrGeneralQ

    I updated my post in the meanwhile, maybe that does help you
     
  5. Offline

    mehboss

    That has nothing to do with what I'm talking about I already have the item I can craft but I can craft it with the material and any display name on that material.

    Example: I make it so I need 4 tnt in a square NAMED Reaper or something to be able to craft let's say, a staff.

    I want the ingredient to have a certain display name.


    Sent from my iPhone using Tapatalk
     
  6. Offline

    MrGeneralQ

    Oooow I see ... I'm afraid I have to experiment a bit with that. Not sure if I will Find out, sorry mate :/
     
  7. Offline

    Zombie_Striker

    @mehboss
    Use PrepareItemCraftEvent. This is called when a player creates an already registered recipe. When a player tries to create the recipe you want, check if a specific items has a displayname. If it does, do nothing. If not, set the "result" to air.
     
  8. Offline

    mehboss

    @Zombie_Striker
    Do I check if what they are putting in is an existing recipe by doing:

    Code:
    ShapedRecipe R = new ShapedRecipe(i);
    
            if (e.getRecipe.equals(R)) {
     
  9. Offline

    Zombie_Striker

    @mehboss
    Yes, as long as R is the same instance as the recipe you register.
     
  10. Offline

    mehboss

    @Zombie_Striker
    How would I make it the same instance if the "new shapeless" variable is in a seperate void

    Code:
    @SuppressWarnings("deprecation")
        public void addItems() {
    
            Plugin config = Bukkit.getPluginManager().getPlugin("CustomRecipes");
    
            for (String item : config.getConfig().getConfigurationSection("Items").getKeys(false)) {
                int type = config.getConfig().getInt("Items." + item + ".Item");
    
                ItemStack i = new ItemStack(Material.getMaterial(type));
                ItemMeta m = i.getItemMeta();
    
                m.setDisplayName(ChatColor.translateAlternateColorCodes('&',
                        config.getConfig().getString("Items." + item + ".Name")));
    
                ShapedRecipe R = new ShapedRecipe(i);
    
                //snipped code
            }
        }
     
  11. Offline

    Zombie_Striker

    @mehboss
    Store the instance in a field.
     
  12. Offline

    mehboss

    @Zombie_Striker
    I am probably doing this wrong but I did this, it does nothing.

    Code:
        ShapedRecipe R = null;
    //won't be null because variable gets set right on enable
    
    
        @EventHandler
        public void check(PrepareItemCraftEvent e) {
    
            CraftingInventory inv = e.getInventory();
    
            Plugin config = Bukkit.getPluginManager().getPlugin("CustomRecipes");
    
            if (inv.getType() == InventoryType.WORKBENCH) {
                if (e.getRecipe().equals(R)) {
                      Bukkit.broadcastMessage("test");
    
    I debugged using send messages and the "getRecipe" line isn't working.
     
    Last edited: Feb 24, 2017
  13. Offline

    Zombie_Striker

    @mehboss
    Try comparing results/ ingredients instead of comparing whole instances.
     
  14. Offline

    mehboss

    Haha, thanks dude.

    RESULT:
    Code:
                if (e.getRecipe().getResult().equals(R.getResult())) {
     
Thread Status:
Not open for further replies.

Share This Page