Search in sources :

Example 1 with CustomRecipe

use of net.minecraft.world.item.crafting.CustomRecipe in project Polymorph by TheIllusiveC4.

the class PolymorphCommands method scanRecipes.

private static <C extends Container, T extends Recipe<C>> int scanRecipes(RecipeType<T> pType, List<String> pOutput, RecipeManager pRecipeManager, Function<Recipe<?>, RecipeWrapper> pFactory) {
    Collection<RecipeWrapper> recipes = pRecipeManager.getAllRecipesFor(pType).stream().map(pFactory).collect(Collectors.toList());
    List<Set<ResourceLocation>> conflicts = new ArrayList<>();
    Set<ResourceLocation> skipped = new TreeSet<>();
    Set<ResourceLocation> processed = new HashSet<>();
    for (RecipeWrapper recipe : recipes) {
        ResourceLocation id = recipe.getId();
        if (processed.contains(id)) {
            continue;
        }
        processed.add(id);
        if (recipe.getRecipe() instanceof CustomRecipe) {
            skipped.add(id);
            continue;
        }
        Set<ResourceLocation> currentGroup = new TreeSet<>();
        for (RecipeWrapper otherRecipe : recipes) {
            if (processed.contains(otherRecipe.getId())) {
                continue;
            }
            if (otherRecipe.conflicts(recipe)) {
                currentGroup.add(id);
                currentGroup.add(otherRecipe.getId());
                processed.add(otherRecipe.getId());
            }
        }
        if (!currentGroup.isEmpty()) {
            conflicts.add(currentGroup);
        }
    }
    pOutput.add("===================================================================");
    pOutput.add(Registry.RECIPE_TYPE.getKey(pType) + " recipe conflicts (" + conflicts.size() + ")");
    pOutput.add("===================================================================");
    pOutput.add("");
    int count = 1;
    for (Set<ResourceLocation> conflict : conflicts) {
        StringJoiner joiner = new StringJoiner(", ");
        conflict.stream().map(ResourceLocation::toString).forEach(joiner::add);
        pOutput.add(count + ": " + joiner);
        pOutput.add("");
        count++;
    }
    if (skipped.size() > 0) {
        pOutput.add("Skipped special recipes: ");
        for (ResourceLocation resourceLocation : skipped) {
            pOutput.add(resourceLocation.toString());
        }
        pOutput.add("");
    }
    return conflicts.size();
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) CustomRecipe(net.minecraft.world.item.crafting.CustomRecipe) ArrayList(java.util.ArrayList) TreeSet(java.util.TreeSet) ResourceLocation(net.minecraft.resources.ResourceLocation) StringJoiner(java.util.StringJoiner) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 StringJoiner (java.util.StringJoiner)1 TreeSet (java.util.TreeSet)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 CustomRecipe (net.minecraft.world.item.crafting.CustomRecipe)1