Recipe help

Discussion in 'Plugin Development' started by MadMaxCookie, May 29, 2016.

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

    MadMaxCookie

    First I'm saving the recipe with this kind of code

    Code:
    ShapedRecipe recipe = new ShapedRecipe(ca.getConfig().getItemStack(cs + ".Product"));
                       
                        // the recipes shape
                        recipe.shape("123", "456", "789");
                       
                        for(Integer i = 1; i <= 9; i++) {
                            try {
                                recipe.setIngredient(i.toString().toCharArray()[0], ca.getConfig().getItemStack(cs + ".Slot" + i).getData());
                            }catch(NullPointerException e) {}
                        }
    all I want is to save the ingredient's ItemStack not its MaterialData so that when they try to craft and input the ingredient's itemstack with displayname the result would be shown to player.
     
  2. Offline

    Zombie_Striker

    @MadMaxCookie
    You have to listen for the PrepareItemCraftEvent and check if your recipe is being craft. From there, you can test each of the ingedient's data. If you don't want the player to be able to craft the item, just cancel the event,
     
  3. Offline

    MadMaxCookie

    @Zombie_Striker

    I have this config
    Code:
    recipeName:
    
        Slot 1:
            ItemStack
        Slot 2:
            ItemStack
        Slot ...9;
            ItemStack
         Product:
            ItemStack
         Type:
            Shaped , Shapeless, Furnace
    
    others:
    and I used the event
    Code:
    ConfigAccessor ca = ConfigAccessor.getInstance();
            Set<String> cs = ca.getConfig().getKeys(false);
           for(Integer i =1; i <=9; i++){
                ItemStack[] slots ={ca.getConfig().getItemStack(cs +".Slot"+ i)};
                if(slots == e.getMatrix()) {
                         // set the result to air
                }
           }
    but nothing happens.
     
  4. Offline

    Zombie_Striker

    @MadMaxCookie
    This is an issue with "==" vs ".equals". You use '==' when you want to check memory location of the objects. You use .equals when you want to check the values of the objects.

    Even still, comparing if every single value is the same is not what you want. What if the player placed two itemstacks into the crafting grid instead of one? You should test if the type, durability, name, and any other specific data you need instead.
     
  5. Offline

    MadMaxCookie

Thread Status:
Not open for further replies.

Share This Page