Search in sources :

Example 21 with IRecipe

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

the class BetterWithAddons method removeCraftingRecipe.

public static void removeCraftingRecipe(ItemStack withoutput) {
    List<IRecipe> craftingList = CraftingManager.getInstance().getRecipeList();
    for (Iterator<IRecipe> craftingIterator = craftingList.iterator(); craftingIterator.hasNext(); ) {
        IRecipe recipe = craftingIterator.next();
        if (withoutput.isEmpty() || !ItemStack.areItemStacksEqual(withoutput, recipe.getRecipeOutput()))
            continue;
        craftingIterator.remove();
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe)

Example 22 with IRecipe

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

the class VanillaStationCrafting method findVanillaRecipe.

public static VanillaStationCrafting findVanillaRecipe(InventoryCraftingStation inv) {
    World world = ((inv.entity != null) ? inv.entity.getWorldObj() : WorldUtils.getLocalWorld());
    InventoryCrafting crafting = new InventoryCrafting(new FakeContainer(), 3, 3);
    for (int i = 0; i < inv.crafting.length; i++) crafting.setInventorySlotContents(i, ItemStack.copyItemStack(inv.crafting[i]));
    IRecipe recipe = findRecipe(crafting, world);
    if (recipe == null)
        return null;
    return new VanillaStationCrafting(world, recipe, inv.crafting, recipe.getCraftingResult(crafting));
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) World(net.minecraft.world.World) InventoryCrafting(net.minecraft.inventory.InventoryCrafting)

Example 23 with IRecipe

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

the class LogisticsCraftingTableTileEntity method cycleRecipe.

public void cycleRecipe(boolean down) {
    cacheRecipe();
    if (targetType == null) {
        return;
    }
    cache = null;
    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) {
        boolean found = false;
        IRecipe prev = null;
        for (IRecipe recipe : list) {
            if (found) {
                cache = recipe;
                break;
            }
            craftInv = new AutoCraftingInventory(placedBy);
            for (int i = 0; i < 9; i++) {
                craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
            }
            if (targetType != null && targetType.equals(ItemIdentifier.get(recipe.getCraftingResult(craftInv)))) {
                if (down) {
                    found = true;
                } else {
                    if (prev == null) {
                        cache = list.get(list.size() - 1);
                    } else {
                        cache = prev;
                    }
                    break;
                }
            }
            prev = recipe;
        }
        if (cache == null) {
            cache = list.get(0);
        }
        craftInv = new AutoCraftingInventory(placedBy);
        for (int i = 0; i < 9; i++) {
            craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
        }
        targetType = ItemIdentifier.get(cache.getCraftingResult(craftInv));
    }
    if (!guiWatcher.isEmpty() && getWorldObj() != null && MainProxy.isServer(getWorldObj())) {
        MainProxy.sendToPlayerList(PacketHandler.getPacket(CraftingSetType.class).setTargetType(targetType).setTilePos(this), guiWatcher);
    }
    cacheRecipe();
}
Also used : CraftingSetType(logisticspipes.network.packets.block.CraftingSetType) IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList)

Example 24 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project malmo by Microsoft.

the class CraftingHelper method getRecipesForRequestedOutput.

/** Attempt to find all recipes that result in an item of the requested output.
     * @param output the desired item, eg from Types.xsd - "diamond_pickaxe" etc - or as a Minecraft name - eg "tile.woolCarpet.blue"
     * @return a list of IRecipe objects that result in this item.
     */
public static List<IRecipe> getRecipesForRequestedOutput(String output) {
    List<IRecipe> matchingRecipes = new ArrayList<IRecipe>();
    ItemStack target = MinecraftTypeHelper.getItemStackFromParameterString(output);
    List<?> recipes = CraftingManager.getInstance().getRecipeList();
    for (Object obj : recipes) {
        if (obj == null)
            continue;
        if (obj instanceof IRecipe) {
            ItemStack is = ((IRecipe) obj).getRecipeOutput();
            if (is == null)
                continue;
            if (ItemStack.areItemsEqual(is, target)) {
                matchingRecipes.add((IRecipe) obj);
            }
        }
    }
    return matchingRecipes;
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 25 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project PneumaticCraft by MineMaarten.

the class CraftingRegistrator method addPressureChamberStorageBlockRecipes.

/**
     * Adds recipes like 9 gold ingot --> 1 gold block, and 1 gold block --> 9 gold ingots.
     */
public static void addPressureChamberStorageBlockRecipes() {
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe recipe : recipes) {
        if (recipe instanceof ShapedRecipes) {
            ShapedRecipes shaped = (ShapedRecipes) recipe;
            ItemStack[] input = shaped.recipeItems;
            ItemStack ref = input[0];
            if (ref == null || input.length < 9)
                continue;
            boolean valid = true;
            for (int i = 0; i < 9; i++) {
                if (input[i] == null || !input[i].isItemEqual(ref)) {
                    valid = false;
                    break;
                }
            }
            if (valid) {
                ItemStack inputStack = ref.copy();
                inputStack.stackSize = 9;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack }, 1.0F, new ItemStack[] { shaped.getRecipeOutput() }, false));
                ItemStack inputStack2 = shaped.getRecipeOutput().copy();
                inputStack2.stackSize = 1;
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[] { inputStack2 }, -0.5F, new ItemStack[] { inputStack }, false));
            }
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ItemStack(net.minecraft.item.ItemStack) PressureChamberRecipe(pneumaticCraft.api.recipe.PressureChamberRecipe)

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