Search in sources :

Example 1 with CraftingResult

use of buildcraft.api.recipes.CraftingResult 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)

Example 2 with CraftingResult

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

the class GuiAssemblyTableOld method updateRecipes.

public void updateRecipes() {
    Set<String> addedRecipes = new HashSet<>();
    List<CraftingResult<ItemStack>> potentialRecipes = table.getPotentialOutputs();
    Iterator<CraftingResult<ItemStack>> cur = potentialRecipes.iterator();
    Collection<String> plannedIcons = table.plannedOutputIcons.keySet();
    Iterator<String> cur2 = plannedIcons.iterator();
    for (AdvancedSlot s : slots) {
        if (cur.hasNext()) {
            ((RecipeSlot) s).crafting = cur.next();
            ((RecipeSlot) s).craftable = true;
            addedRecipes.add(((RecipeSlot) s).crafting.recipe.getId());
        } else {
            String recipe = null;
            while (cur2.hasNext() && (recipe == null || addedRecipes.contains(recipe))) {
                recipe = cur2.next();
            }
            if (recipe != null && !addedRecipes.contains(recipe)) {
                ((RecipeSlot) s).crafting = table.plannedOutputIcons.get(recipe);
                ((RecipeSlot) s).craftable = false;
            } else {
                ((RecipeSlot) s).crafting = null;
            }
        }
    }
}
Also used : AdvancedSlot(buildcraft.core.lib.gui.AdvancedSlot) CraftingResult(buildcraft.api.recipes.CraftingResult) HashSet(java.util.HashSet)

Aggregations

CraftingResult (buildcraft.api.recipes.CraftingResult)2 IStackFilter (buildcraft.api.core.IStackFilter)1 IFlexibleCrafter (buildcraft.api.recipes.IFlexibleCrafter)1 AdvancedSlot (buildcraft.core.lib.gui.AdvancedSlot)1 ArrayStackFilter (buildcraft.lib.inventory.filter.ArrayStackFilter)1 HashSet (java.util.HashSet)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1