Search in sources :

Example 1 with IFlexibleRecipe

use of buildcraft.api.recipes.IFlexibleRecipe in project LogisticsPipes by RS485.

the class AssemblyTable method importRecipe.

@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
    if (!(tile instanceof TileAssemblyTable)) {
        return false;
    }
    TileAssemblyTable table = (TileAssemblyTable) tile;
    //current pipe inputs/outputs
    final ItemIdentifierInventory inputs = new ItemIdentifierInventory(inventory.getSizeInventory() - 2, "AssemblyTableDummyInv", 64, false);
    for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
        inputs.setInventorySlotContents(i, inventory.getIDStackInSlot(i));
    }
    ItemStack output = inventory.getStackInSlot(inventory.getSizeInventory() - 2);
    //see if there's a recipe planned in the table that matches the current pipe settings, if yes take the next, otherwise take the first
    FlexibleRecipe<ItemStack> firstRecipe = null;
    FlexibleRecipe<ItemStack> nextRecipe = null;
    boolean takeNext = false;
    for (IFlexibleRecipe<ItemStack> r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
        if (!(r instanceof FlexibleRecipe)) {
            continue;
        }
        if (!((FlexibleRecipe<ItemStack>) r).inputFluids.isEmpty()) {
            continue;
        }
        if (table.isPlanned(r)) {
            if (firstRecipe == null) {
                firstRecipe = (FlexibleRecipe<ItemStack>) r;
            }
            if (takeNext) {
                nextRecipe = (FlexibleRecipe<ItemStack>) r;
                break;
            }
            if (output != null && ItemStack.areItemStacksEqual(output, ((FlexibleRecipe<ItemStack>) r).output)) {
                if (((FlexibleRecipe<ItemStack>) r).canBeCrafted(new // Read Proxy to IInventory
                IFlexibleCrafter() {

                    @Override
                    public int getCraftingItemStackSize() {
                        return inputs.getSizeInventory();
                    }

                    @Override
                    public ItemStack getCraftingItemStack(int paramInt) {
                        return inputs.getStackInSlot(paramInt);
                    }

                    @Override
                    public int getCraftingFluidStackSize() {
                        return 0;
                    }

                    @Override
                    public FluidStack getCraftingFluidStack(int paramInt) {
                        return null;
                    }

                    @Override
                    public ItemStack decrCraftingItemStack(int paramInt1, int paramInt2) {
                        return null;
                    }

                    @Override
                    public FluidStack decrCraftingFluidStack(int paramInt1, int paramInt2) {
                        return null;
                    }
                })) {
                    takeNext = true;
                }
            }
        }
    }
    if (nextRecipe == null) {
        nextRecipe = firstRecipe;
    }
    if (nextRecipe == null) {
        return false;
    }
    // Import
    inventory.setInventorySlotContents(inventory.getSizeInventory() - 2, nextRecipe.output);
    try {
        for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
            inventory.clearInventorySlotContents(i);
        }
        int i = 0;
        for (Object input : nextRecipe.inputItems) {
            ItemStack processed = null;
            if (input instanceof String) {
                List<ItemStack> ores = OreDictionary.getOres((String) input);
                if (ores != null && ores.size() > 0) {
                    input = ores.get(0);
                }
            } else if (input instanceof ItemStack) {
                processed = (ItemStack) input;
            } else if (input instanceof Item) {
                processed = new ItemStack((Item) input);
            } else if (input instanceof Block) {
                processed = new ItemStack((Block) input, 1, 0);
            } else if (input instanceof Integer) {
                processed = null;
            } else {
                throw new IllegalArgumentException("Unknown Object passed to recipe!");
            }
            if (processed != null) {
                inventory.setInventorySlotContents(i, processed);
                ++i;
            }
        }
    } catch (ClassCastException e) {
    // TODO: make it show a nice error or
    // remove this hack altogether.
    }
    // Compact
    inventory.compact_first(9);
    return true;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) Item(net.minecraft.item.Item) TileAssemblyTable(buildcraft.silicon.TileAssemblyTable) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) FlexibleRecipe(buildcraft.core.recipes.FlexibleRecipe) IFlexibleRecipe(buildcraft.api.recipes.IFlexibleRecipe)

Aggregations

IFlexibleRecipe (buildcraft.api.recipes.IFlexibleRecipe)1 FlexibleRecipe (buildcraft.core.recipes.FlexibleRecipe)1 TileAssemblyTable (buildcraft.silicon.TileAssemblyTable)1 ItemIdentifierInventory (logisticspipes.utils.item.ItemIdentifierInventory)1 Block (net.minecraft.block.Block)1 Item (net.minecraft.item.Item)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1