Search in sources :

Example 16 with IRecipe

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

the class RecipeUtility method removeRecipes.

/**
	 * Removes all recipes found that has this output. You may use this with Forge Ore Dictionary to
	 * remove all recipes with the FoD ID.
	 *
	 * @return True if successful
	 */
public static boolean removeRecipes(ItemStack... itemStacks) {
    boolean didRemove = false;
    for (Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); itr.hasNext(); ) {
        Object obj = itr.next();
        if (obj != null) {
            if (obj instanceof IRecipe) {
                if (((IRecipe) obj).getRecipeOutput() != null) {
                    for (ItemStack itemStack : itemStacks) {
                        if (((IRecipe) obj).getRecipeOutput().isItemEqual(itemStack)) {
                            itr.remove();
                            didRemove = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    return didRemove;
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) Iterator(java.util.Iterator) ItemStack(net.minecraft.item.ItemStack)

Example 17 with IRecipe

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

the class JsonContentLoader method handlePostCalls.

/**
     * Called to handle post call code on generated objects.
     * <p>
     * Separated from {@link #postInit()} due to other processors
     * having special handling.
     *
     * @param generatedObjects
     */
public void handlePostCalls(List<IJsonGenObject> generatedObjects) {
    if (generatedObjects != null && !generatedObjects.isEmpty()) {
        for (IJsonGenObject obj : generatedObjects) {
            debug.start("Handling: " + obj);
            if (obj instanceof IPostInit) {
                ((IPostInit) obj).onPostInit();
            }
            if (obj instanceof IRecipeContainer) {
                List<IRecipe> recipes = new ArrayList();
                ((IRecipeContainer) obj).genRecipes(recipes);
                if (recipes.size() > 0) {
                    debug.start("Adding recipes from gen object:");
                    for (IRecipe recipe : recipes) {
                        if (recipe != null) {
                            if (recipe.getRecipeOutput() != null) {
                                GameRegistry.addRecipe(recipe);
                            } else {
                                debug.log("Null recipe output detected");
                            }
                        } else {
                            debug.log("Null recipe detected");
                        }
                    }
                    debug.end();
                }
            }
            debug.end();
        }
    }
}
Also used : IPostInit(com.builtbroken.mc.core.registry.implement.IPostInit) IRecipe(net.minecraft.item.crafting.IRecipe) IJsonGenObject(com.builtbroken.mc.lib.json.imp.IJsonGenObject) IRecipeContainer(com.builtbroken.mc.core.registry.implement.IRecipeContainer)

Example 18 with IRecipe

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

the class CommandJsonRecipe method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
        if (args[0].equals("generate") || args[0].equals("gen")) {
            if (args.length > 1) {
                String entryID = args[1];
                ItemStack stack = new JsonCraftingRecipeData(null, null, null, false, false).toStack(entryID);
                if (stack != null) {
                    List<IRecipe> recipes = entryID.contains("#") ? InventoryUtility.getRecipesWithOutput(stack) : InventoryUtility.getRecipesWithOutput(stack.getItem());
                    if (recipes != null) {
                        sender.addChatMessage(new ChatComponentText("Found " + recipes.size() + " for '" + entryID + "' saving to external json file"));
                        File writeFile = new File(JsonContentLoader.INSTANCE.externalContentFolder.getParent(), "json-gen/" + (entryID + "-recipes.json").replace(":", "_"));
                        if (!writeFile.getParentFile().exists()) {
                            writeFile.getParentFile().mkdirs();
                        }
                        try {
                            JsonObject object = new JsonObject();
                            int index = 0;
                            for (IRecipe recipe : recipes) {
                                try {
                                    if (recipe instanceof ShapedOreRecipe) {
                                        int width = 0;
                                        int height = 0;
                                        Object[] recipeItems = null;
                                        Field field = ShapedOreRecipe.class.getDeclaredField("input");
                                        field.setAccessible(true);
                                        recipeItems = (Object[]) field.get(recipe);
                                        field = ShapedOreRecipe.class.getDeclaredField("width");
                                        field.setAccessible(true);
                                        width = field.getInt(recipe);
                                        field = ShapedOreRecipe.class.getDeclaredField("height");
                                        field.setAccessible(true);
                                        height = field.getInt(recipe);
                                        Pair<String, HashMap<String, JsonElement>> itemSet = generateItemData(recipeItems, width, height);
                                        //Build data
                                        if (itemSet != null) {
                                            JsonObject recipeObject = new JsonObject();
                                            recipeObject.add("type", new JsonPrimitive("shaped"));
                                            recipeObject.add("output", toItemJson(recipe.getRecipeOutput()));
                                            recipeObject.add("grid", new JsonPrimitive(itemSet.left()));
                                            JsonObject itemEntry = new JsonObject();
                                            for (Map.Entry<String, JsonElement> entry : itemSet.right().entrySet()) {
                                                itemEntry.add(entry.getKey(), entry.getValue());
                                            }
                                            recipeObject.add("items", itemEntry);
                                            object.add("craftingGridRecipe:" + (index++), recipeObject);
                                        } else {
                                            sender.addChatMessage(new ChatComponentText("Failed to map recipe items for '" + recipe + "'"));
                                        }
                                    } else if (recipe instanceof ShapedRecipes) {
                                        Pair<String, HashMap<String, JsonElement>> itemSet = generateItemData(((ShapedRecipes) recipe).recipeItems, ((ShapedRecipes) recipe).recipeWidth, ((ShapedRecipes) recipe).recipeHeight);
                                        //Build data
                                        if (itemSet != null) {
                                            JsonObject recipeObject = new JsonObject();
                                            recipeObject.add("type", new JsonPrimitive("shaped"));
                                            recipeObject.add("output", toItemJson(recipe.getRecipeOutput()));
                                            recipeObject.add("grid", new JsonPrimitive(itemSet.left()));
                                            JsonObject itemEntry = new JsonObject();
                                            for (Map.Entry<String, JsonElement> entry : itemSet.right().entrySet()) {
                                                itemEntry.add(entry.getKey(), entry.getValue());
                                            }
                                            recipeObject.add("items", itemEntry);
                                            object.add("craftingGridRecipe:" + (index++), recipeObject);
                                        } else {
                                            sender.addChatMessage(new ChatComponentText("Failed to map recipe items for '" + recipe + "'"));
                                        }
                                    } else {
                                        sender.addChatMessage(new ChatComponentText("Failed to ID recipe type of '" + recipe + "'"));
                                    }
                                } catch (Exception e) {
                                    sender.addChatMessage(new ChatComponentText("Error processing recipe '" + recipe + "', see logs for details."));
                                    e.printStackTrace();
                                }
                            }
                            if (object.entrySet().size() > 0) {
                                Gson gson = new GsonBuilder().setPrettyPrinting().create();
                                try (FileWriter file = new FileWriter(writeFile)) {
                                    file.write(gson.toJson(object));
                                }
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        sender.addChatMessage(new ChatComponentText("Failed to locate recipes for '" + entryID + "'"));
                    }
                } else {
                    sender.addChatMessage(new ChatComponentText("Failed to locate entry for '" + entryID + "'"));
                }
                return true;
            }
        }
    }
    return handleHelp(sender, args);
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) HashMap(java.util.HashMap) FileWriter(java.io.FileWriter) Field(java.lang.reflect.Field) JsonCraftingRecipeData(com.builtbroken.mc.lib.json.processors.recipe.crafting.JsonCraftingRecipeData) ChatComponentText(net.minecraft.util.ChatComponentText) Pair(com.builtbroken.jlib.type.Pair) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ItemStack(net.minecraft.item.ItemStack) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with IRecipe

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

the class CommandDebugRecipes method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    if (args != null && args.length > 0 && !"help".equalsIgnoreCase(args[0])) {
        String modID = args[0];
        if (Loader.isModLoaded(modID)) {
            sender.addChatMessage(new ChatComponentText("Checking data...."));
            List<Item> items = InventoryUtility.getItemsForMod(modID);
            if (items != null && !items.isEmpty()) {
                HashMap<Item, List<IRecipe>> itemToRecipes = new HashMap();
                sender.addChatMessage(new ChatComponentText("Found " + items.size() + " items for the mod " + modID + " moving on to processing recipes"));
                for (Item item : items) {
                    List<IRecipe> recipes = InventoryUtility.getRecipesWithOutput(item);
                    if (recipes != null && recipes.size() > 0) {
                        itemToRecipes.put(item, recipes);
                    }
                }
                sender.addChatMessage(new ChatComponentText("Mapped " + itemToRecipes.size() + " entries with recipes"));
                if (args.length == 1 || args[1].equalsIgnoreCase("conflict")) {
                    sender.addChatMessage(new ChatComponentText("Not implemented yet"));
                    return true;
                } else if (args[1].equalsIgnoreCase("missing")) {
                    //TODO add handling for subtypes
                    for (Item item : items) {
                        if (!itemToRecipes.containsKey(item)) {
                            if (item instanceof ItemBlock) {
                                Block block = ((ItemBlock) item).field_150939_a;
                                if (block instanceof BlockTile) {
                                    sender.addChatMessage(new ChatComponentText("Tile[" + ((BlockTile) block).staticTile.name + "] has no recipes for any subtype"));
                                } else {
                                    sender.addChatMessage(new ChatComponentText("Block[" + block.getLocalizedName() + "] has no recipes for any subtype"));
                                }
                            } else {
                                sender.addChatMessage(new ChatComponentText("Item[" + item.getItemStackDisplayName(new ItemStack(item)) + "] has no recipes for any subtype"));
                            }
                        }
                    }
                }
            } else {
                sender.addChatMessage(new ChatComponentText("No items are mapped for the mod[" + modID + "]"));
            }
            return true;
        } else {
            //TODO maybe show closest spelling
            sender.addChatMessage(new ChatComponentText("Failed to find mod[" + modID + "]"));
            return true;
        }
    }
    return handleHelp(sender, args);
}
Also used : HashMap(java.util.HashMap) IRecipe(net.minecraft.item.crafting.IRecipe) BlockTile(com.builtbroken.mc.prefab.tile.BlockTile) ItemBlock(net.minecraft.item.ItemBlock) Item(net.minecraft.item.Item) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 20 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project BetterWithAddons by DaedalusGame.

the class InteractionDecoAddon method modifyPaneRecipe.

public void modifyPaneRecipe() {
    List<IRecipe> craftingList = CraftingManager.getInstance().getRecipeList();
    for (Iterator<IRecipe> craftingIterator = craftingList.iterator(); craftingIterator.hasNext(); ) {
        IRecipe recipe = craftingIterator.next();
        ItemStack output = recipe.getRecipeOutput();
        Block block = Block.getBlockFromItem(output.getItem());
        if (block == Blocks.GLASS_PANE || block == Blocks.STAINED_GLASS_PANE) {
            output.setCount((output.getCount() * 3) / 4);
        }
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

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