Search in sources :

Example 1 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project MinecraftForge by MinecraftForge.

the class OreDictionary method initVanillaEntries.

private static void initVanillaEntries() {
    if (!hasInit) {
        // tree- and wood-related things
        registerOre("logWood", new ItemStack(Blocks.LOG, 1, WILDCARD_VALUE));
        registerOre("logWood", new ItemStack(Blocks.LOG2, 1, WILDCARD_VALUE));
        registerOre("plankWood", new ItemStack(Blocks.PLANKS, 1, WILDCARD_VALUE));
        registerOre("slabWood", new ItemStack(Blocks.WOODEN_SLAB, 1, WILDCARD_VALUE));
        registerOre("stairWood", Blocks.OAK_STAIRS);
        registerOre("stairWood", Blocks.SPRUCE_STAIRS);
        registerOre("stairWood", Blocks.BIRCH_STAIRS);
        registerOre("stairWood", Blocks.JUNGLE_STAIRS);
        registerOre("stairWood", Blocks.ACACIA_STAIRS);
        registerOre("stairWood", Blocks.DARK_OAK_STAIRS);
        registerOre("stickWood", Items.STICK);
        registerOre("treeSapling", new ItemStack(Blocks.SAPLING, 1, WILDCARD_VALUE));
        registerOre("treeLeaves", new ItemStack(Blocks.LEAVES, 1, WILDCARD_VALUE));
        registerOre("treeLeaves", new ItemStack(Blocks.LEAVES2, 1, WILDCARD_VALUE));
        registerOre("vine", Blocks.VINE);
        // Ores
        registerOre("oreGold", Blocks.GOLD_ORE);
        registerOre("oreIron", Blocks.IRON_ORE);
        registerOre("oreLapis", Blocks.LAPIS_ORE);
        registerOre("oreDiamond", Blocks.DIAMOND_ORE);
        registerOre("oreRedstone", Blocks.REDSTONE_ORE);
        registerOre("oreEmerald", Blocks.EMERALD_ORE);
        registerOre("oreQuartz", Blocks.QUARTZ_ORE);
        registerOre("oreCoal", Blocks.COAL_ORE);
        // ingots/nuggets
        registerOre("ingotIron", Items.IRON_INGOT);
        registerOre("ingotGold", Items.GOLD_INGOT);
        registerOre("ingotBrick", Items.BRICK);
        registerOre("ingotBrickNether", Items.NETHERBRICK);
        registerOre("nuggetGold", Items.GOLD_NUGGET);
        registerOre("nuggetIron", Items.field_191525_da);
        // gems and dusts
        registerOre("gemDiamond", Items.DIAMOND);
        registerOre("gemEmerald", Items.EMERALD);
        registerOre("gemQuartz", Items.QUARTZ);
        registerOre("gemPrismarine", Items.PRISMARINE_SHARD);
        registerOre("dustPrismarine", Items.PRISMARINE_CRYSTALS);
        registerOre("dustRedstone", Items.REDSTONE);
        registerOre("dustGlowstone", Items.GLOWSTONE_DUST);
        registerOre("gemLapis", new ItemStack(Items.DYE, 1, 4));
        // storage blocks
        registerOre("blockGold", Blocks.GOLD_BLOCK);
        registerOre("blockIron", Blocks.IRON_BLOCK);
        registerOre("blockLapis", Blocks.LAPIS_BLOCK);
        registerOre("blockDiamond", Blocks.DIAMOND_BLOCK);
        registerOre("blockRedstone", Blocks.REDSTONE_BLOCK);
        registerOre("blockEmerald", Blocks.EMERALD_BLOCK);
        registerOre("blockQuartz", Blocks.QUARTZ_BLOCK);
        registerOre("blockCoal", Blocks.COAL_BLOCK);
        // crops
        registerOre("cropWheat", Items.WHEAT);
        registerOre("cropPotato", Items.POTATO);
        registerOre("cropCarrot", Items.CARROT);
        registerOre("cropNetherWart", Items.NETHER_WART);
        registerOre("sugarcane", Items.REEDS);
        registerOre("blockCactus", Blocks.CACTUS);
        // misc materials
        registerOre("dye", new ItemStack(Items.DYE, 1, WILDCARD_VALUE));
        registerOre("paper", new ItemStack(Items.PAPER));
        // mob drops
        registerOre("slimeball", Items.SLIME_BALL);
        registerOre("enderpearl", Items.ENDER_PEARL);
        registerOre("bone", Items.BONE);
        registerOre("gunpowder", Items.GUNPOWDER);
        registerOre("string", Items.STRING);
        registerOre("netherStar", Items.NETHER_STAR);
        registerOre("leather", Items.LEATHER);
        registerOre("feather", Items.FEATHER);
        registerOre("egg", Items.EGG);
        // records
        registerOre("record", Items.RECORD_13);
        registerOre("record", Items.RECORD_CAT);
        registerOre("record", Items.RECORD_BLOCKS);
        registerOre("record", Items.RECORD_CHIRP);
        registerOre("record", Items.RECORD_FAR);
        registerOre("record", Items.RECORD_MALL);
        registerOre("record", Items.RECORD_MELLOHI);
        registerOre("record", Items.RECORD_STAL);
        registerOre("record", Items.RECORD_STRAD);
        registerOre("record", Items.RECORD_WARD);
        registerOre("record", Items.RECORD_11);
        registerOre("record", Items.RECORD_WAIT);
        // blocks
        registerOre("dirt", Blocks.DIRT);
        registerOre("grass", Blocks.GRASS);
        registerOre("stone", Blocks.STONE);
        registerOre("cobblestone", Blocks.COBBLESTONE);
        registerOre("gravel", Blocks.GRAVEL);
        registerOre("sand", new ItemStack(Blocks.SAND, 1, WILDCARD_VALUE));
        registerOre("sandstone", new ItemStack(Blocks.SANDSTONE, 1, WILDCARD_VALUE));
        registerOre("sandstone", new ItemStack(Blocks.RED_SANDSTONE, 1, WILDCARD_VALUE));
        registerOre("netherrack", Blocks.NETHERRACK);
        registerOre("obsidian", Blocks.OBSIDIAN);
        registerOre("glowstone", Blocks.GLOWSTONE);
        registerOre("endstone", Blocks.END_STONE);
        registerOre("torch", Blocks.TORCH);
        registerOre("workbench", Blocks.CRAFTING_TABLE);
        registerOre("blockSlime", Blocks.SLIME_BLOCK);
        registerOre("blockPrismarine", new ItemStack(Blocks.PRISMARINE, 1, BlockPrismarine.EnumType.ROUGH.getMetadata()));
        registerOre("blockPrismarineBrick", new ItemStack(Blocks.PRISMARINE, 1, BlockPrismarine.EnumType.BRICKS.getMetadata()));
        registerOre("blockPrismarineDark", new ItemStack(Blocks.PRISMARINE, 1, BlockPrismarine.EnumType.DARK.getMetadata()));
        registerOre("stoneGranite", new ItemStack(Blocks.STONE, 1, 1));
        registerOre("stoneGranitePolished", new ItemStack(Blocks.STONE, 1, 2));
        registerOre("stoneDiorite", new ItemStack(Blocks.STONE, 1, 3));
        registerOre("stoneDioritePolished", new ItemStack(Blocks.STONE, 1, 4));
        registerOre("stoneAndesite", new ItemStack(Blocks.STONE, 1, 5));
        registerOre("stoneAndesitePolished", new ItemStack(Blocks.STONE, 1, 6));
        registerOre("blockGlassColorless", Blocks.GLASS);
        registerOre("blockGlass", Blocks.GLASS);
        registerOre("blockGlass", new ItemStack(Blocks.STAINED_GLASS, 1, WILDCARD_VALUE));
        //blockGlass{Color} is added below with dyes
        registerOre("paneGlassColorless", Blocks.GLASS_PANE);
        registerOre("paneGlass", Blocks.GLASS_PANE);
        registerOre("paneGlass", new ItemStack(Blocks.STAINED_GLASS_PANE, 1, WILDCARD_VALUE));
        //paneGlass{Color} is added below with dyes
        // chests
        registerOre("chest", Blocks.CHEST);
        registerOre("chest", Blocks.ENDER_CHEST);
        registerOre("chest", Blocks.TRAPPED_CHEST);
        registerOre("chestWood", Blocks.CHEST);
        registerOre("chestEnder", Blocks.ENDER_CHEST);
        registerOre("chestTrapped", Blocks.TRAPPED_CHEST);
    }
    // Build our list of items to replace with ore tags
    Map<ItemStack, String> replacements = new HashMap<ItemStack, String>();
    // wood-related things
    replacements.put(new ItemStack(Items.STICK), "stickWood");
    replacements.put(new ItemStack(Blocks.PLANKS), "plankWood");
    replacements.put(new ItemStack(Blocks.PLANKS, 1, WILDCARD_VALUE), "plankWood");
    replacements.put(new ItemStack(Blocks.WOODEN_SLAB, 1, WILDCARD_VALUE), "slabWood");
    // ingots/nuggets
    replacements.put(new ItemStack(Items.GOLD_INGOT), "ingotGold");
    replacements.put(new ItemStack(Items.IRON_INGOT), "ingotIron");
    // gems and dusts
    replacements.put(new ItemStack(Items.DIAMOND), "gemDiamond");
    replacements.put(new ItemStack(Items.EMERALD), "gemEmerald");
    replacements.put(new ItemStack(Items.PRISMARINE_SHARD), "gemPrismarine");
    replacements.put(new ItemStack(Items.PRISMARINE_CRYSTALS), "dustPrismarine");
    replacements.put(new ItemStack(Items.REDSTONE), "dustRedstone");
    replacements.put(new ItemStack(Items.GLOWSTONE_DUST), "dustGlowstone");
    // crops
    replacements.put(new ItemStack(Items.REEDS), "sugarcane");
    replacements.put(new ItemStack(Blocks.CACTUS), "blockCactus");
    // misc materials
    replacements.put(new ItemStack(Items.PAPER), "paper");
    // mob drops
    replacements.put(new ItemStack(Items.SLIME_BALL), "slimeball");
    replacements.put(new ItemStack(Items.STRING), "string");
    replacements.put(new ItemStack(Items.LEATHER), "leather");
    replacements.put(new ItemStack(Items.ENDER_PEARL), "enderpearl");
    replacements.put(new ItemStack(Items.GUNPOWDER), "gunpowder");
    replacements.put(new ItemStack(Items.NETHER_STAR), "netherStar");
    replacements.put(new ItemStack(Items.FEATHER), "feather");
    replacements.put(new ItemStack(Items.BONE), "bone");
    replacements.put(new ItemStack(Items.EGG), "egg");
    // blocks
    replacements.put(new ItemStack(Blocks.STONE), "stone");
    replacements.put(new ItemStack(Blocks.COBBLESTONE), "cobblestone");
    replacements.put(new ItemStack(Blocks.COBBLESTONE, 1, WILDCARD_VALUE), "cobblestone");
    replacements.put(new ItemStack(Blocks.GLOWSTONE), "glowstone");
    replacements.put(new ItemStack(Blocks.GLASS), "blockGlassColorless");
    replacements.put(new ItemStack(Blocks.PRISMARINE), "prismarine");
    replacements.put(new ItemStack(Blocks.STONE, 1, 1), "stoneGranite");
    replacements.put(new ItemStack(Blocks.STONE, 1, 2), "stoneGranitePolished");
    replacements.put(new ItemStack(Blocks.STONE, 1, 3), "stoneDiorite");
    replacements.put(new ItemStack(Blocks.STONE, 1, 4), "stoneDioritePolished");
    replacements.put(new ItemStack(Blocks.STONE, 1, 5), "stoneAndesite");
    replacements.put(new ItemStack(Blocks.STONE, 1, 6), "stoneAndesitePolished");
    // chests
    replacements.put(new ItemStack(Blocks.CHEST), "chestWood");
    replacements.put(new ItemStack(Blocks.ENDER_CHEST), "chestEnder");
    replacements.put(new ItemStack(Blocks.TRAPPED_CHEST), "chestTrapped");
    // Register dyes
    String[] dyes = { "Black", "Red", "Green", "Brown", "Blue", "Purple", "Cyan", "LightGray", "Gray", "Pink", "Lime", "Yellow", "LightBlue", "Magenta", "Orange", "White" };
    for (int i = 0; i < 16; i++) {
        ItemStack dye = new ItemStack(Items.DYE, 1, i);
        ItemStack block = new ItemStack(Blocks.STAINED_GLASS, 1, 15 - i);
        ItemStack pane = new ItemStack(Blocks.STAINED_GLASS_PANE, 1, 15 - i);
        if (!hasInit) {
            registerOre("dye" + dyes[i], dye);
            registerOre("blockGlass" + dyes[i], block);
            registerOre("paneGlass" + dyes[i], pane);
        }
        replacements.put(dye, "dye" + dyes[i]);
        replacements.put(block, "blockGlass" + dyes[i]);
        replacements.put(pane, "paneGlass" + dyes[i]);
    }
    hasInit = true;
    ItemStack[] replaceStacks = replacements.keySet().toArray(new ItemStack[replacements.keySet().size()]);
    // Ignore recipes for the following items
    ItemStack[] exclusions = new ItemStack[] { new ItemStack(Blocks.LAPIS_BLOCK), new ItemStack(Items.COOKIE), new ItemStack(Blocks.STONEBRICK), new ItemStack(Blocks.STONE_SLAB, 1, WILDCARD_VALUE), new ItemStack(Blocks.STONE_STAIRS), new ItemStack(Blocks.COBBLESTONE_WALL), new ItemStack(Blocks.OAK_FENCE), new ItemStack(Blocks.OAK_FENCE_GATE), new ItemStack(Blocks.OAK_STAIRS), new ItemStack(Blocks.SPRUCE_FENCE), new ItemStack(Blocks.SPRUCE_FENCE_GATE), new ItemStack(Blocks.SPRUCE_STAIRS), new ItemStack(Blocks.BIRCH_STAIRS), new ItemStack(Blocks.BIRCH_FENCE_GATE), new ItemStack(Blocks.BIRCH_STAIRS), new ItemStack(Blocks.JUNGLE_FENCE), new ItemStack(Blocks.JUNGLE_FENCE_GATE), new ItemStack(Blocks.JUNGLE_STAIRS), new ItemStack(Blocks.ACACIA_FENCE), new ItemStack(Blocks.ACACIA_FENCE_GATE), new ItemStack(Blocks.ACACIA_STAIRS), new ItemStack(Blocks.DARK_OAK_FENCE), new ItemStack(Blocks.DARK_OAK_FENCE_GATE), new ItemStack(Blocks.DARK_OAK_STAIRS), new ItemStack(Blocks.WOODEN_SLAB), new ItemStack(Blocks.GLASS_PANE), // Bone Block, to prevent conversion of dyes into bone meal.
    new ItemStack(Blocks.BONE_BLOCK), new ItemStack(Items.BOAT), new ItemStack(Items.OAK_DOOR), //So the above can have a comma and we don't have to keep editing extra lines.
    ItemStack.EMPTY };
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    List<IRecipe> recipesToRemove = new ArrayList<IRecipe>();
    List<IRecipe> recipesToAdd = new ArrayList<IRecipe>();
    // Search vanilla recipes for recipes to replace
    for (Object obj : recipes) {
        if (obj.getClass() == ShapedRecipes.class) {
            ShapedRecipes recipe = (ShapedRecipes) obj;
            ItemStack output = recipe.getRecipeOutput();
            if (!output.isEmpty() && containsMatch(false, exclusions, output)) {
                continue;
            }
            if (containsMatch(true, recipe.recipeItems, replaceStacks)) {
                recipesToRemove.add(recipe);
                recipesToAdd.add(new ShapedOreRecipe(recipe, replacements));
            }
        } else if (obj.getClass() == ShapelessRecipes.class) {
            ShapelessRecipes recipe = (ShapelessRecipes) obj;
            ItemStack output = recipe.getRecipeOutput();
            if (!output.isEmpty() && containsMatch(false, exclusions, output)) {
                continue;
            }
            if (containsMatch(true, recipe.recipeItems.toArray(new ItemStack[recipe.recipeItems.size()]), replaceStacks)) {
                recipesToRemove.add((IRecipe) obj);
                IRecipe newRecipe = new ShapelessOreRecipe(recipe, replacements);
                recipesToAdd.add(newRecipe);
            }
        }
    }
    recipes.removeAll(recipesToRemove);
    recipes.addAll(recipesToAdd);
    if (recipesToRemove.size() > 0) {
        FMLLog.info("Replaced %d ore recipes", recipesToRemove.size());
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) HashMap(java.util.HashMap) IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 2 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project BluePower by Qmunity.

the class SlotCircuitTableCrafting method getCraftingComponents.

private static List<ItemStack> getCraftingComponents(ItemStack gate) {
    List<ItemStack> requiredItems = new ArrayList<ItemStack>();
    List recipeList = CraftingManager.getInstance().getRecipeList();
    for (IRecipe r : (List<IRecipe>) recipeList) {
        ItemStack result = r.getRecipeOutput();
        if (result != null && result.isItemEqual(gate)) {
            if (r instanceof ShapedOreRecipe) {
                ShapedOreRecipe recipe = (ShapedOreRecipe) r;
                for (Object o : recipe.getInput()) {
                    if (o != null) {
                        ItemStack stack;
                        if (o instanceof ItemStack) {
                            stack = (ItemStack) o;
                        } else {
                            List<ItemStack> list = (List<ItemStack>) o;
                            stack = list.size() > 0 ? list.get(0) : null;
                        }
                        if (stack != null) {
                            boolean needsAdding = true;
                            for (ItemStack listStack : requiredItems) {
                                if (listStack.isItemEqual(stack)) {
                                    listStack.stackSize++;
                                    needsAdding = false;
                                    break;
                                }
                            }
                            if (needsAdding)
                                requiredItems.add(stack.copy());
                        }
                    }
                }
                return requiredItems;
            } else if (r instanceof ShapedRecipes) {
                ShapedRecipes recipe = (ShapedRecipes) r;
                for (ItemStack stack : recipe.recipeItems) {
                    if (stack != null) {
                        boolean needsAdding = true;
                        for (ItemStack listStack : requiredItems) {
                            if (listStack.isItemEqual(stack)) {
                                listStack.stackSize++;
                                needsAdding = false;
                                break;
                            }
                        }
                        if (needsAdding)
                            requiredItems.add(stack.copy());
                    }
                }
                return requiredItems;
            }
        }
    }
    return new ArrayList<ItemStack>();
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project BluePower by Qmunity.

the class AlloyFurnaceRegistry method generateRecyclingRecipes.

@SuppressWarnings("unchecked")
public void generateRecyclingRecipes() {
    Collections.addAll(blacklist, Config.alloyFurnaceBlacklist);
    List<Item> blacklist = new ArrayList<Item>();
    for (String configString : this.blacklist) {
        Item item = GameData.getItemRegistry().getObject(configString);
        if (item != null) {
            blacklist.add(item);
        } else {
            BluePower.log.info("Config entry \"" + configString + "\" not an existing item/block name! Will not be added to the blacklist");
        }
    }
    List<ItemStack> registeredRecycledItems = new ArrayList<ItemStack>();
    List<ItemStack> registeredResultItems = new ArrayList<ItemStack>();
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe recipe : recipes) {
        int recyclingAmount = 0;
        ItemStack currentlyRecycledInto = null;
        for (ItemStack recyclingItem : bufferedRecyclingItems) {
            try {
                if (recipe instanceof ShapedRecipes) {
                    ShapedRecipes shaped = (ShapedRecipes) recipe;
                    if (shaped.recipeItems != null) {
                        for (ItemStack input : shaped.recipeItems) {
                            if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
                                ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                    currentlyRecycledInto = moltenDownItem;
                                    recyclingAmount += moltenDownItem.stackSize;
                                }
                            }
                        }
                    }
                } else if (recipe instanceof ShapelessRecipes) {
                    ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
                    if (shapeless.recipeItems != null) {
                        for (ItemStack input : (List<ItemStack>) shapeless.recipeItems) {
                            if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
                                ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                    currentlyRecycledInto = moltenDownItem;
                                    recyclingAmount += moltenDownItem.stackSize;
                                }
                            }
                        }
                    }
                } else if (recipe instanceof ShapedOreRecipe) {
                    ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
                    if (shapedOreRecipe.getInput() != null) {
                        for (Object input : shapedOreRecipe.getInput()) {
                            if (input != null) {
                                List<ItemStack> itemList;
                                if (input instanceof ItemStack) {
                                    itemList = new ArrayList<ItemStack>();
                                    itemList.add((ItemStack) input);
                                } else {
                                    itemList = (List<ItemStack>) input;
                                }
                                for (ItemStack item : itemList) {
                                    if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
                                        ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                        if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                            currentlyRecycledInto = moltenDownItem;
                                            recyclingAmount += moltenDownItem.stackSize;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                } else if (recipe instanceof ShapelessOreRecipe) {
                    ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
                    for (Object input : shapeless.getInput()) {
                        if (input != null) {
                            List<ItemStack> itemList;
                            if (input instanceof ItemStack) {
                                itemList = new ArrayList<ItemStack>();
                                itemList.add((ItemStack) input);
                            } else {
                                itemList = (List<ItemStack>) input;
                            }
                            for (ItemStack item : itemList) {
                                if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
                                    ItemStack moltenDownItem = getRecyclingStack(recyclingItem);
                                    if (currentlyRecycledInto == null || ItemStackUtils.isItemFuzzyEqual(currentlyRecycledInto, moltenDownItem)) {
                                        currentlyRecycledInto = moltenDownItem;
                                        recyclingAmount += moltenDownItem.stackSize;
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            } catch (Throwable e) {
                BluePower.log.error("Error when generating an Alloy Furnace recipe for item " + recyclingItem.getDisplayName() + ", recipe output: " + recipe.getRecipeOutput().getDisplayName());
                e.printStackTrace();
            }
        }
        if (recyclingAmount > 0 && recipe.getRecipeOutput().stackSize > 0) {
            boolean shouldAdd = true;
            for (int i = 0; i < registeredRecycledItems.size(); i++) {
                if (ItemStackUtils.isItemFuzzyEqual(registeredRecycledItems.get(i), recipe.getRecipeOutput())) {
                    if (registeredResultItems.get(i).stackSize < recyclingAmount) {
                        shouldAdd = false;
                        break;
                    } else {
                        registeredResultItems.remove(i);
                        registeredRecycledItems.remove(i);
                        i--;
                    }
                }
            }
            if (shouldAdd) {
                if (blacklist.contains(recipe.getRecipeOutput().getItem())) {
                    BluePower.log.info("Skipped adding item/block " + recipe.getRecipeOutput().getDisplayName() + " to the Alloy Furnace recipes.");
                    continue;
                }
                ItemStack resultItem = new ItemStack(currentlyRecycledInto.getItem(), Math.min(64, recyclingAmount), currentlyRecycledInto.getItemDamage());
                registeredResultItems.add(resultItem);
                registeredRecycledItems.add(recipe.getRecipeOutput());
            }
        }
    }
    for (int i = 0; i < registeredResultItems.size(); i++) {
        addRecipe(registeredResultItems.get(i), registeredRecycledItems.get(i));
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ArrayList(java.util.ArrayList) Item(net.minecraft.item.Item) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 4 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes 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 5 with ShapedRecipes

use of net.minecraft.item.crafting.ShapedRecipes in project Skree by Skelril.

the class MarketVerifyCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
        return CommandResult.empty();
    }
    MarketService service = optService.get();
    Task.builder().async().execute(() -> {
        PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
        List<Clause<String, BigDecimal>> profitMargins = new ArrayList<>();
        for (IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
            ItemStack output = recipe.getRecipeOutput();
            if (output == null) {
                continue;
            }
            Optional<BigDecimal> optResultPrice = service.getPrice(tf(output));
            if (!optResultPrice.isPresent()) {
                continue;
            }
            String name = service.getAlias(tf(output)).orElse(output.getItem().getRegistryName().toString());
            Collection<ItemStack> items = new ArrayList<>();
            if (recipe instanceof ShapedRecipes) {
                items.addAll(Lists.newArrayList(((ShapedRecipes) recipe).recipeItems));
            } else if (recipe instanceof ShapelessRecipes) {
                items.addAll(((ShapelessRecipes) recipe).recipeItems);
            } else {
                src.sendMessage(Text.of(TextColors.RED, "Unsupported recipe for " + name));
                continue;
            }
            items.removeAll(Collections.singleton(null));
            BigDecimal creationCost = BigDecimal.ZERO;
            try {
                for (ItemStack stack : items) {
                    creationCost = creationCost.add(service.getPrice(tf(stack)).orElse(BigDecimal.ZERO));
                }
            } catch (Exception ex) {
                src.sendMessage(Text.of(TextColors.RED, "Couldn't complete checks for " + name));
                continue;
            }
            if (creationCost.equals(BigDecimal.ZERO)) {
                src.sendMessage(Text.of(TextColors.RED, "No ingredients found on market for " + name));
                continue;
            }
            BigDecimal sellPrice = optResultPrice.get();
            sellPrice = sellPrice.multiply(service.getSellFactor(sellPrice));
            profitMargins.add(new Clause<>(name, sellPrice.subtract(creationCost)));
        }
        List<Text> result = profitMargins.stream().sorted((a, b) -> b.getValue().subtract(a.getValue()).intValue()).map(a -> {
            boolean profitable = a.getValue().compareTo(BigDecimal.ZERO) >= 0;
            return Text.of(profitable ? TextColors.RED : TextColors.GREEN, a.getKey().toUpperCase(), " has a profit margin of ", profitable ? "+" : "", MarketImplUtil.format(a.getValue()));
        }).collect(Collectors.toList());
        pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Profit Margin Report")).padding(Text.of(" ")).sendTo(src);
    }).submit(SkreePlugin.inst());
    src.sendMessage(Text.of(TextColors.YELLOW, "Verification in progress..."));
    return CommandResult.success();
}
Also used : java.util(java.util) ItemStack(net.minecraft.item.ItemStack) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) SkreePlugin(com.skelril.skree.SkreePlugin) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Task(org.spongepowered.api.scheduler.Task) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) TextColors(org.spongepowered.api.text.format.TextColors) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) MarketImplUtil(com.skelril.skree.content.market.MarketImplUtil) CommandResult(org.spongepowered.api.command.CommandResult) IRecipe(net.minecraft.item.crafting.IRecipe) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) MarketService(com.skelril.skree.service.MarketService) PaginationService(org.spongepowered.api.service.pagination.PaginationService) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) CraftingManager(net.minecraft.item.crafting.CraftingManager) Clause(com.skelril.nitro.Clause) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) BigDecimal(java.math.BigDecimal) CommandException(org.spongepowered.api.command.CommandException) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Clause(com.skelril.nitro.Clause) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) MarketService(com.skelril.skree.service.MarketService)

Aggregations

ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)28 ItemStack (net.minecraft.item.ItemStack)19 IRecipe (net.minecraft.item.crafting.IRecipe)18 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)14 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)13 ArrayList (java.util.ArrayList)10 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)8 List (java.util.List)6 Item (net.minecraft.item.Item)6 HashMap (java.util.HashMap)5 Block (net.minecraft.block.Block)5 Ingredient (net.minecraft.item.crafting.Ingredient)5 ResourceLocation (net.minecraft.util.ResourceLocation)3 Pair (com.builtbroken.jlib.type.Pair)2 ItemBlock (net.minecraft.item.ItemBlock)2 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1 ISkillTreeEntry (am2.api.spell.component.interfaces.ISkillTreeEntry)1 ISpellPart (am2.api.spell.component.interfaces.ISpellPart)1 ItemSpellPart (am2.items.ItemSpellPart)1 RecipeArsMagica (am2.items.RecipeArsMagica)1