Search in sources :

Example 1 with IFlexibleCrafter

use of buildcraft.api.recipes.IFlexibleCrafter in project BuildCraft by BuildCraft.

the class FlexibleRecipe method craft.

@Override
public CraftingResult<T> craft(IFlexibleCrafter baseCrafter, boolean preview) {
    if (output == null) {
        return null;
    }
    IFlexibleCrafter crafter = baseCrafter;
    if (preview) {
        crafter = new FakeFlexibleCrafter(baseCrafter);
    }
    CraftingResult<T> result = new CraftingResult<>();
    result.recipe = this;
    result.powerCost = powerCost;
    result.craftingTime = craftingTime;
    for (ItemStack requirement : inputItems) {
        IStackFilter filter = new ArrayStackFilter(requirement);
        int amount = requirement.stackSize;
        if (consumeItems(crafter, result, filter, amount) != 0) {
            return null;
        }
    }
    for (List<ItemStack> requirements : inputItemsWithAlternatives) {
        IStackFilter filter = new ArrayStackFilter(requirements.toArray(new ItemStack[requirements.size()]));
        int amount = requirements.get(0).stackSize;
        if (consumeItems(crafter, result, filter, amount) != 0) {
            return null;
        }
    }
    for (FluidStack requirement : inputFluids) {
        int amount = requirement.amount;
        for (int tankid = 0; tankid < crafter.getCraftingFluidStackSize(); tankid++) {
            FluidStack fluid = crafter.getCraftingFluidStack(tankid);
            if (fluid != null && fluid.isFluidEqual(requirement)) {
                int amountUsed;
                if (fluid.amount > amount) {
                    amountUsed = amount;
                    if (!preview) {
                        crafter.decrCraftingFluidStack(tankid, amount);
                    }
                    amount = 0;
                } else {
                    amountUsed = fluid.amount;
                    if (!preview) {
                        crafter.decrCraftingFluidStack(tankid, fluid.amount);
                    }
                    amount -= fluid.amount;
                }
                result.usedFluids.add(new FluidStack(requirement.getFluid(), amountUsed));
            }
            if (amount == 0) {
                break;
            }
        }
        if (amount != 0) {
            return null;
        }
    }
    // Output generation
    result.crafted = output;
    return result;
}
Also used : ArrayStackFilter(buildcraft.lib.inventory.filter.ArrayStackFilter) FluidStack(net.minecraftforge.fluids.FluidStack) IStackFilter(buildcraft.api.core.IStackFilter) IFlexibleCrafter(buildcraft.api.recipes.IFlexibleCrafter) ItemStack(net.minecraft.item.ItemStack) CraftingResult(buildcraft.api.recipes.CraftingResult)

Aggregations

IStackFilter (buildcraft.api.core.IStackFilter)1 CraftingResult (buildcraft.api.recipes.CraftingResult)1 IFlexibleCrafter (buildcraft.api.recipes.IFlexibleCrafter)1 ArrayStackFilter (buildcraft.lib.inventory.filter.ArrayStackFilter)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1