Search in sources :

Example 1 with IGenericRecipe

use of com.minecolonies.api.crafting.IGenericRecipe in project minecolonies by Minecolonies.

the class GenericRecipeCategory method findRecipes.

@NotNull
public List<IGenericRecipe> findRecipes(@NotNull final Map<IRecipeType<?>, List<IGenericRecipe>> vanilla) {
    final List<IGenericRecipe> recipes = new ArrayList<>();
    // vanilla shaped and shapeless crafting recipes
    if (this.crafting.canLearnCraftingRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.CRAFTING)) {
            if (!this.crafting.canLearnLargeRecipes() && recipe.getGridSize() > 2)
                continue;
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // vanilla furnace recipes (do we want to check smoking and blasting too?)
    if (this.crafting.canLearnFurnaceRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.SMELTING)) {
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // custom MineColonies additional recipes
    for (final CustomRecipe customRecipe : CustomRecipeManager.getInstance().getRecipes(this.crafting.getCustomRecipeKey())) {
        final IRecipeStorage recipeStorage = customRecipe.getRecipeStorage();
        if (!recipeStorage.getAlternateOutputs().isEmpty()) {
            // this is a multi-output recipe; assume it replaces a bunch of vanilla
            // recipes we already added above
            recipes.removeIf(r -> ItemStackUtils.compareItemStacksIgnoreStackSize(recipeStorage.getPrimaryOutput(), r.getPrimaryOutput()));
            recipes.removeIf(r -> recipeStorage.getAlternateOutputs().stream().anyMatch(s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, r.getPrimaryOutput())));
        }
        recipes.add(GenericRecipeUtils.create(customRecipe, recipeStorage));
    }
    // and even more recipes that can't be taught, but are just inherent in the worker AI
    recipes.addAll(this.crafting.getAdditionalRecipesForDisplayPurposesOnly());
    return recipes.stream().sorted(Comparator.comparing(IGenericRecipe::getLevelSort).thenComparing(r -> r.getPrimaryOutput().getItem().getRegistryName())).collect(Collectors.toList());
}
Also used : BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IIngredients(mezz.jei.api.ingredients.IIngredients) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) IRecipeType(net.minecraft.item.crafting.IRecipeType) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) LootTableAnalyzer(com.minecolonies.coremod.colony.crafting.LootTableAnalyzer) BlockState(net.minecraft.block.BlockState) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) IDrawableStatic(mezz.jei.api.gui.drawable.IDrawableStatic) Collectors(java.util.stream.Collectors) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) Blocks(net.minecraft.block.Blocks) ResourceLocation(net.minecraft.util.ResourceLocation) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) VanillaTypes(mezz.jei.api.constants.VanillaTypes) NotNull(org.jetbrains.annotations.NotNull) IJob(com.minecolonies.api.colony.jobs.IJob) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IGenericRecipe

use of com.minecolonies.api.crafting.IGenericRecipe in project minecolonies by Minecolonies.

the class JEIPlugin method tryAddingVanillaRecipe.

private void tryAddingVanillaRecipe(@NotNull final List<IGenericRecipe> recipes, @NotNull final IRecipe<?> recipe) {
    // invalid or special recipes
    if (recipe.getResultItem().isEmpty())
        return;
    try {
        final IGenericRecipe genericRecipe = GenericRecipeUtils.create(recipe);
        if (genericRecipe.getInputs().isEmpty())
            return;
        recipes.add(genericRecipe);
    } catch (final Exception ex) {
        Log.getLogger().warn("Error evaluating recipe " + recipe.getId() + "; ignoring.", ex);
    }
}
Also used : IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe)

Example 3 with IGenericRecipe

use of com.minecolonies.api.crafting.IGenericRecipe in project minecolonies by Minecolonies.

the class JEIPlugin method buildVanillaRecipesMap.

private Map<IRecipeType<?>, List<IGenericRecipe>> buildVanillaRecipesMap() {
    final RecipeManager recipeManager = Minecraft.getInstance().level.getRecipeManager();
    final List<IGenericRecipe> craftingRecipes = new ArrayList<>();
    for (final IRecipe<CraftingInventory> recipe : recipeManager.byType(IRecipeType.CRAFTING).values()) {
        if (!recipe.canCraftInDimensions(3, 3))
            continue;
        tryAddingVanillaRecipe(craftingRecipes, recipe);
    }
    final List<IGenericRecipe> smeltingRecipes = new ArrayList<>();
    for (final IRecipe<IInventory> recipe : recipeManager.byType(IRecipeType.SMELTING).values()) {
        tryAddingVanillaRecipe(smeltingRecipes, recipe);
    }
    return new ImmutableMap.Builder<IRecipeType<?>, List<IGenericRecipe>>().put(IRecipeType.CRAFTING, craftingRecipes).put(IRecipeType.SMELTING, smeltingRecipes).build();
}
Also used : CraftingInventory(net.minecraft.inventory.CraftingInventory) IInventory(net.minecraft.inventory.IInventory) IRecipeType(net.minecraft.item.crafting.IRecipeType) RecipeManager(net.minecraft.item.crafting.RecipeManager) IRecipeManager(mezz.jei.api.recipe.IRecipeManager) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with IGenericRecipe

use of com.minecolonies.api.crafting.IGenericRecipe in project minecolonies by ldtteam.

the class GenericRecipeCategory method findRecipes.

@NotNull
public List<IGenericRecipe> findRecipes(@NotNull final Map<IRecipeType<?>, List<IGenericRecipe>> vanilla) {
    final List<IGenericRecipe> recipes = new ArrayList<>();
    // vanilla shaped and shapeless crafting recipes
    if (this.crafting.canLearnCraftingRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.CRAFTING)) {
            if (!this.crafting.canLearnLargeRecipes() && recipe.getGridSize() > 2)
                continue;
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // vanilla furnace recipes (do we want to check smoking and blasting too?)
    if (this.crafting.canLearnFurnaceRecipes()) {
        for (final IGenericRecipe recipe : vanilla.get(IRecipeType.SMELTING)) {
            final IGenericRecipe safeRecipe = GenericRecipeUtils.filterInputs(recipe, this.crafting.getIngredientValidator());
            if (safeRecipe == null || !this.crafting.isRecipeCompatible(safeRecipe))
                continue;
            recipes.add(safeRecipe);
        }
    }
    // custom MineColonies additional recipes
    for (final CustomRecipe customRecipe : CustomRecipeManager.getInstance().getRecipes(this.crafting.getCustomRecipeKey())) {
        final IRecipeStorage recipeStorage = customRecipe.getRecipeStorage();
        if (!recipeStorage.getAlternateOutputs().isEmpty()) {
            // this is a multi-output recipe; assume it replaces a bunch of vanilla
            // recipes we already added above
            recipes.removeIf(r -> ItemStackUtils.compareItemStacksIgnoreStackSize(recipeStorage.getPrimaryOutput(), r.getPrimaryOutput()));
            recipes.removeIf(r -> recipeStorage.getAlternateOutputs().stream().anyMatch(s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, r.getPrimaryOutput())));
        }
        recipes.add(GenericRecipeUtils.create(customRecipe, recipeStorage));
    }
    // and even more recipes that can't be taught, but are just inherent in the worker AI
    recipes.addAll(this.crafting.getAdditionalRecipesForDisplayPurposesOnly());
    return recipes.stream().sorted(Comparator.comparing(IGenericRecipe::getLevelSort).thenComparing(r -> r.getPrimaryOutput().getItem().getRegistryName())).collect(Collectors.toList());
}
Also used : BuildingEntry(com.minecolonies.api.colony.buildings.registry.BuildingEntry) java.util(java.util) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) ItemStackUtils(com.minecolonies.api.util.ItemStackUtils) IIngredients(mezz.jei.api.ingredients.IIngredients) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) IGuiHelper(mezz.jei.api.helpers.IGuiHelper) IRecipeType(net.minecraft.item.crafting.IRecipeType) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) LootTableAnalyzer(com.minecolonies.coremod.colony.crafting.LootTableAnalyzer) BlockState(net.minecraft.block.BlockState) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) ICraftingBuildingModule(com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule) IDrawableStatic(mezz.jei.api.gui.drawable.IDrawableStatic) Collectors(java.util.stream.Collectors) IGuiItemStackGroup(mezz.jei.api.gui.ingredient.IGuiItemStackGroup) Blocks(net.minecraft.block.Blocks) ResourceLocation(net.minecraft.util.ResourceLocation) CustomRecipeManager(com.minecolonies.coremod.colony.crafting.CustomRecipeManager) VanillaTypes(mezz.jei.api.constants.VanillaTypes) NotNull(org.jetbrains.annotations.NotNull) IJob(com.minecolonies.api.colony.jobs.IJob) CustomRecipe(com.minecolonies.coremod.colony.crafting.CustomRecipe) IRecipeStorage(com.minecolonies.api.crafting.IRecipeStorage) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with IGenericRecipe

use of com.minecolonies.api.crafting.IGenericRecipe in project minecolonies by ldtteam.

the class GenericRecipeUtils method create.

@NotNull
public static IGenericRecipe create(@NotNull final IRecipe<?> recipe) {
    final IGenericRecipe original = Objects.requireNonNull(GenericRecipe.of(recipe));
    final List<List<ItemStack>> inputs = compact(recipe.getIngredients());
    return new GenericRecipe(original.getPrimaryOutput(), original.getAdditionalOutputs(), inputs, original.getGridSize(), original.getIntermediate(), original.getLootTable(), new ArrayList<>(), -1);
}
Also used : IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) GenericRecipe(com.minecolonies.api.crafting.GenericRecipe) NonNullList(net.minecraft.util.NonNullList) IGenericRecipe(com.minecolonies.api.crafting.IGenericRecipe) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IGenericRecipe (com.minecolonies.api.crafting.IGenericRecipe)8 IRecipeType (net.minecraft.item.crafting.IRecipeType)4 NotNull (org.jetbrains.annotations.NotNull)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 ICraftingBuildingModule (com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule)2 BuildingEntry (com.minecolonies.api.colony.buildings.registry.BuildingEntry)2 IJob (com.minecolonies.api.colony.jobs.IJob)2 GenericRecipe (com.minecolonies.api.crafting.GenericRecipe)2 IRecipeStorage (com.minecolonies.api.crafting.IRecipeStorage)2 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)2 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)2 CustomRecipe (com.minecolonies.coremod.colony.crafting.CustomRecipe)2 CustomRecipeManager (com.minecolonies.coremod.colony.crafting.CustomRecipeManager)2 LootTableAnalyzer (com.minecolonies.coremod.colony.crafting.LootTableAnalyzer)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)2 java.util (java.util)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 VanillaTypes (mezz.jei.api.constants.VanillaTypes)2