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;
}
Aggregations