Search in sources :

Example 26 with IRecipe

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

the class PipeBlockRequestTable method cacheRecipe.

public void cacheRecipe() {
    ItemIdentifier oldTargetType = targetType;
    cache = null;
    resultInv.clearInventorySlotContents(0);
    AutoCraftingInventory craftInv = new AutoCraftingInventory(null);
    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, getWorld())) {
            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(null);
                for (int i = 0; i < 9; i++) {
                    craftInv.setInventorySlotContents(i, matrix.getStackInSlot(i));
                }
                ItemStack result = recipe.getCraftingResult(craftInv);
                if (targetType == ItemIdentifier.get(result)) {
                    resultInv.setInventorySlotContents(0, result);
                    cache = recipe;
                    break;
                }
            }
        }
        if (cache == null) {
            cache = list.get(0);
            ItemStack result = cache.getCraftingResult(craftInv);
            resultInv.setInventorySlotContents(0, result);
            targetType = ItemIdentifier.get(result);
        }
    } else {
        targetType = null;
    }
    if (targetType != oldTargetType && !localGuiWatcher.isEmpty() && getWorld() != null && MainProxy.isServer(getWorld())) {
        MainProxy.sendToPlayerList(PacketHandler.getPacket(CraftingSetType.class).setTargetType(targetType).setTilePos(container), localGuiWatcher);
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) CraftingSetType(logisticspipes.network.packets.block.CraftingSetType) IRecipe(net.minecraft.item.crafting.IRecipe) AutoCraftingInventory(logisticspipes.blocks.crafting.AutoCraftingInventory) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 27 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project ArsMagica2 by Mithion.

the class TileEntityArcaneDeconstructor method getDeconstructionRecipe.

private boolean getDeconstructionRecipe() {
    ItemStack checkStack = getStackInSlot(0);
    ArrayList<ItemStack> recipeItems = new ArrayList<ItemStack>();
    if (checkStack == null)
        return false;
    if (checkStack.getItem() == ItemsCommonProxy.spell) {
        int numStages = SpellUtils.instance.numStages(checkStack);
        for (int i = 0; i < numStages; ++i) {
            ISpellShape shape = SpellUtils.instance.getShapeForStage(checkStack, i);
            Object[] componentParts = shape.getRecipeItems();
            if (componentParts != null) {
                for (Object o : componentParts) {
                    ItemStack stack = objectToItemStack(o);
                    if (stack != null) {
                        if (stack.getItem() == ItemsCommonProxy.bindingCatalyst) {
                            stack.setItemDamage(((Binding) SkillManager.instance.getSkill("Binding")).getBindingType(checkStack));
                        }
                        recipeItems.add(stack.copy());
                    }
                }
            }
            ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(checkStack, i);
            for (ISpellComponent component : components) {
                componentParts = component.getRecipeItems();
                if (componentParts != null) {
                    for (Object o : componentParts) {
                        ItemStack stack = objectToItemStack(o);
                        if (stack != null) {
                            if (stack.getItem() == ItemsCommonProxy.crystalPhylactery) {
                                ItemsCommonProxy.crystalPhylactery.setSpawnClass(stack, ((Summon) SkillManager.instance.getSkill("Summon")).getSummonType(checkStack));
                                ItemsCommonProxy.crystalPhylactery.addFill(stack, 100);
                            }
                            recipeItems.add(stack.copy());
                        }
                    }
                }
            }
            ISpellModifier[] modifiers = SpellUtils.instance.getModifiersForStage(checkStack, i);
            for (ISpellModifier modifier : modifiers) {
                componentParts = modifier.getRecipeItems();
                if (componentParts != null) {
                    for (Object o : componentParts) {
                        ItemStack stack = objectToItemStack(o);
                        if (stack != null)
                            recipeItems.add(stack.copy());
                    }
                }
            }
        }
        int numShapeGroups = SpellUtils.instance.numShapeGroups(checkStack);
        for (int i = 0; i < numShapeGroups; ++i) {
            int[] parts = SpellUtils.instance.getShapeGroupParts(checkStack, i);
            for (int partID : parts) {
                ISkillTreeEntry entry = SkillManager.instance.getSkill(partID);
                if (entry != null && entry instanceof ISpellPart) {
                    Object[] componentParts = ((ISpellPart) entry).getRecipeItems();
                    if (componentParts != null) {
                        for (Object o : componentParts) {
                            ItemStack stack = objectToItemStack(o);
                            if (stack != null) {
                                if (stack.getItem() == ItemsCommonProxy.bindingCatalyst) {
                                    stack.setItemDamage(((Binding) SkillManager.instance.getSkill("Binding")).getBindingType(checkStack));
                                }
                                recipeItems.add(stack.copy());
                            }
                        }
                    }
                }
            }
        }
        deconstructionRecipe = recipeItems.toArray(new ItemStack[recipeItems.size()]);
        return true;
    } else {
        IRecipe recipe = RecipeUtilities.getRecipeFor(checkStack);
        if (recipe == null)
            return false;
        Object[] recipeParts = RecipeUtilities.getRecipeItems(recipe);
        if (recipeParts != null && checkStack != null && recipe.getRecipeOutput() != null) {
            if (recipe.getRecipeOutput().getItem() == checkStack.getItem() && recipe.getRecipeOutput().getItemDamage() == checkStack.getItemDamage() && recipe.getRecipeOutput().stackSize > 1)
                return false;
            for (Object o : recipeParts) {
                ItemStack stack = objectToItemStack(o);
                if (stack != null && !stack.getItem().hasContainerItem(stack)) {
                    stack.stackSize = 1;
                    recipeItems.add(stack.copy());
                }
            }
        }
        deconstructionRecipe = recipeItems.toArray(new ItemStack[recipeItems.size()]);
        return true;
    }
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 28 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project ArsMagica2 by Mithion.

the class GuiArcaneCompendium method getAndAnalyzeRecipe.

private void getAndAnalyzeRecipe() {
    if (renderStack == null)
        return;
    if (renderStack.getItem() == ItemsCommonProxy.essence || renderStack.getItem() == ItemsCommonProxy.deficitCrystal) {
        RecipeArsMagica essenceRecipe = RecipesEssenceRefiner.essenceRefinement().recipeFor(renderStack);
        if (essenceRecipe != null) {
            craftingComponents = essenceRecipe.getRecipeItems();
            recipeHeight = 2;
        } else {
            craftingComponents = null;
        }
    } else if (renderStack.getItem() instanceof ItemSpellPart) {
        ISkillTreeEntry part = SkillManager.instance.getSkill(this.entryName);
        if (part == null)
            return;
        ArrayList<Object> recipe = new ArrayList<Object>();
        if (part instanceof ISpellPart) {
            Object[] recipeItems = ((ISpellPart) part).getRecipeItems();
            SpellRecipeItemsEvent event = new SpellRecipeItemsEvent(SkillManager.instance.getSkillName(part), SkillManager.instance.getShiftedPartID(part), recipeItems);
            MinecraftForge.EVENT_BUS.post(event);
            recipeItems = event.recipeItems;
            if (recipeItems != null) {
                for (int i = 0; i < recipeItems.length; ++i) {
                    Object o = recipeItems[i];
                    boolean matches = false;
                    if (o instanceof ItemStack) {
                        recipe.add(o);
                    } else if (o instanceof Item) {
                        recipe.add(new ItemStack((Item) o));
                    } else if (o instanceof Block) {
                        recipe.add(new ItemStack((Block) o));
                    } else if (o instanceof String) {
                        if (((String) o).startsWith("P:")) {
                            //potion
                            String s = ((String) o).substring(2);
                            int pfx = SpellRecipeManager.parsePotionMeta(s);
                            recipe.add(new ItemStack(Items.potionitem, 1, pfx));
                        } else if (((String) o).startsWith("E:")) {
                            //essence
                            String s = ((String) o);
                            try {
                                int[] types = SpellRecipeManager.ParseEssenceIDs(s);
                                int type = 0;
                                for (int t : types) type |= t;
                                int amount = (Integer) recipeItems[++i];
                                recipe.add(new ItemStack(ItemsCommonProxy.essence, amount, ItemsCommonProxy.essence.META_MAX + type));
                            } catch (Throwable t) {
                                continue;
                            }
                        } else {
                            recipe.add(OreDictionary.getOres((String) o));
                        }
                    }
                }
            }
        }
        craftingComponents = recipe.toArray();
    } else {
        IRecipe recipe = RecipeUtilities.getRecipeFor(renderStack);
        if (recipe != null) {
            renderStack = recipe.getRecipeOutput();
            if (recipe instanceof ShapedRecipes) {
                recipeWidth = ((ShapedRecipes) recipe).recipeWidth;
                recipeHeight = ((ShapedRecipes) recipe).recipeHeight;
                craftingComponents = ((ShapedRecipes) recipe).recipeItems;
            } else if (recipe instanceof ShapedOreRecipe) {
                recipeWidth = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "width");
                recipeHeight = ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, ((ShapedOreRecipe) recipe), "height");
                craftingComponents = ((ShapedOreRecipe) recipe).getInput();
            } else if (recipe instanceof ShapelessRecipes) {
                recipeWidth = ((ShapelessRecipes) recipe).getRecipeSize();
                recipeHeight = -1;
                craftingComponents = ((ShapelessRecipes) recipe).recipeItems.toArray();
            } else if (recipe instanceof ShapelessOreRecipe) {
                recipeWidth = ((ShapelessOreRecipe) recipe).getRecipeSize();
                recipeHeight = -1;
                craftingComponents = ((ShapelessOreRecipe) recipe).getInput().toArray();
            } else {
                craftingComponents = null;
            }
        } else {
            craftingComponents = null;
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ItemSpellPart(am2.items.ItemSpellPart) ISpellPart(am2.api.spell.component.interfaces.ISpellPart) RecipeArsMagica(am2.items.RecipeArsMagica) Item(net.minecraft.item.Item) RenderItem(net.minecraft.client.renderer.entity.RenderItem) SpellRecipeItemsEvent(am2.api.events.SpellRecipeItemsEvent) ISkillTreeEntry(am2.api.spell.component.interfaces.ISkillTreeEntry) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 29 with IRecipe

use of net.minecraft.item.crafting.IRecipe in project VoodooCraft by Mod-DevCafeTeam.

the class TileDeathGlyph method hasRecipe.

/**
     * Checks the CraftingManager and the FurnaceRecipes for a recipe for the ItemStack and returns true if it finds one
     */
private static boolean hasRecipe(ItemStack stack) {
    if (stack == null)
        return false;
    //Check crafting recipes
    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe r : recipes) if (r.getRecipeOutput() != null && r.getRecipeOutput().isItemEqual(stack))
        return true;
    //Check furnace recipes
    Collection<ItemStack> furnaceResults = FurnaceRecipes.instance().getSmeltingList().values();
    for (ItemStack s : furnaceResults) if (s.isItemEqual(stack))
        return true;
    return false;
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 30 with IRecipe

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

the class CraftingPlugin method addShapelessRecipe.

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

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