Search in sources :

Example 1 with AbstractPainterTemplate

use of crazypants.enderio.base.recipe.painter.AbstractPainterTemplate in project EnderIO by SleepyTrousers.

the class PainterRecipeCategory method splitRecipes.

// ------------ Recipes
@SuppressWarnings("null")
@Nonnull
private static List<PainterRecipeWrapper> splitRecipes(@Nonnull Collection<IMachineRecipe> recipes, List<ItemStack> validItems) {
    long start = System.nanoTime();
    List<AbstractPainterTemplate<?>> basicPainterTemplates = new ArrayList<AbstractPainterTemplate<?>>();
    for (IMachineRecipe recipe : recipes) {
        if (recipe instanceof AbstractPainterTemplate<?>) {
            basicPainterTemplates.add((AbstractPainterTemplate<?>) recipe);
        }
    }
    List<PainterRecipeWrapper> recipesWrappers = new ArrayList<PainterRecipeWrapper>();
    for (ItemStack target : validItems) {
        for (AbstractPainterTemplate<?> basicPainterTemplate : basicPainterTemplates) {
            if (basicPainterTemplate.isValidTarget(target)) {
                recipesWrappers.add(new PainterRecipeWrapper(basicPainterTemplate, target, new ArrayList<ItemStack>(), new ArrayList<ItemStack>()));
            }
        }
    }
    List<ItemStack> paints = ClientConfig.jeiUseShortenedPainterRecipes.get() ? getLimitedItems(validItems) : validItems;
    int count = 0;
    for (ItemStack paint : paints) {
        try {
            for (PainterRecipeWrapper painterRecipeWrapper : recipesWrappers) {
                if (painterRecipeWrapper.recipe.isRecipe(paint, painterRecipeWrapper.target)) {
                    for (ResultStack result : painterRecipeWrapper.recipe.getCompletedResult(paint, painterRecipeWrapper.target)) {
                        painterRecipeWrapper.results.add(result.item);
                        painterRecipeWrapper.paints.add(paint);
                        count++;
                    }
                }
            }
        } catch (Exception e) {
            Log.warn("PainterRecipeCategory: Error while accessing item '" + paint + "': " + e);
            e.printStackTrace();
        }
    }
    long end = System.nanoTime();
    for (PainterRecipeWrapper painterRecipeWrapper : recipesWrappers) {
        if (painterRecipeWrapper.results.isEmpty()) {
            Log.warn("PainterRecipeCategory: Empty recipe group: " + painterRecipeWrapper.recipe + " for " + painterRecipeWrapper.target);
        }
    }
    Log.info(String.format("PainterRecipeCategory: Added %d painter recipes in %d groups to JEI in %.3f seconds.", count, recipesWrappers.size(), (end - start) / 1000000000d));
    return recipesWrappers;
}
Also used : ArrayList(java.util.ArrayList) ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack) AbstractPainterTemplate(crazypants.enderio.base.recipe.painter.AbstractPainterTemplate) ItemStack(net.minecraft.item.ItemStack) IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe) Nonnull(javax.annotation.Nonnull)

Example 2 with AbstractPainterTemplate

use of crazypants.enderio.base.recipe.painter.AbstractPainterTemplate in project EnderIO by SleepyTrousers.

the class TileEntityPainter method isMachineItemValidForSlot.

@Override
public boolean isMachineItemValidForSlot(int i, @Nonnull ItemStack itemStack) {
    if (i > 1) {
        return false;
    }
    ItemStack paint = i == 0 ? getStackInSlot(1) : itemStack;
    ItemStack targt = i == 0 ? itemStack : getStackInSlot(0);
    Map<String, IMachineRecipe> recipes = MachineRecipeRegistry.instance.getRecipesForMachine(getMachineName());
    for (IMachineRecipe rec : recipes.values()) {
        if (rec instanceof AbstractPainterTemplate<?>) {
            AbstractPainterTemplate<?> temp = (AbstractPainterTemplate<?>) rec;
            if (temp.isPartialRecipe(paint, targt)) {
                return true;
            }
        }
    }
    return false;
}
Also used : AbstractPainterTemplate(crazypants.enderio.base.recipe.painter.AbstractPainterTemplate) ItemStack(net.minecraft.item.ItemStack) IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe)

Aggregations

IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)2 AbstractPainterTemplate (crazypants.enderio.base.recipe.painter.AbstractPainterTemplate)2 ItemStack (net.minecraft.item.ItemStack)2 ResultStack (crazypants.enderio.base.recipe.IMachineRecipe.ResultStack)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1