Search in sources :

Example 1 with RecipeShapedOreLarge

use of com.builtbroken.mc.lib.recipe.item.grid.RecipeShapedOreLarge in project Engine by VoltzEngine-Project.

the class JsonCraftingRecipeData method genRecipes.

@Override
public void genRecipes(List<IRecipe> recipes) {
    //If output is a string convert
    if (output instanceof String) {
        Object out = convertItemEntry((String) output);
        if (out != null) {
            output = out;
        }
    }
    if (shaped) {
        //Shaped starts with a series of strings representing the grid, then goes "char, item, char2, item2...."
        boolean convert = false;
        int gridEnd = 0;
        for (int i = 0; i < data.length; i++) {
            Object dataObject = data[i];
            //Do not convert until after the first char entry
            if (dataObject instanceof Character) {
                if (gridEnd == 0) {
                    gridEnd = i;
                }
                convert = true;
            } else if (convert) {
                Object out = convertItemEntry((String) dataObject);
                if (out != null) {
                    data[i] = out;
                } else {
                    Engine.logger().error("The item value of [" + dataObject + "] could not be parsed into a valid recipe item entry. Recipe -> " + this);
                    return;
                }
            }
        }
        //Create recipe
        if (output instanceof Block) {
            if (largeGrid) {
                recipes.add(new RecipeShapedOreLarge((Block) output, data));
            } else {
                recipes.add(new ShapedOreRecipe((Block) output, data));
            }
        } else if (output instanceof Item) {
            if (largeGrid) {
                recipes.add(new RecipeShapedOreLarge((Item) output, data));
            } else {
                recipes.add(new ShapedOreRecipe((Item) output, data));
            }
        } else if (output instanceof ItemStack) {
            if (largeGrid) {
                recipes.add(new RecipeShapedOreLarge((ItemStack) output, data));
            } else {
                recipes.add(new ShapedOreRecipe((ItemStack) output, data));
            }
        } else {
            Engine.logger().error("The type of output value [" + output + "] could not be recognized for recipe creation. Recipe -> " + this);
        }
    } else {
        //Shapeless is an array of string data
        for (int i = 0; i < data.length; i++) {
            Object dataObject = data[i];
            if (dataObject instanceof String) {
                //Convert entries to correct outputs
                Object out = convertItemEntry((String) dataObject);
                if (out != null) {
                    data[i] = out;
                } else {
                    Engine.logger().error("The item value of [" + dataObject + "] could not be parsed into a valid recipe item entry. Recipe -> " + this);
                    return;
                }
            } else {
                Engine.logger().error("The item value of [" + dataObject + "] is not a valid string for parsing. Recipe -> " + this);
                return;
            }
        }
        //Create recipe
        if (output instanceof Block) {
            recipes.add(new ShapelessOreRecipe((Block) output, data));
        } else if (output instanceof Item) {
            recipes.add(new ShapelessOreRecipe((Item) output, data));
        } else if (output instanceof ItemStack) {
            recipes.add(new ShapelessOreRecipe((ItemStack) output, data));
        } else {
            Engine.logger().error("The type of output value [" + output + "] could not be recognized for recipe creation. Recipe -> " + this);
        }
    }
}
Also used : Item(net.minecraft.item.Item) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) RecipeShapedOreLarge(com.builtbroken.mc.lib.recipe.item.grid.RecipeShapedOreLarge)

Aggregations

RecipeShapedOreLarge (com.builtbroken.mc.lib.recipe.item.grid.RecipeShapedOreLarge)1 Block (net.minecraft.block.Block)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)1 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)1