Search in sources :

Example 1 with IVanillaRecipeFactory

use of mezz.jei.api.recipe.IVanillaRecipeFactory in project EnderIO by SleepyTrousers.

the class DarkSteelUpgradeRecipeCategory method registerBookEnchantmentRecipes.

private static int registerBookEnchantmentRecipes(@Nonnull IModRegistry registry, @Nonnull NNList<ItemStack> ingredients) {
    int count = 0;
    Collection<Enchantment> enchantments = ForgeRegistries.ENCHANTMENTS.getValuesCollection();
    List<IRecipeWrapper> anvilRecipes = new ArrayList<>();
    IVanillaRecipeFactory factory = registry.getJeiHelpers().getVanillaRecipeFactory();
    for (ItemStack ingredient : ingredients) {
        if (ingredient.isItemEnchantable()) {
            for (Enchantment enchantment : enchantments) {
                if (enchantment.canApply(ingredient)) {
                    Item item = ingredient.getItem();
                    List<ItemStack> perLevelBooks = Lists.newArrayList();
                    List<ItemStack> perLevelOutputs = Lists.newArrayList();
                    for (int level = 1; level <= enchantment.getMaxLevel(); level++) {
                        Map<Enchantment, Integer> enchMap = Collections.singletonMap(enchantment, level);
                        ItemStack bookEnchant = new ItemStack(Items.ENCHANTED_BOOK);
                        EnchantmentHelper.setEnchantments(enchMap, bookEnchant);
                        if (item.isBookEnchantable(ingredient, bookEnchant)) {
                            perLevelBooks.add(bookEnchant);
                            ItemStack withEnchant = ingredient.copy();
                            EnchantmentHelper.setEnchantments(enchMap, withEnchant);
                            perLevelOutputs.add(withEnchant);
                        }
                    }
                    if (!perLevelBooks.isEmpty() && !perLevelOutputs.isEmpty()) {
                        anvilRecipes.add(factory.createAnvilRecipe(ingredient, perLevelBooks, perLevelOutputs));
                        count++;
                    }
                }
            }
        }
    }
    registry.addRecipes(anvilRecipes, VanillaRecipeCategoryUid.ANVIL);
    return count;
}
Also used : Item(net.minecraft.item.Item) IDarkSteelItem(crazypants.enderio.api.upgrades.IDarkSteelItem) ArrayList(java.util.ArrayList) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) Enchantment(net.minecraft.enchantment.Enchantment) ItemStack(net.minecraft.item.ItemStack) IVanillaRecipeFactory(mezz.jei.api.recipe.IVanillaRecipeFactory)

Example 2 with IVanillaRecipeFactory

use of mezz.jei.api.recipe.IVanillaRecipeFactory in project EnderIO by SleepyTrousers.

the class DarkSteelUpgradeRecipeCategory method register.

public static void register(IModRegistry registry) {
    long start = System.nanoTime();
    registry.addRecipeCatalyst(new ItemStack(blockDarkSteelAnvil.getBlockNN()), VanillaRecipeCategoryUid.ANVIL);
    NNList<ItemStack> blacklist = new NNList<>();
    for (UpgradePath rec : allRecipes) {
        rec.getOutput().getItem().getSubItems(getCreativeTab(rec), blacklist);
    }
    NNList<ItemStack> seen = new NNList<>();
    for (UpgradePath rec : allRecipes) {
        if (!inList(blacklist, rec.getOutput()) && !inList(seen, rec.getOutput())) {
            seen.add(rec.getOutput());
        }
    }
    int enchantmentRecipes = registerBookEnchantmentRecipes(registry, seen);
    final IVanillaRecipeFactory factory = registry.getJeiHelpers().getVanillaRecipeFactory();
    Collection<IRecipeWrapper> anvilRecipes = NullHelper.notnullJ(allRecipes.stream().map(rec -> factory.createAnvilRecipe(rec.getInput(), Collections.singletonList(rec.getUpgrade()), Collections.singletonList(rec.getOutput()))).collect(Collectors.toList()), "Stream#collect");
    registry.addRecipes(anvilRecipes, VanillaRecipeCategoryUid.ANVIL);
    Log.info(String.format("DarkSteelUpgradeRecipeCategory: Added %d dark steel upgrade recipes and %d enchantment recipes for upgradable items to JEI in %.3f seconds.", allRecipes.size(), enchantmentRecipes, (System.nanoTime() - start) / 1000000000d));
}
Also used : UpgradePath(crazypants.enderio.base.handler.darksteel.DarkSteelRecipeManager.UpgradePath) NNList(com.enderio.core.common.util.NNList) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) ItemStack(net.minecraft.item.ItemStack) IVanillaRecipeFactory(mezz.jei.api.recipe.IVanillaRecipeFactory)

Aggregations

IRecipeWrapper (mezz.jei.api.recipe.IRecipeWrapper)2 IVanillaRecipeFactory (mezz.jei.api.recipe.IVanillaRecipeFactory)2 ItemStack (net.minecraft.item.ItemStack)2 NNList (com.enderio.core.common.util.NNList)1 IDarkSteelItem (crazypants.enderio.api.upgrades.IDarkSteelItem)1 UpgradePath (crazypants.enderio.base.handler.darksteel.DarkSteelRecipeManager.UpgradePath)1 ArrayList (java.util.ArrayList)1 Enchantment (net.minecraft.enchantment.Enchantment)1 Item (net.minecraft.item.Item)1