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());
}
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);
}
}
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();
}
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());
}
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);
}
Aggregations