Search in sources :

Example 31 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.

the class CraftingPlugin method addRecipe.

public static void addRecipe(@Nullable ItemStack result, Object... recipeArray) {
    ProcessedRecipe processedRecipe;
    try {
        processedRecipe = processRecipe(RecipeType.SHAPED, result, recipeArray);
    } catch (InvalidRecipeException ex) {
        Game.logTrace(Level.WARN, ex.getRawMessage());
        return;
    }
    if (processedRecipe.isOreRecipe) {
        IRecipe recipe = new ShapedOreRecipe(processedRecipe.result, processedRecipe.recipeArray);
        addRecipe(recipe);
    } else
        GameRegistry.addRecipe(processedRecipe.result, processedRecipe.recipeArray);
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) InvalidRecipeException(mods.railcraft.common.util.crafting.InvalidRecipeException)

Example 32 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Railcraft by Railcraft.

the class RollingMachinePlugin method generateRecipes.

@Override
public void generateRecipes(RecipeGenerator generator) {
    ItemStack machine = EquipmentVariant.ROLLING_MACHINE_POWERED.getStack();
    if (machine != null) {
        RecipeTemplate template = generator.createRecipeTemplate(slots, machine, "/gui/CraftGuideRecipe.png", 163, 1, 163, 61);
        for (IRecipe recipe : RailcraftCraftingManager.rollingMachine.getRecipeList()) {
            Object[] array = new Object[11];
            System.arraycopy(generator.getCraftingRecipe(recipe), 0, array, 0, 10);
            array[10] = machine;
            generator.addRecipe(template, array);
        }
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 33 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Engine by VoltzEngine-Project.

the class JsonRecipeReplacementProcessor method loadComplete.

@Override
public void loadComplete() {
    //Init replacement data
    Iterator it = replacementData.iterator();
    while (it.hasNext()) {
        JsonRecipeReplacementData data = (JsonRecipeReplacementData) it.next();
        if (data.output == null) {
            data.output = data.convertItemEntry(data.outputValue);
        }
        if (data.output == null) {
            Engine.logger().error("JsonRecipeReplacementProcessor: Failed to locate item entry for '" + data.outputValue + "' ignoring value.");
            it.remove();
        }
    }
    //Loop recipes and remove entries
    it = CraftingManager.getInstance().getRecipeList().iterator();
    while (it.hasNext()) {
        Object r = it.next();
        if (r instanceof IRecipe) {
            final ItemStack result = ((IRecipe) r).getRecipeOutput();
            if (result != null) {
                //Loop replacement data checking for match
                for (JsonRecipeReplacementData data : replacementData) {
                    if ("grid".equalsIgnoreCase(data.craftingType) && data.doesMatchForReplacement(result)) {
                        Engine.logger().info("JsonRecipeReplacementProcessor: Removed recipe -> " + r);
                        //Remove and exit loop
                        it.remove();
                        break;
                    }
                }
            } else //Error to note broken recipe might exist
            {
                Engine.logger().error("JsonRecipeReplacementProcessor: Potential broken recipe with no output -> " + r);
            }
        }
    }
    //Loop to finalize data
    for (JsonRecipeReplacementData data : replacementData) {
        if (!data.subProcessingData.isEmpty()) {
            final List<IJsonGenObject> objects = new ArrayList();
            for (Map.Entry<String, JsonElement> entry : data.subProcessingData.entrySet()) {
                JsonContentLoader.INSTANCE.process(entry.getKey(), entry.getValue(), objects);
            }
            JsonContentLoader.INSTANCE.handlePostCalls(objects);
        }
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) JsonElement(com.google.gson.JsonElement) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map)

Example 34 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project Engine by VoltzEngine-Project.

the class ModManager method firePostInit.

/**
     * Called during post init phase of mod loading
     */
public void firePostInit() {
    for (Object object : temp_registry_list) {
        if (object instanceof IPostInit) {
            ((IPostInit) object).onPostInit();
        }
    }
    for (Object object : temp_registry_list) {
        if (object instanceof IRecipeContainer) {
            List<IRecipe> recipes = new ArrayList();
            ((IRecipeContainer) object).genRecipes(recipes);
            for (IRecipe recipe : recipes) {
                if (recipe.getRecipeOutput() != null) {
                    if (recipe.getRecipeOutput().getItem() != null) {
                        if (recipe.getRecipeOutput().getMaxStackSize() > 0) {
                            //TODO check that input -> output
                            //TODO check for basic errors
                            //TODO check size
                            //TODO check for missing items
                            //TODO check for oreName replacement
                            GameRegistry.addRecipe(recipe);
                        } else if (Engine.runningAsDev) {
                            throw new IllegalArgumentException("Recipe[" + recipe + "] output's stack size is less than 1");
                        }
                    } else if (Engine.runningAsDev) {
                        throw new IllegalArgumentException("Recipe[" + recipe + "] output's item is null");
                    }
                } else if (Engine.runningAsDev) {
                    throw new IllegalArgumentException("Recipe[" + recipe + "] output is null");
                }
            }
        }
    }
}
Also used : IPostInit(com.builtbroken.mc.core.registry.implement.IPostInit) IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) IRecipeContainer(com.builtbroken.mc.core.registry.implement.IRecipeContainer)

Aggregations

IRecipe (net.minecraft.item.crafting.IRecipe)34 ItemStack (net.minecraft.item.ItemStack)25 ArrayList (java.util.ArrayList)12 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)7 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)7 List (java.util.List)4 CraftingSetType (logisticspipes.network.packets.block.CraftingSetType)4 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)4 HashMap (java.util.HashMap)3 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)3 Block (net.minecraft.block.Block)3 Item (net.minecraft.item.Item)3 IPostInit (com.builtbroken.mc.core.registry.implement.IPostInit)2 IRecipeContainer (com.builtbroken.mc.core.registry.implement.IRecipeContainer)2 IJsonGenObject (com.builtbroken.mc.lib.json.imp.IJsonGenObject)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 AutoCraftingInventory (logisticspipes.blocks.crafting.AutoCraftingInventory)2 InvalidRecipeException (mods.railcraft.common.util.crafting.InvalidRecipeException)2 ChatComponentText (net.minecraft.util.ChatComponentText)2