Search in sources :

Example 1 with IMachineRecipe

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

the class PoweredTask method readFromNBT.

@Nullable
public static IPoweredTask readFromNBT(@Nonnull NBTTagCompound nbtRoot) {
    IMachineRecipe recipe;
    float usedEnergy = nbtRoot.getFloat(KEY_USED_ENERGY);
    long seed = nbtRoot.getLong(KEY_SEED);
    float outputMultiplier = nbtRoot.getFloat(KEY_CHANCE_OUTPUT);
    float chanceMultiplier = nbtRoot.getFloat(KEY_CHANCE_MULTI);
    NBTTagList inputItems = (NBTTagList) nbtRoot.getTag(KEY_INPUT_STACKS);
    NNList<MachineRecipeInput> ins = new NNList<MachineRecipeInput>();
    for (int i = 0; i < inputItems.tagCount(); i++) {
        NBTTagCompound stackTag = inputItems.getCompoundTagAt(i);
        MachineRecipeInput mi = MachineRecipeInput.readFromNBT(stackTag);
        ins.add(mi);
    }
    String uid = nbtRoot.getString(KEY_RECIPE);
    recipe = MachineRecipeRegistry.instance.getRecipeForUid(uid);
    if (recipe != null) {
        return new PoweredTask(recipe, usedEnergy, seed, outputMultiplier, chanceMultiplier, ins);
    }
    return null;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NNList(com.enderio.core.common.util.NNList) IPoweredTask(crazypants.enderio.base.machine.interfaces.IPoweredTask) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe) Nullable(javax.annotation.Nullable)

Example 2 with IMachineRecipe

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

the class AbstractPoweredTaskEntity method processTasks.

@Override
protected boolean processTasks(boolean redstoneChecksPassed) {
    if (!redstoneChecksPassed) {
        return false;
    }
    boolean requiresClientSync = false;
    // Process any current items
    requiresClientSync |= checkProgress(redstoneChecksPassed);
    if (currentTask != null || !hasPower() || !hasInputStacks()) {
        return requiresClientSync;
    }
    if (startFailed) {
        ticksSinceCheckedRecipe++;
        if (ticksSinceCheckedRecipe < 20) {
            return false;
        }
    }
    ticksSinceCheckedRecipe = 0;
    // If a recipe could not be started we will try with the same chance next time
    if (theNextSeed == null) {
        theNextSeed = random.nextLong();
    }
    // Then see if we need to start a new one
    IMachineRecipe nextRecipe = canStartNextTask(theNextSeed);
    if (nextRecipe != null) {
        boolean started = startNextTask(nextRecipe, theNextSeed);
        if (started) {
            // this chance value has been used up
            theNextSeed = null;
        }
        startFailed = !started;
    } else {
        startFailed = true;
    }
    return requiresClientSync;
}
Also used : IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe)

Example 3 with IMachineRecipe

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

the class TileSoulBinder method isMachineItemValidForSlot.

@Override
public boolean isMachineItemValidForSlot(int slot, @Nonnull ItemStack item) {
    if (!slotDefinition.isInputSlot(slot)) {
        return false;
    }
    MachineRecipeInput newInput = new MachineRecipeInput(slot, item);
    int otherSlot = slot == 0 ? 1 : 0;
    if (Prep.isInvalid(getStackInSlot(otherSlot))) {
        List<IMachineRecipe> recipes = MachineRecipeRegistry.instance.getRecipesForInput(getMachineName(), newInput);
        if (recipes.isEmpty()) {
            return false;
        }
        for (IMachineRecipe rec : recipes) {
            if (rec != null && rec.isValidInput(newInput)) {
                return true;
            }
        }
    } else {
        NNList<MachineRecipeInput> inputs = new NNList<>(newInput, new MachineRecipeInput(otherSlot, getStackInSlot(otherSlot)));
        return MachineRecipeRegistry.instance.getRecipeForInputs(getMachineName(), inputs) != null;
    }
    return false;
}
Also used : NNList(com.enderio.core.common.util.NNList) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe)

Example 4 with IMachineRecipe

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

the class TileSliceAndSplice method isMachineItemValidForSlot.

@Override
public boolean isMachineItemValidForSlot(int slot, @Nonnull ItemStack itemstack) {
    if (Prep.isInvalid(itemstack)) {
        return false;
    }
    if (!slotDefinition.isInputSlot(slot)) {
        return false;
    }
    if (slot == axeIndex) {
        return FarmingTool.AXE.itemMatches(itemstack);
    }
    if (slot == shearsIndex) {
        return FarmingTool.SHEARS.itemMatches(itemstack);
    }
    ItemStack currentStackInSlot = getStackInSlot(slot);
    if (Prep.isValid(currentStackInSlot)) {
        return currentStackInSlot.isItemEqual(itemstack);
    }
    int numSlotsFilled = 0;
    for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) {
        if (i >= 0 && i < inventory.length && i != axeIndex && i != shearsIndex) {
            if (Prep.isValid(getStackInSlot(i))) {
                numSlotsFilled++;
            }
        }
    }
    List<IMachineRecipe> recipes = MachineRecipeRegistry.instance.getRecipesForInput(getMachineName(), MachineRecipeInput.create(slot, itemstack));
    return isValidInputForAlloyRecipe(slot, itemstack, numSlotsFilled, recipes);
}
Also used : ItemStack(net.minecraft.item.ItemStack) IMachineRecipe(crazypants.enderio.base.recipe.IMachineRecipe)

Example 5 with IMachineRecipe

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

Aggregations

IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)9 ItemStack (net.minecraft.item.ItemStack)4 NNList (com.enderio.core.common.util.NNList)2 IPoweredTask (crazypants.enderio.base.machine.interfaces.IPoweredTask)2 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)2 AbstractPainterTemplate (crazypants.enderio.base.recipe.painter.AbstractPainterTemplate)2 ResultStack (crazypants.enderio.base.recipe.IMachineRecipe.ResultStack)1 VanillaSmeltingRecipe (crazypants.enderio.base.recipe.alloysmelter.VanillaSmeltingRecipe)1 ISoulBinderRecipe (crazypants.enderio.base.recipe.soul.ISoulBinderRecipe)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1