Search in sources :

Example 11 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class RecipeLoader method addRecipes.

public static void addRecipes() {
    final RecipeFactory recipeFactory = new RecipeFactory(Config.getConfigDirectory(), EnderIO.DOMAIN);
    recipeFactory.createFolder("recipes");
    recipeFactory.createFolder("recipes/user");
    recipeFactory.createFolder("recipes/examples");
    recipeFactory.placeXSD("recipes");
    recipeFactory.placeXSD("recipes/user");
    recipeFactory.placeXSD("recipes/examples");
    recipeFactory.createFileUser("recipes/user/user_recipes.xml");
    NNList<Triple<Integer, RecipeFactory, String>> recipeFiles = new NNList<>();
    for (ModContainer modContainer : Loader.instance().getModList()) {
        Object mod = modContainer.getMod();
        if (mod instanceof IEnderIOAddon) {
            recipeFiles.addAll(((IEnderIOAddon) mod).getRecipeFiles());
            for (String filename : ((IEnderIOAddon) mod).getExampleFiles()) {
                recipeFactory.copyCore("recipes/examples/" + filename + ".xml");
            }
        }
    }
    Collections.sort(recipeFiles, new Comparator<Triple<Integer, RecipeFactory, String>>() {

        @Override
        public int compare(Triple<Integer, RecipeFactory, String> o1, Triple<Integer, RecipeFactory, String> o2) {
            return o1.getLeft().compareTo(o2.getLeft());
        }
    });
    Set<File> userfiles = new HashSet<>(recipeFactory.listXMLFiles("recipes/user"));
    for (Triple<Integer, RecipeFactory, String> triple : recipeFiles) {
        RecipeFactory factory = triple.getMiddle();
        if (factory != null) {
            userfiles.addAll(factory.listXMLFiles("recipes/user"));
        }
    }
    /*
     * Note that we load the recipes in core-imc-user order but merge them in reverse order. The loading order allows aliases to be added in the expected order,
     * while the reverse merging allows user recipes to replace imc recipes to replace core recipes.
     */
    Recipes config = new Recipes();
    if (RecipeConfig.loadCoreRecipes.get()) {
        try {
            for (Triple<Integer, RecipeFactory, String> triple : recipeFiles) {
                config = readCoreFile(NullHelper.first(triple.getMiddle(), recipeFactory), "recipes/" + triple.getRight()).addRecipes(config, false);
            }
        } catch (InvalidRecipeConfigException e) {
            recipeError(NullHelper.first(e.getFilename(), "Core Recipes"), e.getMessage());
        }
    }
    if (imcRecipes != null) {
        config = handleIMCRecipes(config);
        imcRecipes = null;
    }
    for (File file : userfiles) {
        final Recipes userFile = readUserFile(recipeFactory, file.getName(), file);
        if (userFile != null) {
            try {
                config = userFile.addRecipes(config, true);
            } catch (InvalidRecipeConfigException e) {
                recipeError(NullHelper.first(e.getFilename(), file.getName()), e.getMessage());
            }
        }
    }
    config.register("");
    for (ModContainer modContainer : Loader.instance().getModList()) {
        Object mod = modContainer.getMod();
        if (mod instanceof IEnderIOAddon) {
            ((IEnderIOAddon) mod).postRecipeRegistration();
        }
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) IEnderIOAddon(crazypants.enderio.api.addon.IEnderIOAddon) Triple(org.apache.commons.lang3.tuple.Triple) NNList(com.enderio.core.common.util.NNList) Recipes(crazypants.enderio.base.config.recipes.xml.Recipes) File(java.io.File) HashSet(java.util.HashSet)

Example 12 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class Sagmilling method register.

@Override
public void register(@Nonnull String recipeName) {
    if (isValid() && isActive()) {
        ThingsRecipeInput recipeInput = new ThingsRecipeInput(input.getThing());
        NNList<RecipeOutput> recipeOutputs = new NNList<>();
        for (Output output : getOutputs()) {
            if (output instanceof OutputWithChance) {
                recipeOutputs.add(new RecipeOutput(output.getItemStack(), ((OutputWithChance) output).getChance()));
            } else {
                recipeOutputs.add(new RecipeOutput(output.getItemStack(), 1));
            }
        }
        Recipe recipe = new Recipe(recipeInput, energy, bonus, recipeOutputs.toArray(new RecipeOutput[0]));
        SagMillRecipeManager.getInstance().addRecipe(recipe);
    }
}
Also used : Recipe(crazypants.enderio.base.recipe.Recipe) RecipeOutput(crazypants.enderio.base.recipe.RecipeOutput) NNList(com.enderio.core.common.util.NNList) RecipeOutput(crazypants.enderio.base.recipe.RecipeOutput) ThingsRecipeInput(crazypants.enderio.base.recipe.ThingsRecipeInput)

Example 13 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class EnchanterRecipe method getVariants.

public NNList<NNList<MachineRecipeInput>> getVariants() {
    NNList<NNList<MachineRecipeInput>> result = new NNList<>();
    for (int level = 1; level <= enchantment.getMaxLevel(); level++) {
        for (ItemStack item : input.getItemStacks()) {
            item = item.copy();
            for (ItemStack lapis : LAPIS.getItemStacks()) {
                lapis = lapis.copy();
                item.setCount(stackSizePerLevel * level);
                lapis.setCount(getLapizForLevel(level));
                if (item.getCount() <= item.getMaxStackSize() && lapis.getCount() <= lapis.getMaxStackSize()) {
                    result.add(getQuantitiesConsumed(new NNList<>(new MachineRecipeInput(0, BOOK.getItemStacks().get(0)), new MachineRecipeInput(1, item), new MachineRecipeInput(2, lapis))));
                }
            }
        }
    }
    return result;
}
Also used : NNList(com.enderio.core.common.util.NNList) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) ItemStack(net.minecraft.item.ItemStack)

Example 14 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class VatMachineRecipe method getQuantitiesConsumed.

@Override
@Nonnull
public NNList<MachineRecipeInput> getQuantitiesConsumed(@Nonnull NNList<MachineRecipeInput> inputs) {
    NNList<MachineRecipeInput> result = new NNList<MachineRecipeInput>();
    VatRecipe rec = (VatRecipe) getRecipeForInputs(inputs);
    FluidStack inputFluidStack = rec.getRequiredFluidInput(inputs);
    result.add(new MachineRecipeInput(0, inputFluidStack));
    for (MachineRecipeInput ri : inputs) {
        if (!ri.isFluid() && Prep.isValid(ri.item)) {
            ItemStack st = ri.item.copy();
            st.setCount(rec.getNumConsumed(ri.item));
            result.add(new MachineRecipeInput(ri.slotNumber, st));
        }
    }
    return result;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) NNList(com.enderio.core.common.util.NNList) MachineRecipeInput(crazypants.enderio.base.recipe.MachineRecipeInput) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 15 with NNList

use of com.enderio.core.common.util.NNList in project EnderIO by SleepyTrousers.

the class Recipe method getInputStacks.

@Override
@Nonnull
public NNList<ItemStack> getInputStacks() {
    NNList<ItemStack> res = new NNList<>();
    for (int i = 0; i < inputs.length; i++) {
        IRecipeInput in = inputs[i];
        if (in != null && !in.isFluid()) {
            final int slotNumber = in.getSlotNumber() >= 0 ? in.getSlotNumber() : i;
            while (res.size() <= slotNumber) {
                res.add(Prep.getEmpty());
            }
            ItemStack input = in.getInput();
            if (Prep.isValid(input)) {
                res.set(slotNumber, input);
            }
        }
    }
    return res;
}
Also used : NNList(com.enderio.core.common.util.NNList) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

NNList (com.enderio.core.common.util.NNList)53 ItemStack (net.minecraft.item.ItemStack)37 Nonnull (javax.annotation.Nonnull)12 BlockPos (net.minecraft.util.math.BlockPos)8 EntityItem (net.minecraft.entity.item.EntityItem)7 MachineRecipeInput (crazypants.enderio.base.recipe.MachineRecipeInput)5 Block (net.minecraft.block.Block)5 IBlockState (net.minecraft.block.state.IBlockState)5 IHarvestResult (crazypants.enderio.api.farm.IHarvestResult)4 ArrayList (java.util.ArrayList)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 GhostBackgroundItemSlot (com.enderio.core.client.gui.widget.GhostBackgroundItemSlot)3 Recipe (crazypants.enderio.base.recipe.Recipe)3 RecipeOutput (crazypants.enderio.base.recipe.RecipeOutput)3 ThingsRecipeInput (crazypants.enderio.base.recipe.ThingsRecipeInput)3 World (net.minecraft.world.World)3 Triple (org.apache.commons.lang3.tuple.Triple)3 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)2 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)2 IMachineRecipe (crazypants.enderio.base.recipe.IMachineRecipe)2