use of com.minecolonies.api.crafting.IRecipeStorage in project minecolonies by Minecolonies.
the class EntityAIWorkBaker method createNewProduct.
/**
* Create a new product depending on what the baker has available on resources.
*
* @return the next state to transit to.
*/
private AIState createNewProduct() {
progress = 0;
final List<IItemHandler> handlers = getOwnBuilding().getHandlers();
IRecipeStorage storage = null;
int recipeId = 0;
for (final IRecipeStorage tempStorage : BakerRecipes.getRecipes()) {
if (tempStorage.canFullFillRecipe(handlers.toArray(new IItemHandler[handlers.size()]))) {
storage = tempStorage;
break;
}
recipeId++;
}
if (storage == null) {
final List<IRecipeStorage> recipes = BakerRecipes.getRecipes();
final List<ItemStack> lastRecipe = recipes.get(recipes.size() - 1).getInput();
final ItemStack[] arrayToRequestAndRetrieve = lastRecipe.toArray(new ItemStack[lastRecipe.size()]);
checkIfRequestForItemExistOrCreate(arrayToRequestAndRetrieve);
setDelay(UNABLE_TO_CRAFT_DELAY);
return PREPARING;
}
final BakingProduct bakingProduct = new BakingProduct(storage.getPrimaryOutput().copy(), recipeId);
getOwnBuilding().addToTasks(bakingProduct.getState(), bakingProduct);
currentBakingProduct = bakingProduct;
return getState();
}
use of com.minecolonies.api.crafting.IRecipeStorage in project minecolonies by Minecolonies.
the class AbstractCraftingRequestResolver method attemptResolveForBuildingAndStack.
@Nullable
protected List<IToken<?>> attemptResolveForBuildingAndStack(@NotNull final IRequestManager manager, @NotNull final AbstractBuildingWorker building, final ItemStack stack) {
final IRecipeStorage fullfillableCrafting = building.getFirstFullFillableRecipe(stack);
if (fullfillableCrafting != null) {
return ImmutableList.of();
}
final IRecipeStorage craftableCrafting = building.getFirstRecipe(stack);
if (craftableCrafting == null) {
return null;
}
return createRequestsForRecipe(manager, building, stack, craftableCrafting);
}
Aggregations