Search in sources :

Example 1 with ResultStack

use of crazypants.enderio.base.recipe.IMachineRecipe.ResultStack in project EnderIO by SleepyTrousers.

the class PainterRecipeCategory method setRecipe.

@Override
public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull PainterRecipeCategory.PainterRecipeWrapper currentRecipe, @Nonnull IIngredients ingredients) {
    IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
    IGuiIngredientGroup<EnergyIngredient> group = recipeLayout.getIngredientsGroup(EnergyIngredient.class);
    guiItemStacks.init(0, true, 67 - xOff - 1, 34 - yOff - 1);
    guiItemStacks.init(1, true, 38 - xOff - 1, 34 - yOff - 1);
    guiItemStacks.init(2, false, 121 - xOff - 1, 34 - yOff - 1);
    group.init(3, true, EnergyIngredientRenderer.INSTANCE, 108 - xOff, 60 - yOff, 50, 10, 0, 0);
    IFocus<?> focus = recipeLayout.getFocus();
    if (focus != null) {
        Object focusValue = focus.getValue();
        if (focusValue instanceof ItemStack) {
            ItemStack focused = (ItemStack) focusValue;
            List<ItemStack> paints = new ArrayList<ItemStack>();
            List<ItemStack> results = new ArrayList<ItemStack>();
            if (focus.getMode() == IFocus.Mode.OUTPUT) {
                // JEI is focusing on the output item. Limit the recipe to the fixed input item, the focused output item and the matching paint.
                IBlockState paint = PaintUtil.getSourceBlock(focused);
                ItemStack paintAsStack = PaintUtil.getPaintAsStack(paint);
                paints.add(paintAsStack);
                results.add(focused);
            } else if (stackHelper.isEquivalent(focused, currentRecipe.target)) {
                // between weird and wrong. So remove the recipe "item+item" from the list to get "anything+item=anything".
                for (int i = 0; i < currentRecipe.paints.size(); i++) {
                    ItemStack resultStack = currentRecipe.results.get(i);
                    ItemStack paintStack = currentRecipe.paints.get(i);
                    if (!stackHelper.isEquivalent(focused, paintStack)) {
                        paints.add(paintStack);
                        results.add(resultStack);
                    }
                }
            } else {
                // JEI is focusing on the paint. Limit the output items to things that are painted with this paint.
                for (ResultStack result : currentRecipe.recipe.getCompletedResult(focused, currentRecipe.target)) {
                    paints.add(focused);
                    results.add(result.item);
                }
            }
            if (!paints.isEmpty()) {
                guiItemStacks.set(1, paints);
                guiItemStacks.set(2, results);
                return;
            }
        }
    }
    guiItemStacks.set(0, currentRecipe.target);
    guiItemStacks.set(1, currentRecipe.paints);
    guiItemStacks.set(2, currentRecipe.results);
    group.set(ingredients);
}
Also used : EnergyIngredient(crazypants.enderio.base.integration.jei.energy.EnergyIngredient) IBlockState(net.minecraft.block.state.IBlockState) ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack) IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ResultStack

use of crazypants.enderio.base.recipe.IMachineRecipe.ResultStack 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 3 with ResultStack

use of crazypants.enderio.base.recipe.IMachineRecipe.ResultStack in project EnderIO by SleepyTrousers.

the class AbstractPoweredTaskEntity method mergeResults.

protected void mergeResults(@Nonnull ResultStack[] results) {
    final int numOutputSlots = slotDefinition.getNumOutputSlots();
    if (numOutputSlots > 0) {
        List<ItemStack> outputStacks = new ArrayList<ItemStack>(numOutputSlots);
        for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
            ItemStack it = inventory[i];
            if (it != null && Prep.isValid(it)) {
                it = it.copy();
            }
            outputStacks.add(it);
        }
        for (ResultStack result : results) {
            if (Prep.isValid(result.item)) {
                int numMerged = mergeItemResult(result.item, outputStacks);
                if (numMerged > 0) {
                    result.item.shrink(numMerged);
                }
            } else if (result.fluid != null) {
                mergeFluidResult(result);
            }
        }
        int listIndex = 0;
        for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
            ItemStack st = outputStacks.get(listIndex);
            if (st != null && Prep.isValid(st)) {
                st = st.copy();
            }
            inventory[i] = st;
            listIndex++;
        }
    } else {
        for (ResultStack result : results) {
            if (Prep.isValid(result.item)) {
                Block.spawnAsEntity(world, pos, result.item.copy());
                result.item.setCount(0);
            } else if (result.fluid != null) {
                mergeFluidResult(result);
            }
        }
    }
    cachedNextRecipe = null;
}
Also used : ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ResultStack

use of crazypants.enderio.base.recipe.IMachineRecipe.ResultStack in project EnderIO by SleepyTrousers.

the class AbstractPoweredTaskEntity method canInsertResult.

protected boolean canInsertResult(long nextSeed, @Nonnull IMachineRecipe nextRecipe) {
    final IPoweredTask task = createTask(nextRecipe, nextSeed);
    if (task == null) {
        return false;
    }
    ResultStack[] nextResults = task.getCompletedResult();
    List<ItemStack> outputStacks = null;
    final int numOutputSlots = slotDefinition.getNumOutputSlots();
    if (numOutputSlots > 0) {
        outputStacks = new ArrayList<ItemStack>(numOutputSlots);
        boolean allFull = true;
        for (int i = slotDefinition.minOutputSlot; i <= slotDefinition.maxOutputSlot; i++) {
            ItemStack st = inventory[i];
            if (st != null && Prep.isValid(st)) {
                st = st.copy();
                if (allFull && st.getCount() < st.getMaxStackSize()) {
                    allFull = false;
                }
            } else {
                allFull = false;
            }
            outputStacks.add(st);
        }
        if (allFull) {
            return false;
        }
    }
    for (ResultStack result : nextResults) {
        if (Prep.isValid(result.item)) {
            if (outputStacks == null || mergeItemResult(result.item, outputStacks) == 0) {
                return false;
            }
        } else if (result.fluid != null) {
            if (!canInsertResultFluid(result)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack) IPoweredTask(crazypants.enderio.base.machine.interfaces.IPoweredTask) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ResultStack

use of crazypants.enderio.base.recipe.IMachineRecipe.ResultStack in project EnderIO by SleepyTrousers.

the class PoweredTask method getCompletedResult.

@Override
@Nonnull
public ResultStack[] getCompletedResult() {
    Random rand = new Random(nextSeed);
    NNList<ResultStack> result = new NNList<>();
    result.addAll(recipe.getCompletedResult(rand.nextLong(), getBonusType().doChances() ? chanceMultiplier : 1f, inputs));
    if (getBonusType().doMultiply()) {
        float mul = outputMultiplier - 1f;
        while (mul > 0) {
            if (rand.nextFloat() < mul) {
                result.addAll(recipe.getCompletedResult(rand.nextLong(), getBonusType().doChances() ? chanceMultiplier : 1f, inputs));
            }
            mul--;
        }
    }
    return result.toArray(new ResultStack[0]);
}
Also used : Random(java.util.Random) ResultStack(crazypants.enderio.base.recipe.IMachineRecipe.ResultStack) NNList(com.enderio.core.common.util.NNList) Nonnull(javax.annotation.Nonnull)

Aggregations

ResultStack (crazypants.enderio.base.recipe.IMachineRecipe.ResultStack)6 ItemStack (net.minecraft.item.ItemStack)4 ArrayList (java.util.ArrayList)3 Nonnull (javax.annotation.Nonnull)2 NNList (com.enderio.core.common.util.NNList)1 EnergyIngredient (crazypants.enderio.base.integration.jei.energy.EnergyIngredient)1 IPoweredTask (crazypants.enderio.base.machine.interfaces.IPoweredTask)1 IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)1 EnchanterRecipe (crazypants.enderio.base.recipe.enchanter.EnchanterRecipe)1 AbstractPainterTemplate (crazypants.enderio.base.recipe.painter.AbstractPainterTemplate)1 Random (java.util.Random)1 IGuiItemStackGroup (mezz.jei.api.gui.IGuiItemStackGroup)1 IBlockState (net.minecraft.block.state.IBlockState)1