Solved Making my own crafting table type system

Discussion in 'Plugin Development' started by Blockhead7360, Sep 5, 2016.

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

    Blockhead7360

    Hello! I know I posted something about this before, but now I have another problem.

    Basically, I made my own crafting GUI that accepts ItemStacks instead of just Materials like the regular crafting table.

    However, even when I enter a correct recipe, it says that the recipe isn't correct.

    Here is my method that checks to see if the recipe is correct:
    Code:
    public static ItemStack isCrafting(List<ItemStack> inv){
            //-123
            //A---
            //B---
            //C---
           
           
            for (CraftingRecipe cr : recipes){
                List<ItemStack> crs = new ArrayList<ItemStack>();
                for (String s1 : cr.getCreator().getShape()){
                    for (int s2 = 0; s2 < s1.length(); s2++){
                        if (s1.charAt(s2) == ' '){
                            crs.add(new ItemStack(Material.AIR, 1));
                        }else{
                            crs.add(cr.getCreator().getIngredients().get(s1.charAt(s2)));
                        }
                    }
                }
                if (isRecipe(crs, inv)){
                    return cr.getOutput();
                }
               
            }
            return null;
    
        }
    Here is "isRecipe()":
    Code:
    public static boolean isRecipe(List<ItemStack> correct, List<ItemStack> inv){
            int m = 0;
            for (int i = 0; i < correct.size(); i++){
                if (correct.get(i).equals(inv.get(i))){
                    m++;
                }
            }
            return m == correct.size();
           
           
        }
    Here is where the List<ItemStack> inv is generated:
    Code:
    public List<ItemStack> invToRecipe(Inventory inventory){
            List<ItemStack> provided = new ArrayList<ItemStack>();
            int[] allSlots = new int[]{12, 13, 14, 21, 22, 23, 30, 31, 32};
            for (int i : allSlots){
                if (inventory.getItem(i) == null){
                    provided.add(new ItemStack(Material.AIR, 1));
                }else{
                    provided.add(inventory.getItem(i));
                }
            }
           
            return provided;
        }
    The allSlots numbers are the slots of the inventory that have the crafting recipe.

    Here is the method where I added the test recipe:
    Code:
    CustomCraftingTable table = new CustomCraftingTable(1);
            CraftingRecipe destroyTool = new CraftingRecipe(table.dest());
            destroyTool = destroyTool.creator()
                    .setShape("GSG", "GSG", "GSG")
                    .setIngredient('G', new ItemStack(Material.GOLD_NUGGET, 1))
                    .setIngredient('S', new ItemStack(Material.STICK, 1))
                    .create();
    That CraftingRecipe is added to the "recipes" list as shown in the methods above.
    The ingredients is a hashmap character and ItemStack.
    The shape is a String[]{arg1, arg2, arg3}

    Please help, thanks!
     
  2. Offline

    Zombie_Striker

    @Blockhead7360
    Have you tried debugging? Have you tried printing out the two values?
    BTW: This will check for types, lore, names, Durability, and Amount. This means there has to be only one item in the stack and any weapons or tools cannot be damaged.
     
    Blockhead7360 likes this.
  3. Offline

    Blockhead7360

    @Zombie_Striker fixed it. You see the "table.dest()" in the last method? I forgot to finish creating that.

    Marking as solved.
     
Thread Status:
Not open for further replies.

Share This Page