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