Search in sources :

Example 1 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project BetterStorage by copygirl.

the class Recipes method addTileRecipes.

private static void addTileRecipes() {
    // Crate recipe
    if (BetterStorageTiles.crate != null)
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.crate), "o/o", "/ /", "o/o", 'o', "plankWood", '/', "stickWood"));
    // Reinforced chest recipes
    if (BetterStorageTiles.reinforcedChest != null)
        for (ContainerMaterial material : ContainerMaterial.getMaterials()) {
            IRecipe recipe = material.getReinforcedRecipe(Blocks.chest, BetterStorageTiles.reinforcedChest);
            if (recipe != null)
                GameRegistry.addRecipe(recipe);
        }
    // Locker recipe
    if (BetterStorageTiles.locker != null) {
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.locker), "ooo", "o |", "ooo", 'o', "plankWood", '|', Blocks.trapdoor));
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.locker), "ooo", "| o", "ooo", 'o', "plankWood", '|', Blocks.trapdoor));
        // Reinforced locker recipes
        if (BetterStorageTiles.reinforcedLocker != null)
            for (ContainerMaterial material : ContainerMaterial.getMaterials()) {
                IRecipe recipe = material.getReinforcedRecipe(BetterStorageTiles.locker, BetterStorageTiles.reinforcedLocker);
                if (recipe != null)
                    GameRegistry.addRecipe(recipe);
            }
    }
    // Armor stand recipe
    if (BetterStorageTiles.armorStand != null)
        GameRegistry.addShapedRecipe(new ItemStack(BetterStorageTiles.armorStand), " i ", "/i/", " s ", 's', new ItemStack(Blocks.stone_slab, 1, 0), 'i', Items.iron_ingot, '/', Items.stick);
    // Backpack recipe
    if (BetterStorageTiles.backpack != null)
        GameRegistry.addShapedRecipe(new ItemStack(BetterStorageItems.itemBackpack), "#i#", "#O#", "###", '#', Items.leather, 'O', Blocks.wool, 'i', Items.gold_ingot);
    // Cardboard box recipe
    if ((BetterStorageTiles.cardboardBox != null) && (BetterStorageItems.cardboardSheet != null))
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.cardboardBox), "ooo", "o o", "ooo", 'o', "sheetCardboard"));
    // Crafting Station recipe
    if (BetterStorageTiles.craftingStation != null)
        GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(BetterStorageTiles.craftingStation), "B-B", "PTP", "WCW", 'B', Blocks.stonebrick, '-', Blocks.light_weighted_pressure_plate, 'P', Blocks.piston, 'T', Blocks.crafting_table, 'W', "plankWood", 'C', ((BetterStorageTiles.crate != null) ? BetterStorageTiles.crate : Blocks.chest)));
    // Present recipe
    if ((BetterStorageTiles.present != null) && (BetterStorageTiles.cardboardBox != null)) {
        GameRegistry.addRecipe(new PresentRecipe());
        BetterStorageCrafting.addStationRecipe(new PresentRemoveNametagRecipe());
    }
    // Flint Block recipe
    if (BetterStorageTiles.flintBlock != null) {
        GameRegistry.addShapedRecipe(new ItemStack(BetterStorageTiles.flintBlock), "ooo", "ooo", "ooo", 'o', Items.flint);
        GameRegistry.addShapelessRecipe(new ItemStack(Items.flint, 9), BetterStorageTiles.flintBlock);
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ContainerMaterial(net.mcft.copy.betterstorage.tile.ContainerMaterial) ItemStack(net.minecraft.item.ItemStack) PresentRecipe(net.mcft.copy.betterstorage.item.recipe.PresentRecipe) PresentRemoveNametagRecipe(net.mcft.copy.betterstorage.item.recipe.PresentRemoveNametagRecipe)

Example 2 with IRecipe

use of net.minecraft.item.crafting.IRecipe 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 IRecipe

use of net.minecraft.item.crafting.IRecipe 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 IRecipe

use of net.minecraft.item.crafting.IRecipe in project LogisticsPipes by RS485.

the class LogisticsCraftingTableTileEntity method getOutput.

public ItemStack getOutput(IResource wanted, IRoutedPowerProvider power) {
    boolean isFuzzy = isFuzzy();
    if (cache == null) {
        cacheRecipe();
        if (cache == null) {
            return null;
        }
    }
    int[] toUse = new int[9];
    int[] used = new int[inv.getSizeInventory()];
    outer: for (int i = 0; i < 9; i++) {
        ItemIdentifierStack item = matrix.getIDStackInSlot(i);
        if (item == null) {
            toUse[i] = -1;
            continue;
        }
        ItemIdentifier ident = item.getItem();
        for (int j = 0; j < inv.getSizeInventory(); j++) {
            item = inv.getIDStackInSlot(j);
            if (item == null) {
                continue;
            }
            if (isFuzzy ? (testFuzzy(ident, item, i)) : ident.equalsForCrafting(item.getItem())) {
                if (item.getStackSize() > used[j]) {
                    used[j]++;
                    toUse[i] = j;
                    continue outer;
                }
            }
        }
        //Not enough material
        return null;
    }
    AutoCraftingInventory crafter = new AutoCraftingInventory(placedBy);
    for (int i = 0; i < 9; i++) {
        int j = toUse[i];
        if (j != -1) {
            crafter.setInventorySlotContents(i, inv.getStackInSlot(j));
        }
    }
    IRecipe recipe = cache;
    outputFuzzyFlags.stack = resultInv.getIDStackInSlot(0);
    if (!recipe.matches(crafter, getWorldObj())) {
        if (isFuzzy && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
            recipe = null;
            for (IRecipe r : CraftingUtil.getRecipeList()) {
                if (r.matches(crafter, getWorldObj()) && outputFuzzyFlags.matches(ItemIdentifier.get(r.getRecipeOutput()), IResource.MatchSettings.NORMAL)) {
                    recipe = r;
                    break;
                }
            }
            if (recipe == null) {
                return null;
            }
        } else {
            //Fix MystCraft
            return null;
        }
    }
    ItemStack result = recipe.getCraftingResult(crafter);
    if (result == null) {
        return null;
    }
    if (isFuzzy && outputFuzzyFlags.getBitSet().nextSetBit(0) != -1) {
        if (!outputFuzzyFlags.matches(ItemIdentifier.get(result), IResource.MatchSettings.NORMAL)) {
            return null;
        }
        if (!outputFuzzyFlags.matches(wanted.getAsItem(), IResource.MatchSettings.NORMAL)) {
            return null;
        }
    } else {
        if (!resultInv.getIDStackInSlot(0).getItem().equalsWithoutNBT(ItemIdentifier.get(result))) {
            return null;
        }
        if (!wanted.matches(resultInv.getIDStackInSlot(0).getItem(), IResource.MatchSettings.WITHOUT_NBT)) {
            return null;
        }
    }
    if (!power.useEnergy(Configs.LOGISTICS_CRAFTING_TABLE_POWER_USAGE)) {
        return null;
    }
    crafter = new AutoCraftingInventory(placedBy);
    for (int i = 0; i < 9; i++) {
        int j = toUse[i];
        if (j != -1) {
            crafter.setInventorySlotContents(i, inv.decrStackSize(j, 1));
        }
    }
    result = recipe.getCraftingResult(crafter);
    if (fake == null) {
        fake = MainProxy.getFakePlayer(this);
    }
    result = result.copy();
    SlotCrafting craftingSlot = new SlotCrafting(fake, crafter, resultInv, 0, 0, 0);
    craftingSlot.onPickupFromSlot(fake, result);
    for (int i = 0; i < 9; i++) {
        ItemStack left = crafter.getStackInSlot(i);
        crafter.setInventorySlotContents(i, null);
        if (left != null) {
            left.stackSize = inv.addCompressed(left, false);
            if (left.stackSize > 0) {
                ItemIdentifierInventory.dropItems(worldObj, left, xCoord, yCoord, zCoord);
            }
        }
    }
    for (int i = 0; i < fake.inventory.getSizeInventory(); i++) {
        ItemStack left = fake.inventory.getStackInSlot(i);
        fake.inventory.setInventorySlotContents(i, null);
        if (left != null) {
            left.stackSize = inv.addCompressed(left, false);
            if (left.stackSize > 0) {
                ItemIdentifierInventory.dropItems(worldObj, left, xCoord, yCoord, zCoord);
            }
        }
    }
    return result;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRecipe(net.minecraft.item.crafting.IRecipe) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting)

Example 5 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project LogisticsPipes by RS485.

the class LogisticsCraftingTableTileEntity method cacheRecipe.

public void cacheRecipe() {
    ItemIdentifier oldTargetType = targetType;
    cache = null;
    resultInv.clearInventorySlotContents(0);
    AutoCraftingInventory craftInv = new AutoCraftingInventory(placedBy);
    for (int i = 0; i < 9; i++) {
        craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
    }
    List<IRecipe> list = new ArrayList<>();
    for (IRecipe r : CraftingUtil.getRecipeList()) {
        if (r.matches(craftInv, getWorldObj())) {
            list.add(r);
        }
    }
    if (list.size() == 1) {
        cache = list.get(0);
        resultInv.setInventorySlotContents(0, cache.getCraftingResult(craftInv));
        targetType = null;
    } else if (list.size() > 1) {
        if (targetType != null) {
            for (IRecipe recipe : list) {
                craftInv = new AutoCraftingInventory(placedBy);
                for (int i = 0; i < 9; i++) {
                    craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
                }
                ItemStack result = recipe.getCraftingResult(craftInv);
                if (result != null && targetType.equals(ItemIdentifier.get(result))) {
                    resultInv.setInventorySlotContents(0, result);
                    cache = recipe;
                    break;
                }
            }
        }
        if (cache == null) {
            for (IRecipe r : list) {
                ItemStack result = r.getCraftingResult(craftInv);
                if (result != null) {
                    cache = r;
                    resultInv.setInventorySlotContents(0, result);
                    targetType = ItemIdentifier.get(result);
                    break;
                }
            }
        }
    } else {
        targetType = null;
    }
    outputFuzzyFlags.stack = resultInv.getIDStackInSlot(0);
    if (((targetType == null && oldTargetType != null) || (targetType != null && !targetType.equals(oldTargetType))) && !guiWatcher.isEmpty() && getWorldObj() != null && MainProxy.isServer(getWorldObj())) {
        MainProxy.sendToPlayerList(PacketHandler.getPacket(CraftingSetType.class).setTargetType(targetType).setTilePos(this), guiWatcher);
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) CraftingSetType(logisticspipes.network.packets.block.CraftingSetType) IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) 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