Search in sources :

Example 6 with IRecipeStorage

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();
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) ItemStack(net.minecraft.item.ItemStack)

Example 7 with IRecipeStorage

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);
}
Also used : IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)7 ItemStack (net.minecraft.item.ItemStack)2 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 AddRemoveRecipeMessage (com.minecolonies.coremod.network.messages.AddRemoveRecipeMessage)1 ChangeRecipePriorityMessage (com.minecolonies.coremod.network.messages.ChangeRecipePriorityMessage)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1 Nullable (org.jetbrains.annotations.Nullable)1